From: Daniel Karbach Date: Sat, 11 Aug 2012 14:36:05 +0000 (+0200) Subject: reorganized BattleState's interface X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=e27fcf693589ede18b753d5f64f9dfecfe6344bd;p=l2e.git reorganized BattleState's interface …and more to come ;) --- diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index 978581f..cfec612 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -76,36 +76,35 @@ 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 &GetItemMenu() { return itemMenu; } + const graphics::Menu &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::size_type index) { return monsters[index]; } const Monster &MonsterAt(std::vector::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 &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 &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 &GetItemMenu() { return itemMenu; } - const graphics::Menu &GetItemMenu() const { return itemMenu; } - const std::vector > &MonsterPositions() const { return monsterPositions; } bool MonsterPositionOccupied(int index) { return index >= 0 && index < int(monsters.size()) && monsters[index].Health() > 0; } const std::vector > &HeroesPositions() const { return heroesPositions; } diff --git a/src/battle/states/SelectAttackType.cpp b/src/battle/states/SelectAttackType.cpp index b8d604d..1726092 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->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: diff --git a/src/battle/states/SelectIkari.cpp b/src/battle/states/SelectIkari.cpp index 605ba2c..97a951d 100644 --- a/src/battle/states/SelectIkari.cpp +++ b/src/battle/states/SelectIkari.cpp @@ -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)); } } } diff --git a/src/battle/states/SelectItem.cpp b/src/battle/states/SelectItem.cpp index a8c23bb..22369f3 100644 --- a/src/battle/states/SelectItem.cpp +++ b/src/battle/states/SelectItem.cpp @@ -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)); } } } diff --git a/src/battle/states/SelectSpell.cpp b/src/battle/states/SelectSpell.cpp index a9c06cc..a13d8fc 100644 --- a/src/battle/states/SelectSpell.cpp +++ b/src/battle/states/SelectSpell.cpp @@ -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)); } } }