+Uint16 BattleState::CalculateDamage(const Stats &attacker, const Stats &defender) const {
+ // TODO: find out real formula and add some randomness
+ return attacker.Attack() / 2 - defender.Defense() / 4;
+}
+
+void BattleState::ApplyDamage() {
+ if (attackCursor < 0) return;
+ AttackChoice &ac(CurrentAttack().isMonster ? monsterAttacks[CurrentAttack().index] : AttackChoiceAt(CurrentAttack().index));
+ TargetSelection &ts(ac.Selection());
+ if (ts.TargetsEnemies()) {
+ for (int i(0); i < MaxMonsters(); ++i) {
+ Monster &monster(MonsterAt(i));
+ if (ts.IsBad(i)) {
+ monster.SubtractHealth(ts.GetAmount(i));
+ if (monster.Health() == 0) {
+ expReward += monster.ExpReward();
+ goldReward += monster.GoldReward();
+ }
+ }
+ }
+ } else {
+ for (int i(0); i < NumHeroes(); ++i) {
+ Hero &hero(HeroAt(i));
+ if (ts.IsBad(i)) {
+ hero.SubtractHealth(ts.GetAmount(i));
+ }
+ }
+ }
+}
+
+AttackChoice &BattleState::CurrentAttackAttackChoice() {
+ if (CurrentAttack().isMonster) {
+ return monsterAttacks[CurrentAttack().index];
+ } else {
+ return AttackChoiceAt(CurrentAttack().index);
+ }
+}
+