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()) {
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.

View File

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

View File

@ -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;

View File

@ -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;
}

View File

@ -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() {

View File

@ -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<uint8_t>& GetTypes() const noexcept;
[[nodiscard]] bool HasType(uint8_t type) const noexcept;

View File

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

View File

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