]> git.localhorst.tv Git - l2e.git/commitdiff
moved spell and ikari menu initialization to Hero
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 21 Aug 2012 18:58:48 +0000 (20:58 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 21 Aug 2012 18:58:48 +0000 (20:58 +0200)
src/battle/BattleState.cpp
src/battle/BattleState.h
src/battle/Hero.cpp
src/battle/Hero.h

index b7017c98824246b1251d8431d7223ea31e98055b..65bdb9180b56e86dbff54a64a5f21f356f06f4e7 100644 (file)
@@ -75,9 +75,9 @@ void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
        heroesLayout->CalculatePositions(background->w, background->h, heroesPositions);
        for (int i(0); i < 4; ++i) {
                heroes[i].SpellMenu() = res->spellMenuPrototype;
-               LoadSpellMenu(i);
+               heroes[i].UpdateSpellMenu();
                heroes[i].IkariMenu() = res->ikariMenuPrototype;
-               LoadIkariMenu(i);
+               heroes[i].UpdateIkariMenu(res);
                heroTags[i] = HeroTag(this, i);
                smallHeroTags[i] = SmallHeroTag(this, i);
        }
@@ -103,94 +103,6 @@ void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
        LoadInventory();
 }
 
-void BattleState::LoadSpellMenu(vector<Hero>::size_type index) {
-       assert(index >= 0 && index < 4);
-       heroes[index].SpellMenu().Clear();
-       heroes[index].SpellMenu().Reserve(HeroAt(index).Spells().size());
-       for (vector<const Spell *>::const_iterator i(HeroAt(index).Spells().begin()), end(HeroAt(index).Spells().end()); i != end; ++i) {
-               bool enabled((*i)->CanUseInBattle() && (*i)->Cost() <= HeroAt(index).Mana());
-               heroes[index].SpellMenu().Add((*i)->Name(), *i, enabled, 0, (*i)->Cost());
-       }
-}
-
-void BattleState::LoadIkariMenu(vector<Hero>::size_type index) {
-       assert(index >= 0 && index < 4);
-       heroes[index].IkariMenu().Clear();
-       heroes[index].IkariMenu().Reserve(6);
-
-       if (HeroAt(index).HasWeapon()) {
-               heroes[index].IkariMenu().Add(
-                               HeroAt(index).Weapon()->Name(),
-                               HeroAt(index).Weapon(),
-                               HeroAt(index).Weapon()->HasIkari() && HeroAt(index).Weapon()->GetIkari()->Cost() <= HeroAt(index).IP(),
-                               res->weaponMenuIcon,
-                               0,
-                               HeroAt(index).Weapon()->HasIkari() ? HeroAt(index).Weapon()->GetIkari()->Name() : "");
-       } else {
-               heroes[index].IkariMenu().Add(res->noEquipmentText, 0, false, res->weaponMenuIcon);
-       }
-
-       if (HeroAt(index).HasArmor()) {
-               heroes[index].IkariMenu().Add(
-                               HeroAt(index).Armor()->Name(),
-                               HeroAt(index).Armor(),
-                               HeroAt(index).Armor()->HasIkari() && HeroAt(index).Armor()->GetIkari()->Cost() <= HeroAt(index).IP(),
-                               res->armorMenuIcon,
-                               0,
-                               HeroAt(index).Armor()->HasIkari() ? HeroAt(index).Armor()->GetIkari()->Name() : "");
-       } else {
-               heroes[index].IkariMenu().Add(res->noEquipmentText, 0, false, res->armorMenuIcon);
-       }
-
-       if (HeroAt(index).HasShield()) {
-               heroes[index].IkariMenu().Add(
-                               HeroAt(index).Shield()->Name(),
-                               HeroAt(index).Shield(),
-                               HeroAt(index).Shield()->HasIkari() && HeroAt(index).Shield()->GetIkari()->Cost() <= HeroAt(index).IP(),
-                               res->shieldMenuIcon,
-                               0,
-                               HeroAt(index).Shield()->HasIkari() ? HeroAt(index).Shield()->GetIkari()->Name() : "");
-       } else {
-               heroes[index].IkariMenu().Add(res->noEquipmentText, 0, false, res->shieldMenuIcon);
-       }
-
-       if (HeroAt(index).HasHelmet()) {
-               heroes[index].IkariMenu().Add(
-                               HeroAt(index).Helmet()->Name(),
-                               HeroAt(index).Helmet(),
-                               HeroAt(index).Helmet()->HasIkari() && HeroAt(index).Helmet()->GetIkari()->Cost() <= HeroAt(index).IP(),
-                               res->helmetMenuIcon,
-                               0,
-                               HeroAt(index).Helmet()->HasIkari() ? HeroAt(index).Helmet()->GetIkari()->Name() : "");
-       } else {
-               heroes[index].IkariMenu().Add(res->noEquipmentText, 0, false, res->helmetMenuIcon);
-       }
-
-       if (HeroAt(index).HasRing()) {
-               heroes[index].IkariMenu().Add(
-                               HeroAt(index).Ring()->Name(),
-                               HeroAt(index).Ring(),
-                               HeroAt(index).Ring()->HasIkari() && HeroAt(index).Ring()->GetIkari()->Cost() <= HeroAt(index).IP(),
-                               res->ringMenuIcon,
-                               0,
-                               HeroAt(index).Ring()->HasIkari() ? HeroAt(index).Ring()->GetIkari()->Name() : "");
-       } else {
-               heroes[index].IkariMenu().Add(res->noEquipmentText, 0, false, res->ringMenuIcon);
-       }
-
-       if (HeroAt(index).HasJewel()) {
-               heroes[index].IkariMenu().Add(
-                               HeroAt(index).Jewel()->Name(),
-                               HeroAt(index).Jewel(),
-                               HeroAt(index).Jewel()->HasIkari() && HeroAt(index).Jewel()->GetIkari()->Cost() <= HeroAt(index).IP(),
-                               res->jewelMenuIcon,
-                               0,
-                               HeroAt(index).Jewel()->HasIkari() ? HeroAt(index).Jewel()->GetIkari()->Name() : "");
-       } else {
-               heroes[index].IkariMenu().Add(res->noEquipmentText, 0, false, res->jewelMenuIcon);
-       }
-}
-
 void BattleState::LoadInventory() {
        const Inventory &inv(*res->inventory);
        itemMenu.Clear();
index a4f403741e5dd72dfcbe731072a09feecccb8e16..3561609e91c105a34413a8b29d042d7d1a0c50ce 100644 (file)
@@ -161,8 +161,6 @@ public:
        void RenderSmallHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
 
 private:
-       void LoadSpellMenu(std::vector<Hero>::size_type heroIndex);
-       void LoadIkariMenu(std::vector<Hero>::size_type heroIndex);
        void LoadInventory();
 
        Uint16 CalculateDamage(const Stats &attacker, const Stats &defender) const;
index a3361c6045e0e368bfcbde718d51e80cfcde96ea..17ec08a2bbc8316abd84fadb827d02f087d80745 100644 (file)
@@ -7,6 +7,16 @@
 
 #include "Hero.h"
 
+#include "AttackChoice.h"
+#include "Resources.h"
+#include "../common/Ikari.h"
+#include "../common/Item.h"
+#include "../common/Spell.h"
+
+using common::Ikari;
+using common::Spell;
+using std::vector;
+
 namespace battle {
 
 Hero::Hero()
@@ -53,4 +63,91 @@ void Hero::SubtractHealth(int amount) {
        }
 }
 
+
+void Hero::UpdateSpellMenu() {
+       SpellMenu().Clear();
+       SpellMenu().Reserve(Spells().size());
+       for (vector<const Spell *>::const_iterator i(Spells().begin()), end(Spells().end()); i != end; ++i) {
+               bool enabled((*i)->CanUseInBattle() && (*i)->Cost() <= Mana());
+               SpellMenu().Add((*i)->Name(), *i, enabled, 0, (*i)->Cost());
+       }
+}
+
+void Hero::UpdateIkariMenu(const Resources *res) {
+       IkariMenu().Clear();
+       IkariMenu().Reserve(6);
+
+       if (HasWeapon()) {
+               IkariMenu().Add(
+                               Weapon()->Name(),
+                               Weapon(),
+                               Weapon()->HasIkari() && Weapon()->GetIkari()->Cost() <= IP(),
+                               res->weaponMenuIcon,
+                               0,
+                               Weapon()->HasIkari() ? Weapon()->GetIkari()->Name() : "");
+       } else {
+               IkariMenu().Add(res->noEquipmentText, 0, false, res->weaponMenuIcon);
+       }
+
+       if (HasArmor()) {
+               IkariMenu().Add(
+                               Armor()->Name(),
+                               Armor(),
+                               Armor()->HasIkari() && Armor()->GetIkari()->Cost() <= IP(),
+                               res->armorMenuIcon,
+                               0,
+                               Armor()->HasIkari() ? Armor()->GetIkari()->Name() : "");
+       } else {
+               IkariMenu().Add(res->noEquipmentText, 0, false, res->armorMenuIcon);
+       }
+
+       if (HasShield()) {
+               IkariMenu().Add(
+                               Shield()->Name(),
+                               Shield(),
+                               Shield()->HasIkari() && Shield()->GetIkari()->Cost() <= IP(),
+                               res->shieldMenuIcon,
+                               0,
+                               Shield()->HasIkari() ? Shield()->GetIkari()->Name() : "");
+       } else {
+               IkariMenu().Add(res->noEquipmentText, 0, false, res->shieldMenuIcon);
+       }
+
+       if (HasHelmet()) {
+               IkariMenu().Add(
+                               Helmet()->Name(),
+                               Helmet(),
+                               Helmet()->HasIkari() && Helmet()->GetIkari()->Cost() <= IP(),
+                               res->helmetMenuIcon,
+                               0,
+                               Helmet()->HasIkari() ? Helmet()->GetIkari()->Name() : "");
+       } else {
+               IkariMenu().Add(res->noEquipmentText, 0, false, res->helmetMenuIcon);
+       }
+
+       if (HasRing()) {
+               IkariMenu().Add(
+                               Ring()->Name(),
+                               Ring(),
+                               Ring()->HasIkari() && Ring()->GetIkari()->Cost() <= IP(),
+                               res->ringMenuIcon,
+                               0,
+                               Ring()->HasIkari() ? Ring()->GetIkari()->Name() : "");
+       } else {
+               IkariMenu().Add(res->noEquipmentText, 0, false, res->ringMenuIcon);
+       }
+
+       if (HasJewel()) {
+               IkariMenu().Add(
+                               Jewel()->Name(),
+                               Jewel(),
+                               Jewel()->HasIkari() && Jewel()->GetIkari()->Cost() <= IP(),
+                               res->jewelMenuIcon,
+                               0,
+                               Jewel()->HasIkari() ? Jewel()->GetIkari()->Name() : "");
+       } else {
+               IkariMenu().Add(res->noEquipmentText, 0, false, res->jewelMenuIcon);
+       }
+}
+
 }
index 275db6da22a160ef1cf8c4815ad55a0da7145248..44d0b4d0c3372dc9a4f320965c4cf3f06b757b72 100644 (file)
@@ -26,6 +26,8 @@ namespace graphics {
 
 namespace battle {
 
+class Resources;
+
 class Hero {
 
 public:
@@ -93,6 +95,10 @@ public:
        AttackChoice &GetAttackChoice() { return attackChoice; }
        const AttackChoice &GetAttackChoice() const { return attackChoice; }
 
+public:
+       void UpdateSpellMenu();
+       void UpdateIkariMenu(const Resources *);
+
 // temporary setters until loader is implemented
 public:
        void SetName(const char *n) { name = n; }