4 #include "../battle/fwd.h"
5 #include "../battle/Monster.h"
6 #include "../math/Fixed.h"
7 #include "../math/Vector.h"
8 #include "../graphics/fwd.h"
9 #include "../graphics/Animation.h"
16 /// An entity that can be placed on a map, moved around, animated, and possibly
17 /// interact with the player.
21 static const int TYPE_ID = 605;
29 ORIENTATION_NORTH = 0,
31 ORIENTATION_SOUTH = 2,
35 FLAG_NONBLOCKING = 0x01,
37 FLAG_FIXED_ORIENTATION = 0x04,
41 /// Pixel resolved position of the entity's top left corner on the map.
42 math::Vector<math::Fixed<8> > &Position() { return position; }
43 const math::Vector<math::Fixed<8> > &Position() const { return position; }
45 /// Velocity of the entity in pixels per second.
46 math::Vector<math::Fixed<8> > &Velocity() { return velocity; }
47 const math::Vector<math::Fixed<8> > &Velocity() const { return velocity; }
49 /// Offset of the entity's sprite's to left corner relative to Position().
50 math::Vector<int> &SpriteOffset() { return spriteOffset; }
51 const math::Vector<int> &SpriteOffset() const { return spriteOffset; }
53 /// Reset the entity to the stored tile coordinates (usually set when
54 /// loading game data).
55 void ResetPosition(const math::Vector<int> &tileSize) { position = tilePosition * tileSize; }
57 /// Set the animation to use for animated entities.
58 /// For orientable entities, the animation should have north, south, east,
59 /// and west sprites at offsets (0,0), (1,0), (2,0), and (3,0) respectively.
60 /// If the entity can carry, row offset 2 is used.
61 /// If the entity can push, row offset 4 is used.
62 void SetAnimation(const graphics::Animation *a);
63 /// Start the animation on a global timer.
64 void StartAnimation(app::Application &ctrl);
65 /// Start the animation on a state timer.
66 void StartAnimation(app::State &ctrl);
67 /// Stop the animation.
69 /// Check if an animation is running.
70 bool AnimationRunning() const { return runner.Running(); }
72 /// Set the sprite used for the non-animated state.
73 /// For orientable entities, the sprite should have north, south, east, and
74 /// west sprites at offsets (0,0), (1,0), (2,0), and (3,0) respectively.
75 void SetSprite(const graphics::Sprite *s) { sprite = s; }
77 /// Change the entity's orientation to given one.
78 /// If the entity is moving, velocity is changed accordingly.
79 void SetOrientation(Orientation);
80 Orientation GetOrientation() const { return orientation; }
81 /// Set the entity's speed in pixels per second.
82 /// This speed is then combined with the orientation to form a velocity.
83 void SetSpeed(math::Fixed<8>);
85 /// Change to a natural, relaxed animation state (row offset 0).
87 /// Change animation to represent a carrying thingamabob (row offset 2).
89 /// Set a pushy animation state (row offset 4).
92 /// Set some basic boolean properties.
93 /// Parameter should be a combination from the Flags enum.
94 void SetFlags(int f) { flags = f; }
95 /// Check if the entity is blocking other entities from occupying its tile.
96 bool Blocking() const { return !(flags & FLAG_NONBLOCKING); }
97 /// Check if a battle should be launched when stepping onto a neighboring
99 bool Hostile() const { return partyLayout && numMonsters > 0; }
100 /// Check if this entity can be pushed around.
101 bool Pushable() const { return flags & FLAG_PUSHABLE; }
102 /// Check if the entity's orientation has any effect on the column rendered
103 /// from the animation or sprite.
104 bool CanTurn() const { return !(flags & FLAG_FIXED_ORIENTATION); }
106 /// Set a layout in battle for the party described by SetMonsters().
107 void SetPartyLayout(battle::PartyLayout *l) { partyLayout = l; }
108 /// Get the layout in battle for the party described by
109 /// Monsters{Begin,End}().
110 battle::PartyLayout *PartyLayout() { return partyLayout; }
112 /// Add monsters. This will cause the entity to be Hostile() and result in a
113 /// battle scene with given monsters when touched.
114 void SetMonsters(battle::Monster **m, int num) { monsters = m; numMonsters = num; }
115 battle::Monster **MonstersBegin() { return monsters; }
116 battle::Monster **MonstersEnd() { return monsters + numMonsters; }
118 /// Get an entity that should follow in this one's steps or 0 if none.
119 Entity *Follower() { return follower; }
120 const Entity *Follower() const { return follower; }
121 /// Add an entity that follows this one.
122 /// If this already has a follower, it is added to that one instead.
123 void AddFollower(Entity *);
124 /// Remove given entity from this entity or its follower.
125 void RemoveFollower(Entity *);
127 /// Check if position locks into grid defined by given tileSize.
128 bool TileLock(const math::Vector<int> &tileSize) const;
130 /// Integrate this entity's physical properties over given time interval.
131 void Update(Uint32 deltaT);
133 void Render(SDL_Surface *, const math::Vector<int> &offset) const;
135 static void CreateTypeDescription();
136 static void Construct(void *);
137 static void Load(void *);
140 void UpdateVelocity();
144 const graphics::Animation *animation;
145 const graphics::Sprite *sprite;
146 battle::PartyLayout *partyLayout;
147 battle::Monster **monsters;
149 graphics::AnimationRunner runner;
150 math::Vector<int> spriteOffset;
151 math::Vector<int> tilePosition;
152 math::Vector<math::Fixed<8> > position;
153 math::Vector<math::Fixed<8> > velocity;
154 Orientation orientation;
155 math::Fixed<8> speed;
162 #endif /* MAP_ENTITY_H_ */