3 #include "../battle/Monster.h"
4 #include "../battle/PartyLayout.h"
5 #include "../graphics/Animation.h"
6 #include "../graphics/Sprite.h"
7 #include "../loader/Interpreter.h"
8 #include "../loader/TypeDescription.h"
10 using battle::Monster;
11 using battle::PartyLayout;
12 using graphics::Animation;
13 using graphics::Sprite;
16 using loader::FieldDescription;
17 using loader::Interpreter;
18 using loader::TypeDescription;
29 , direction(ORIENTATION_NORTH)
30 , orientation(ORIENTATION_NORTH)
33 runner.SetFrameShift(1);
37 void Entity::SetOrientation(Orientation o) {
40 runner.SetColOffset(o);
44 void Entity::SetDirection(Orientation o) {
50 void Entity::SetSpeed(Fixed<8> s) {
56 void Entity::StartAnimation(app::Application &ctrl) {
60 void Entity::StartAnimation(app::State &ctrl) {
64 void Entity::StopAnimation() {
69 void Entity::SetHandsFree() {
70 runner.SetRowOffset(0);
73 void Entity::SetCarrying() {
74 runner.SetRowOffset(2);
77 void Entity::SetPushing() {
78 runner.SetRowOffset(4);
82 void Entity::AddFollower(Entity *f) {
84 follower->AddFollower(f);
90 void Entity::RemoveFollower(Entity *f) {
92 follower = follower->follower;
93 } else if (follower) {
94 follower->RemoveFollower(f);
98 void Entity::SetAnimation(const graphics::Animation *a) {
100 runner.ChangeAnimation(animation);
102 sprite = animation->GetSprite();
107 void Entity::UpdateVelocity() {
109 velocity = Vector<Fixed<8> >();
113 case ORIENTATION_NORTH:
114 velocity = Vector<Fixed<8> >(0, -speed);
116 case ORIENTATION_EAST:
117 velocity = Vector<Fixed<8> >(speed, 0);
119 case ORIENTATION_SOUTH:
120 velocity = Vector<Fixed<8> >(0, speed);
122 case ORIENTATION_WEST:
123 velocity = Vector<Fixed<8> >(-speed, 0);
129 bool Entity::TileLock(const math::Vector<int> &tileSize) const {
130 Vector<int> tilePosition(ToInt(position));
131 return tilePosition % tileSize == Vector<int>();
135 void Entity::Update(Uint32 deltaT) {
136 position += velocity * deltaT;
140 void Entity::Render(SDL_Surface *dest, const Vector<int> &offset) const {
141 if (runner.Running()) {
142 runner.Draw(dest, offset + ToInt(position) + spriteOffset);
144 sprite->Draw(dest, offset + ToInt(position) + spriteOffset, CanTurn() ? orientation : 0);
149 void Entity::CreateTypeDescription() {
152 TypeDescription &td(TypeDescription::Create(TYPE_ID, "Entity"));
153 td.SetConstructor(&Construct);
155 td.SetSize(sizeof(Entity));
157 td.AddField("animation", FieldDescription(((char *)&e.animation) - ((char *)&e), Animation::TYPE_ID).SetReferenced());
158 td.AddField("sprite", FieldDescription(((char *)&e.sprite) - ((char *)&e), Sprite::TYPE_ID).SetReferenced());
159 td.AddField("partyLayout", FieldDescription(((char *)&e.partyLayout) - ((char *)&e), PartyLayout::TYPE_ID).SetReferenced());
160 td.AddField("monsters", FieldDescription(((char *)&e.monsters) - ((char *)&e), Monster::TYPE_ID).SetReferenced().SetAggregate());
161 td.AddField("spriteOffset", FieldDescription(((char *)&e.spriteOffset) - ((char *)&e), Interpreter::VECTOR_ID));
162 td.AddField("position", FieldDescription(((char *)&e.tilePosition) - ((char *)&e), Interpreter::VECTOR_ID));
163 td.AddField("flags", FieldDescription(((char *)&e.flags) - ((char *)&e), Interpreter::NUMBER_ID));
166 void Entity::Construct(void *data) {
170 void Entity::Load(void *data) {
171 Entity *entity(reinterpret_cast<Entity *>(data));
172 if (entity->animation) {
173 entity->runner.ChangeAnimation(entity->animation);
174 if (!entity->sprite) {
175 entity->sprite = entity->animation->GetSprite();