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