ctrl.PopState(); // quit the battle scene
return;
}
+ // TODO: this should not push a state while quitting
if (AttackSelectionDone()) {
ctrl.PushState(new PerformAttacks(this));
} else {
} else {
TargetSelection &ts(AttackChoiceAt(CurrentAttack().index).Selection());
if (ts.TargetsEnemies()) {
- for (int i(0); i < NumHeroes(); ++i) {
- if (ts.IsSelected(i)) {
+ for (int i(0); i < MaxMonsters(); ++i) {
+ if (ts.IsSelected(i) && MonsterAt(i).Health() > 0) {
ts.SetBad(i, 15);
}
}
} else {
- for (int i(0); i < MaxMonsters(); ++i) {
- if (ts.IsSelected(i) && MonsterAt(i).Health() > 0) {
+ for (int i(0); i < NumHeroes(); ++i) {
+ if (ts.IsSelected(i) && HeroAt(i).Health() > 0) {
ts.SetBad(i, 15);
}
}
}
}
+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) {
+ if (ts.IsBad(i)) {
+ MonsterAt(i).SubtractHealth(ts.GetAmount(i));
+ }
+ }
+ } else {
+ for (int i(0); i < NumHeroes(); ++i) {
+ if (ts.IsSelected(i) && MonsterAt(i).Health() > 0) {
+ HeroAt(i).SubtractHealth(ts.GetAmount(i));
+ }
+ }
+ }
+}
+
void BattleState::ClearAllAttacks() {
attackCursor = -1;
activeHero = -1;
Uint16 MaxHealth() const { return maxHealth; }
Uint16 Health() const { return health; }
int RelativeHealth(int max) const { return Health() * max / MaxHealth(); }
+ void SubtractHealth(int amount);
Uint16 MaxMana() const { return maxMana; }
Uint16 Mana() const { return mana; }
Uint16 MaxHealth() const { return maxHealth; }
Uint16 Health() const { return health; }
int RelativeHealth(int max) const { return health * max / maxHealth; }
+ void SubtractHealth(int amount);
Uint16 MaxMana() const { return maxMana; }
Uint16 Mana() const { return mana; }
void SetGood(int index, int amount) { selected[index].type = State::GOOD; selected[index].number = amount; }
void SetBad(int index, int amount) { selected[index].type = State::BAD; selected[index].number = amount; }
int GetAmount(int index) const { return selected[index].number; }
+ bool Missed(int index) const { return selected[index].type == State::MISS; }
+ bool IsGood(int index) const { return selected[index].type == State::GOOD; }
+ bool IsBad(int index) const { return selected[index].type == State::BAD; }
private:
void FindNextEnemy();