From: Daniel Karbach Date: Tue, 21 Aug 2012 19:14:04 +0000 (+0200) Subject: removed redundant BattleState::ActiveHeroAttackChoice() X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=2147d00bbcb43f5cb4499091f646057cb6944cb3;p=l2e.git removed redundant BattleState::ActiveHeroAttackChoice() --- diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index e9eca69..bac9647 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -106,9 +106,7 @@ public: const HeroTag &HeroTagAt(int index) const { assert(index >= 0 && index < NumHeroes()); return heroTags[index]; } const geometry::Point &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]; } diff --git a/src/battle/states/SelectAttackType.cpp b/src/battle/states/SelectAttackType.cpp index 3603e1b..4bac0bb 100644 --- a/src/battle/states/SelectAttackType.cpp +++ b/src/battle/states/SelectAttackType.cpp @@ -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(); } } diff --git a/src/battle/states/SelectIkari.cpp b/src/battle/states/SelectIkari.cpp index 7ccfdc4..d66f8b5 100644 --- a/src/battle/states/SelectIkari.cpp +++ b/src/battle/states/SelectIkari.cpp @@ -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)); } } } diff --git a/src/battle/states/SelectItem.cpp b/src/battle/states/SelectItem.cpp index 0291b73..045f3cc 100644 --- a/src/battle/states/SelectItem.cpp +++ b/src/battle/states/SelectItem.cpp @@ -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)); } } } diff --git a/src/battle/states/SelectSpell.cpp b/src/battle/states/SelectSpell.cpp index f8b00e5..3b4573f 100644 --- a/src/battle/states/SelectSpell.cpp +++ b/src/battle/states/SelectSpell.cpp @@ -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)); } } }