]> git.localhorst.tv Git - l2e.git/commitdiff
added target selection type detection for weapons
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 21 Aug 2012 21:27:32 +0000 (23:27 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 21 Aug 2012 21:27:32 +0000 (23:27 +0200)
src/battle/TargetSelection.cpp
src/battle/TargetSelection.h
src/battle/states/SelectAttackType.cpp

index 1906c2bb7960ac4b1804300c34d8d498fb3cf8fc..5fbf78525d21d1318b636b5b63beb6f756c57c5c 100644 (file)
@@ -8,6 +8,7 @@
 #include "TargetSelection.h"
 
 #include "BattleState.h"
+#include "../common/TargetingMode.h"
 
 namespace battle {
 
@@ -23,6 +24,21 @@ TargetSelection::TargetSelection(BattleState *battle, bool multiple, bool atEnem
        }
 }
 
+
+void TargetSelection::ReadMode(const common::TargetingMode &tm) {
+       if (tm.TargetsEnemy()) {
+               SelectEnemies();
+       } else {
+               SelectHeroes();
+       }
+       if (tm.TargetsSingle()) {
+               SelectSingle();
+       } else if (tm.TargetsMultiple()) {
+               SelectMultiple();
+       }
+}
+
+
 void TargetSelection::SelectEnemies() {
        if (TargetsEnemies()) return;
        enemy = true;
index 70c95b52a469ad9f5280aa1ed554ba911c7fbe8a..b57a41df26c5d3ab80bd772b876f07221185cb02 100644 (file)
@@ -10,6 +10,8 @@
 
 #include <vector>
 
+namespace common { class TargetingMode; }
+
 namespace battle {
 
 class BattleState;
@@ -31,6 +33,8 @@ public:
        bool SelectSingle() const { return !SelectMultiple(); }
        void SetSingle() { multiple = false; }
 
+       void ReadMode(const common::TargetingMode &);
+
        void SelectEnemies();
        void SelectHeroes();
        void Select(int index) { selected[index].type = State::SELECTED; selection = index; }
index 4bac0bbe50cf1d8ebf7a827f042e14588bd304cb..a6e288afdd306f0ea2b29e2601f419c9cc75b575 100644 (file)
 #include "../BattleState.h"
 #include "../../app/Application.h"
 #include "../../app/Input.h"
+#include "../../common/Item.h"
 #include "../../geometry/operators.h"
 
 #include <stdexcept>
 
 using app::Application;
 using app::Input;
+using common::Item;
 using geometry::Point;
 using geometry::Vector;
 
@@ -69,21 +71,33 @@ void SelectAttackType::HandleEvents(const Input &input) {
                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:
+                               // TODO: detect single/multiple/all attack mode
                                if (battle->ActiveHero().CanUseMagic()) {
                                        ctrl->PushState(new SelectSpell(battle, this));
                                }
                                break;
                        case AttackChoice::DEFEND:
-                               battle->ActiveHero().GetAttackChoice().SetType(AttackChoice::DEFEND);
+                               ac.SetType(AttackChoice::DEFEND);
                                battle->NextHero();
                                break;
                        case AttackChoice::IKARI:
@@ -96,12 +110,12 @@ void SelectAttackType::HandleEvents(const Input &input) {
                                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));
                } else {
-                       battle->ActiveHero().GetAttackChoice().Reset();
+                       ac.Reset();
                }
        }