namespace battle {
+void AttackChoice::Reset() {
+ thing = 0;
+ selection.Reset();
+ type = UNDECIDED;
+}
+
}
#include "TargetSelection.h"
+namespace common { class Item; }
+
namespace battle {
class AttackChoice {
};
public:
- explicit AttackChoice(BattleState *b = 0) : type(UNDECIDED), selection(b) { }
+ explicit AttackChoice(BattleState *b = 0) : thing(0), selection(b), type(UNDECIDED) { }
~AttackChoice() { }
public:
Type GetType() const { return type; }
void SetType(Type t) { type = t; }
+ const common::Item *GetItem() const { return (const common::Item *)thing; }
+ void SetItem(const common::Item *i) { thing = i; }
TargetSelection &Selection() { return selection; }
const TargetSelection &Selection() const { return selection; }
+ void Reset();
+
private:
- Type type;
+ const void *thing;
TargetSelection selection;
+ Type type;
};
const geometry::Point<int> &HeroTagPositionAt(std::vector<Hero>::size_type 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]; }
TargetSelection &ActiveHeroTargets() { return attackChoices[activeHero].Selection(); }
const TargetSelection &ActiveHeroTargets() const { return attackChoices[activeHero].Selection(); }
bool AttackSelectionDone() const { return activeHero >= (int) heroes.size(); }
// TODO: detect single/multiple/all attack mode
battle->ActiveHeroTargets().SetSingle();
battle->ActiveHeroTargets().Reset();
- ctrl->PushState(new SelectTarget(battle, this, &battle->ActiveHeroTargets(), battle->Res().weaponTargetCursor, true));
+ ctrl->PushState(new SelectTarget(battle, this, &battle->ActiveHeroTargets(), battle->Res().weaponTargetCursor));
break;
case AttackChoice::MAGIC:
if (battle->ActiveHero().CanUseMagic()) {
throw std::logic_error("selected invalid attack type");
}
} else if (input.JustPressed(Input::ACTION_B)) {
+ battle->ActiveHeroAttackChoice().Reset();
battle->PreviousHero();
if (battle->BeforeFirstHero()) {
ctrl->ChangeState(new SelectMoveAction(battle));
} else {
- battle->SetAttackType(AttackChoice::UNDECIDED);
+ battle->ActiveHeroAttackChoice().Reset();
}
}
#include "SelectItem.h"
#include "SelectAttackType.h"
+#include "SelectTarget.h"
#include "../BattleState.h"
#include "../../app/Application.h"
#include "../../app/Input.h"
+#include "../../common/Item.h"
#include "../../geometry/Point.h"
#include "../../geometry/operators.h"
#include "../../graphics/Frame.h"
using app::Application;
using app::Input;
+using common::Item;
using geometry::Point;
using geometry::Vector;
using graphics::Frame;
}
void SelectItem::ResumeState(Application &ctrl, SDL_Surface *screen) {
-
+ if (battle->ActiveHeroTargets().HasSelected()) {
+ ctrl.PopState();
+ }
}
void SelectItem::PauseState(Application &ctrl, SDL_Surface *screen) {
void SelectItem::HandleInput(const Input &input) {
if (input.JustPressed(Input::ACTION_A)) {
- // TODO: switch to target select
if (battle->GetItemMenu().SelectedIsEnabled()) {
- battle->SetAttackType(AttackChoice::ITEM);
- battle->NextHero();
- ctrl->PopState();
+ const Item *item(battle->GetItemMenu().Selected());
+ battle->ActiveHeroTargets().Reset();
+ if (item->TargetAlly()) {
+ battle->ActiveHeroTargets().SelectHeroes();
+ } else {
+ battle->ActiveHeroTargets().SelectEnemies();
+ }
+ if (item->TargetAll()) {
+ battle->SetAttackType(AttackChoice::ITEM);
+ // TODO: remove item from inventory
+ battle->ActiveHeroAttackChoice().SetItem(item);
+ battle->NextHero();
+ ctrl->PopState();
+ } else {
+ if (item->TargetOne()) {
+ battle->ActiveHeroTargets().SetSingle();
+ } else {
+ battle->ActiveHeroTargets().SetMultiple();
+ }
+ ctrl->PushState(new SelectTarget(battle, parent, &battle->ActiveHeroTargets(), battle->Res().itemTargetCursor));
+ }
+// battle->SetAttackType(AttackChoice::ITEM);
+// battle->NextHero();
+// ctrl->PopState();
}
}
if (input.JustPressed(Input::ACTION_B)) {
: public app::State {
public:
- SelectTarget(BattleState *battle, SelectAttackType *parent, TargetSelection *selection, const graphics::Sprite *cursorIcon, bool startWithEnemy)
+ SelectTarget(BattleState *battle, SelectAttackType *parent, TargetSelection *selection, const graphics::Sprite *cursorIcon)
: ctrl(0), battle(battle), parent(parent), selection(selection), cursorIcon(cursorIcon), flipFlop(true) { }
public:
void SetName(const char *n) { name = n; }
void SetMenuIcon(const graphics::Sprite *icon) { menuIcon = icon; }
void SetUsableInBattle() { usability |= USABILITY_BATTLE; }
+ void SetTargettingMode(int m) { targettingMode = m; }
-private:
+public:
enum Usability {
USABILITY_MOST_USEFUL = 1,
USABILITY_EQUIPABLE = 2,
SDL_Surface *targetingIconsImg(IMG_Load("test-data/targeting-icons.png"));
Sprite weaponTargetCursor(targetingIconsImg, 32, 32);
+ Sprite itemTargetCursor(targetingIconsImg, 32, 32, 0, 64);
battleRes.weaponTargetCursor = &weaponTargetCursor;
// TODO: add image for magic targeting cursor
battleRes.magicTargetCursor = &weaponTargetCursor;
// TODO: add image for item targeting cursor
- battleRes.itemTargetCursor = &weaponTargetCursor;
+ battleRes.itemTargetCursor = &itemTargetCursor;
battleRes.spellMenuHeadline = "Please choose a spell.";
battleRes.spellMenuPrototype = Menu</* Spell */ void *>(&normalFont, &disabledFont, &handCursorSprite, 12, 6, 8, 0, 2, 32);
antidote.SetName("Antidote");
antidote.SetMenuIcon(&potionIcon);
antidote.SetUsableInBattle();
+ antidote.SetTargettingMode(Item::TARGETTING_MODE_ALLY | Item::TARGETTING_MODE_ONE);
inventory.Add(&antidote, 9);
Item magicJar;
magicJar.SetName("Magic jar");
magicJar.SetMenuIcon(&potionIcon);
magicJar.SetUsableInBattle();
+ magicJar.SetTargettingMode(Item::TARGETTING_MODE_ALLY | Item::TARGETTING_MODE_ONE);
inventory.Add(&magicJar, 4);
Item hiPotion;
hiPotion.SetName("Hi-Potion");
hiPotion.SetMenuIcon(&potionIcon);
hiPotion.SetUsableInBattle();
+ hiPotion.SetTargettingMode(Item::TARGETTING_MODE_ALLY | Item::TARGETTING_MODE_ONE);
inventory.Add(&hiPotion, 4);
Item powerPotion;
powerPotion.SetName("Power potion");
sleepBall.SetName("Sleep ball");
sleepBall.SetMenuIcon(&ballIcon);
sleepBall.SetUsableInBattle();
+ sleepBall.SetTargettingMode(Item::TARGETTING_MODE_ENEMY | Item::TARGETTING_MODE_ONE);
inventory.Add(&sleepBall, 1);
+ Item multiBall;
+ multiBall.SetName("Multi-ball!");
+ multiBall.SetMenuIcon(&ballIcon);
+ multiBall.SetUsableInBattle();
+ multiBall.SetTargettingMode(Item::TARGETTING_MODE_ENEMY | Item::TARGETTING_MODE_MULTIPLE);
+ inventory.Add(&multiBall, 1);
Item figgoru;
figgoru.SetName("Figgoru");
figgoru.SetMenuIcon(&crankIcon);
+ figgoru.SetTargettingMode(Item::TARGETTING_MODE_ENEMY | Item::TARGETTING_MODE_ALL);
inventory.Add(&figgoru, 1);
battleRes.inventory = &inventory;