From 68510cd21025741773b6746376a24602be791829 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Tue, 21 Aug 2012 21:02:58 +0200 Subject: [PATCH 1/1] fixed a bug in BattleState::PreviousHero() didn't account for dead heroes; now does --- src/battle/BattleState.cpp | 7 +++++++ src/battle/BattleState.h | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index 65bdb91..5012104 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -59,6 +59,13 @@ void BattleState::NextHero() { } } +void BattleState::PreviousHero() { + --activeHero; + while (activeHero >= 0 && heroes[activeHero].Health() == 0) { + --activeHero; + } +} + void BattleState::SwapHeroes(int lhs, int rhs) { if (lhs < 0 || lhs >= numHeroes || rhs < 0 || rhs >= numHeroes || lhs == rhs) return; std::swap(heroes[lhs], heroes[rhs]); diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index 3561609..0143fe0 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -93,7 +93,7 @@ public: void NextHero(); bool BeforeFirstHero() const { return activeHero < 0; } - void PreviousHero() { --activeHero; } + void PreviousHero(); void SwapHeroes(int lhs, int rhs); Hero &ActiveHero() { return heroes[activeHero]; } const Hero &ActiveHero() const { return heroes[activeHero]; } -- 2.39.2