+ attackOrder.push_back(Order(i, true));
+ }
+ std::sort(attackOrder.begin(), attackOrder.end(), OrderCompare(this));
+
+ monsterAttacks.resize(monsters.size(), AttackChoice(this));
+}
+
+void BattleState::NextAttack() {
+ ++attackCursor;
+ while (attackCursor < int(attackOrder.size())) {
+ if (attackOrder[attackCursor].isMonster) {
+ if (MonsterAt(attackOrder[attackCursor].index).Health() > 0) break;
+ } else {
+ if (HeroAt(attackOrder[attackCursor].index).Health() > 0) break;
+ }
+ ++attackCursor;
+ }
+}
+
+void BattleState::CalculateDamage() {
+ if (CurrentAttack().isMonster) {
+ // TODO: run monster's attack script
+ monsterAttacks[CurrentAttack().index].SetType(AttackChoice::SWORD);
+ monsterAttacks[CurrentAttack().index].Selection().SelectSingle();
+ monsterAttacks[CurrentAttack().index].Selection().SelectHeroes();
+ monsterAttacks[CurrentAttack().index].Selection().SetBad(0, 15);
+ } else {
+ TargetSelection &ts(AttackChoiceAt(CurrentAttack().index).Selection());
+ if (ts.TargetsEnemies()) {
+ for (int i(0); i < NumHeroes(); ++i) {
+ if (ts.IsSelected(i)) {
+ ts.SetBad(i, 15);
+ }
+ }
+ } else {
+ for (int i(0); i < MaxMonsters(); ++i) {
+ if (ts.IsSelected(i) && MonsterAt(i).Health() > 0) {
+ ts.SetBad(i, 15);
+ }
+ }
+ }
+ }
+}
+
+void BattleState::ClearAllAttacks() {
+ attackCursor = -1;
+ activeHero = -1;
+ for (int i(0); i < numHeroes; ++i) {
+ attackChoices[i] = AttackChoice(this);