- // TODO: this should not push a state while quitting
- if (AttackSelectionDone()) {
- ctrl.PushState(new PerformAttacks(this));
- } else {
- ctrl.PushState(new SelectMoveAction(this));
- }
-}
-
-bool BattleState::Victory() const {
- for (int i(0); i < MaxMonsters(); ++i) {
- if (MonsterAt(i).Health() > 0) return false;
- }
- return true;
-}
-
-bool BattleState::Defeat() const {
- for (int i(0); i < NumHeroes(); ++i) {
- if (HeroAt(i).Health() > 0) return false;
- }
- return true;
-}
-
-void BattleState::PauseState(Application &ctrl, SDL_Surface *screen) {
-
-}
-
-
-class OrderCompare {
- public:
- OrderCompare(BattleState *battle) : battle(battle) { }
- bool operator ()(const BattleState::Order &lhs, const BattleState::Order &rhs) {
- int lagl(lhs.isMonster ? battle->MonsterAt(lhs.index).GetStats().Agility() : battle->HeroAt(lhs.index).GetStats().Agility());
- int ragl(rhs.isMonster ? battle->MonsterAt(rhs.index).GetStats().Agility() : battle->HeroAt(rhs.index).GetStats().Agility());
- return lagl > ragl;
- }
- private:
- BattleState *battle;
-};
-
-void BattleState::CalculateAttackOrder() {
- attackOrder.reserve(monsters.size() + NumHeroes());
- for (int i(0); i < NumHeroes(); ++i) {
- attackOrder.push_back(Order(i, false));
- }
- for (vector<Monster>::size_type i(0), end(monsters.size()); i < end; ++i) {
- attackOrder.push_back(Order(i, true));
- MonsterAt(i).GetAttackChoice() = AttackChoice(this);
- }
- std::sort(attackOrder.begin(), attackOrder.end(), OrderCompare(this));
-}
-
-void BattleState::NextAttack() {
- if (Victory() || Defeat()) {
- attackCursor = attackOrder.size();
- return;
- }
- ++attackCursor;
- while (attackCursor < int(attackOrder.size())) {
- if (attackOrder[attackCursor].isMonster) {
- if (MonsterAt(attackOrder[attackCursor].index).Health() > 0) break;