]> git.localhorst.tv Git - l2e.git/blob - src/map/MapState.h
renamed state callbacks
[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 OnEnterState(app::Application &ctrl, SDL_Surface *screen);
34         virtual void OnExitState(app::Application &ctrl, SDL_Surface *screen);
35         virtual void OnResumeState(app::Application &ctrl, SDL_Surface *screen);
36         virtual void OnPauseState(app::Application &ctrl, SDL_Surface *screen);
37         virtual void Resize(int width, int height);
38
39         virtual void HandleEvents(const app::Input &);
40         virtual void UpdateWorld(float deltaT);
41         virtual void Render(SDL_Surface *);
42
43 public:
44         void AddEntity(Entity *e) { entities.push_back(e); }
45         void ControlEntity(Entity *e) { controlled = e; camera.SetTarget(&e->Position()); }
46
47         void SetWalkingSpeed(float s) { walkingSpeed = s; }
48
49         void Transition(Map *, const geometry::Vector<int> &coordinates);
50
51         virtual void HandleSyscall(common::ScriptRunner &);
52
53 private:
54         static bool ZCompare(const Entity *lhs, const Entity *rhs);
55
56         void UnloadMap();
57         void LoadMap(Map *);
58
59         bool CheckBlocking();
60         bool CheckBlocking(const geometry::Vector<int> &position, Entity::Orientation direction) const;
61
62         void OnTileLock();
63         bool OnGridLock();
64         void OnMove(bool);
65
66         void UpdateFollower(Entity &);
67         void StopFollowers(Entity &);
68
69         void LockEntities();
70         bool CheckMonster();
71
72         bool CheckLockTrigger();
73         bool CheckMoveTrigger();
74         void RunTrigger(Trigger &);
75
76         enum Syscalls {
77                 TRANSITION = 1,
78                 WARP = 2,
79         };
80
81 private:
82         common::GameConfig *game;
83         app::Application *ctrl;
84         Map *map;
85         Entity *controlled;
86         Entity *pushed;
87         common::ScriptRunner runner;
88         app::Timer<float> moveTimer;
89         geometry::Vector<int> lastLock;
90         graphics::Camera camera;
91         std::vector<Entity *> entities;
92         float walkingSpeed;
93         int nextDirection;
94         bool afterLock;
95         bool skipLock;
96         bool pushing;
97         bool debug;
98
99 };
100
101 }
102
103 #endif /* MAP_MAPSTATE_H_ */