]> git.localhorst.tv Git - l2e.git/commitdiff
reorganized BattleState's interface
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 11 Aug 2012 14:36:05 +0000 (16:36 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 11 Aug 2012 14:36:05 +0000 (16:36 +0200)
…and more to come ;)

src/battle/BattleState.h
src/battle/states/SelectAttackType.cpp
src/battle/states/SelectIkari.cpp
src/battle/states/SelectItem.cpp
src/battle/states/SelectSpell.cpp

index 978581f3062843018925d782ecf63d5de3995d46..cfec6129a8cb0f47e81589e689a5182280f6a34e 100644 (file)
@@ -76,36 +76,35 @@ 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::Item *> &GetItemMenu() { return itemMenu; }
+       const graphics::Menu<const common::Item *> &GetItemMenu() const { return itemMenu; }
+
        bool HasMoreHeroes() const { return activeHero < numHeroes; }
        void NextHero() { ++activeHero; }
        bool BeforeFirstHero() const { return activeHero < 0; }
        void PreviousHero() { --activeHero; }
+       void SwapHeroes(int lhs, int rhs);
        Hero &ActiveHero() { return heroes[activeHero]; }
        const Hero &ActiveHero() const { return heroes[activeHero]; }
+
        Hero &HeroAt(int index) { return heroes[index]; }
        const Hero &HeroAt(int index) const { return heroes[index]; }
        Monster &MonsterAt(std::vector<Monster>::size_type index) { return monsters[index]; }
        const Monster &MonsterAt(std::vector<Monster>::size_type index) const { return monsters[index]; }
-       void SwapHeroes(int lhs, int rhs);
-       const HeroTag &ActiveHeroTag() const { return heroTags[activeHero]; }
+
        const HeroTag &HeroTagAt(int index) const { return heroTags[index]; }
        const geometry::Point<int> &HeroTagPositionAt(int index) const { return heroTagPositions[index]; }
+
        bool HasChosenAttackType() const { return attackChoices[activeHero].GetType() != AttackChoice::UNDECIDED; }
-       void SetAttackType(AttackChoice::Type t) { attackChoices[activeHero].SetType(t); }
        AttackChoice &ActiveHeroAttackChoice() { return attackChoices[activeHero]; }
        const AttackChoice &ActiveHeroAttackChoice() const { return attackChoices[activeHero]; }
        const AttackChoice &AttackChoiceAt(int index) const { return attackChoices[index]; }
-       TargetSelection &ActiveHeroTargets() { return attackChoices[activeHero].Selection(); }
-       const TargetSelection &ActiveHeroTargets() const { return attackChoices[activeHero].Selection(); }
        bool AttackSelectionDone() const { return activeHero >= numHeroes; }
 
-       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::Item *> &GetItemMenu() { return itemMenu; }
-       const graphics::Menu<const common::Item *> &GetItemMenu() const { return itemMenu; }
-
        const std::vector<geometry::Point<int> > &MonsterPositions() const { return monsterPositions; }
        bool MonsterPositionOccupied(int index) { return index >= 0 && index < int(monsters.size()) && monsters[index].Health() > 0; }
        const std::vector<geometry::Point<int> > &HeroesPositions() const { return heroesPositions; }
