#include "../BattleState.h"
#include "../../app/Application.h"
#include "../../app/Input.h"
-#include "../../geometry/operators.h"
+#include "../../common/Item.h"
#include <stdexcept>
using app::Application;
using app::Input;
-using geometry::Point;
+using common::Item;
using geometry::Vector;
namespace battle {
-void SelectAttackType::EnterState(Application &c, SDL_Surface *screen) {
+void SelectAttackType::OnEnterState(Application &c, SDL_Surface *screen) {
ctrl = &c;
}
-void SelectAttackType::ExitState(Application &c, SDL_Surface *screen) {
+void SelectAttackType::OnExitState(Application &c, SDL_Surface *screen) {
ctrl = 0;
}
-void SelectAttackType::ResumeState(Application &ctrl, SDL_Surface *screen) {
+void SelectAttackType::OnResumeState(Application &ctrl, SDL_Surface *screen) {
if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
battle->ActiveHero().GetAttackChoice().SetType(battle->GetAttackTypeMenu().Selected());
battle->NextHero();
}
}
-void SelectAttackType::PauseState(Application &ctrl, SDL_Surface *screen) {
+void SelectAttackType::OnPauseState(Application &ctrl, SDL_Surface *screen) {
}
-void SelectAttackType::Resize(int width, int height) {
+void SelectAttackType::OnResize(int width, int height) {
}
battle->GetAttackTypeMenu().Select(AttackChoice::SWORD);
}
+ Hero &hero(battle->ActiveHero());
+ AttackChoice &ac(hero.GetAttackChoice());
if (input.JustPressed(Input::ACTION_A)) {
switch (battle->GetAttackTypeMenu().Selected()) {
case AttackChoice::SWORD:
- // TODO: detect single/multiple/all attack mode
- battle->ActiveHero().GetAttackChoice().Selection().SetSingle();
- battle->ActiveHero().GetAttackChoice().Selection().Reset();
- ctrl->PushState(new SelectTarget(battle, this, &battle->ActiveHero().GetAttackChoice().Selection(), battle->Res().weaponTargetCursor));
+ 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()) {
}
break;
case AttackChoice::DEFEND:
- battle->ActiveHero().GetAttackChoice().SetType(AttackChoice::DEFEND);
+ ac.SetType(AttackChoice::DEFEND);
battle->NextHero();
break;
case AttackChoice::IKARI:
throw std::logic_error("selected invalid attack type");
}
} else if (input.JustPressed(Input::ACTION_B)) {
- battle->ActiveHero().GetAttackChoice().Reset();
+ ac.Reset();
battle->PreviousHero();
if (battle->BeforeFirstHero()) {
ctrl->ChangeState(new SelectMoveAction(battle));
}
void SelectAttackType::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
- Point<int> position(
+ Vector<int> position(
(battle->Width() - battle->GetAttackTypeMenu().Width()) / 2,
battle->Height() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2);
battle->GetAttackTypeMenu().Render(screen, position + offset);