]> git.localhorst.tv Git - l2e.git/blob - src/map/MapState.h
renamed namespace geometry -> math
[l2e.git] / src / map / MapState.h
1 #ifndef MAP_MAPSTATE_H_
2 #define MAP_MAPSTATE_H_
3
4 #include "Entity.h"
5 #include "fwd.h"
6 #include "../app/State.h"
7 #include "../common/fwd.h"
8 #include "../common/ScriptHost.h"
9 #include "../common/ScriptRunner.h"
10 #include "../math/Vector.h"
11 #include "../graphics/Camera.h"
12
13 #include <vector>
14
15 namespace map {
16
17 /// Shows a map and its entities an optionally control a single entity.
18 class MapState
19 : public app::State
20 , public common::ScriptHost {
21
22 public:
23         explicit MapState(common::GameConfig *, Map *);
24         virtual ~MapState() { }
25
26 public:
27         virtual void HandleEvents(const app::Input &);
28         virtual void UpdateWorld(float deltaT);
29         virtual void Render(SDL_Surface *);
30
31 public:
32         void AddEntity(Entity *e) { entities.push_back(e); }
33         void ControlEntity(Entity *e) { controlled = e; camera.SetTarget(&e->Position()); }
34
35         void SetWalkingSpeed(float s) { walkingSpeed = s; }
36
37         void Transition(Map *, const math::Vector<int> &coordinates);
38
39         virtual void HandleSyscall(common::ScriptRunner &);
40
41 private:
42         virtual void OnEnterState(SDL_Surface *screen);
43         virtual void OnExitState(SDL_Surface *screen);
44         virtual void OnResumeState(SDL_Surface *screen);
45         virtual void OnPauseState(SDL_Surface *screen);
46
47         virtual void OnResize(int width, int height);
48
49 private:
50         static bool ZCompare(const Entity *lhs, const Entity *rhs);
51
52         void UnloadMap();
53         void LoadMap(Map *);
54
55         bool CheckBlocking();
56         bool CheckBlocking(const math::Vector<int> &position, Entity::Orientation direction) const;
57
58         void OnTileLock();
59         bool OnGridLock();
60         void OnMove(bool);
61
62         void UpdateFollower(Entity &);
63         void StopFollowers(Entity &);
64
65         void LockEntities();
66         bool CheckMonster();
67
68         bool CheckLockTrigger();
69         bool CheckMoveTrigger();
70         void RunTrigger(Trigger &);
71
72         enum Syscalls {
73                 TRANSITION = 1,
74                 WARP = 2,
75         };
76
77 private:
78         common::GameConfig *game;
79         Map *map;
80         Entity *controlled;
81         Entity *pushed;
82         common::ScriptRunner runner;
83         app::Timer<float> moveTimer;
84         math::Vector<int> lastLock;
85         graphics::Camera camera;
86         std::vector<Entity *> entities;
87         float walkingSpeed;
88         int nextDirection;
89         bool afterLock;
90         bool skipLock;
91         bool pushing;
92         bool debug;
93
94 };
95
96 }
97
98 #endif /* MAP_MAPSTATE_H_ */