#include "PartyLayout.h"
#include "states/SelectMoveAction.h"
+#include "states/PerformAttacks.h"
#include "../app/Application.h"
#include "../app/Input.h"
#include "../common/Ikari.h"
#include "../geometry/operators.h"
#include "../graphics/Sprite.h"
+#include <algorithm>
#include <stdexcept>
using app::Application;
heroes.push_back(h);
}
+void BattleState::SwapHeroes(std::vector<Hero>::size_type lhs, std::vector<Hero>::size_type rhs) {
+ if (lhs < 0 || lhs >= heroes.size() || rhs < 0 || rhs >= heroes.size() || lhs == rhs) return;
+ std::swap(heroes[lhs], heroes[rhs]);
+}
+
void BattleState::Resize(int w, int h) {
LoadSpellMenu(i);
ikariMenus.push_back(res->ikariMenuPrototype);
LoadIkariMenu(i);
- heroTags[i] = HeroTag(&heroes[i], attackChoices + i, res, HeroTag::Alignment((i + 1) % 2));
+ heroTags[i] = HeroTag(this, i);
}
int tagHeight(attackTypeMenu.Height());
itemMenu.AddEmptyEntry();
}
}
+ ClearAllAttacks();
}
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) {
}
-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) {
}
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);
}
}