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