4 * Created on: Oct 7, 2012
12 #include "../graphics/Animation.h"
13 #include "../graphics/Sprite.h"
14 #include "../loader/Interpreter.h"
15 #include "../loader/TypeDescription.h"
16 #include "../map/Entity.h"
20 using graphics::Animation;
21 using graphics::Sprite;
22 using loader::FieldDescription;
23 using loader::Interpreter;
24 using loader::TypeDescription;
51 memset(equipment, 0, sizeof(equipment));
55 void Hero::SubtractHealth(int amount) {
56 if (amount > Health()) {
60 int ipGain(amount * 255 / health);
61 if (ip + ipGain > 255) {
70 int Hero::NextLevel() const {
71 int levelOffset(Level() - 1);
72 if (levelOffset < numLevels) {
73 return levelLadder[levelOffset] - Experience();
80 bool Hero::CanEquip(const Item &item) const {
81 return useMask & item.HeroMask();
84 bool Hero::CanInvoke(const Spell &spell) const {
85 return useMask & spell.HeroMask();
89 void Hero::CreateTypeDescription() {
92 TypeDescription &td(TypeDescription::Create(TYPE_ID, "Hero"));
93 td.SetConstructor(&Construct);
94 td.SetSize(sizeof(Hero));
96 td.AddField("name", FieldDescription(((char *)&h.name) - ((char *)&h), Interpreter::STRING_ID).SetReferenced());
98 td.AddField("maxHealth", FieldDescription(((char *)&h.maxHealth) - ((char *)&h), Interpreter::NUMBER_ID));
99 td.AddField("health", FieldDescription(((char *)&h.health) - ((char *)&h), Interpreter::NUMBER_ID));
100 td.AddField("maxMana", FieldDescription(((char *)&h.maxMana) - ((char *)&h), Interpreter::NUMBER_ID));
101 td.AddField("mana", FieldDescription(((char *)&h.mana) - ((char *)&h), Interpreter::NUMBER_ID));
102 td.AddField("ip", FieldDescription(((char *)&h.ip) - ((char *)&h), Interpreter::NUMBER_ID));
104 td.AddField("stats", FieldDescription(((char *)&h.stats) - ((char *)&h), Stats::TYPE_ID));
106 td.AddField("level", FieldDescription(((char *)&h.level) - ((char *)&h), Interpreter::NUMBER_ID));
107 td.AddField("ladder", FieldDescription(((char *)&h.levelLadder) - ((char *)&h), Interpreter::NUMBER_ID).SetReferenced().SetAggregate());
109 td.AddField("useMask", FieldDescription(((char *)&h.useMask) - ((char *)&h), Interpreter::NUMBER_ID));
111 td.AddField("battleSprite", FieldDescription(((char *)&h.battleSprite) - ((char *)&h), Sprite::TYPE_ID).SetReferenced().SetDescription("the sprite used for battle scenes"));
112 td.AddField("attackAnimation", FieldDescription(((char *)&h.attackAnimation) - ((char *)&h), Animation::TYPE_ID).SetReferenced().SetDescription("the animation played for physical attacks"));
113 td.AddField("spellAnimation", FieldDescription(((char *)&h.spellAnimation) - ((char *)&h), Animation::TYPE_ID).SetReferenced().SetDescription("the animation played for magical attacks"));
114 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"));
116 td.AddField("mapEntity", FieldDescription(((char *)&h.mapEntity) - ((char *)&h), Entity::TYPE_ID).SetDescription("the entity representing the hero on maps"));
119 void Hero::Construct(void *data) {