4 * Created on: Aug 6, 2012
10 #include "AttackChoice.h"
11 #include "Resources.h"
12 #include "../common/Ikari.h"
13 #include "../common/Item.h"
14 #include "../common/Spell.h"
15 #include "../loader/TypeDescription.h"
19 using loader::FieldDescription;
20 using loader::TypeDescription;
55 void Hero::SubtractHealth(int amount) {
56 if (amount > Health()) {
60 int ipGain(amount * 255 / health);
61 if (ip + ipGain > 255) {
70 void Hero::UpdateSpellMenu() {
72 SpellMenu().Reserve(Spells().size());
73 for (vector<const Spell *>::const_iterator i(Spells().begin()), end(Spells().end()); i != end; ++i) {
74 bool enabled((*i)->CanUseInBattle() && (*i)->Cost() <= Mana());
75 SpellMenu().Add((*i)->Name(), *i, enabled, 0, (*i)->Cost());
79 void Hero::UpdateIkariMenu(const Resources *res) {
81 IkariMenu().Reserve(6);
87 Weapon()->HasIkari() && Weapon()->GetIkari()->Cost() <= IP(),
90 Weapon()->HasIkari() ? Weapon()->GetIkari()->Name() : "");
92 IkariMenu().Add(res->noEquipmentText, 0, false, res->weaponMenuIcon);
99 Armor()->HasIkari() && Armor()->GetIkari()->Cost() <= IP(),
102 Armor()->HasIkari() ? Armor()->GetIkari()->Name() : "");
104 IkariMenu().Add(res->noEquipmentText, 0, false, res->armorMenuIcon);
111 Shield()->HasIkari() && Shield()->GetIkari()->Cost() <= IP(),
114 Shield()->HasIkari() ? Shield()->GetIkari()->Name() : "");
116 IkariMenu().Add(res->noEquipmentText, 0, false, res->shieldMenuIcon);
123 Helmet()->HasIkari() && Helmet()->GetIkari()->Cost() <= IP(),
126 Helmet()->HasIkari() ? Helmet()->GetIkari()->Name() : "");
128 IkariMenu().Add(res->noEquipmentText, 0, false, res->helmetMenuIcon);
135 Ring()->HasIkari() && Ring()->GetIkari()->Cost() <= IP(),
138 Ring()->HasIkari() ? Ring()->GetIkari()->Name() : "");
140 IkariMenu().Add(res->noEquipmentText, 0, false, res->ringMenuIcon);
147 Jewel()->HasIkari() && Jewel()->GetIkari()->Cost() <= IP(),
150 Jewel()->HasIkari() ? Jewel()->GetIkari()->Name() : "");
152 IkariMenu().Add(res->noEquipmentText, 0, false, res->jewelMenuIcon);
157 void Hero::CreateTypeDescription() {
160 int animationId(TypeDescription::GetTypeId("Animation"));
161 int numberId(TypeDescription::GetTypeId("Number"));
162 int spriteId(TypeDescription::GetTypeId("Sprite"));
163 int statsId(TypeDescription::GetTypeId("Stats"));
164 int stringId(TypeDescription::GetTypeId("String"));
166 TypeDescription &td(TypeDescription::CreateOrGet("Hero"));
167 td.SetConstructor(&Construct);
168 td.SetSize(sizeof(Hero));
170 td.AddField("name", FieldDescription(((char *)&h.name) - ((char *)&h), stringId, true));
171 td.AddField("sprite", FieldDescription(((char *)&h.sprite) - ((char *)&h), spriteId, true));
172 td.AddField("level", FieldDescription(((char *)&h.level) - ((char *)&h), numberId, false));
174 td.AddField("maxHealth", FieldDescription(((char *)&h.maxHealth) - ((char *)&h), numberId, false));
175 td.AddField("health", FieldDescription(((char *)&h.health) - ((char *)&h), numberId, false));
176 td.AddField("maxMana", FieldDescription(((char *)&h.maxMana) - ((char *)&h), numberId, false));
177 td.AddField("mana", FieldDescription(((char *)&h.mana) - ((char *)&h), numberId, false));
178 td.AddField("ip", FieldDescription(((char *)&h.ip) - ((char *)&h), numberId, false));
179 td.AddField("stats", FieldDescription(((char *)&h.stats) - ((char *)&h), statsId, false));
181 td.AddField("attackAnimation", FieldDescription(((char *)&h.attackAnimation) - ((char *)&h), animationId, true));
182 td.AddField("spellAnimation", FieldDescription(((char *)&h.spellAnimation) - ((char *)&h), animationId, true));
183 td.AddField("meleeAnimation", FieldDescription(((char *)&h.meleeAnimation) - ((char *)&h), animationId, true));
186 void Hero::Construct(void *data) {