#ifndef MAP_MAPSTATE_H_
#define MAP_MAPSTATE_H_
+#include "Entity.h"
#include "fwd.h"
#include "../app/State.h"
+#include "../common/fwd.h"
+#include "../common/ScriptHost.h"
+#include "../common/ScriptRunner.h"
#include "../geometry/Vector.h"
#include "../graphics/Camera.h"
+#include <vector>
+
namespace map {
+/// Shows a map and its entities an optionally control a single entity.
class MapState
-: public app::State {
+: public app::State
+, public common::ScriptHost {
public:
- explicit MapState(const Map *);
+ explicit MapState(common::GameConfig *, Map *);
virtual ~MapState() { }
public:
- virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
- virtual void ExitState(app::Application &ctrl, SDL_Surface *screen);
- virtual void ResumeState(app::Application &ctrl, SDL_Surface *screen);
- virtual void PauseState(app::Application &ctrl, SDL_Surface *screen);
- virtual void Resize(int width, int height);
-
virtual void HandleEvents(const app::Input &);
virtual void UpdateWorld(float deltaT);
virtual void Render(SDL_Surface *);
+public:
+ void AddEntity(Entity *e) { entities.push_back(e); }
+ void ControlEntity(Entity *e) { controlled = e; camera.SetTarget(&e->Position()); }
+
+ void SetWalkingSpeed(float s) { walkingSpeed = s; }
+
+ void Transition(Map *, const geometry::Vector<int> &coordinates);
+
+ virtual void HandleSyscall(common::ScriptRunner &);
+
+private:
+ virtual void OnEnterState(SDL_Surface *screen);
+ virtual void OnExitState(SDL_Surface *screen);
+ virtual void OnResumeState(SDL_Surface *screen);
+ virtual void OnPauseState(SDL_Surface *screen);
+
+ virtual void OnResize(int width, int height);
+
+private:
+ static bool ZCompare(const Entity *lhs, const Entity *rhs);
+
+ void UnloadMap();
+ void LoadMap(Map *);
+
+ bool CheckBlocking();
+ bool CheckBlocking(const geometry::Vector<int> &position, Entity::Orientation direction) const;
+
+ void OnTileLock();
+ bool OnGridLock();
+ void OnMove(bool);
+
+ void UpdateFollower(Entity &);
+ void StopFollowers(Entity &);
+
+ void LockEntities();
+ bool CheckMonster();
+
+ bool CheckLockTrigger();
+ bool CheckMoveTrigger();
+ void RunTrigger(Trigger &);
+
+ enum Syscalls {
+ TRANSITION = 1,
+ WARP = 2,
+ };
+
private:
- const Map *map;
- geometry::Vector<int> tempTarget;
+ common::GameConfig *game;
+ Map *map;
+ Entity *controlled;
+ Entity *pushed;
+ common::ScriptRunner runner;
+ app::Timer<float> moveTimer;
+ geometry::Vector<int> lastLock;
graphics::Camera camera;
+ std::vector<Entity *> entities;
+ float walkingSpeed;
+ int nextDirection;
+ bool afterLock;
+ bool skipLock;
+ bool pushing;
+ bool debug;
};