From 2a3e39f2960bd359dfc8df8f439281dec30c633a Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Tue, 21 Aug 2012 20:47:29 +0200 Subject: [PATCH] moved some Hero related stuff out of BattleState --- src/battle/BattleState.cpp | 41 +++++++++++++++++++------------------- src/battle/BattleState.h | 17 +++++++--------- src/battle/Hero.h | 15 ++++++++++++++ 3 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index fd4be08..b7017c9 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -74,9 +74,9 @@ void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) { monstersLayout->CalculatePositions(background->w, background->h, monsterPositions); heroesLayout->CalculatePositions(background->w, background->h, heroesPositions); for (int i(0); i < 4; ++i) { - spellMenus[i] = res->spellMenuPrototype; + heroes[i].SpellMenu() = res->spellMenuPrototype; LoadSpellMenu(i); - ikariMenus[i] = res->ikariMenuPrototype; + heroes[i].IkariMenu() = res->ikariMenuPrototype; LoadIkariMenu(i); heroTags[i] = HeroTag(this, i); smallHeroTags[i] = SmallHeroTag(this, i); @@ -105,21 +105,21 @@ void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) { void BattleState::LoadSpellMenu(vector::size_type index) { assert(index >= 0 && index < 4); - spellMenus[index].Clear(); - spellMenus[index].Reserve(HeroAt(index).Spells().size()); + heroes[index].SpellMenu().Clear(); + heroes[index].SpellMenu().Reserve(HeroAt(index).Spells().size()); for (vector::const_iterator i(HeroAt(index).Spells().begin()), end(HeroAt(index).Spells().end()); i != end; ++i) { bool enabled((*i)->CanUseInBattle() && (*i)->Cost() <= HeroAt(index).Mana()); - spellMenus[index].Add((*i)->Name(), *i, enabled, 0, (*i)->Cost()); + heroes[index].SpellMenu().Add((*i)->Name(), *i, enabled, 0, (*i)->Cost()); } } void BattleState::LoadIkariMenu(vector::size_type index) { assert(index >= 0 && index < 4); - ikariMenus[index].Clear(); - ikariMenus[index].Reserve(6); + heroes[index].IkariMenu().Clear(); + heroes[index].IkariMenu().Reserve(6); if (HeroAt(index).HasWeapon()) { - ikariMenus[index].Add( + heroes[index].IkariMenu().Add( HeroAt(index).Weapon()->Name(), HeroAt(index).Weapon(), HeroAt(index).Weapon()->HasIkari() && HeroAt(index).Weapon()->GetIkari()->Cost() <= HeroAt(index).IP(), @@ -127,11 +127,11 @@ void BattleState::LoadIkariMenu(vector::size_type index) { 0, HeroAt(index).Weapon()->HasIkari() ? HeroAt(index).Weapon()->GetIkari()->Name() : ""); } else { - ikariMenus[index].Add(res->noEquipmentText, 0, false, res->weaponMenuIcon); + heroes[index].IkariMenu().Add(res->noEquipmentText, 0, false, res->weaponMenuIcon); } if (HeroAt(index).HasArmor()) { - ikariMenus[index].Add( + heroes[index].IkariMenu().Add( HeroAt(index).Armor()->Name(), HeroAt(index).Armor(), HeroAt(index).Armor()->HasIkari() && HeroAt(index).Armor()->GetIkari()->Cost() <= HeroAt(index).IP(), @@ -139,11 +139,11 @@ void BattleState::LoadIkariMenu(vector::size_type index) { 0, HeroAt(index).Armor()->HasIkari() ? HeroAt(index).Armor()->GetIkari()->Name() : ""); } else { - ikariMenus[index].Add(res->noEquipmentText, 0, false, res->armorMenuIcon); + heroes[index].IkariMenu().Add(res->noEquipmentText, 0, false, res->armorMenuIcon); } if (HeroAt(index).HasShield()) { - ikariMenus[index].Add( + heroes[index].IkariMenu().Add( HeroAt(index).Shield()->Name(), HeroAt(index).Shield(), HeroAt(index).Shield()->HasIkari() && HeroAt(index).Shield()->GetIkari()->Cost() <= HeroAt(index).IP(), @@ -151,11 +151,11 @@ void BattleState::LoadIkariMenu(vector::size_type index) { 0, HeroAt(index).Shield()->HasIkari() ? HeroAt(index).Shield()->GetIkari()->Name() : ""); } else { - ikariMenus[index].Add(res->noEquipmentText, 0, false, res->shieldMenuIcon); + heroes[index].IkariMenu().Add(res->noEquipmentText, 0, false, res->shieldMenuIcon); } if (HeroAt(index).HasHelmet()) { - ikariMenus[index].Add( + heroes[index].IkariMenu().Add( HeroAt(index).Helmet()->Name(), HeroAt(index).Helmet(), HeroAt(index).Helmet()->HasIkari() && HeroAt(index).Helmet()->GetIkari()->Cost() <= HeroAt(index).IP(), @@ -163,11 +163,11 @@ void BattleState::LoadIkariMenu(vector::size_type index) { 0, HeroAt(index).Helmet()->HasIkari() ? HeroAt(index).Helmet()->GetIkari()->Name() : ""); } else { - ikariMenus[index].Add(res->noEquipmentText, 0, false, res->helmetMenuIcon); + heroes[index].IkariMenu().Add(res->noEquipmentText, 0, false, res->helmetMenuIcon); } if (HeroAt(index).HasRing()) { - ikariMenus[index].Add( + heroes[index].IkariMenu().Add( HeroAt(index).Ring()->Name(), HeroAt(index).Ring(), HeroAt(index).Ring()->HasIkari() && HeroAt(index).Ring()->GetIkari()->Cost() <= HeroAt(index).IP(), @@ -175,11 +175,11 @@ void BattleState::LoadIkariMenu(vector::size_type index) { 0, HeroAt(index).Ring()->HasIkari() ? HeroAt(index).Ring()->GetIkari()->Name() : ""); } else { - ikariMenus[index].Add(res->noEquipmentText, 0, false, res->ringMenuIcon); + heroes[index].IkariMenu().Add(res->noEquipmentText, 0, false, res->ringMenuIcon); } if (HeroAt(index).HasJewel()) { - ikariMenus[index].Add( + heroes[index].IkariMenu().Add( HeroAt(index).Jewel()->Name(), HeroAt(index).Jewel(), HeroAt(index).Jewel()->HasIkari() && HeroAt(index).Jewel()->GetIkari()->Cost() <= HeroAt(index).IP(), @@ -187,7 +187,7 @@ void BattleState::LoadIkariMenu(vector::size_type index) { 0, HeroAt(index).Jewel()->HasIkari() ? HeroAt(index).Jewel()->GetIkari()->Name() : ""); } else { - ikariMenus[index].Add(res->noEquipmentText, 0, false, res->jewelMenuIcon); + heroes[index].IkariMenu().Add(res->noEquipmentText, 0, false, res->jewelMenuIcon); } } @@ -410,7 +410,7 @@ void BattleState::ClearAllAttacks() { attackCursor = -1; activeHero = -1; for (int i(0); i < numHeroes; ++i) { - attackChoices[i] = AttackChoice(this); + heroes[i].GetAttackChoice() = AttackChoice(this); } attackOrder.clear(); monsterAttacks.clear(); @@ -448,7 +448,6 @@ void BattleState::RenderMonsters(SDL_Surface *screen, const Vector &offset) assert(screen); for (vector::size_type i(0), end(monsters.size()); i < end; ++i) { if (MonsterPositionOccupied(i)) { - // TODO: better solution for running animations if (monsters[i].GetAnimation().Running()) { monsters[i].GetAnimation().DrawCenter(screen, monsterPositions[i] + offset); } else { diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index 9f30fb5..a4f4037 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -8,7 +8,6 @@ #ifndef BATTLE_BATTLESTATE_H_ #define BATTLE_BATTLESTATE_H_ -#include "AttackChoice.h" #include "AttackTypeMenu.h" #include "Hero.h" #include "HeroTag.h" @@ -41,6 +40,7 @@ namespace graphics { namespace battle { +class AttackChoice; class PartyLayout; class Stats; @@ -84,10 +84,10 @@ public: AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; } MoveMenu &GetMoveMenu() { return moveMenu; } - graphics::Menu &GetSpellMenu() { return spellMenus[activeHero]; } - const graphics::Menu &GetSpellMenu() const { return spellMenus[activeHero]; } - graphics::Menu &GetIkariMenu() { return ikariMenus[activeHero]; } - const graphics::Menu &GetIkariMenu() const { return ikariMenus[activeHero]; } + graphics::Menu &GetSpellMenu() { return heroes[activeHero].SpellMenu(); } + const graphics::Menu &GetSpellMenu() const { return heroes[activeHero].SpellMenu(); } + graphics::Menu &GetIkariMenu() { return heroes[activeHero].IkariMenu(); } + const graphics::Menu &GetIkariMenu() const { return heroes[activeHero].IkariMenu(); } graphics::Menu &GetItemMenu() { return itemMenu; } const graphics::Menu &GetItemMenu() const { return itemMenu; } @@ -109,8 +109,8 @@ public: bool HasChosenAttackType() const { return ActiveHeroAttackChoice().GetType() != AttackChoice::UNDECIDED; } AttackChoice &ActiveHeroAttackChoice() { return AttackChoiceAt(activeHero); } const AttackChoice &ActiveHeroAttackChoice() const { return AttackChoiceAt(activeHero); } - AttackChoice &AttackChoiceAt(int index) { assert(index >= 0 && index < NumHeroes()); return attackChoices[index]; } - const AttackChoice &AttackChoiceAt(int index) const { assert(index >= 0 && index < NumHeroes()); return attackChoices[index]; } + AttackChoice &AttackChoiceAt(int index) { assert(index >= 0 && index < NumHeroes()); return heroes[index].GetAttackChoice(); } + const AttackChoice &AttackChoiceAt(int index) const { assert(index >= 0 && index < NumHeroes()); return heroes[index].GetAttackChoice(); } AttackChoice &MonsterAttackChoiceAt(int index) { assert(index >= 0 && index < MaxMonsters()); return monsterAttacks[index]; } const AttackChoice &MonsterAttackChoiceAt(int index) const { assert(index >= 0 && index < MaxMonsters()); return monsterAttacks[index]; } bool AttackSelectionDone() const { return activeHero >= numHeroes; } @@ -181,14 +181,11 @@ private: std::vector monsterAttacks; std::vector attackOrder; Hero heroes[4]; - graphics::Menu spellMenus[4]; graphics::Menu itemMenu; - graphics::Menu ikariMenus[4]; HeroTag heroTags[4]; SmallHeroTag smallHeroTags[4]; geometry::Point heroTagPositions[4]; geometry::Point smallHeroTagPositions[4]; - AttackChoice attackChoices[4]; int numHeroes; int activeHero; int attackCursor; diff --git a/src/battle/Hero.h b/src/battle/Hero.h index fd90a1b..275db6d 100644 --- a/src/battle/Hero.h +++ b/src/battle/Hero.h @@ -8,8 +8,10 @@ #ifndef BATTLE_HERO_H_ #define BATTLE_HERO_H_ +#include "AttackChoice.h" #include "Stats.h" #include "../graphics/Animation.h" +#include "../graphics/Menu.h" #include #include @@ -83,6 +85,14 @@ public: const graphics::Animation *AttackAnimation() const { return attackAnimation; } const graphics::Animation *SpellAnimation() const { return spellAnimation; } + graphics::Menu &SpellMenu() { return spellMenu; } + const graphics::Menu &SpellMenu() const { return spellMenu; } + graphics::Menu &IkariMenu() { return ikariMenu; } + const graphics::Menu &IkariMenu() const { return ikariMenu; } + + AttackChoice &GetAttackChoice() { return attackChoice; } + const AttackChoice &GetAttackChoice() const { return attackChoice; } + // temporary setters until loader is implemented public: void SetName(const char *n) { name = n; } @@ -127,6 +137,11 @@ private: graphics::AnimationRunner animation; + graphics::Menu spellMenu; + graphics::Menu ikariMenu; + + AttackChoice attackChoice; + // TODO: vector does not seem to be a good choice std::vector spells; -- 2.39.2