]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/BattleState.cpp
turned battle's menu vectors into arrays
[l2e.git] / src / battle / BattleState.cpp
index cbea81a82cb5d1564344abe6e24d757bbca70d0e..9e84206b3908dde82be2eba8fec5da82bf4e8661 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "PartyLayout.h"
 #include "states/SelectMoveAction.h"
+#include "states/PerformAttacks.h"
 #include "../app/Application.h"
 #include "../app/Input.h"
 #include "../common/Ikari.h"
@@ -63,9 +64,9 @@ void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
        monstersLayout->CalculatePositions(background->w, background->h, monsterPositions);
        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);
+               spellMenus[i] = res->spellMenuPrototype;
                LoadSpellMenu(i);
-               ikariMenus.push_back(res->ikariMenuPrototype);
+               ikariMenus[i] = res->ikariMenuPrototype;
                LoadIkariMenu(i);
                heroTags[i] = HeroTag(this, i);
        }
@@ -180,6 +181,7 @@ void BattleState::LoadInventory() {
                        itemMenu.AddEmptyEntry();
                }
        }
+       ClearAllAttacks();
 }
 
 void BattleState::ExitState(Application &ctrl, SDL_Surface *screen) {
@@ -187,13 +189,16 @@ void BattleState::ExitState(Application &ctrl, SDL_Surface *screen) {
 }
 
 void BattleState::ResumeState(Application &ctrl, SDL_Surface *screen) {
-       // TODO: check for victory, defeat or run
-       // reset attack choices
-       activeHero = -1;
-       for (vector<Hero>::size_type i(0), end(heroes.size()); i < end; ++i) {
-               attackChoices[i] = AttackChoice(this);
+       // TODO: check for victory or defeat
+       if (ranAway) {
+               ctrl.PopState(); // quit the battle scene
+               return;
+       }
+       if (AttackSelectionDone()) {
+               ctrl.PushState(new PerformAttacks(this));
+       } else {
+               ctrl.PushState(new SelectMoveAction(this));
        }
-       ctrl.PushState(new SelectMoveAction(this));
 }
 
 void BattleState::PauseState(Application &ctrl, SDL_Surface *screen) {
@@ -201,7 +206,15 @@ void BattleState::PauseState(Application &ctrl, SDL_Surface *screen) {
 }
 
 
-void BattleState::HandleInput(const Input &input) {
+void BattleState::ClearAllAttacks() {
+       activeHero = -1;
+       for (vector<Hero>::size_type i(0), end(heroes.size()); i < end; ++i) {
+               attackChoices[i] = AttackChoice(this);
+       }
+}
+
+
+void BattleState::HandleEvents(const Input &input) {
 
 }
 
@@ -237,7 +250,7 @@ void BattleState::RenderMonsters(SDL_Surface *screen, const Vector<int> &offset)
 
 void BattleState::RenderHeroes(SDL_Surface *screen, const Vector<int> &offset) {
        for (vector<Hero>::size_type i(0), end(heroes.size()); i < end; ++i) {
-               heroes[i].Sprite()->DrawCenterBottom(screen, heroesPositions[i] + offset);
+               heroes[i].Sprite()->DrawCenterBottom(screen, heroesPositions[i] + offset, 0, 1);
        }
 }