index b8d604d91a68dd28937a04f7668beb441c94fc91..17260928af9455b7a6aaa40468a4cd52276e0da5 100644 (file)
@@ -36,8 +36,8 @@ void SelectAttackType::ExitState(Application &c, SDL_Surface *screen) {
 }
 
 void SelectAttackType::ResumeState(Application &ctrl, SDL_Surface *screen) {
-       if (battle->ActiveHeroTargets().HasSelected()) {
-               battle->SetAttackType(battle->GetAttackTypeMenu().Selected());
+       if (battle->ActiveHeroAttackChoice().Selection().HasSelected()) {
+               battle->ActiveHeroAttackChoice().SetType(battle->GetAttackTypeMenu().Selected());
                battle->NextHero();
        }
        if (battle->AttackSelectionDone()) {
@@ -73,9 +73,9 @@ void SelectAttackType::HandleEvents(const Input &input) {
                switch (battle->GetAttackTypeMenu().Selected()) {
                        case AttackChoice::SWORD:
                                // TODO: detect single/multiple/all attack mode
-                               battle->ActiveHeroTargets().SetSingle();
-                               battle->ActiveHeroTargets().Reset();
-                               ctrl->PushState(new SelectTarget(battle, this, &battle->ActiveHeroTargets(), battle->Res().weaponTargetCursor));
+                               battle->ActiveHeroAttackChoice().Selection().SetSingle();
+                               battle->ActiveHeroAttackChoice().Selection().Reset();
+                               ctrl->PushState(new SelectTarget(battle, this, &battle->ActiveHeroAttackChoice().Selection(), battle->Res().weaponTargetCursor));
                                break;
                        case AttackChoice::MAGIC:
                                if (battle->ActiveHero().CanUseMagic()) {
@@ -83,7 +83,7 @@ void SelectAttackType::HandleEvents(const Input &input) {
                                }
                                break;
                        case AttackChoice::DEFEND:
-                               battle->SetAttackType(AttackChoice::DEFEND);
+                               battle->ActiveHeroAttackChoice().SetType(AttackChoice::DEFEND);
                                battle->NextHero();
                                break;
                        case AttackChoice::IKARI:
index 605ba2caef9ea52670ee5e898b4bea3bb29dab4a..97a951d7c82fea11a5f12d3e2eb4d99847127a1e 100644 (file)
@@ -36,8 +36,8 @@ void SelectIkari::ExitState(Application &c, SDL_Surface *screen) {
 }
 
 void SelectIkari::ResumeState(Application &ctrl, SDL_Surface *screen) {
-       if (battle->ActiveHeroTargets().HasSelected()) {
-               battle->SetAttackType(AttackChoice::IKARI);
+       if (battle->ActiveHeroAttackChoice().Selection().HasSelected()) {
+               battle->ActiveHeroAttackChoice().SetType(AttackChoice::IKARI);
                battle->ActiveHeroAttackChoice().SetItem(battle->GetIkariMenu().Selected());
                ctrl.PopState();
        }
@@ -57,25 +57,25 @@ void SelectIkari::HandleEvents(const Input &input) {
        if (input.JustPressed(Input::ACTION_A)) {
                if (battle->GetIkariMenu().SelectedIsEnabled() && battle->GetIkariMenu().Selected()->HasIkari()) {
                        const Ikari *ikari(battle->GetIkariMenu().Selected()->GetIkari());
-                       battle->ActiveHeroTargets().Reset();
+                       battle->ActiveHeroAttackChoice().Selection().Reset();
                        if (ikari->GetTargetingMode().TargetsAlly()) {
-                               battle->ActiveHeroTargets().SelectHeroes();
+                               battle->ActiveHeroAttackChoice().Selection().SelectHeroes();
                        } else {
-                               battle->ActiveHeroTargets().SelectEnemies();
+                               battle->ActiveHeroAttackChoice().Selection().SelectEnemies();
                        }
                        if (ikari->GetTargetingMode().TargetsAll()) {
-                               battle->SetAttackType(AttackChoice::MAGIC);
+                               battle->ActiveHeroAttackChoice().SetType(AttackChoice::MAGIC);
                                // TODO: remove item from inventory
                                battle->ActiveHeroAttackChoice().SetItem(battle->GetIkariMenu().Selected());
                                battle->NextHero();
                                ctrl->PopState();
                        } else {
                                if (ikari->GetTargetingMode().TargetsSingle()) {
-                                       battle->ActiveHeroTargets().SetSingle();
+                                       battle->ActiveHeroAttackChoice().Selection().SetSingle();
                                } else {
-                                       battle->ActiveHeroTargets().SetMultiple();
+                                       battle->ActiveHeroAttackChoice().Selection().SetMultiple();
                                }
-                               ctrl->PushState(new SelectTarget(battle, parent, &battle->ActiveHeroTargets(), ikari->IsMagical() ? battle->Res().magicTargetCursor : battle->Res().weaponTargetCursor));
+                               ctrl->PushState(new SelectTarget(battle, parent, &battle->ActiveHeroAttackChoice().Selection(), ikari->IsMagical() ? battle->Res().magicTargetCursor : battle->Res().weaponTargetCursor));
                        }
                }
        }
index a8c23bb763a9acaf9682dfd841044ae33d3bf8f6..22369f304252d6cf7ff82cae5e86bc738ebe2621 100644 (file)
@@ -35,8 +35,8 @@ void SelectItem::ExitState(Application &c, SDL_Surface *screen) {
 }
 
 void SelectItem::ResumeState(Application &ctrl, SDL_Surface *screen) {
-       if (battle->ActiveHeroTargets().HasSelected()) {
-               battle->SetAttackType(AttackChoice::ITEM);
+       if (battle->ActiveHeroAttackChoice().Selection().HasSelected()) {
+               battle->ActiveHeroAttackChoice().SetType(AttackChoice::ITEM);
                battle->ActiveHeroAttackChoice().SetItem(battle->GetItemMenu().Selected());
                ctrl.PopState();
        }
@@ -56,25 +56,25 @@ void SelectItem::HandleEvents(const Input &input) {
        if (input.JustPressed(Input::ACTION_A)) {
                if (battle->GetItemMenu().SelectedIsEnabled()) {
                        const Item *item(battle->GetItemMenu().Selected());
-                       battle->ActiveHeroTargets().Reset();
+                       battle->ActiveHeroAttackChoice().Selection().Reset();
                        if (item->GetTargetingMode().TargetsAlly()) {
-                               battle->ActiveHeroTargets().SelectHeroes();
+                               battle->ActiveHeroAttackChoice().Selection().SelectHeroes();
                        } else {
-                               battle->ActiveHeroTargets().SelectEnemies();
+                               battle->ActiveHeroAttackChoice().Selection().SelectEnemies();
                        }
                        if (item->GetTargetingMode().TargetsAll()) {
-                               battle->SetAttackType(AttackChoice::ITEM);
+                               battle->ActiveHeroAttackChoice().SetType(AttackChoice::ITEM);
                                // TODO: remove item from inventory
                                battle->ActiveHeroAttackChoice().SetItem(item);
                                battle->NextHero();
                                ctrl->PopState();
                        } else {
                                if (item->GetTargetingMode().TargetsSingle()) {
-                                       battle->ActiveHeroTargets().SetSingle();
+                                       battle->ActiveHeroAttackChoice().Selection().SetSingle();
                                } else {
-                                       battle->ActiveHeroTargets().SetMultiple();
+                                       battle->ActiveHeroAttackChoice().Selection().SetMultiple();
                                }
-                               ctrl->PushState(new SelectTarget(battle, parent, &battle->ActiveHeroTargets(), battle->Res().itemTargetCursor));
+                               ctrl->PushState(new SelectTarget(battle, parent, &battle->ActiveHeroAttackChoice().Selection(), battle->Res().itemTargetCursor));
                        }
                }
        }
index a9c06cceccc912ca59e3530ce361e52b7fbb2880..a13d8fc822e3596fecb99676f9f5b6212fd072e6 100644 (file)
@@ -36,8 +36,8 @@ void SelectSpell::ExitState(Application &c, SDL_Surface *screen) {
 }
 
 void SelectSpell::ResumeState(Application &ctrl, SDL_Surface *screen) {
-       if (battle->ActiveHeroTargets().HasSelected()) {
-               battle->SetAttackType(AttackChoice::MAGIC);
+       if (battle->ActiveHeroAttackChoice().Selection().HasSelected()) {
+               battle->ActiveHeroAttackChoice().SetType(AttackChoice::MAGIC);
                battle->ActiveHeroAttackChoice().SetSpell(battle->GetSpellMenu().Selected());
                ctrl.PopState();
        }
@@ -57,25 +57,25 @@ void SelectSpell::HandleEvents(const Input &input) {
        if (input.JustPressed(Input::ACTION_A)) {
                if (battle->GetSpellMenu().SelectedIsEnabled()) {
                        const Spell *spell(battle->GetSpellMenu().Selected());
-                       battle->ActiveHeroTargets().Reset();
+                       battle->ActiveHeroAttackChoice().Selection().Reset();
                        if (spell->GetTargetingMode().TargetsAlly()) {
-                               battle->ActiveHeroTargets().SelectHeroes();
+                               battle->ActiveHeroAttackChoice().Selection().SelectHeroes();
                        } else {
-                               battle->ActiveHeroTargets().SelectEnemies();
+                               battle->ActiveHeroAttackChoice().Selection().SelectEnemies();
                        }
                        if (spell->GetTargetingMode().TargetsAll()) {
-                               battle->SetAttackType(AttackChoice::MAGIC);
+                               battle->ActiveHeroAttackChoice().SetType(AttackChoice::MAGIC);
                                // TODO: remove item from inventory
                                battle->ActiveHeroAttackChoice().SetSpell(spell);
                                battle->NextHero();
                                ctrl->PopState();
                        } else {
                                if (spell->GetTargetingMode().TargetsSingle()) {
-                                       battle->ActiveHeroTargets().SetSingle();
+                                       battle->ActiveHeroAttackChoice().Selection().SetSingle();
                                } else {
-                                       battle->ActiveHeroTargets().SetMultiple();
+                                       battle->ActiveHeroAttackChoice().Selection().SetMultiple();
                                }
-                               ctrl->PushState(new SelectTarget(battle, parent, &battle->ActiveHeroTargets(), battle->Res().magicTargetCursor));
+                               ctrl->PushState(new SelectTarget(battle, parent, &battle->ActiveHeroAttackChoice().Selection(), battle->Res().magicTargetCursor));
                        }
                }
        }