]> git.localhorst.tv Git - l2e.git/blob - src/map/Entity.h
closed the gap between battle and map state (yay)
[l2e.git] / src / map / Entity.h
1 /*
2  * Entity.h
3  *
4  *  Created on: Sep 29, 2012
5  *      Author: holy
6  */
7
8 #ifndef MAP_ENTITY_H_
9 #define MAP_ENTITY_H_
10
11 #include "../battle/fwd.h"
12 #include "../battle/Monster.h"
13 #include "../geometry/Vector.h"
14 #include "../graphics/fwd.h"
15 #include "../graphics/Animation.h"
16
17 #include <functional>
18 #include <SDL.h>
19
20 namespace map {
21
22 class Entity {
23
24 public:
25         Entity();
26         ~Entity() { }
27
28 public:
29         enum Orientation {
30                 ORIENTATION_NORTH = 0,
31                 ORIENTATION_EAST = 1,
32                 ORIENTATION_SOUTH = 2,
33                 ORIENTATION_WEST = 3,
34         };
35         enum Flags {
36                 FLAG_NONBLOCKING = 0x01,
37         };
38
39 public:
40         geometry::Vector<float> &Position() { return position; }
41         const geometry::Vector<float> &Position() const { return position; }
42
43         geometry::Vector<float> &Velocity() { return velocity; }
44         const geometry::Vector<float> &Velocity() const { return velocity; }
45
46         geometry::Vector<int> &SpriteOffset() { return spriteOffset; }
47         const geometry::Vector<int> &SpriteOffset() const { return spriteOffset; }
48
49         void SetAnimation(const graphics::Animation *a);
50         void StartAnimation(app::Application &ctrl);
51         void StartAnimation(app::State &ctrl);
52         void StopAnimation();
53         bool AnimationRunning() const { return runner.Running(); }
54
55         void SetOrientation(Orientation);
56         Orientation GetOrientation() const { return orientation; }
57         void SetSpeed(float);
58
59         void SetFlags(int f) { flags = f; }
60         bool Blocking() const { return !(flags & FLAG_NONBLOCKING); }
61         bool Hostile() const { return partyLayout && numMonsters > 0; }
62
63         void SetPartyLayout(battle::PartyLayout *l) { partyLayout = l; }
64         battle::PartyLayout *PartyLayout() { return partyLayout; }
65
66         void SetMonsters(battle::Monster *m, int num) { monsters = m; numMonsters = num; }
67         battle::Monster *MonstersBegin() { return monsters; }
68         battle::Monster *MonstersEnd() { return monsters + numMonsters; }
69
70         Entity *Follower() { return follower; }
71         const Entity *Follower() const { return follower; }
72         void AddFollower(Entity *);
73         void RemoveFollower(Entity *);
74
75         bool TileLock(const geometry::Vector<int> &tileSize) const;
76
77         void Update(float deltaT);
78
79         void Render(SDL_Surface *, const geometry::Vector<int> &offset) const;
80
81         static void CreateTypeDescription();
82         static void Construct(void *);
83         static void Load(void *);
84
85 private:
86         void UpdateVelocity();
87
88 private:
89         Entity *follower;
90         const graphics::Animation *animation;
91         battle::PartyLayout *partyLayout;
92         battle::Monster *monsters;
93         int numMonsters;
94         graphics::AnimationRunner runner;
95         geometry::Vector<int> spriteOffset;
96         geometry::Vector<float> position;
97         geometry::Vector<float> velocity;
98         Orientation orientation;
99         float speed;
100         int flags;
101
102 };
103
104 }
105
106 #endif /* MAP_ENTITY_H_ */