From: Daniel Karbach Date: Fri, 10 Aug 2012 13:18:30 +0000 (+0200) Subject: added spell target select X-Git-Url: http://git.localhorst.tv/?a=commitdiff_plain;h=b6469d8a22e60335fd8d9304569e648310ddc399;p=l2e.git added spell target select --- diff --git a/src/battle/AttackChoice.h b/src/battle/AttackChoice.h index 42eb0d3..f365203 100644 --- a/src/battle/AttackChoice.h +++ b/src/battle/AttackChoice.h @@ -10,7 +10,10 @@ #include "TargetSelection.h" -namespace common { class Item; } +namespace common { + class Item; + class Spell; +} namespace battle { @@ -35,6 +38,8 @@ public: void SetType(Type t) { type = t; } const common::Item *GetItem() const { return (const common::Item *)thing; } void SetItem(const common::Item *i) { thing = i; } + const common::Spell *GetSpell() const { return (const common::Spell *)thing; } + void SetSpell(const common::Spell *s) { thing = s; } TargetSelection &Selection() { return selection; } const TargetSelection &Selection() const { return selection; } diff --git a/src/battle/states/SelectItem.cpp b/src/battle/states/SelectItem.cpp index 97dd63f..96def09 100644 --- a/src/battle/states/SelectItem.cpp +++ b/src/battle/states/SelectItem.cpp @@ -74,9 +74,6 @@ void SelectItem::HandleInput(const Input &input) { } 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)) { diff --git a/src/battle/states/SelectSpell.cpp b/src/battle/states/SelectSpell.cpp index db5bb45..62e7c46 100644 --- a/src/battle/states/SelectSpell.cpp +++ b/src/battle/states/SelectSpell.cpp @@ -9,15 +9,18 @@ #include "SelectAttackType.h" #include "SelectMoveAction.h" +#include "SelectTarget.h" #include "../BattleState.h" #include "../../app/Application.h" #include "../../app/Input.h" +#include "../../common/Spell.h" #include "../../geometry/operators.h" #include "../../geometry/Point.h" #include "../../graphics/Frame.h" using app::Application; using app::Input; +using common::Spell; using geometry::Point; using geometry::Vector; using graphics::Frame; @@ -33,7 +36,9 @@ void SelectSpell::ExitState(Application &c, SDL_Surface *screen) { } void SelectSpell::ResumeState(Application &ctrl, SDL_Surface *screen) { - + if (battle->ActiveHeroTargets().HasSelected()) { + ctrl.PopState(); + } } void SelectSpell::PauseState(Application &ctrl, SDL_Surface *screen) { @@ -48,11 +53,28 @@ void SelectSpell::Resize(int width, int height) { void SelectSpell::HandleInput(const Input &input) { if (input.JustPressed(Input::ACTION_A)) { - // TODO: switch to target select if (battle->GetSpellMenu().SelectedIsEnabled()) { - battle->SetAttackType(AttackChoice::MAGIC); - battle->NextHero(); - ctrl->PopState(); + const Spell *spell(battle->GetSpellMenu().Selected()); + battle->ActiveHeroTargets().Reset(); + if (spell->GetTargetingMode().TargetsAlly()) { + battle->ActiveHeroTargets().SelectHeroes(); + } else { + battle->ActiveHeroTargets().SelectEnemies(); + } + if (spell->GetTargetingMode().TargetsAll()) { + battle->SetAttackType(AttackChoice::MAGIC); + // TODO: remove item from inventory + battle->ActiveHeroAttackChoice().SetSpell(spell); + battle->NextHero(); + ctrl->PopState(); + } else { + if (spell->GetTargetingMode().TargetsSingle()) { + battle->ActiveHeroTargets().SetSingle(); + } else { + battle->ActiveHeroTargets().SetMultiple(); + } + ctrl->PushState(new SelectTarget(battle, parent, &battle->ActiveHeroTargets(), battle->Res().magicTargetCursor)); + } } } if (input.JustPressed(Input::ACTION_B)) { diff --git a/src/main.cpp b/src/main.cpp index 3c871cd..1289bde 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -199,10 +199,11 @@ int main(int argc, char **argv) { SDL_Surface *targetingIconsImg(IMG_Load("test-data/targeting-icons.png")); Sprite weaponTargetCursor(targetingIconsImg, 32, 32); + Sprite magicTargetCursor(targetingIconsImg, 32, 32, 0, 32); Sprite itemTargetCursor(targetingIconsImg, 32, 32, 0, 64); battleRes.weaponTargetCursor = &weaponTargetCursor; // TODO: add image for magic targeting cursor - battleRes.magicTargetCursor = &weaponTargetCursor; + battleRes.magicTargetCursor = &magicTargetCursor; // TODO: add image for item targeting cursor battleRes.itemTargetCursor = &itemTargetCursor; @@ -213,24 +214,28 @@ int main(int argc, char **argv) { strongSpell.SetName("Strong"); strongSpell.SetCost(3); strongSpell.SetUsableInBattle(); + strongSpell.GetTargetingMode().TargetMultipleAllies(); maxim.AddSpell(&strongSpell); selan.AddSpell(&strongSpell); Spell strongerSpell; strongerSpell.SetName("Stronger"); strongerSpell.SetCost(8); strongerSpell.SetUsableInBattle(); + strongerSpell.GetTargetingMode().TargetMultipleAllies(); maxim.AddSpell(&strongerSpell); selan.AddSpell(&strongerSpell); Spell championSpell; championSpell.SetName("Champion"); championSpell.SetCost(16); championSpell.SetUsableInBattle(); + championSpell.GetTargetingMode().TargetMultipleAllies(); maxim.AddSpell(&championSpell); selan.AddSpell(&championSpell); Spell rallySpell; rallySpell.SetName("Rally"); rallySpell.SetCost(10); rallySpell.SetUsableInBattle(); + rallySpell.GetTargetingMode().TargetMultipleAllies(); maxim.AddSpell(&rallySpell); selan.AddSpell(&rallySpell); Spell escapeSpell; @@ -241,23 +246,12 @@ int main(int argc, char **argv) { valorSpell.SetName("Valor"); valorSpell.SetCost(30); valorSpell.SetUsableInBattle(); + valorSpell.GetTargetingMode().TargetMultipleAllies(); maxim.AddSpell(&valorSpell); selan.AddSpell(&valorSpell); battleRes.spellMenuHeadline = "Please choose a spell."; battleRes.spellMenuPrototype = Menu(&normalFont, &disabledFont, &handCursorSprite, 9, 6, 8, 0, 2, 32, 2, ':'); - battleRes.spellMenuPrototype.Add("Poison : 2", 0); - battleRes.spellMenuPrototype.Add("Warp : 8", 0, false); - battleRes.spellMenuPrototype.Add("Release : 2", 0); - battleRes.spellMenuPrototype.Add("Waken : 4", 0); - battleRes.spellMenuPrototype.Add("Light : 0", 0, false); - battleRes.spellMenuPrototype.Add("Fake : 4", 0); - battleRes.spellMenuPrototype.Add("Trick : 5", 0); - battleRes.spellMenuPrototype.Add("Flash : 5", 0); - battleRes.spellMenuPrototype.Add("Fireball : 6", 0); - battleRes.spellMenuPrototype.Add("Vortex : 7", 0); - battleRes.spellMenuPrototype.Add("Blizzard : 8", 0); - battleRes.spellMenuPrototype.Add("Spark : 3", 0); SDL_Surface *itemIcons(IMG_Load("test-data/item-icons.png")); Sprite potionIcon(itemIcons, 16, 16);