Add new Creature::IsUsable function, which replaces IsFainted functionality in several places.
continuous-integration/drone/push Build is passing Details

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2021-06-19 12:33:31 +02:00
parent 8241a2d7b1
commit 762915b1f7
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
8 changed files with 11 additions and 6 deletions

View File

@ -50,8 +50,8 @@ void TurnHandler::ExecuteChoice(const ArbUt::BorrowedPtr<BaseTurnChoice>& choice
if (battle->HasEnded()) { if (battle->HasEnded()) {
return; return;
} }
// If the user is fainted, we don't want to execute its choice. // If the user is not usable, we don't want to execute its choice.
if (user->IsFainted()) { if (!user->IsUsable()) {
return; return;
} }
// If the user is not in the field, we don't want to execute its choice. // If the user is not in the field, we don't want to execute its choice.

View File

@ -4,7 +4,7 @@
void CreatureLib::Battling::ExperienceLibrary::HandleExperienceGain( void CreatureLib::Battling::ExperienceLibrary::HandleExperienceGain(
CreatureLib::Battling::Creature* faintedMon, CreatureLib::Battling::Creature* faintedMon,
const std::unordered_set<ArbUt::BorrowedPtr<Creature>>& opponents) const { const std::unordered_set<ArbUt::BorrowedPtr<Creature>>& opponents) const {
for (auto opponent : opponents) { for (const auto& opponent : opponents) {
if (opponent->IsFainted()) if (opponent->IsFainted())
continue; continue;
if (!opponent->AllowedExperienceGain()) if (!opponent->AllowedExperienceGain())

View File

@ -34,7 +34,7 @@ namespace CreatureLib::Battling {
for (const auto& creature : p) { for (const auto& creature : p) {
if (creature == nullptr) if (creature == nullptr)
continue; continue;
if (creature->IsFainted()) if (!creature->IsUsable())
continue; continue;
if (creature->IsOnBattleField()) if (creature->IsOnBattleField())
continue; continue;

View File

@ -10,7 +10,7 @@ bool BattleSide::AllPossibleSlotsFilled() const {
try { try {
for (size_t i = 0; i < _creatures.Count(); i++) { for (size_t i = 0; i < _creatures.Count(); i++) {
auto c = _creatures[i]; auto c = _creatures[i];
if (!c.HasValue() || c.GetValue()->IsFainted()) { if (!c.HasValue() || !c.GetValue()->IsUsable()) {
if (_battle->CanSlotBeFilled(_index, i)) { if (_battle->CanSlotBeFilled(_index, i)) {
return false; return false;
} }

View File

@ -143,6 +143,8 @@ namespace CreatureLib::Battling {
this->_boostedStats.SetStat(stat, s); this->_boostedStats.SetStat(stat, s);
} }
bool Creature::IsUsable() const noexcept { return !this->IsFainted(); }
bool Creature::IsFainted() const noexcept { return this->_currentHealth == 0; } bool Creature::IsFainted() const noexcept { return this->_currentHealth == 0; }
void Creature::OnFaint() { void Creature::OnFaint() {

View File

@ -122,6 +122,8 @@ namespace CreatureLib::Battling {
const CreatureLib::Library::TalentIndex& GetRealTalent() const noexcept { return _talentIndex; } const CreatureLib::Library::TalentIndex& GetRealTalent() const noexcept { return _talentIndex; }
const ArbUt::StringView& GetActiveTalent() const; 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]] bool IsFainted() const noexcept;
[[nodiscard]] const std::vector<uint8_t>& GetTypes() const noexcept; [[nodiscard]] const std::vector<uint8_t>& GetTypes() const noexcept;
[[nodiscard]] bool HasType(uint8_t type) const noexcept; [[nodiscard]] bool HasType(uint8_t type) const noexcept;

View File

@ -35,7 +35,7 @@ namespace CreatureLib::Battling {
for (Creature* c : _party) { for (Creature* c : _party) {
if (c == nullptr) if (c == nullptr)
continue; continue;
if (c->IsFainted()) if (!c->IsUsable())
continue; continue;
return true; return true;
} }

View File

@ -10,6 +10,7 @@
#include <exception> #include <exception>
#include <memory> #include <memory>
#include <numeric> #include <numeric>
#include <optional>
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>