]> git.localhorst.tv Git - l2e.git/commitdiff
added item target selection
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 10 Aug 2012 10:46:41 +0000 (12:46 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 10 Aug 2012 10:46:41 +0000 (12:46 +0200)
src/battle/AttackChoice.cpp
src/battle/AttackChoice.h
src/battle/BattleState.h
src/battle/states/SelectAttackType.cpp
src/battle/states/SelectItem.cpp
src/battle/states/SelectTarget.h
src/common/Item.h
src/main.cpp
test-data/targeting-icons.png

index c966b5379043366fc513b73babbba97a0cb44378..5d3359b86523d373dcb9719b9074196bf8a746ff 100644 (file)
@@ -9,4 +9,10 @@
 
 namespace battle {
 
+void AttackChoice::Reset() {
+       thing = 0;
+       selection.Reset();
+       type = UNDECIDED;
+}
+
 }
index 0068e6f67e50049c1e751c7da9240bf6c1a7a499..42eb0d3c51c2b40bde00a98e788f34bfa7891169 100644 (file)
@@ -10,6 +10,8 @@
 
 #include "TargetSelection.h"
 
+namespace common { class Item; }
+
 namespace battle {
 
 class AttackChoice {
@@ -25,18 +27,23 @@ public:
        };
 
 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;
 
 };
 
index 3b293546382c1668a732eb80dff6eff64a26c500..1a0586c9025e31b42113468bc06c50e607517bfe 100644 (file)
@@ -86,6 +86,8 @@ public:
        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(); }
index 1039e513125432ed9c4c509889a17543ff6250a5..90d483ca693cd5018110252dddda6dd215262a20 100644 (file)
@@ -75,7 +75,7 @@ void SelectAttackType::HandleInput(const Input &input) {
                                // 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()) {
@@ -96,11 +96,12 @@ void SelectAttackType::HandleInput(const Input &input) {
                                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();
                }
        }
 
index 4f6c7af1eb049b4b6d0492132a823a4f0b0a22e4..a2d178eb251f83db906d7c662ddf34c3606c6322 100644 (file)
@@ -8,15 +8,18 @@
 #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;
@@ -32,7 +35,9 @@ void SelectItem::ExitState(Application &c, SDL_Surface *screen) {
 }
 
 void SelectItem::ResumeState(Application &ctrl, SDL_Surface *screen) {
-
+       if (battle->ActiveHeroTargets().HasSelected()) {
+               ctrl.PopState();
+       }
 }
 
 void SelectItem::PauseState(Application &ctrl, SDL_Surface *screen) {
@@ -47,11 +52,31 @@ void SelectItem::Resize(int width, int height) {
 
 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)) {
index b9085a5b51bc56951bb772d174fcb6b611e3fe03..f84dd3176abe6a8b6a4dd48752e7e192edaae46e 100644 (file)
@@ -24,7 +24,7 @@ class SelectTarget
 : 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:
index 2f662074c286e75b619a8d539899637fd96ba427..1dde8878f7c0d4f2dfe79fcd80e516ec150f4edd 100644 (file)
@@ -79,8 +79,9 @@ 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,
index 5e14001b8454e922348c7260ffd7bbdec9b1e95b..503c426512ee5aa565378177e2ac4a6a305e46ba 100644 (file)
@@ -197,11 +197,12 @@ int main(int argc, char **argv) {
 
                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);
@@ -244,16 +245,19 @@ int main(int argc, char **argv) {
                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");
@@ -266,10 +270,18 @@ int main(int argc, char **argv) {
                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;
 
index 64b32bf9f98a043edfd6c7a16f084938b3329b38..c0e56fa83adda1b1386bbf9564296876c24d65af 100644 (file)
Binary files a/test-data/targeting-icons.png and b/test-data/targeting-icons.png differ