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