4 * Created on: Oct 7, 2012
10 #include "../loader/TypeDescription.h"
12 using loader::FieldDescription;
13 using loader::TypeDescription;
45 void Hero::SubtractHealth(int amount) {
46 if (amount > Health()) {
50 int ipGain(amount * 255 / health);
51 if (ip + ipGain > 255) {
60 void Hero::CreateTypeDescription() {
63 int animationId(TypeDescription::GetTypeId("Animation"));
64 int numberId(TypeDescription::GetTypeId("Number"));
65 int spriteId(TypeDescription::GetTypeId("Sprite"));
66 int statsId(TypeDescription::GetTypeId("Stats"));
67 int stringId(TypeDescription::GetTypeId("String"));
69 TypeDescription &td(TypeDescription::CreateOrGet("Hero"));
70 td.SetConstructor(&Construct);
71 td.SetSize(sizeof(Hero));
73 td.AddField("name", FieldDescription(((char *)&h.name) - ((char *)&h), stringId, true));
75 td.AddField("maxHealth", FieldDescription(((char *)&h.maxHealth) - ((char *)&h), numberId, false));
76 td.AddField("health", FieldDescription(((char *)&h.health) - ((char *)&h), numberId, false));
77 td.AddField("maxMana", FieldDescription(((char *)&h.maxMana) - ((char *)&h), numberId, false));
78 td.AddField("mana", FieldDescription(((char *)&h.mana) - ((char *)&h), numberId, false));
79 td.AddField("ip", FieldDescription(((char *)&h.ip) - ((char *)&h), numberId, false));
81 td.AddField("stats", FieldDescription(((char *)&h.stats) - ((char *)&h), statsId, false));
83 td.AddField("level", FieldDescription(((char *)&h.level) - ((char *)&h), numberId, false));
85 td.AddField("battleSprite", FieldDescription(((char *)&h.battleSprite) - ((char *)&h), spriteId, true));
86 td.AddField("attackAnimation", FieldDescription(((char *)&h.attackAnimation) - ((char *)&h), animationId, true));
87 td.AddField("spellAnimation", FieldDescription(((char *)&h.spellAnimation) - ((char *)&h), animationId, true));
88 td.AddField("meleeAnimation", FieldDescription(((char *)&h.meleeAnimation) - ((char *)&h), animationId, true));
90 td.AddField("mapSprite", FieldDescription(((char *)&h.mapSprite) - ((char *)&h), spriteId, true));
93 void Hero::Construct(void *data) {