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