From: Daniel Karbach Date: Sun, 7 Oct 2012 17:39:55 +0000 (+0200) Subject: moved Hero and Stats to common X-Git-Url: http://git.localhorst.tv/?a=commitdiff_plain;h=06b6411e5dc8fc6b905530f7adbde8bd0c2bb0ea;p=l2e.git moved Hero and Stats to common --- diff --git a/Debug/src/battle/subdir.mk b/Debug/src/battle/subdir.mk index 7d95878..0f0ff35 100644 --- a/Debug/src/battle/subdir.mk +++ b/Debug/src/battle/subdir.mk @@ -15,7 +15,6 @@ CPP_SRCS += \ ../src/battle/PartyLayout.cpp \ ../src/battle/Resources.cpp \ ../src/battle/SmallHeroTag.cpp \ -../src/battle/Stats.cpp \ ../src/battle/TargetSelection.cpp OBJS += \ @@ -30,7 +29,6 @@ OBJS += \ ./src/battle/PartyLayout.o \ ./src/battle/Resources.o \ ./src/battle/SmallHeroTag.o \ -./src/battle/Stats.o \ ./src/battle/TargetSelection.o CPP_DEPS += \ @@ -45,7 +43,6 @@ CPP_DEPS += \ ./src/battle/PartyLayout.d \ ./src/battle/Resources.d \ ./src/battle/SmallHeroTag.d \ -./src/battle/Stats.d \ ./src/battle/TargetSelection.d diff --git a/Debug/src/common/subdir.mk b/Debug/src/common/subdir.mk index 8072d36..78f304e 100644 --- a/Debug/src/common/subdir.mk +++ b/Debug/src/common/subdir.mk @@ -4,24 +4,33 @@ # Add inputs and outputs from these tool invocations to the build variables CPP_SRCS += \ +../src/common/GameState.cpp \ +../src/common/Hero.cpp \ ../src/common/Ikari.cpp \ ../src/common/Inventory.cpp \ ../src/common/Item.cpp \ ../src/common/Spell.cpp \ +../src/common/Stats.cpp \ ../src/common/TargetingMode.cpp OBJS += \ +./src/common/GameState.o \ +./src/common/Hero.o \ ./src/common/Ikari.o \ ./src/common/Inventory.o \ ./src/common/Item.o \ ./src/common/Spell.o \ +./src/common/Stats.o \ ./src/common/TargetingMode.o CPP_DEPS += \ +./src/common/GameState.d \ +./src/common/Hero.d \ ./src/common/Ikari.d \ ./src/common/Inventory.d \ ./src/common/Item.d \ ./src/common/Spell.d \ +./src/common/Stats.d \ ./src/common/TargetingMode.d diff --git a/Release/src/battle/subdir.mk b/Release/src/battle/subdir.mk index 68f2a2c..c926a31 100644 --- a/Release/src/battle/subdir.mk +++ b/Release/src/battle/subdir.mk @@ -15,7 +15,6 @@ CPP_SRCS += \ ../src/battle/PartyLayout.cpp \ ../src/battle/Resources.cpp \ ../src/battle/SmallHeroTag.cpp \ -../src/battle/Stats.cpp \ ../src/battle/TargetSelection.cpp OBJS += \ @@ -30,7 +29,6 @@ OBJS += \ ./src/battle/PartyLayout.o \ ./src/battle/Resources.o \ ./src/battle/SmallHeroTag.o \ -./src/battle/Stats.o \ ./src/battle/TargetSelection.o CPP_DEPS += \ @@ -45,7 +43,6 @@ CPP_DEPS += \ ./src/battle/PartyLayout.d \ ./src/battle/Resources.d \ ./src/battle/SmallHeroTag.d \ -./src/battle/Stats.d \ ./src/battle/TargetSelection.d diff --git a/Release/src/common/subdir.mk b/Release/src/common/subdir.mk index 1146aab..910092d 100644 --- a/Release/src/common/subdir.mk +++ b/Release/src/common/subdir.mk @@ -4,24 +4,33 @@ # Add inputs and outputs from these tool invocations to the build variables CPP_SRCS += \ +../src/common/GameState.cpp \ +../src/common/Hero.cpp \ ../src/common/Ikari.cpp \ ../src/common/Inventory.cpp \ ../src/common/Item.cpp \ ../src/common/Spell.cpp \ +../src/common/Stats.cpp \ ../src/common/TargetingMode.cpp OBJS += \ +./src/common/GameState.o \ +./src/common/Hero.o \ ./src/common/Ikari.o \ ./src/common/Inventory.o \ ./src/common/Item.o \ ./src/common/Spell.o \ +./src/common/Stats.o \ ./src/common/TargetingMode.o CPP_DEPS += \ +./src/common/GameState.d \ +./src/common/Hero.d \ ./src/common/Ikari.d \ ./src/common/Inventory.d \ ./src/common/Item.d \ ./src/common/Spell.d \ +./src/common/Stats.d \ ./src/common/TargetingMode.d diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index d958663..d309502 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -29,6 +29,7 @@ using app::Input; using common::Inventory; using common::Item; using common::Spell; +using common::Stats; using geometry::Vector; using graphics::Menu; diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index fbaa1d0..e002b7c 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -19,6 +19,7 @@ #include "../app/fwd.h" #include "../app/State.h" #include "../common/fwd.h" +#include "../common/Stats.h" #include "../geometry/Vector.h" #include "../graphics/Animation.h" #include "../graphics/fwd.h" @@ -138,8 +139,8 @@ private: void LoadInventory(); void DecideMonsterAttack(Monster &) const; - void CalculateDamage(const Stats &attackerStats, TargetSelection &targets) const; - Uint16 CalculateDamage(const Stats &attacker, const Stats &defender) const; + void CalculateDamage(const common::Stats &attackerStats, TargetSelection &targets) const; + Uint16 CalculateDamage(const common::Stats &attacker, const common::Stats &defender) const; private: SDL_Surface *background; diff --git a/src/battle/Hero.cpp b/src/battle/Hero.cpp index 8138bc1..1d8393e 100644 --- a/src/battle/Hero.cpp +++ b/src/battle/Hero.cpp @@ -12,58 +12,26 @@ #include "../common/Ikari.h" #include "../common/Item.h" #include "../common/Spell.h" -#include "../loader/TypeDescription.h" using common::Ikari; using common::Spell; -using loader::FieldDescription; -using loader::TypeDescription; using std::vector; namespace battle { Hero::Hero() -: name("") -, sprite(0) - -, weapon(0) -, armor(0) -, shield(0) -, helmet(0) -, ring(0) -, jewel(0) - -, meleeAnimation(0) -, attackAnimation(0) -, spellAnimation(0) - -, maxHealth(0) -, health(0) -, maxMana(0) -, mana(0) - -, level(0) -, ip(0) { +: master(0) { } -Hero::~Hero() { +Hero::Hero(common::Hero &h) +: master(&h) +, stats(h.GetStats()) { } +Hero::~Hero() { -void Hero::SubtractHealth(int amount) { - if (amount > Health()) { - health = 0; - } else { - health -= amount; - int ipGain(amount * 255 / health); - if (ip + ipGain > 255) { - ip = 255; - } else { - ip += ipGain; - } - } } @@ -153,38 +121,4 @@ void Hero::UpdateIkariMenu(const Resources *res) { } } - -void Hero::CreateTypeDescription() { - Hero h; - - int animationId(TypeDescription::GetTypeId("Animation")); - int numberId(TypeDescription::GetTypeId("Number")); - int spriteId(TypeDescription::GetTypeId("Sprite")); - int statsId(TypeDescription::GetTypeId("Stats")); - int stringId(TypeDescription::GetTypeId("String")); - - TypeDescription &td(TypeDescription::CreateOrGet("Hero")); - td.SetConstructor(&Construct); - td.SetSize(sizeof(Hero)); - - td.AddField("name", FieldDescription(((char *)&h.name) - ((char *)&h), stringId, true)); - td.AddField("sprite", FieldDescription(((char *)&h.sprite) - ((char *)&h), spriteId, true)); - td.AddField("level", FieldDescription(((char *)&h.level) - ((char *)&h), numberId, false)); - - td.AddField("maxHealth", FieldDescription(((char *)&h.maxHealth) - ((char *)&h), numberId, false)); - td.AddField("health", FieldDescription(((char *)&h.health) - ((char *)&h), numberId, false)); - td.AddField("maxMana", FieldDescription(((char *)&h.maxMana) - ((char *)&h), numberId, false)); - td.AddField("mana", FieldDescription(((char *)&h.mana) - ((char *)&h), numberId, false)); - td.AddField("ip", FieldDescription(((char *)&h.ip) - ((char *)&h), numberId, false)); - td.AddField("stats", FieldDescription(((char *)&h.stats) - ((char *)&h), statsId, false)); - - td.AddField("attackAnimation", FieldDescription(((char *)&h.attackAnimation) - ((char *)&h), animationId, true)); - td.AddField("spellAnimation", FieldDescription(((char *)&h.spellAnimation) - ((char *)&h), animationId, true)); - td.AddField("meleeAnimation", FieldDescription(((char *)&h.meleeAnimation) - ((char *)&h), animationId, true)); -} - -void Hero::Construct(void *data) { - new (data) Hero; -} - } diff --git a/src/battle/Hero.h b/src/battle/Hero.h index 385962f..d719288 100644 --- a/src/battle/Hero.h +++ b/src/battle/Hero.h @@ -10,8 +10,9 @@ #include "fwd.h" #include "AttackChoice.h" -#include "Stats.h" #include "../common/fwd.h" +#include "../common/Hero.h" +#include "../common/Stats.h" #include "../geometry/Vector.h" #include "../graphics/Animation.h" #include "../graphics/fwd.h" @@ -26,60 +27,61 @@ class Hero { public: Hero(); + Hero(common::Hero &); ~Hero(); public: - const char *Name() const { return name; } - Uint8 Level() const { return level; } - const graphics::Sprite *Sprite() const { return sprite; } + const char *Name() const { return master->Name(); } + Uint8 Level() const { return master->Level(); } + const graphics::Sprite *Sprite() const { return master->BattleSprite(); } - const std::vector &Spells() const { return spells; } + const std::vector &Spells() const { return master->Spells(); } - Uint16 MaxHealth() const { return maxHealth; } - Uint16 Health() const { return health; } + Uint16 MaxHealth() const { return master->MaxHealth(); } + Uint16 Health() const { return master->Health(); } int RelativeHealth(int max) const { return Health() * max / MaxHealth(); } - void SubtractHealth(int amount); + void SubtractHealth(int amount) { master->SubtractHealth(amount); } - Uint16 MaxMana() const { return maxMana; } - Uint16 Mana() const { return mana; } + Uint16 MaxMana() const { return master->MaxMana(); } + Uint16 Mana() const { return master->Mana(); } int RelativeMana(int max) const { return MaxMana() == 0 ? 0 : Mana() * max / MaxMana(); } bool CanUseMagic() const { return MaxMana() > 0; } - Uint8 MaxIP() const { return 255; } - Uint8 IP() const { return ip; } + Uint8 MaxIP() const { return master->MaxIP(); } + Uint8 IP() const { return master->IP(); } int RelativeIP(int max) const { return IP() * max / MaxIP(); } - Stats &GetStats() { return stats; } - const Stats &GetStats() const { return stats; } - - common::Item *Weapon() { return weapon; } - common::Item *Armor() { return armor; } - common::Item *Shield() { return shield; } - common::Item *Helmet() { return helmet; } - common::Item *Ring() { return ring; } - common::Item *Jewel() { return jewel; } - - const common::Item *Weapon() const { return weapon; } - const common::Item *Armor() const { return armor; } - const common::Item *Shield() const { return shield; } - const common::Item *Helmet() const { return helmet; } - const common::Item *Ring() const { return ring; } - const common::Item *Jewel() const { return jewel; } - - bool HasWeapon() const { return weapon; } - bool HasArmor() const { return armor; } - bool HasShield() const { return shield; } - bool HasHelmet() const { return helmet; } - bool HasRing() const { return ring; } - bool HasJewel() const { return jewel; } + common::Stats &GetStats() { return stats; } + const common::Stats &GetStats() const { return stats; } + + common::Item *Weapon() { return master->Weapon(); } + common::Item *Armor() { return master->Armor(); } + common::Item *Shield() { return master->Shield(); } + common::Item *Helmet() { return master->Helmet(); } + common::Item *Ring() { return master->Ring(); } + common::Item *Jewel() { return master->Jewel(); } + + const common::Item *Weapon() const { return master->Weapon(); } + const common::Item *Armor() const { return master->Armor(); } + const common::Item *Shield() const { return master->Shield(); } + const common::Item *Helmet() const { return master->Helmet(); } + const common::Item *Ring() const { return master->Ring(); } + const common::Item *Jewel() const { return master->Jewel(); } + + bool HasWeapon() const { return master->HasWeapon(); } + bool HasArmor() const { return master->HasArmor(); } + bool HasShield() const { return master->HasShield(); } + bool HasHelmet() const { return master->HasHelmet(); } + bool HasRing() const { return master->HasRing(); } + bool HasJewel() const { return master->HasJewel(); } graphics::AnimationRunner &GetAnimation() { return animation; } const graphics::AnimationRunner &GetAnimation() const { return animation; } void SetAnimation(const graphics::AnimationRunner &a) { animation = a; } - const graphics::Animation *MeleeAnimation() const { return meleeAnimation; } - const graphics::Animation *AttackAnimation() const { return attackAnimation; } - const graphics::Animation *SpellAnimation() const { return spellAnimation; } + const graphics::Animation *MeleeAnimation() const { return master->MeleeAnimation(); } + const graphics::Animation *AttackAnimation() const { return master->AttackAnimation(); } + const graphics::Animation *SpellAnimation() const { return master->SpellAnimation(); } geometry::Vector &Position() { return position; } const geometry::Vector &Position() const { return position; } @@ -96,50 +98,8 @@ public: void UpdateSpellMenu(); void UpdateIkariMenu(const Resources *); -// temporary setters until loader is implemented -public: - void SetName(const char *n) { name = n; } - void SetLevel(Uint8 l) { level = l; } - void SetSprite(graphics::Sprite *s) { sprite = s; } - - void SetMaxHealth(Uint16 h) { maxHealth = h; } - void SetHealth(Uint16 h) { health = h; } - void SetMaxMana(Uint16 m) { maxMana = m; } - void SetMana(Uint16 m) { mana = m; } - void SetIP(Uint8 i) { ip = i; } - - void SetStats(const Stats &s) { stats = s; } - - void SetWeapon(common::Item *i) { weapon = i; } - void SetArmor(common::Item *i) { armor = i; } - void SetShield(common::Item *i) { shield = i; } - void SetHelmet(common::Item *i) { helmet = i; } - void SetRing(common::Item *i) { ring = i; } - void SetJewel(common::Item *i) { jewel = i; } - - void AddSpell(const common::Spell *s) { spells.push_back(s); } - - void SetMeleeAnimation(const graphics::Animation *a) { meleeAnimation = a; } - void SetAttackAnimation(const graphics::Animation *a) { attackAnimation = a; } - void SetSpellAnimation(const graphics::Animation *a) { spellAnimation = a; } - - static void CreateTypeDescription(); - static void Construct(void *); - private: - const char *name; - graphics::Sprite *sprite; - - common::Item *weapon; - common::Item *armor; - common::Item *shield; - common::Item *helmet; - common::Item *ring; - common::Item *jewel; - - const graphics::Animation *meleeAnimation; - const graphics::Animation *attackAnimation; - const graphics::Animation *spellAnimation; + common::Hero *master; graphics::AnimationRunner animation; @@ -150,16 +110,7 @@ private: AttackChoice attackChoice; - // TODO: vector does not seem to be a good choice - std::vector spells; - - int maxHealth, health; - int maxMana, mana; - - Stats stats; - - int level; - int ip; + common::Stats stats; }; diff --git a/src/battle/Monster.h b/src/battle/Monster.h index 3497c04..f1073f2 100644 --- a/src/battle/Monster.h +++ b/src/battle/Monster.h @@ -9,8 +9,8 @@ #define BATTLE_MONSTER_H_ #include "AttackChoice.h" -#include "Stats.h" #include "../common/fwd.h" +#include "../common/Stats.h" #include "../geometry/Vector.h" #include "../graphics/Animation.h" #include "../graphics/fwd.h" @@ -39,8 +39,8 @@ public: Uint16 Mana() const { return mana; } int RelativeMana(int max) const { return mana * max / maxMana; } - Stats &GetStats() { return stats; } - const Stats &GetStats() const { return stats; } + common::Stats &GetStats() { return stats; } + const common::Stats &GetStats() const { return stats; } Uint16 ExpReward() const { return expReward; } Uint16 GoldReward() const { return goldReward; } @@ -71,7 +71,7 @@ public: void SetHealth(Uint16 h) { health = h; } void SetMaxMana(Uint16 m) { maxMana = m; } void SetMana(Uint16 m) { mana = m; } - void SetStats(const Stats &s) { stats = s; } + void SetStats(const common::Stats &s) { stats = s; } void SetReward(Uint16 exp, Uint16 gold) { expReward = exp; goldReward = gold; } void SetMeleeAnimation(const graphics::Animation *a) { meleeAnimation = a; } @@ -104,7 +104,7 @@ private: int maxHealth, health; int maxMana, mana; - Stats stats; + common::Stats stats; int expReward, goldReward; diff --git a/src/battle/Stats.cpp b/src/battle/Stats.cpp deleted file mode 100644 index a2a442c..0000000 --- a/src/battle/Stats.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Stats.cpp - * - * Created on: Aug 19, 2012 - * Author: holy - */ - -#include "Stats.h" - -#include "../loader/TypeDescription.h" - -using loader::FieldDescription; -using loader::TypeDescription; - -namespace battle { - -Stats::Stats() -: attack(0) -, defense(0) -, strength(0) -, agility(0) -, intelligence(0) -, magicResistance(0) -, gut(0) { - -} - -Stats::Stats(Uint16 attack, Uint16 defense, Uint16 strength, Uint16 agility, Uint16 intelligence, Uint8 gut, Uint16 magicResistance) -: attack(attack) -, defense(defense) -, strength(strength) -, agility(agility) -, intelligence(intelligence) -, magicResistance(magicResistance) -, gut(gut) { - -} - - -void Stats::CreateTypeDescription() { - Stats s; - - int numberId(TypeDescription::GetTypeId("Number")); - - TypeDescription &td(TypeDescription::CreateOrGet("Stats")); - td.SetConstructor(&Construct); - td.SetSize(sizeof(Stats)); - - td.AddField("atp", FieldDescription(((char *)&s.attack) - ((char *)&s), numberId, false)); - td.AddField("dfp", FieldDescription(((char *)&s.defense) - ((char *)&s), numberId, false)); - td.AddField("str", FieldDescription(((char *)&s.strength) - ((char *)&s), numberId, false)); - td.AddField("agl", FieldDescription(((char *)&s.agility) - ((char *)&s), numberId, false)); - td.AddField("int", FieldDescription(((char *)&s.intelligence) - ((char *)&s), numberId, false)); - td.AddField("gut", FieldDescription(((char *)&s.gut) - ((char *)&s), numberId, false)); - td.AddField("mgr", FieldDescription(((char *)&s.magicResistance) - ((char *)&s), numberId, false)); -} - -void Stats::Construct(void *data) { - new (data) Stats; -} - -} diff --git a/src/battle/Stats.h b/src/battle/Stats.h deleted file mode 100644 index e53111d..0000000 --- a/src/battle/Stats.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Stats.h - * - * Created on: Aug 19, 2012 - * Author: holy - */ - -#ifndef BATTLE_STATS_H_ -#define BATTLE_STATS_H_ - -#include - -namespace battle { - -class Stats { - -public: - Stats(); - Stats(Uint16 attack, Uint16 defense, Uint16 strength, Uint16 agility, Uint16 intelligence, Uint8 gut, Uint16 magicResistance); - -public: - Uint16 Attack() const { return attack; } - Uint16 Defense() const { return defense; } - Uint16 Strength() const { return strength; } - Uint16 Agility() const { return agility; } - Uint16 Intelligence() const { return intelligence; } - Uint8 Gut() const { return gut; } - Uint16 MagicResistance() const { return magicResistance; } - - void SetAttack(Uint16 a) { attack = a; } - void SetDefense(Uint16 d) { defense = d; } - void SetStrength(Uint16 s) { strength = s; } - void SetAgility(Uint16 a) { agility = a; } - void SetIntelligence(Uint16 i) { intelligence = i; } - void SetGut(Uint8 g) { gut = g; } - void SetMagicResistance(Uint16 m) { magicResistance = m; } - - static void CreateTypeDescription(); - static void Construct(void *); - -private: - int attack; - int defense; - int strength; - int agility; - int intelligence; - int magicResistance; - int gut; - -}; - -} - -#endif /* BATTLE_STATS_H_ */ diff --git a/src/battle/fwd.h b/src/battle/fwd.h index 5e629f3..c4df5ba 100644 --- a/src/battle/fwd.h +++ b/src/battle/fwd.h @@ -29,7 +29,6 @@ class SelectMoveAction; class SelectSpell; class SelectTarget; class SmallHeroTag; -class Stats; class SwapHeroes; class TargetSelection; diff --git a/src/common/GameState.cpp b/src/common/GameState.cpp new file mode 100644 index 0000000..7992d43 --- /dev/null +++ b/src/common/GameState.cpp @@ -0,0 +1,20 @@ +/* + * GameState.cpp + * + * Created on: Oct 7, 2012 + * Author: holy + */ + +#include "GameState.h" + +namespace common { + +GameState::GameState() +: money(0) { + party[0] = heroes; + party[1] = 0; + party[2] = 0; + party[3] = 0; +} + +} diff --git a/src/common/GameState.h b/src/common/GameState.h new file mode 100644 index 0000000..f1edf48 --- /dev/null +++ b/src/common/GameState.h @@ -0,0 +1,30 @@ +/* + * GameState.h + * + * Created on: Oct 7, 2012 + * Author: holy + */ + +#ifndef COMMON_GAMESTATE_H_ +#define COMMON_GAMESTATE_H_ + +#include "Hero.h" + +#include + +namespace common { + +struct GameState { + + GameState(); + + Hero heroes[7]; + Hero *party[4]; + + Uint32 money; + +}; + +} + +#endif /* COMMON_GAMESTATE_H_ */ diff --git a/src/common/Hero.cpp b/src/common/Hero.cpp new file mode 100644 index 0000000..98b92ca --- /dev/null +++ b/src/common/Hero.cpp @@ -0,0 +1,97 @@ +/* + * Hero.cpp + * + * Created on: Oct 7, 2012 + * Author: holy + */ + +#include "Hero.h" + +#include "../loader/TypeDescription.h" + +using loader::FieldDescription; +using loader::TypeDescription; + +namespace common { + +Hero::Hero() +: name(0) + +, maxHealth(0) +, health(0) +, maxMana(0) +, mana(0) +, ip(0) + +, level(0) + +, weapon(0) +, armor(0) +, shield(0) +, helmet(0) +, ring(0) +, jewel(0) + +, battleSprite(0) +, meleeAnimation(0) +, attackAnimation(0) +, spellAnimation(0) + +, mapSprite(0) { + +} + + +void Hero::SubtractHealth(int amount) { + if (amount > Health()) { + health = 0; + } else { + health -= amount; + int ipGain(amount * 255 / health); + if (ip + ipGain > 255) { + ip = 255; + } else { + ip += ipGain; + } + } +} + + +void Hero::CreateTypeDescription() { + Hero h; + + int animationId(TypeDescription::GetTypeId("Animation")); + int numberId(TypeDescription::GetTypeId("Number")); + int spriteId(TypeDescription::GetTypeId("Sprite")); + int statsId(TypeDescription::GetTypeId("Stats")); + int stringId(TypeDescription::GetTypeId("String")); + + TypeDescription &td(TypeDescription::CreateOrGet("Hero")); + td.SetConstructor(&Construct); + td.SetSize(sizeof(Hero)); + + td.AddField("name", FieldDescription(((char *)&h.name) - ((char *)&h), stringId, true)); + + td.AddField("maxHealth", FieldDescription(((char *)&h.maxHealth) - ((char *)&h), numberId, false)); + td.AddField("health", FieldDescription(((char *)&h.health) - ((char *)&h), numberId, false)); + td.AddField("maxMana", FieldDescription(((char *)&h.maxMana) - ((char *)&h), numberId, false)); + td.AddField("mana", FieldDescription(((char *)&h.mana) - ((char *)&h), numberId, false)); + td.AddField("ip", FieldDescription(((char *)&h.ip) - ((char *)&h), numberId, false)); + + td.AddField("stats", FieldDescription(((char *)&h.stats) - ((char *)&h), statsId, false)); + + td.AddField("level", FieldDescription(((char *)&h.level) - ((char *)&h), numberId, false)); + + td.AddField("battleSprite", FieldDescription(((char *)&h.battleSprite) - ((char *)&h), spriteId, true)); + td.AddField("attackAnimation", FieldDescription(((char *)&h.attackAnimation) - ((char *)&h), animationId, true)); + td.AddField("spellAnimation", FieldDescription(((char *)&h.spellAnimation) - ((char *)&h), animationId, true)); + td.AddField("meleeAnimation", FieldDescription(((char *)&h.meleeAnimation) - ((char *)&h), animationId, true)); + + td.AddField("mapSprite", FieldDescription(((char *)&h.mapSprite) - ((char *)&h), spriteId, true)); +} + +void Hero::Construct(void *data) { + new (data) Hero; +} + +} diff --git a/src/common/Hero.h b/src/common/Hero.h new file mode 100644 index 0000000..d78d149 --- /dev/null +++ b/src/common/Hero.h @@ -0,0 +1,123 @@ +/* + * Hero.h + * + * Created on: Oct 7, 2012 + * Author: holy + */ + +#ifndef COMMON_HERO_H_ +#define COMMON_HERO_H_ + +#include "fwd.h" +#include "Stats.h" +#include "../graphics/fwd.h" + +#include + +namespace common { + +class Hero { + +public: + Hero(); + ~Hero() { } + +public: + const char *Name() const { return name; } + + Uint16 MaxHealth() const { return maxHealth; } + Uint16 Health() const { return health; } + int RelativeHealth(int max) const { return Health() * max / MaxHealth(); } + void SubtractHealth(int amount); + + Uint16 MaxMana() const { return maxMana; } + Uint16 Mana() const { return mana; } + int RelativeMana(int max) const { return MaxMana() == 0 ? 0 : Mana() * max / MaxMana(); } + bool CanUseMagic() const { return MaxMana() > 0; } + + Uint8 MaxIP() const { return 255; } + Uint8 IP() const { return ip; } + int RelativeIP(int max) const { return IP() * max / MaxIP(); } + + Stats &GetStats() { return stats; } + const Stats &GetStats() const { return stats; } + + Uint8 Level() const { return level; } + + Item *Weapon() { return weapon; } + Item *Armor() { return armor; } + Item *Shield() { return shield; } + Item *Helmet() { return helmet; } + Item *Ring() { return ring; } + Item *Jewel() { return jewel; } + + const Item *Weapon() const { return weapon; } + const Item *Armor() const { return armor; } + const Item *Shield() const { return shield; } + const Item *Helmet() const { return helmet; } + const Item *Ring() const { return ring; } + const Item *Jewel() const { return jewel; } + + bool HasWeapon() const { return weapon; } + bool HasArmor() const { return armor; } + bool HasShield() const { return shield; } + bool HasHelmet() const { return helmet; } + bool HasRing() const { return ring; } + bool HasJewel() const { return jewel; } + + const std::vector &Spells() const { return spells; } + + graphics::Sprite *BattleSprite() { return battleSprite; } + graphics::Animation *MeleeAnimation() { return meleeAnimation; } + graphics::Animation *AttackAnimation() { return attackAnimation; } + graphics::Animation *SpellAnimation() { return spellAnimation; } + + graphics::Sprite *MapSprite() { return mapSprite; } + + static void CreateTypeDescription(); + static void Construct(void *); + +// temporary setters +public: + void SetWeapon(common::Item *i) { weapon = i; } + void SetArmor(common::Item *i) { armor = i; } + void SetShield(common::Item *i) { shield = i; } + void SetHelmet(common::Item *i) { helmet = i; } + void SetRing(common::Item *i) { ring = i; } + void SetJewel(common::Item *i) { jewel = i; } + + void AddSpell(Spell *s) { spells.push_back(s); } + +private: + const char *name; + + int maxHealth, health; + int maxMana, mana; + int ip; + + Stats stats; + + int level; + + Item *weapon; + Item *armor; + Item *shield; + Item *helmet; + Item *ring; + Item *jewel; + + // TODO: vector does not seem to be a good choice + std::vector spells; + + graphics::Sprite *battleSprite; + graphics::Animation *meleeAnimation; + graphics::Animation *attackAnimation; + graphics::Animation *spellAnimation; + + graphics::Sprite *mapSprite; + +}; + +} + +#endif /* COMMON_HERO_H_ */ diff --git a/src/common/Stats.cpp b/src/common/Stats.cpp new file mode 100644 index 0000000..58d5db6 --- /dev/null +++ b/src/common/Stats.cpp @@ -0,0 +1,62 @@ +/* + * Stats.cpp + * + * Created on: Aug 19, 2012 + * Author: holy + */ + +#include "Stats.h" + +#include "../loader/TypeDescription.h" + +using loader::FieldDescription; +using loader::TypeDescription; + +namespace common { + +Stats::Stats() +: attack(0) +, defense(0) +, strength(0) +, agility(0) +, intelligence(0) +, magicResistance(0) +, gut(0) { + +} + +Stats::Stats(Uint16 attack, Uint16 defense, Uint16 strength, Uint16 agility, Uint16 intelligence, Uint8 gut, Uint16 magicResistance) +: attack(attack) +, defense(defense) +, strength(strength) +, agility(agility) +, intelligence(intelligence) +, magicResistance(magicResistance) +, gut(gut) { + +} + + +void Stats::CreateTypeDescription() { + Stats s; + + int numberId(TypeDescription::GetTypeId("Number")); + + TypeDescription &td(TypeDescription::CreateOrGet("Stats")); + td.SetConstructor(&Construct); + td.SetSize(sizeof(Stats)); + + td.AddField("atp", FieldDescription(((char *)&s.attack) - ((char *)&s), numberId, false)); + td.AddField("dfp", FieldDescription(((char *)&s.defense) - ((char *)&s), numberId, false)); + td.AddField("str", FieldDescription(((char *)&s.strength) - ((char *)&s), numberId, false)); + td.AddField("agl", FieldDescription(((char *)&s.agility) - ((char *)&s), numberId, false)); + td.AddField("int", FieldDescription(((char *)&s.intelligence) - ((char *)&s), numberId, false)); + td.AddField("gut", FieldDescription(((char *)&s.gut) - ((char *)&s), numberId, false)); + td.AddField("mgr", FieldDescription(((char *)&s.magicResistance) - ((char *)&s), numberId, false)); +} + +void Stats::Construct(void *data) { + new (data) Stats; +} + +} diff --git a/src/common/Stats.h b/src/common/Stats.h new file mode 100644 index 0000000..620fc1d --- /dev/null +++ b/src/common/Stats.h @@ -0,0 +1,54 @@ +/* + * Stats.h + * + * Created on: Aug 19, 2012 + * Author: holy + */ + +#ifndef COMMON_STATS_H_ +#define COMMON_STATS_H_ + +#include + +namespace common { + +class Stats { + +public: + Stats(); + Stats(Uint16 attack, Uint16 defense, Uint16 strength, Uint16 agility, Uint16 intelligence, Uint8 gut, Uint16 magicResistance); + +public: + Uint16 Attack() const { return attack; } + Uint16 Defense() const { return defense; } + Uint16 Strength() const { return strength; } + Uint16 Agility() const { return agility; } + Uint16 Intelligence() const { return intelligence; } + Uint8 Gut() const { return gut; } + Uint16 MagicResistance() const { return magicResistance; } + + void SetAttack(Uint16 a) { attack = a; } + void SetDefense(Uint16 d) { defense = d; } + void SetStrength(Uint16 s) { strength = s; } + void SetAgility(Uint16 a) { agility = a; } + void SetIntelligence(Uint16 i) { intelligence = i; } + void SetGut(Uint8 g) { gut = g; } + void SetMagicResistance(Uint16 m) { magicResistance = m; } + + static void CreateTypeDescription(); + static void Construct(void *); + +private: + int attack; + int defense; + int strength; + int agility; + int intelligence; + int magicResistance; + int gut; + +}; + +} + +#endif /* COMMON_STATS_H_ */ diff --git a/src/common/fwd.h b/src/common/fwd.h index 6238cbf..3f7e46f 100644 --- a/src/common/fwd.h +++ b/src/common/fwd.h @@ -10,11 +10,14 @@ namespace common { +struct GameState; +class Hero; class HeroGroup; class Ikari; class Inventory; class Item; class Spell; +class Stats; class TargetingMode; } diff --git a/src/loader/Caster.cpp b/src/loader/Caster.cpp index a3a6707..6d6d718 100644 --- a/src/loader/Caster.cpp +++ b/src/loader/Caster.cpp @@ -9,9 +9,9 @@ #include "TypeDescription.h" -using battle::Hero; using battle::Monster; using battle::PartyLayout; +using common::Hero; using common::Item; using common::Spell; using std::string; diff --git a/src/loader/Caster.h b/src/loader/Caster.h index 72a92aa..a3042ac 100644 --- a/src/loader/Caster.h +++ b/src/loader/Caster.h @@ -27,7 +27,7 @@ private: public: battle::Resources *GetBattleResources(const std::string &identifier); - battle::Hero *GetHero(const std::string &identifier); + common::Hero *GetHero(const std::string &identifier); common::Item *GetItem(const std::string &identifier); battle::Monster *GetMonster(const std::string &identifier); battle::PartyLayout *GetPartyLayout(const std::string &identifier); diff --git a/src/loader/Interpreter.cpp b/src/loader/Interpreter.cpp index 0b81323..28e9b39 100644 --- a/src/loader/Interpreter.cpp +++ b/src/loader/Interpreter.cpp @@ -15,6 +15,7 @@ #include "../common/Ikari.h" #include "../common/Item.h" #include "../common/Spell.h" +#include "../common/Stats.h" #include "../common/TargetingMode.h" #include "../graphics/ComplexAnimation.h" #include "../graphics/Font.h" @@ -31,10 +32,10 @@ using battle::Hero; using battle::Monster; using battle::PartyLayout; -using battle::Stats; using common::Ikari; using common::Item; using common::Spell; +using common::Stats; using common::TargetingMode; using graphics::Animation; using graphics::Color; diff --git a/src/main.cpp b/src/main.cpp index c4bc0bf..f971d46 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,11 +13,12 @@ #include "battle/Monster.h" #include "battle/PartyLayout.h" #include "battle/Resources.h" -#include "battle/Stats.h" +#include "common/Hero.h" #include "common/Ikari.h" #include "common/Inventory.h" #include "common/Item.h" #include "common/Spell.h" +#include "common/Stats.h" #include "geometry/Vector.h" #include "graphics/ComplexAnimation.h" #include "graphics/Font.h" @@ -54,14 +55,14 @@ using app::Application; using app::Arguments; using app::Input; using battle::BattleState; -using battle::Hero; using battle::Monster; using battle::PartyLayout; -using battle::Stats; +using common::Hero; using common::Ikari; using common::Inventory; using common::Item; using common::Spell; +using common::Stats; using geometry::Vector; using graphics::ComplexAnimation; using graphics::Font; diff --git a/test-data/test.l2s b/test-data/test.l2s index b2fc8b6..4b1106c 100644 --- a/test-data/test.l2s +++ b/test-data/test.l2s @@ -73,7 +73,7 @@ Sprite maximSprite { export Hero maxim { name: "Maxim", level: 1, - sprite: maximSprite, + battleSprite: maximSprite, maxHealth: 33, health: 33, maxMana: 20, @@ -151,7 +151,7 @@ Sprite selanSprite { export Hero selan { name: "Selan", level: 1, - sprite: selanSprite, + battleSprite: selanSprite, maxHealth: 28, health: 28, maxMana: 23, @@ -223,7 +223,7 @@ Sprite guySprite { export Hero guy { name: "Guy", level: 1, - sprite: guySprite, + battleSprite: guySprite, maxHealth: 38, health: 38, maxMana: 0, @@ -277,7 +277,7 @@ Sprite dekarSprite { export Hero dekar { name: "Dekar", level: 1, - sprite: dekarSprite, + battleSprite: dekarSprite, maxHealth: 38, health: 38, maxMana: 0,