X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FSelectAttackType.cpp;h=f4a107e881afcd1f9e4f52bafa0acc4b1a9861f8;hb=092a2dd175a4001a495c84ee85211734fb928c83;hp=c5e0bba3b580ebcd20886fed04996f54f590b130;hpb=57675025108b7ad3989737f18ebfeec8e5e44889;p=l2e.git diff --git a/src/battle/states/SelectAttackType.cpp b/src/battle/states/SelectAttackType.cpp index c5e0bba..f4a107e 100644 --- a/src/battle/states/SelectAttackType.cpp +++ b/src/battle/states/SelectAttackType.cpp @@ -7,50 +7,57 @@ #include "SelectAttackType.h" +#include "SelectIkari.h" #include "SelectItem.h" #include "SelectMoveAction.h" #include "SelectSpell.h" +#include "SelectTarget.h" #include "../AttackChoice.h" #include "../BattleState.h" #include "../../app/Application.h" #include "../../app/Input.h" -#include "../../geometry/operators.h" +#include "../../common/Item.h" +#include "../../math/Vector.h" #include using app::Application; using app::Input; -using geometry::Point; -using geometry::Vector; +using common::Item; +using math::Vector; namespace battle { -void SelectAttackType::EnterState(Application &c, SDL_Surface *screen) { - ctrl = &c; +void SelectAttackType::OnEnterState(SDL_Surface *screen) { + } -void SelectAttackType::ExitState(Application &c, SDL_Surface *screen) { - ctrl = 0; +void SelectAttackType::OnExitState(SDL_Surface *screen) { + } -void SelectAttackType::ResumeState(Application &ctrl, SDL_Surface *screen) { +void SelectAttackType::OnResumeState(SDL_Surface *screen) { + if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) { + battle->ActiveHero().GetAttackChoice().SetType(battle->GetAttackTypeMenu().Selected()); + battle->NextHero(); + } if (battle->AttackSelectionDone()) { // pass through - ctrl.PopState(); + Ctrl().PopState(); } } -void SelectAttackType::PauseState(Application &ctrl, SDL_Surface *screen) { +void SelectAttackType::OnPauseState(SDL_Surface *screen) { } -void SelectAttackType::Resize(int width, int height) { +void SelectAttackType::OnResize(int width, int height) { } -void SelectAttackType::HandleInput(const Input &input) { +void SelectAttackType::HandleEvents(const Input &input) { if (input.IsDown(Input::PAD_UP)) { battle->GetAttackTypeMenu().Select(AttackChoice::MAGIC); } else if (input.IsDown(Input::PAD_RIGHT)) { @@ -63,46 +70,59 @@ void SelectAttackType::HandleInput(const Input &input) { battle->GetAttackTypeMenu().Select(AttackChoice::SWORD); } + Hero &hero(battle->ActiveHero()); + AttackChoice &ac(hero.GetAttackChoice()); if (input.JustPressed(Input::ACTION_A)) { - battle->SetAttackType(battle->GetAttackTypeMenu().Selected()); switch (battle->GetAttackTypeMenu().Selected()) { case AttackChoice::SWORD: - // TODO: switch to target select - battle->NextHero(); + if (hero.HasWeapon()) { + if (hero.Weapon()->GetTargetingMode().TargetsAll()) { + ac.SetType(AttackChoice::SWORD); + battle->NextHero(); + break; + } else { + ac.Selection().ReadMode(hero.Weapon()->GetTargetingMode()); + } + } else { + ac.Selection().SetSingle(); + } + ac.Selection().Reset(); + Ctrl().PushState(new SelectTarget(battle, this, &ac.Selection(), battle->Res().weaponTargetCursor)); break; case AttackChoice::MAGIC: if (battle->ActiveHero().CanUseMagic()) { - ctrl->PushState(new SelectSpell(battle, this)); + Ctrl().PushState(new SelectSpell(battle, this)); } break; case AttackChoice::DEFEND: + ac.SetType(AttackChoice::DEFEND); battle->NextHero(); break; case AttackChoice::IKARI: - // TODO: switch to ikari attack select - battle->NextHero(); + Ctrl().PushState(new SelectIkari(battle, this)); break; case AttackChoice::ITEM: - ctrl->PushState(new SelectItem(battle, this)); + Ctrl().PushState(new SelectItem(battle, this)); break; default: throw std::logic_error("selected invalid attack type"); } } else if (input.JustPressed(Input::ACTION_B)) { - battle->SetAttackType(AttackChoice::UNDECIDED); + ac.Reset(); battle->PreviousHero(); if (battle->BeforeFirstHero()) { - ctrl->ChangeState(new SelectMoveAction(battle)); + Ctrl().ChangeState(new SelectMoveAction(battle)); + } else { + battle->ActiveHero().GetAttackChoice().Reset(); } } if (battle->AttackSelectionDone()) { - // TODO: switch to battle animation instead - ctrl->PopState(); + Ctrl().PopState(); } } -void SelectAttackType::UpdateWorld(float deltaT) { +void SelectAttackType::UpdateWorld(Uint32 deltaT) { } @@ -115,9 +135,9 @@ void SelectAttackType::Render(SDL_Surface *screen) { } void SelectAttackType::RenderMenu(SDL_Surface *screen, const Vector &offset) { - Point position( - (battle->BackgroundWidth() - battle->GetAttackTypeMenu().Width()) / 2, - battle->BackgroundHeight() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2); + Vector position( + (battle->Width() - battle->GetAttackTypeMenu().Width()) / 2, + battle->Height() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2); battle->GetAttackTypeMenu().Render(screen, position + offset); }