]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/BattleState.cpp
added spells
[l2e.git] / src / battle / BattleState.cpp
index ad225173fce209625a452265c0913cf5b1d9adda..c54fecaca88dd10acdb79ff16b597fe82a6d7cf5 100644 (file)
@@ -13,6 +13,7 @@
 #include "../app/Input.h"
 #include "../common/Inventory.h"
 #include "../common/Item.h"
+#include "../common/Spell.h"
 #include "../geometry/operators.h"
 #include "../graphics/Sprite.h"
 
@@ -22,6 +23,7 @@ using app::Application;
 using app::Input;
 using common::Inventory;
 using common::Item;
+using common::Spell;
 using geometry::Point;
 using geometry::Vector;
 using graphics::Menu;
@@ -55,7 +57,7 @@ void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
        heroesLayout->CalculatePositions(background->w, background->h, heroesPositions);
        for (vector<Hero>::size_type i(0), end(heroes.size()); i < end; ++i) {
                spellMenus.push_back(res->spellMenuPrototype);
-               // TODO: insert spell menu entries
+               LoadSpellMenu(i);
                ikariMenus.push_back(res->ikariMenuPrototype);
                // TODO: insert ikari menu entries
                heroTags[i] = HeroTag(&heroes[i], attackChoices + i, res, HeroTag::Alignment((i + 1) % 2));
@@ -74,6 +76,15 @@ void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
        LoadInventory();
 }
 
+void BattleState::LoadSpellMenu(vector<Hero>::size_type index) {
+       spellMenus[index].Clear();
+       spellMenus[index].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());
+               spellMenus[index].Add((*i)->Name(), *i, enabled, 0, (*i)->Cost());
+       }
+}
+
 void BattleState::LoadInventory() {
        const Inventory &inv(*res->inventory);
        itemMenu.Clear();