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).SetReferenced());
74 td.AddField("maxHealth", FieldDescription(((char *)&h.maxHealth) - ((char *)&h), numberId));
75 td.AddField("health", FieldDescription(((char *)&h.health) - ((char *)&h), numberId));
76 td.AddField("maxMana", FieldDescription(((char *)&h.maxMana) - ((char *)&h), numberId));
77 td.AddField("mana", FieldDescription(((char *)&h.mana) - ((char *)&h), numberId));
78 td.AddField("ip", FieldDescription(((char *)&h.ip) - ((char *)&h), numberId));
80 td.AddField("stats", FieldDescription(((char *)&h.stats) - ((char *)&h), statsId));
82 td.AddField("level", FieldDescription(((char *)&h.level) - ((char *)&h), numberId));
84 td.AddField("battleSprite", FieldDescription(((char *)&h.battleSprite) - ((char *)&h), spriteId).SetReferenced().SetDescription("the sprite used for battle scenes"));
85 td.AddField("attackAnimation", FieldDescription(((char *)&h.attackAnimation) - ((char *)&h), animationId).SetReferenced().SetDescription("the animation played for physical attacks"));
86 td.AddField("spellAnimation", FieldDescription(((char *)&h.spellAnimation) - ((char *)&h), animationId).SetReferenced().SetDescription("the animation played for magical attacks"));
87 td.AddField("meleeAnimation", FieldDescription(((char *)&h.meleeAnimation) - ((char *)&h), animationId).SetReferenced().SetDescription("the animation played on attacked monsters when the hero has no weapon"));
89 td.AddField("mapEntity", FieldDescription(((char *)&h.mapEntity) - ((char *)&h), entityId).SetDescription("the entity representing the hero on maps"));
92 void Hero::Construct(void *data) {