diff --git a/src/Battling/Flow/TurnHandler.cpp b/src/Battling/Flow/TurnHandler.cpp index ff469f0..62a56f7 100644 --- a/src/Battling/Flow/TurnHandler.cpp +++ b/src/Battling/Flow/TurnHandler.cpp @@ -50,8 +50,8 @@ void TurnHandler::ExecuteChoice(const ArbUt::BorrowedPtr& choice if (battle->HasEnded()) { return; } - // If the user is fainted, we don't want to execute its choice. - if (user->IsFainted()) { + // If the user is not usable, we don't want to execute its choice. + if (!user->IsUsable()) { return; } // If the user is not in the field, we don't want to execute its choice. diff --git a/src/Battling/Library/ExperienceLibrary.cpp b/src/Battling/Library/ExperienceLibrary.cpp index 58ab90d..0931347 100644 --- a/src/Battling/Library/ExperienceLibrary.cpp +++ b/src/Battling/Library/ExperienceLibrary.cpp @@ -4,7 +4,7 @@ void CreatureLib::Battling::ExperienceLibrary::HandleExperienceGain( CreatureLib::Battling::Creature* faintedMon, const std::unordered_set>& opponents) const { - for (auto opponent : opponents) { + for (const auto& opponent : opponents) { if (opponent->IsFainted()) continue; if (!opponent->AllowedExperienceGain()) diff --git a/src/Battling/Models/BattleParty.hpp b/src/Battling/Models/BattleParty.hpp index 6415414..1f83a07 100644 --- a/src/Battling/Models/BattleParty.hpp +++ b/src/Battling/Models/BattleParty.hpp @@ -34,7 +34,7 @@ namespace CreatureLib::Battling { for (const auto& creature : p) { if (creature == nullptr) continue; - if (creature->IsFainted()) + if (!creature->IsUsable()) continue; if (creature->IsOnBattleField()) continue; diff --git a/src/Battling/Models/BattleSide.cpp b/src/Battling/Models/BattleSide.cpp index f9543ac..53f46e2 100644 --- a/src/Battling/Models/BattleSide.cpp +++ b/src/Battling/Models/BattleSide.cpp @@ -10,7 +10,7 @@ bool BattleSide::AllPossibleSlotsFilled() const { try { for (size_t i = 0; i < _creatures.Count(); i++) { auto c = _creatures[i]; - if (!c.HasValue() || c.GetValue()->IsFainted()) { + if (!c.HasValue() || !c.GetValue()->IsUsable()) { if (_battle->CanSlotBeFilled(_index, i)) { return false; } diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index 70675f5..3de7220 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -143,6 +143,8 @@ namespace CreatureLib::Battling { this->_boostedStats.SetStat(stat, s); } + bool Creature::IsUsable() const noexcept { return !this->IsFainted(); } + bool Creature::IsFainted() const noexcept { return this->_currentHealth == 0; } void Creature::OnFaint() { diff --git a/src/Battling/Models/Creature.hpp b/src/Battling/Models/Creature.hpp index 5b466d4..820add5 100644 --- a/src/Battling/Models/Creature.hpp +++ b/src/Battling/Models/Creature.hpp @@ -122,6 +122,8 @@ namespace CreatureLib::Battling { const CreatureLib::Library::TalentIndex& GetRealTalent() const noexcept { return _talentIndex; } const ArbUt::StringView& GetActiveTalent() const; + /// Are we allowed to use this creature in a battle? + [[nodiscard]] virtual bool IsUsable() const noexcept; [[nodiscard]] bool IsFainted() const noexcept; [[nodiscard]] const std::vector& GetTypes() const noexcept; [[nodiscard]] bool HasType(uint8_t type) const noexcept; diff --git a/src/Battling/Models/CreatureParty.hpp b/src/Battling/Models/CreatureParty.hpp index 0d71f59..1d4dc57 100644 --- a/src/Battling/Models/CreatureParty.hpp +++ b/src/Battling/Models/CreatureParty.hpp @@ -35,7 +35,7 @@ namespace CreatureLib::Battling { for (Creature* c : _party) { if (c == nullptr) continue; - if (c->IsFainted()) + if (!c->IsUsable()) continue; return true; } diff --git a/src/Precompiled.hxx b/src/Precompiled.hxx index aebe9fd..1e34b8a 100644 --- a/src/Precompiled.hxx +++ b/src/Precompiled.hxx @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include