Make Creature use smart pointers.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-06-02 16:20:47 +02:00
parent 1ef50fd3a6
commit 62583ecb17
6 changed files with 19 additions and 14 deletions

View File

@@ -2,7 +2,8 @@
#include "../Models/Creature.hpp"
void CreatureLib::Battling::ExperienceLibrary::HandleExperienceGain(
CreatureLib::Battling::Creature* faintedMon, const std::unordered_set<Creature*>& opponents) const {
CreatureLib::Battling::Creature* faintedMon,
const std::unordered_set<ArbUt::BorrowedPtr<Creature>>& opponents) const {
for (auto opponent : opponents) {
if (opponent == nullptr)
continue;

View File

@@ -1,5 +1,6 @@
#ifndef CREATURELIB_EXPERIENCELIBRARY_HPP
#define CREATURELIB_EXPERIENCELIBRARY_HPP
#include <Arbutils/Memory/BorrowedPtr.hpp>
#include <unordered_set>
namespace CreatureLib::Battling {
@@ -9,7 +10,8 @@ namespace CreatureLib::Battling {
public:
virtual ~ExperienceLibrary() = default;
virtual void HandleExperienceGain(Creature* faintedMon, const std::unordered_set<Creature*>& opponents) const;
virtual void HandleExperienceGain(Creature* faintedMon,
const std::unordered_set<ArbUt::BorrowedPtr<Creature>>& opponents) const;
};
}

View File

@@ -6,7 +6,7 @@
using namespace CreatureLib;
Battling::Creature::Creature(const BattleLibrary* library,
Battling::Creature::Creature(ArbUt::BorrowedPtr<const BattleLibrary> library,
const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species,
const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant, uint8_t level,
uint32_t experience, uint32_t uid, Library::Gender gender, uint8_t coloring,
@@ -87,7 +87,7 @@ void Battling::Creature::RecalculateBoostedStat(Library::Statistic stat) {
const ArbUt::BorrowedPtr<CreatureLib::Battling::Battle>& Battling::Creature::GetBattle() const { return _battle; }
Battling::BattleSide* Battling::Creature::GetBattleSide() const { return _side; }
const ArbUt::BorrowedPtr<CreatureLib::Battling::BattleSide>& Battling::Creature::GetBattleSide() const { return _side; }
bool Battling::Creature::IsFainted() const noexcept { return this->_currentHealth == 0; }

View File

@@ -21,7 +21,7 @@ namespace CreatureLib::Battling {
class Creature : public ScriptSource {
protected:
const BattleLibrary* _library;
ArbUt::BorrowedPtr<const BattleLibrary> _library;
ArbUt::BorrowedPtr<const Library::CreatureSpecies> _species;
ArbUt::BorrowedPtr<const Library::SpeciesVariant> _variant;
@@ -42,7 +42,7 @@ namespace CreatureLib::Battling {
Library::StatisticSet<uint32_t> _boostedStats;
ArbUt::BorrowedPtr<Battle> _battle = nullptr;
BattleSide* _side = nullptr;
ArbUt::BorrowedPtr<BattleSide> _side = nullptr;
bool _onBattleField = false;
std::string _nickname = "";
@@ -51,7 +51,7 @@ namespace CreatureLib::Battling {
bool _hasOverridenTalent;
ArbUt::CaseInsensitiveConstString _overridenTalentName = ""_cnc;
std::unordered_set<Creature*> _seenOpponents = {};
std::unordered_set<ArbUt::BorrowedPtr<Creature>> _seenOpponents;
ArbUt::UniquePtrList<LearnedAttack> _attacks;
bool _allowedExperienceGain;
@@ -63,7 +63,8 @@ namespace CreatureLib::Battling {
void OnFaint();
public:
Creature(const BattleLibrary* library, const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species,
Creature(ArbUt::BorrowedPtr<const BattleLibrary> library,
const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species,
const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant, uint8_t level, uint32_t experience,
uint32_t uid, Library::Gender gender, uint8_t coloring,
const ArbUt::BorrowedPtr<const Library::Item> heldItem, std::string nickname,
@@ -100,7 +101,7 @@ namespace CreatureLib::Battling {
void SetBattleData(ArbUt::BorrowedPtr<Battle> battle, BattleSide* side);
const ArbUt::BorrowedPtr<Battle>& GetBattle() const;
BattleSide* GetBattleSide() const;
const ArbUt::BorrowedPtr<BattleSide>& GetBattleSide() const;
void SetOnBattleField(bool value) { _onBattleField = value; }
bool IsOnBattleField() const { return _onBattleField; }
@@ -118,8 +119,8 @@ namespace CreatureLib::Battling {
void OverrideActiveTalent(const ArbUt::CaseInsensitiveConstString& talent);
void AddExperience(uint32_t amount);
void MarkOpponentAsSeen(Creature* creature) { _seenOpponents.insert(creature); }
const std::unordered_set<Creature*>& GetSeenOpponents() const { return _seenOpponents; }
void MarkOpponentAsSeen(ArbUt::BorrowedPtr<Creature> creature) { _seenOpponents.insert(creature); }
const std::unordered_set<ArbUt::BorrowedPtr<Creature>>& GetSeenOpponents() const { return _seenOpponents; }
size_t ScriptCount() const override;
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override;