}
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));
-
- monsterAttacks.resize(monsters.size(), AttackChoice(this));
}
void BattleState::NextAttack() {
}
void BattleState::CalculateDamage() {
- AttackChoice &ac(CurrentAttack().isMonster ? monsterAttacks[CurrentAttack().index] : HeroAt(CurrentAttack().index).GetAttackChoice());
+ AttackChoice &ac(CurrentAttack().isMonster ? MonsterAt(CurrentAttack().index).GetAttackChoice() : HeroAt(CurrentAttack().index).GetAttackChoice());
if (ac.GetType() == AttackChoice::DEFEND) return;
if (CurrentAttack().isMonster) {
void BattleState::ApplyDamage() {
if (attackCursor < 0) return;
- AttackChoice &ac(CurrentAttack().isMonster ? monsterAttacks[CurrentAttack().index] : HeroAt(CurrentAttack().index).GetAttackChoice());
+ AttackChoice &ac(CurrentAttack().isMonster ? MonsterAt(CurrentAttack().index).GetAttackChoice() : HeroAt(CurrentAttack().index).GetAttackChoice());
TargetSelection &ts(ac.Selection());
if (ts.TargetsEnemies()) {
for (int i(0); i < MaxMonsters(); ++i) {
AttackChoice &BattleState::CurrentAttackAttackChoice() {
if (CurrentAttack().isMonster) {
- return monsterAttacks[CurrentAttack().index];
+ return MonsterAt(CurrentAttack().index).GetAttackChoice();
} else {
return HeroAt(CurrentAttack().index).GetAttackChoice();
}
void BattleState::ClearAllAttacks() {
attackCursor = -1;
activeHero = -1;
- for (int i(0); i < numHeroes; ++i) {
- heroes[i].GetAttackChoice() = AttackChoice(this);
+ for (int i(0); i < NumHeroes(); ++i) {
+ HeroAt(i).GetAttackChoice() = AttackChoice(this);
+ }
+ for (int i(0); i < MaxMonsters(); ++i) {
+ MonsterAt(i).GetAttackChoice() = AttackChoice(this);
}
attackOrder.clear();
- monsterAttacks.clear();
}
const geometry::Point<int> &HeroTagPositionAt(int index) const { assert(index >= 0 && index < NumHeroes()); return heroTagPositions[index]; }
bool HasChosenAttackType() const { return ActiveHero().GetAttackChoice().GetType() != AttackChoice::UNDECIDED; }
- AttackChoice &MonsterAttackChoiceAt(int index) { assert(index >= 0 && index < MaxMonsters()); return monsterAttacks[index]; }
- const AttackChoice &MonsterAttackChoiceAt(int index) const { assert(index >= 0 && index < MaxMonsters()); return monsterAttacks[index]; }
+ AttackChoice &MonsterAttackChoiceAt(int index) { assert(index >= 0 && index < MaxMonsters()); return monsters[index].GetAttackChoice(); }
+ const AttackChoice &MonsterAttackChoiceAt(int index) const { assert(index >= 0 && index < MaxMonsters()); return monsters[index].GetAttackChoice(); }
bool AttackSelectionDone() const { return activeHero >= numHeroes; }
int NumHeroes() const { return numHeroes; }
std::vector<geometry::Point<int> > monsterPositions;
std::vector<geometry::Point<int> > heroesPositions;
std::vector<Monster> monsters;
- std::vector<AttackChoice> monsterAttacks;
std::vector<Order> attackOrder;
Hero heroes[4];
graphics::Menu<const common::Item *> itemMenu;
#ifndef BATTLE_MONSTER_H_
#define BATTLE_MONSTER_H_
+#include "AttackChoice.h"
#include "Stats.h"
#include "../graphics/Animation.h"
void SetAttackAnimation(const graphics::Animation *a) { attackAnimation = a; }
void SetSpellAnimation(const graphics::Animation *a) { spellAnimation = a; }
+ AttackChoice &GetAttackChoice() { return attackChoice; }
+ const AttackChoice &GetAttackChoice() const { return attackChoice; }
+
private:
const char *name;
graphics::Sprite *sprite;
graphics::AnimationRunner animation;
+ AttackChoice attackChoice;
+
Uint16 maxHealth, health;
Uint16 maxMana, mana;