4 * Created on: Oct 7, 2012
10 #include "../graphics/Animation.h"
11 #include "../graphics/Sprite.h"
12 #include "../loader/Interpreter.h"
13 #include "../loader/TypeDescription.h"
14 #include "../map/Entity.h"
16 using graphics::Animation;
17 using graphics::Sprite;
18 using loader::FieldDescription;
19 using loader::Interpreter;
20 using loader::TypeDescription;
51 void Hero::SubtractHealth(int amount) {
52 if (amount > Health()) {
56 int ipGain(amount * 255 / health);
57 if (ip + ipGain > 255) {
66 void Hero::CreateTypeDescription() {
69 TypeDescription &td(TypeDescription::Create(TYPE_ID, "Hero"));
70 td.SetConstructor(&Construct);
71 td.SetSize(sizeof(Hero));
73 td.AddField("name", FieldDescription(((char *)&h.name) - ((char *)&h), Interpreter::STRING_ID).SetReferenced());
75 td.AddField("maxHealth", FieldDescription(((char *)&h.maxHealth) - ((char *)&h), Interpreter::NUMBER_ID));
76 td.AddField("health", FieldDescription(((char *)&h.health) - ((char *)&h), Interpreter::NUMBER_ID));
77 td.AddField("maxMana", FieldDescription(((char *)&h.maxMana) - ((char *)&h), Interpreter::NUMBER_ID));
78 td.AddField("mana", FieldDescription(((char *)&h.mana) - ((char *)&h), Interpreter::NUMBER_ID));
79 td.AddField("ip", FieldDescription(((char *)&h.ip) - ((char *)&h), Interpreter::NUMBER_ID));
81 td.AddField("stats", FieldDescription(((char *)&h.stats) - ((char *)&h), Stats::TYPE_ID));
83 td.AddField("level", FieldDescription(((char *)&h.level) - ((char *)&h), Interpreter::NUMBER_ID));
85 td.AddField("battleSprite", FieldDescription(((char *)&h.battleSprite) - ((char *)&h), Sprite::TYPE_ID).SetReferenced().SetDescription("the sprite used for battle scenes"));
86 td.AddField("attackAnimation", FieldDescription(((char *)&h.attackAnimation) - ((char *)&h), Animation::TYPE_ID).SetReferenced().SetDescription("the animation played for physical attacks"));
87 td.AddField("spellAnimation", FieldDescription(((char *)&h.spellAnimation) - ((char *)&h), Animation::TYPE_ID).SetReferenced().SetDescription("the animation played for magical attacks"));
88 td.AddField("meleeAnimation", FieldDescription(((char *)&h.meleeAnimation) - ((char *)&h), Animation::TYPE_ID).SetReferenced().SetDescription("the animation played on attacked monsters when the hero has no weapon"));
90 td.AddField("mapEntity", FieldDescription(((char *)&h.mapEntity) - ((char *)&h), Entity::TYPE_ID).SetDescription("the entity representing the hero on maps"));
93 void Hero::Construct(void *data) {