]> git.localhorst.tv Git - l2e.git/commitdiff
moved some Hero related stuff out of BattleState
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 21 Aug 2012 18:47:29 +0000 (20:47 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 21 Aug 2012 18:47:29 +0000 (20:47 +0200)
src/battle/BattleState.cpp
src/battle/BattleState.h
src/battle/Hero.h

index fd4be082847813a5c41b16d1dd1155f54b64a572..b7017c98824246b1251d8431d7223ea31e98055b 100644 (file)
@@ -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<Hero>::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 Spell *>::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<Hero>::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<Hero>::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<Hero>::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<Hero>::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<Hero>::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<Hero>::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<Hero>::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<int> &offset)
        assert(screen);
        for (vector<Monster>::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 {
index 9f30fb5a1d439effc3b4ef8857ac1d7d69d1df60..a4f403741e5dd72dfcbe731072a09feecccb8e16 100644 (file)
@@ -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<const common::Spell *> &GetSpellMenu() { return spellMenus[activeHero]; }
-       const graphics::Menu<const common::Spell *> &GetSpellMenu() const { return spellMenus[activeHero]; }
-       graphics::Menu<const common::Item *> &GetIkariMenu() { return ikariMenus[activeHero]; }
-       const graphics::Menu<const common::Item *> &GetIkariMenu() const { return ikariMenus[activeHero]; }
+       graphics::Menu<const common::Spell *> &GetSpellMenu() { return heroes[activeHero].SpellMenu(); }
+       const graphics::Menu<const common::Spell *> &GetSpellMenu() const { return heroes[activeHero].SpellMenu(); }
+       graphics::Menu<const common::Item *> &GetIkariMenu() { return heroes[activeHero].IkariMenu(); }
+       const graphics::Menu<const common::Item *> &GetIkariMenu() const { return heroes[activeHero].IkariMenu(); }
        graphics::Menu<const common::Item *> &GetItemMenu() { return itemMenu; }
        const graphics::Menu<const common::Item *> &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<AttackChoice> monsterAttacks;
        std::vector<Order> attackOrder;
        Hero heroes[4];
-       graphics::Menu<const common::Spell *> spellMenus[4];
        graphics::Menu<const common::Item *> itemMenu;
-       graphics::Menu<const common::Item *> ikariMenus[4];
        HeroTag heroTags[4];
        SmallHeroTag smallHeroTags[4];
        geometry::Point<int> heroTagPositions[4];
        geometry::Point<int> smallHeroTagPositions[4];
-       AttackChoice attackChoices[4];
        int numHeroes;
        int activeHero;
        int attackCursor;
index fd90a1bb175b9e879e791111e3bd68e3d594f9d4..275db6da22a160ef1cf8c4815ad55a0da7145248 100644 (file)
@@ -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 <vector>
 #include <SDL.h>
@@ -83,6 +85,14 @@ public:
        const graphics::Animation *AttackAnimation() const { return attackAnimation; }
        const graphics::Animation *SpellAnimation() const { return spellAnimation; }
 
+       graphics::Menu<const common::Spell *> &SpellMenu() { return spellMenu; }
+       const graphics::Menu<const common::Spell *> &SpellMenu() const { return spellMenu; }
+       graphics::Menu<const common::Item *> &IkariMenu() { return ikariMenu; }
+       const graphics::Menu<const common::Item *> &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<const common::Spell *> spellMenu;
+       graphics::Menu<const common::Item *> ikariMenu;
+
+       AttackChoice attackChoice;
+
        // TODO: vector does not seem to be a good choice
        std::vector<const common::Spell *> spells;