]> git.localhorst.tv Git - l2e.git/commitdiff
removed redundant BattleState::ActiveHeroAttackChoice()
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 21 Aug 2012 19:14:04 +0000 (21:14 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 21 Aug 2012 19:14:04 +0000 (21:14 +0200)
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 e9eca69000c262ce599cfb578ef986d463039080..bac9647590917e4cdf9aa547a9e7f619a066f26c 100644 (file)
@@ -106,9 +106,7 @@ public:
        const HeroTag &HeroTagAt(int index) const { assert(index >= 0 && index < NumHeroes()); return heroTags[index]; }
        const geometry::Point<int> &HeroTagPositionAt(int index) const { assert(index >= 0 && index < NumHeroes()); return heroTagPositions[index]; }
 
-       bool HasChosenAttackType() const { return ActiveHeroAttackChoice().GetType() != AttackChoice::UNDECIDED; }
-       AttackChoice &ActiveHeroAttackChoice() { return AttackChoiceAt(activeHero); }
-       const AttackChoice &ActiveHeroAttackChoice() const { return AttackChoiceAt(activeHero); }
+       bool HasChosenAttackType() const { return ActiveHero().GetAttackChoice().GetType() != AttackChoice::UNDECIDED; }
        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]; }
index 3603e1bb529aeb7eb587e06c691037786ddcf925..4bac0bbe50cf1d8ebf7a827f042e14588bd304cb 100644 (file)
@@ -36,8 +36,8 @@ void SelectAttackType::ExitState(Application &c, SDL_Surface *screen) {
 }
 
 void SelectAttackType::ResumeState(Application &ctrl, SDL_Surface *screen) {
-       if (battle->ActiveHeroAttackChoice().Selection().HasSelected()) {
-               battle->ActiveHeroAttackChoice().SetType(battle->GetAttackTypeMenu().Selected());
+       if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
+               battle->ActiveHero().GetAttackChoice().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->ActiveHeroAttackChoice().Selection().SetSingle();
-                               battle->ActiveHeroAttackChoice().Selection().Reset();
-                               ctrl->PushState(new SelectTarget(battle, this, &battle->ActiveHeroAttackChoice().Selection(), battle->Res().weaponTargetCursor));
+                               battle->ActiveHero().GetAttackChoice().Selection().SetSingle();
+                               battle->ActiveHero().GetAttackChoice().Selection().Reset();
+                               ctrl->PushState(new SelectTarget(battle, this, &battle->ActiveHero().GetAttackChoice().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->ActiveHeroAttackChoice().SetType(AttackChoice::DEFEND);
+                               battle->ActiveHero().GetAttackChoice().SetType(AttackChoice::DEFEND);
                                battle->NextHero();
                                break;
                        case AttackChoice::IKARI:
@@ -96,12 +96,12 @@ void SelectAttackType::HandleEvents(const Input &input) {
                                throw std::logic_error("selected invalid attack type");
                }
        } else if (input.JustPressed(Input::ACTION_B)) {
-               battle->ActiveHeroAttackChoice().Reset();
+               battle->ActiveHero().GetAttackChoice().Reset();
                battle->PreviousHero();
                if (battle->BeforeFirstHero()) {
                        ctrl->ChangeState(new SelectMoveAction(battle));
                } else {
-                       battle->ActiveHeroAttackChoice().Reset();
+                       battle->ActiveHero().GetAttackChoice().Reset();
                }
        }
 
index 7ccfdc481aefa411c44339c7da9bb5d3fe0f2c80..d66f8b5458dff6fccd822a38d278e6b61ea5a776 100644 (file)
@@ -36,9 +36,9 @@ void SelectIkari::ExitState(Application &c, SDL_Surface *screen) {
 }
 
 void SelectIkari::ResumeState(Application &ctrl, SDL_Surface *screen) {
-       if (battle->ActiveHeroAttackChoice().Selection().HasSelected()) {
-               battle->ActiveHeroAttackChoice().SetType(AttackChoice::IKARI);
-               battle->ActiveHeroAttackChoice().SetItem(battle->GetIkariMenu().Selected());
+       if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
+               battle->ActiveHero().GetAttackChoice().SetType(AttackChoice::IKARI);
+               battle->ActiveHero().GetAttackChoice().SetItem(battle->GetIkariMenu().Selected());
                ctrl.PopState();
        }
 }
@@ -56,26 +56,27 @@ void SelectIkari::Resize(int width, int height) {
 void SelectIkari::HandleEvents(const Input &input) {
        if (input.JustPressed(Input::ACTION_A)) {
                if (battle->GetIkariMenu().SelectedIsEnabled() && battle->GetIkariMenu().Selected()->HasIkari()) {
+                       AttackChoice &ac(battle->ActiveHero().GetAttackChoice());
                        const Ikari *ikari(battle->GetIkariMenu().Selected()->GetIkari());
-                       battle->ActiveHeroAttackChoice().Selection().Reset();
+                       ac.Selection().Reset();
                        if (ikari->GetTargetingMode().TargetsAlly()) {
-                               battle->ActiveHeroAttackChoice().Selection().SelectHeroes();
+                               ac.Selection().SelectHeroes();
                        } else {
-                               battle->ActiveHeroAttackChoice().Selection().SelectEnemies();
+                               ac.Selection().SelectEnemies();
                        }
                        if (ikari->GetTargetingMode().TargetsAll()) {
-                               battle->ActiveHeroAttackChoice().SetType(AttackChoice::MAGIC);
+                               ac.SetType(AttackChoice::MAGIC);
                                // TODO: remove item from inventory
-                               battle->ActiveHeroAttackChoice().SetItem(battle->GetIkariMenu().Selected());
+                               ac.SetItem(battle->GetIkariMenu().Selected());
                                battle->NextHero();
                                ctrl->PopState();
                        } else {
                                if (ikari->GetTargetingMode().TargetsSingle()) {
-                                       battle->ActiveHeroAttackChoice().Selection().SetSingle();
+                                       ac.Selection().SetSingle();
                                } else {
-                                       battle->ActiveHeroAttackChoice().Selection().SetMultiple();
+                                       ac.Selection().SetMultiple();
                                }
-                               ctrl->PushState(new SelectTarget(battle, parent, &battle->ActiveHeroAttackChoice().Selection(), ikari->IsMagical() ? battle->Res().magicTargetCursor : battle->Res().weaponTargetCursor));
+                               ctrl->PushState(new SelectTarget(battle, parent, &ac.Selection(), ikari->IsMagical() ? battle->Res().magicTargetCursor : battle->Res().weaponTargetCursor));
                        }
                }
        }
index 0291b739c9c2746b5b17f6f72edf58fabb203f57..045f3cc6f09e6fc7561b0efa5c8cc7d613cd7284 100644 (file)
@@ -35,9 +35,9 @@ void SelectItem::ExitState(Application &c, SDL_Surface *screen) {
 }
 
 void SelectItem::ResumeState(Application &ctrl, SDL_Surface *screen) {
-       if (battle->ActiveHeroAttackChoice().Selection().HasSelected()) {
-               battle->ActiveHeroAttackChoice().SetType(AttackChoice::ITEM);
-               battle->ActiveHeroAttackChoice().SetItem(battle->GetItemMenu().Selected());
+       if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
+               battle->ActiveHero().GetAttackChoice().SetType(AttackChoice::ITEM);
+               battle->ActiveHero().GetAttackChoice().SetItem(battle->GetItemMenu().Selected());
                ctrl.PopState();
        }
 }
@@ -55,26 +55,27 @@ void SelectItem::Resize(int width, int height) {
 void SelectItem::HandleEvents(const Input &input) {
        if (input.JustPressed(Input::ACTION_A)) {
                if (battle->GetItemMenu().SelectedIsEnabled()) {
+                       AttackChoice &ac(battle->ActiveHero().GetAttackChoice());
                        const Item *item(battle->GetItemMenu().Selected());
-                       battle->ActiveHeroAttackChoice().Selection().Reset();
+                       ac.Selection().Reset();
                        if (item->GetTargetingMode().TargetsAlly()) {
-                               battle->ActiveHeroAttackChoice().Selection().SelectHeroes();
+                               ac.Selection().SelectHeroes();
                        } else {
-                               battle->ActiveHeroAttackChoice().Selection().SelectEnemies();
+                               ac.Selection().SelectEnemies();
                        }
                        if (item->GetTargetingMode().TargetsAll()) {
-                               battle->ActiveHeroAttackChoice().SetType(AttackChoice::ITEM);
+                               ac.SetType(AttackChoice::ITEM);
                                // TODO: remove item from inventory
-                               battle->ActiveHeroAttackChoice().SetItem(item);
+                               ac.SetItem(item);
                                battle->NextHero();
                                ctrl->PopState();
                        } else {
                                if (item->GetTargetingMode().TargetsSingle()) {
-                                       battle->ActiveHeroAttackChoice().Selection().SetSingle();
+                                       ac.Selection().SetSingle();
                                } else {
-                                       battle->ActiveHeroAttackChoice().Selection().SetMultiple();
+                                       ac.Selection().SetMultiple();
                                }
-                               ctrl->PushState(new SelectTarget(battle, parent, &battle->ActiveHeroAttackChoice().Selection(), battle->Res().itemTargetCursor));
+                               ctrl->PushState(new SelectTarget(battle, parent, &ac.Selection(), battle->Res().itemTargetCursor));
                        }
                }
        }
index f8b00e5b97cb53c8e651d071627813a3ee599ab8..3b4573f485f526f0ad80fcae5cf27d8b5552273e 100644 (file)
@@ -36,9 +36,9 @@ void SelectSpell::ExitState(Application &c, SDL_Surface *screen) {
 }
 
 void SelectSpell::ResumeState(Application &ctrl, SDL_Surface *screen) {
-       if (battle->ActiveHeroAttackChoice().Selection().HasSelected()) {
-               battle->ActiveHeroAttackChoice().SetType(AttackChoice::MAGIC);
-               battle->ActiveHeroAttackChoice().SetSpell(battle->GetSpellMenu().Selected());
+       if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
+               battle->ActiveHero().GetAttackChoice().SetType(AttackChoice::MAGIC);
+               battle->ActiveHero().GetAttackChoice().SetSpell(battle->GetSpellMenu().Selected());
                ctrl.PopState();
        }
 }
@@ -56,26 +56,27 @@ void SelectSpell::Resize(int width, int height) {
 void SelectSpell::HandleEvents(const Input &input) {
        if (input.JustPressed(Input::ACTION_A)) {
                if (battle->GetSpellMenu().SelectedIsEnabled()) {
+                       AttackChoice &ac(battle->ActiveHero().GetAttackChoice());
                        const Spell *spell(battle->GetSpellMenu().Selected());
-                       battle->ActiveHeroAttackChoice().Selection().Reset();
+                       ac.Selection().Reset();
                        if (spell->GetTargetingMode().TargetsAlly()) {
-                               battle->ActiveHeroAttackChoice().Selection().SelectHeroes();
+                               ac.Selection().SelectHeroes();
                        } else {
-                               battle->ActiveHeroAttackChoice().Selection().SelectEnemies();
+                               ac.Selection().SelectEnemies();
                        }
                        if (spell->GetTargetingMode().TargetsAll()) {
-                               battle->ActiveHeroAttackChoice().SetType(AttackChoice::MAGIC);
+                               ac.SetType(AttackChoice::MAGIC);
                                // TODO: remove item from inventory
-                               battle->ActiveHeroAttackChoice().SetSpell(spell);
+                               ac.SetSpell(spell);
                                battle->NextHero();
                                ctrl->PopState();
                        } else {
                                if (spell->GetTargetingMode().TargetsSingle()) {
-                                       battle->ActiveHeroAttackChoice().Selection().SetSingle();
+                                       ac.Selection().SetSingle();
                                } else {
-                                       battle->ActiveHeroAttackChoice().Selection().SetMultiple();
+                                       ac.Selection().SetMultiple();
                                }
-                               ctrl->PushState(new SelectTarget(battle, parent, &battle->ActiveHeroAttackChoice().Selection(), battle->Res().magicTargetCursor));
+                               ctrl->PushState(new SelectTarget(battle, parent, &ac.Selection(), battle->Res().magicTargetCursor));
                        }
                }
        }