]> git.localhorst.tv Git - l2e.git/blob - src/map/Entity.h
fc1dc812194d5332e415e37501a35b90bc690301
[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                 FLAG_PUSHABLE = 0x02,
38                 FLAG_FIXED_ORIENTATION = 0x04,
39         };
40
41 public:
42         geometry::Vector<float> &Position() { return position; }
43         const geometry::Vector<float> &Position() const { return position; }
44
45         geometry::Vector<float> &Velocity() { return velocity; }
46         const geometry::Vector<float> &Velocity() const { return velocity; }
47
48         geometry::Vector<int> &SpriteOffset() { return spriteOffset; }
49         const geometry::Vector<int> &SpriteOffset() const { return spriteOffset; }
50
51         void SetAnimation(const graphics::Animation *a);
52         void StartAnimation(app::Application &ctrl);
53         void StartAnimation(app::State &ctrl);
54         void StopAnimation();
55         bool AnimationRunning() const { return runner.Running(); }
56
57         void SetSprite(const graphics::Sprite *s) { sprite = s; }
58
59         void SetOrientation(Orientation);
60         Orientation GetOrientation() const { return orientation; }
61         void SetSpeed(float);
62
63         void SetHandsFree();
64         void SetCarrying();
65         void SetPushing();
66
67         void SetFlags(int f) { flags = f; }
68         bool Blocking() const { return !(flags & FLAG_NONBLOCKING); }
69         bool Hostile() const { return partyLayout && numMonsters > 0; }
70         bool Pushable() const { return flags & FLAG_PUSHABLE; }
71         bool CanTurn() const { return !(flags & FLAG_FIXED_ORIENTATION); }
72
73         void SetPartyLayout(battle::PartyLayout *l) { partyLayout = l; }
74         battle::PartyLayout *PartyLayout() { return partyLayout; }
75
76         void SetMonsters(battle::Monster *m, int num) { monsters = m; numMonsters = num; }
77         battle::Monster *MonstersBegin() { return monsters; }
78         battle::Monster *MonstersEnd() { return monsters + numMonsters; }
79
80         Entity *Follower() { return follower; }
81         const Entity *Follower() const { return follower; }
82         void AddFollower(Entity *);
83         void RemoveFollower(Entity *);
84
85         bool TileLock(const geometry::Vector<int> &tileSize) const;
86
87         void Update(float deltaT);
88
89         void Render(SDL_Surface *, const geometry::Vector<int> &offset) const;
90
91         static void CreateTypeDescription();
92         static void Construct(void *);
93         static void Load(void *);
94
95 private:
96         void UpdateVelocity();
97
98 private:
99         Entity *follower;
100         const graphics::Animation *animation;
101         const graphics::Sprite *sprite;
102         battle::PartyLayout *partyLayout;
103         battle::Monster *monsters;
104         int numMonsters;
105         graphics::AnimationRunner runner;
106         geometry::Vector<int> spriteOffset;
107         geometry::Vector<float> position;
108         geometry::Vector<float> velocity;
109         Orientation orientation;
110         float speed;
111         int flags;
112
113 };
114
115 }
116
117 #endif /* MAP_ENTITY_H_ */