4 * Created on: Oct 7, 2012
10 #include "../loader/TypeDescription.h"
12 using loader::FieldDescription;
13 using loader::TypeDescription;
43 void Hero::SubtractHealth(int amount) {
44 if (amount > Health()) {
48 int ipGain(amount * 255 / health);
49 if (ip + ipGain > 255) {
58 void Hero::CreateTypeDescription() {
61 int animationId(TypeDescription::GetTypeId("Animation"));
62 int entityId(TypeDescription::GetTypeId("Entity"));
63 int numberId(TypeDescription::GetTypeId("Number"));
64 int spriteId(TypeDescription::GetTypeId("Sprite"));
65 int statsId(TypeDescription::GetTypeId("Stats"));
66 int stringId(TypeDescription::GetTypeId("String"));
68 TypeDescription &td(TypeDescription::CreateOrGet("Hero"));
69 td.SetConstructor(&Construct);
70 td.SetSize(sizeof(Hero));
72 td.AddField("name", FieldDescription(((char *)&h.name) - ((char *)&h), stringId, true));
74 td.AddField("maxHealth", FieldDescription(((char *)&h.maxHealth) - ((char *)&h), numberId, false));
75 td.AddField("health", FieldDescription(((char *)&h.health) - ((char *)&h), numberId, false));
76 td.AddField("maxMana", FieldDescription(((char *)&h.maxMana) - ((char *)&h), numberId, false));
77 td.AddField("mana", FieldDescription(((char *)&h.mana) - ((char *)&h), numberId, false));
78 td.AddField("ip", FieldDescription(((char *)&h.ip) - ((char *)&h), numberId, false));
80 td.AddField("stats", FieldDescription(((char *)&h.stats) - ((char *)&h), statsId, false));
82 td.AddField("level", FieldDescription(((char *)&h.level) - ((char *)&h), numberId, false));
84 td.AddField("battleSprite", FieldDescription(((char *)&h.battleSprite) - ((char *)&h), spriteId, true));
85 td.AddField("attackAnimation", FieldDescription(((char *)&h.attackAnimation) - ((char *)&h), animationId, true));
86 td.AddField("spellAnimation", FieldDescription(((char *)&h.spellAnimation) - ((char *)&h), animationId, true));
87 td.AddField("meleeAnimation", FieldDescription(((char *)&h.meleeAnimation) - ((char *)&h), animationId, true));
89 td.AddField("mapEntity", FieldDescription(((char *)&h.mapEntity) - ((char *)&h), entityId, false));
92 void Hero::Construct(void *data) {