3 #include "../common/Item.h"
4 #include "../common/Spell.h"
5 #include "../common/Stats.h"
6 #include "../graphics/Animation.h"
7 #include "../graphics/Sprite.h"
8 #include "../loader/Interpreter.h"
9 #include "../loader/TypeDescription.h"
15 using graphics::Animation;
16 using graphics::Sprite;
17 using loader::FieldDescription;
18 using loader::Interpreter;
19 using loader::TypeDescription;
45 const char *Capsule::ClassName() const {
46 return GetClass().name;
49 const char *Capsule::Tribe() const {
50 return GetClass().tribe;
53 const Spell *Capsule::Attack1() const {
54 return GetClass().attacks[0];
57 const Spell *Capsule::Attack2() const {
58 return GetClass().attacks[1];
61 const Spell *Capsule::Attack3() const {
62 return GetClass().attacks[2];
66 Uint16 Capsule::MaxHealth() const {
67 return maxHealth + GetClass().healthBoost;
71 Stats Capsule::GetStats() const {
72 return stats + GetClass().statBoost;
75 int Capsule::NextLevel() const {
76 int levelOffset(Level() - 1);
77 if (levelOffset < numLevels) {
78 return levelLadder[levelOffset] - Experience();
84 void Capsule::UpgradeClass() {
89 void Capsule::NextClass() {
90 if (maxClass == numClasses) {
94 if (curClass >= maxClass) {
99 void Capsule::PreviousClass() {
100 if (maxClass == numClasses) {
105 curClass = maxClass - 1;
109 void Capsule::SetClass(int index) {
110 if (maxClass == numClasses) {
117 if (curClass >= maxClass) {
118 curClass = maxClass - 1;
123 Sprite *Capsule::BattleSprite() {
124 return GetClass().battleSprite;
127 const Sprite *Capsule::BattleSprite() const {
128 return GetClass().battleSprite;
131 Animation *Capsule::MeleeAnimation() {
132 return GetClass().meleeAnimation;
135 Animation *Capsule::AttackAnimation() {
136 return GetClass().attackAnimation;
139 Animation *Capsule::SpellAnimation() {
140 return GetClass().spellAnimation;
144 Capsule::Class &Capsule::GetClass() {
145 assert(classes && curClass < numClasses);
146 return classes[curClass];
149 const Capsule::Class &Capsule::GetClass() const {
150 assert(classes && curClass < numClasses);
151 return classes[curClass];
155 int Capsule::HungerEmpty() const {
156 return HungerTotal() - HungerFull();
159 int Capsule::HungerTotal() const {
160 return GetClass().hunger;
163 int Capsule::HungerFull() const {
164 return GetClass().hungerFull;
167 bool Capsule::IsHungry() const {
168 return HungerEmpty();
171 void Capsule::Feed(const common::Item *item) {
172 // TODO: find out how to calculate an item's feed value
173 // TODO: an item the capsule favors (changes on every feed and after every
174 // battle) doubles the value
176 GetClass().hungerFull += value;
177 if (GetClass().hungerFull >= GetClass().hunger) {
178 GetClass().hungerFull = GetClass().hunger;
183 const common::Item *Capsule::UpgradeItem() const {
184 return GetClass().upgradeItem;
187 void Capsule::UpgradeSpecial() {
188 maxClass = GetClass().upgradeClass + 1;
189 curClass = GetClass().upgradeClass;
193 Capsule::Class::Class()
214 void Capsule::CreateTypeDescription() {
217 TypeDescription &td(TypeDescription::Create(TYPE_ID, "Capsule"));
218 td.SetConstructor(&Construct);
219 td.SetSize(sizeof(Capsule));
221 td.AddField("name", FieldDescription(((char *)&c.name) - ((char *)&c), Interpreter::STRING_ID).SetReferenced());
222 td.AddField("alignment", FieldDescription(((char *)&c.alignment) - ((char *)&c), Interpreter::STRING_ID).SetReferenced());
224 td.AddField("alignmentCursor", FieldDescription(((char *)&c.alignmentCursor) - ((char *)&c), Interpreter::VECTOR_ID));
225 td.AddField("alignmentSprite", FieldDescription(((char *)&c.alignmentSprite) - ((char *)&c), Sprite::TYPE_ID).SetReferenced());
227 td.AddField("maxHealth", FieldDescription(((char *)&c.maxHealth) - ((char *)&c), Interpreter::NUMBER_ID));
229 td.AddField("stats", FieldDescription(((char *)&c.stats) - ((char *)&c), Stats::TYPE_ID));
231 td.AddField("level", FieldDescription(((char *)&c.level) - ((char *)&c), Interpreter::NUMBER_ID));
232 td.AddField("experience", FieldDescription(((char *)&c.experience) - ((char *)&c), Interpreter::NUMBER_ID));
234 td.AddField("ladder", FieldDescription(((char *)&c.levelLadder) - ((char *)&c), Interpreter::NUMBER_ID).SetReferenced().SetAggregate());
236 td.AddField("classes", FieldDescription(((char *)&c.classes) - ((char *)&c), Class::TYPE_ID).SetReferenced().SetAggregate());
237 td.AddField("class", FieldDescription(((char *)&c.curClass) - ((char *)&c), Interpreter::NUMBER_ID));
238 td.AddField("maxClass", FieldDescription(((char *)&c.maxClass) - ((char *)&c), Interpreter::NUMBER_ID));
240 Class::CreateTypeDescription();
243 void Capsule::Construct(void *data) {
248 void Capsule::Class::CreateTypeDescription() {
251 TypeDescription &td(TypeDescription::Create(TYPE_ID, "CapsuleClass"));
252 td.SetConstructor(&Construct);
253 td.SetSize(sizeof(Class));
255 td.AddField("name", FieldDescription(((char *)&c.name) - ((char *)&c), Interpreter::STRING_ID).SetReferenced());
256 td.AddField("tribe", FieldDescription(((char *)&c.tribe) - ((char *)&c), Interpreter::STRING_ID).SetReferenced());
258 td.AddField("attack1", FieldDescription(((char *)&c.attacks[0]) - ((char *)&c), Spell::TYPE_ID).SetReferenced());
259 td.AddField("attack2", FieldDescription(((char *)&c.attacks[1]) - ((char *)&c), Spell::TYPE_ID).SetReferenced());
260 td.AddField("attack3", FieldDescription(((char *)&c.attacks[2]) - ((char *)&c), Spell::TYPE_ID).SetReferenced());
262 td.AddField("battleSprite", FieldDescription(((char *)&c.battleSprite) - ((char *)&c), Sprite::TYPE_ID).SetReferenced());
263 td.AddField("meleeAnimation", FieldDescription(((char *)&c.meleeAnimation) - ((char *)&c), Animation::TYPE_ID).SetReferenced());
264 td.AddField("attackAnimation", FieldDescription(((char *)&c.attackAnimation) - ((char *)&c), Animation::TYPE_ID).SetReferenced());
265 td.AddField("spellAnimation", FieldDescription(((char *)&c.spellAnimation) - ((char *)&c), Animation::TYPE_ID).SetReferenced());
267 td.AddField("upgradeItem", FieldDescription(((char *)&c.upgradeItem) - ((char *)&c), common::Item::TYPE_ID).SetReferenced());
268 td.AddField("upgradeClass", FieldDescription(((char *)&c.upgradeClass) - ((char *)&c), Interpreter::NUMBER_ID));
269 td.AddField("hunger", FieldDescription(((char *)&c.hunger) - ((char *)&c), Interpreter::NUMBER_ID));
271 td.AddField("healthBoost", FieldDescription(((char *)&c.healthBoost) - ((char *)&c), Interpreter::NUMBER_ID));
272 td.AddField("statBoost", FieldDescription(((char *)&c.statBoost) - ((char *)&c), Stats::TYPE_ID));
275 void Capsule::Class::Construct(void *data) {
276 new (data) Capsule::Class;