6 #include "../graphics/Animation.h"
7 #include "../graphics/Sprite.h"
8 #include "../loader/Interpreter.h"
9 #include "../loader/TypeDescription.h"
10 #include "../map/Entity.h"
14 using graphics::Animation;
15 using graphics::Sprite;
16 using loader::FieldDescription;
17 using loader::Interpreter;
18 using loader::TypeDescription;
46 memset(equipment, 0, sizeof(equipment));
50 void Hero::SubtractHealth(int amount) {
51 if (amount > Health()) {
55 int ipGain(amount * 255 / health);
56 if (ip + ipGain > 255) {
65 int Hero::NextLevel() const {
66 int levelOffset(Level() - 1);
67 if (levelOffset < numLevels) {
68 return levelLadder[levelOffset] - Experience();
74 void Hero::AddExperience(int exp, vector<Upgrade> &info) {
75 if (level > numLevels) {
76 // don't award any experience if at highest level
77 info.push_back(Upgrade(
78 name, Upgrade::LEVEL_NEXT, NextLevel()));
82 while (remain >= NextLevel()) {
83 int added = NextLevel();
88 info.push_back(Upgrade(name, Upgrade::LEVEL_UP, level));
90 // TODO: upgrade attributes and push info
92 if (level > numLevels) {
93 info.push_back(Upgrade(
94 name, Upgrade::LEVEL_NEXT, NextLevel()));
99 info.push_back(Upgrade(
100 name, Upgrade::LEVEL_NEXT, NextLevel()));
104 bool Hero::CanEquip(const Item &item) const {
105 return useMask & item.HeroMask();
108 bool Hero::CanInvoke(const Spell &spell) const {
109 return useMask & spell.HeroMask();
113 void Hero::CreateTypeDescription() {
116 TypeDescription &td(TypeDescription::Create(TYPE_ID, "Hero"));
117 td.SetConstructor(&Construct);
118 td.SetSize(sizeof(Hero));
120 td.AddField("name", FieldDescription(((char *)&h.name) - ((char *)&h), Interpreter::STRING_ID).SetReferenced());
122 td.AddField("maxHealth", FieldDescription(((char *)&h.maxHealth) - ((char *)&h), Interpreter::NUMBER_ID));
123 td.AddField("health", FieldDescription(((char *)&h.health) - ((char *)&h), Interpreter::NUMBER_ID));
124 td.AddField("maxMana", FieldDescription(((char *)&h.maxMana) - ((char *)&h), Interpreter::NUMBER_ID));
125 td.AddField("mana", FieldDescription(((char *)&h.mana) - ((char *)&h), Interpreter::NUMBER_ID));
126 td.AddField("ip", FieldDescription(((char *)&h.ip) - ((char *)&h), Interpreter::NUMBER_ID));
128 td.AddField("stats", FieldDescription(((char *)&h.stats) - ((char *)&h), Stats::TYPE_ID));
130 td.AddField("level", FieldDescription(((char *)&h.level) - ((char *)&h), Interpreter::NUMBER_ID));
131 td.AddField("ladder", FieldDescription(((char *)&h.levelLadder) - ((char *)&h), Interpreter::NUMBER_ID).SetAggregate());
133 td.AddField("useMask", FieldDescription(((char *)&h.useMask) - ((char *)&h), Interpreter::NUMBER_ID));
135 td.AddField("battleSprite", FieldDescription(((char *)&h.battleSprite) - ((char *)&h), Sprite::TYPE_ID).SetReferenced().SetDescription("the sprite used for battle scenes"));
136 td.AddField("attackAnimation", FieldDescription(((char *)&h.attackAnimation) - ((char *)&h), Animation::TYPE_ID).SetReferenced().SetDescription("the animation played for physical attacks"));
137 td.AddField("spellAnimation", FieldDescription(((char *)&h.spellAnimation) - ((char *)&h), Animation::TYPE_ID).SetReferenced().SetDescription("the animation played for magical attacks"));
138 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"));
140 td.AddField("mapEntity", FieldDescription(((char *)&h.mapEntity) - ((char *)&h), Entity::TYPE_ID).SetDescription("the entity representing the hero on maps"));
143 void Hero::Construct(void *data) {