5 #include "../graphics/Animation.h"
6 #include "../graphics/Sprite.h"
7 #include "../loader/Interpreter.h"
8 #include "../loader/TypeDescription.h"
9 #include "../map/Entity.h"
13 using graphics::Animation;
14 using graphics::Sprite;
15 using loader::FieldDescription;
16 using loader::Interpreter;
17 using loader::TypeDescription;
45 memset(equipment, 0, sizeof(equipment));
49 void Hero::SubtractHealth(int amount) {
50 if (amount > Health()) {
54 int ipGain(amount * 255 / health);
55 if (ip + ipGain > 255) {
64 int Hero::NextLevel() const {
65 int levelOffset(Level() - 1);
66 if (levelOffset < numLevels) {
67 return levelLadder[levelOffset] - Experience();
73 void Hero::AddExperience(int exp, vector<UpgradeInfo> &info) {
74 if (level > numLevels) {
75 // don't award any experience if at highest level
79 while (remain >= NextLevel()) {
80 int added = NextLevel();
85 info.push_back(UpgradeInfo(UPGRADE_LVL, level));
87 // TODO: upgrade attributes and push info
89 if (level > numLevels) {
97 bool Hero::CanEquip(const Item &item) const {
98 return useMask & item.HeroMask();
101 bool Hero::CanInvoke(const Spell &spell) const {
102 return useMask & spell.HeroMask();
106 void Hero::CreateTypeDescription() {
109 TypeDescription &td(TypeDescription::Create(TYPE_ID, "Hero"));
110 td.SetConstructor(&Construct);
111 td.SetSize(sizeof(Hero));
113 td.AddField("name", FieldDescription(((char *)&h.name) - ((char *)&h), Interpreter::STRING_ID).SetReferenced());
115 td.AddField("maxHealth", FieldDescription(((char *)&h.maxHealth) - ((char *)&h), Interpreter::NUMBER_ID));
116 td.AddField("health", FieldDescription(((char *)&h.health) - ((char *)&h), Interpreter::NUMBER_ID));
117 td.AddField("maxMana", FieldDescription(((char *)&h.maxMana) - ((char *)&h), Interpreter::NUMBER_ID));
118 td.AddField("mana", FieldDescription(((char *)&h.mana) - ((char *)&h), Interpreter::NUMBER_ID));
119 td.AddField("ip", FieldDescription(((char *)&h.ip) - ((char *)&h), Interpreter::NUMBER_ID));
121 td.AddField("stats", FieldDescription(((char *)&h.stats) - ((char *)&h), Stats::TYPE_ID));
123 td.AddField("level", FieldDescription(((char *)&h.level) - ((char *)&h), Interpreter::NUMBER_ID));
124 td.AddField("ladder", FieldDescription(((char *)&h.levelLadder) - ((char *)&h), Interpreter::NUMBER_ID).SetAggregate());
126 td.AddField("useMask", FieldDescription(((char *)&h.useMask) - ((char *)&h), Interpreter::NUMBER_ID));
128 td.AddField("battleSprite", FieldDescription(((char *)&h.battleSprite) - ((char *)&h), Sprite::TYPE_ID).SetReferenced().SetDescription("the sprite used for battle scenes"));
129 td.AddField("attackAnimation", FieldDescription(((char *)&h.attackAnimation) - ((char *)&h), Animation::TYPE_ID).SetReferenced().SetDescription("the animation played for physical attacks"));
130 td.AddField("spellAnimation", FieldDescription(((char *)&h.spellAnimation) - ((char *)&h), Animation::TYPE_ID).SetReferenced().SetDescription("the animation played for magical attacks"));
131 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"));
133 td.AddField("mapEntity", FieldDescription(((char *)&h.mapEntity) - ((char *)&h), Entity::TYPE_ID).SetDescription("the entity representing the hero on maps"));
136 void Hero::Construct(void *data) {