}
void BattleState::CalculateDamage() {
+ AttackChoice &ac(CurrentAttack().isMonster ? monsterAttacks[CurrentAttack().index] : AttackChoiceAt(CurrentAttack().index));
+ if (ac.GetType() == AttackChoice::DEFEND) return;
+
if (CurrentAttack().isMonster) {
const Stats &attackerStats(MonsterAt(CurrentAttack().index).GetStats());
// TODO: run monster's attack script
- monsterAttacks[CurrentAttack().index].SetType(AttackChoice::SWORD);
- monsterAttacks[CurrentAttack().index].Selection().SelectSingle();
- monsterAttacks[CurrentAttack().index].Selection().SelectHeroes();
+ ac.SetType(AttackChoice::SWORD);
+ ac.Selection().SelectSingle();
+ ac.Selection().SelectHeroes();
for (int i(0); i < NumHeroes(); ++i) {
if (HeroAt(i).Health() > 0) {
const Stats &defenderStats(HeroAt(i).GetStats());
Uint16 damage(CalculateDamage(attackerStats, defenderStats));
- monsterAttacks[CurrentAttack().index].Selection().SetBad(0, damage);
+ ac.Selection().SetBad(0, damage);
break;
}
}
} else {
const Stats &attackerStats(HeroAt(CurrentAttack().index).GetStats());
- TargetSelection &ts(AttackChoiceAt(CurrentAttack().index).Selection());
+ TargetSelection &ts(ac.Selection());
bool hitSome(false);
if (ts.TargetsEnemies()) {
for (int i(0); i < MaxMonsters(); ++i) {
void BattleState::RenderMonsters(SDL_Surface *screen, const Vector<int> &offset) {
for (vector<Monster>::size_type i(0), end(monsters.size()); i < end; ++i) {
if (MonsterPositionOccupied(i)) {
- monsters[i].Sprite()->DrawCenter(screen, monsterPositions[i] + offset);
+ // TODO: better solution for running animations
+ if (monsters[i].AttackAnimation() && monsters[i].AttackAnimation()->Running()) {
+ monsters[i].AttackAnimation()->DrawCenter(screen, monsterPositions[i] + offset);
+ } else if (monsters[i].SpellAnimation() && monsters[i].SpellAnimation()->Running()) {
+ monsters[i].SpellAnimation()->DrawCenter(screen, monsterPositions[i] + offset);
+ } else {
+ monsters[i].Sprite()->DrawCenter(screen, monsterPositions[i] + offset);
+ }
}
}
}