Rework clearing battle from creatures.
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
2020-12-28 15:10:49 +01:00
parent a284641b5a
commit 3742e07b03
3 changed files with 47 additions and 4 deletions

View File

@@ -48,7 +48,7 @@ namespace CreatureLib::Battling {
}
}
virtual ~Battle() = default;
virtual ~Battle() { ClearBattle(); }
[[nodiscard]] const ArbUt::BorrowedPtr<const BattleLibrary>& GetLibrary() const noexcept;
[[nodiscard]] uint32_t GetCurrentTurn() const noexcept { return _currentTurn; }
@@ -117,13 +117,16 @@ namespace CreatureLib::Battling {
long GetLastTurnTimeMicroseconds() const noexcept { return _lastTurnTime; }
void EndBattle() {
this->_hasEnded = true;
void EndBattle() { this->_hasEnded = true; }
void ClearBattle() {
for (size_t i = 0; i < _numberOfSides; i++) {
auto side = _sides[i];
for (auto c : side->GetCreatures()) {
if (c.HasValue()) {
c.GetValue()->ClearBattleData();
if (c.GetValue()->GetBattle() == this) {
c.GetValue()->ClearBattleData();
}
}
}
}