diff --git a/CInterface/Battling/EventData.cpp b/CInterface/Battling/EventData.cpp index 4c664ef..b0f8978 100644 --- a/CInterface/Battling/EventData.cpp +++ b/CInterface/Battling/EventData.cpp @@ -6,18 +6,23 @@ export void CreatureLib_EventData_Destruct(const EventData* p) { delete p; } #define SIMPLE_GET_FUNC(type, name, returnType) \ export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); } +#define SIMPLE_GET_FUNC_SMART_PTR(type, name, returnType) \ + export returnType CreatureLib_##type##_##name(const type* p) { return p->name().operator->(); } SIMPLE_GET_FUNC(EventData, GetKind, EventDataKind); -SIMPLE_GET_FUNC(DamageEvent, GetCreature, Creature*); +SIMPLE_GET_FUNC_SMART_PTR(DamageEvent, GetCreature, Creature*); SIMPLE_GET_FUNC(DamageEvent, GetDamageSource, DamageSource); SIMPLE_GET_FUNC(DamageEvent, GetOriginalHealth, uint32_t); SIMPLE_GET_FUNC(DamageEvent, GetNewHealth, uint32_t); -SIMPLE_GET_FUNC(HealEvent, GetCreature, Creature*); +SIMPLE_GET_FUNC_SMART_PTR(HealEvent, GetCreature, Creature*); SIMPLE_GET_FUNC(HealEvent, GetOriginalHealth, uint32_t); SIMPLE_GET_FUNC(HealEvent, GetNewHealth, uint32_t); -SIMPLE_GET_FUNC(FaintEvent, GetCreature, Creature*); +SIMPLE_GET_FUNC_SMART_PTR(FaintEvent, GetCreature, Creature*); export const char* CreatureLib_DisplayTextEvent_GetText(const DisplayTextEvent* p) { return p->GetText().c_str(); } + +#undef SIMPLE_GET_FUNC +#undef SIMPLE_GET_FUNC_SMART_PTR \ No newline at end of file diff --git a/CInterface/Battling/TurnChoices.cpp b/CInterface/Battling/TurnChoices.cpp index 51da88e..0e59fde 100644 --- a/CInterface/Battling/TurnChoices.cpp +++ b/CInterface/Battling/TurnChoices.cpp @@ -23,7 +23,7 @@ export void CreatureLib_BaseTurnChoice_Destruct(const BaseTurnChoice* p) { delet export returnType CreatureLib_##type##_##name(const type* p) { return p->name().operator->(); } SIMPLE_GET_FUNC(BaseTurnChoice, GetKind, TurnChoiceKind) -SIMPLE_GET_FUNC(BaseTurnChoice, GetUser, Creature*) +SIMPLE_GET_FUNC_SMART_PTR(BaseTurnChoice, GetUser, Creature*) SIMPLE_GET_FUNC_SMART_PTR(AttackTurnChoice, GetAttack, LearnedAttack*) SIMPLE_GET_FUNC(AttackTurnChoice, GetKind, TurnChoiceKind) @@ -38,7 +38,7 @@ export uint8_t CreatureLib_BaseTurnChoice_GetTargetCreatureIndex(const AttackTur return p->GetTarget().GetCreatureIndex(); } -SIMPLE_GET_FUNC(SwitchTurnChoice, GetNewCreature, Creature*) +SIMPLE_GET_FUNC_SMART_PTR(SwitchTurnChoice, GetNewCreature, Creature*) #undef SIMPLE_GET_FUNC #undef SIMPLE_GET_FUNC_SMART_PTR \ No newline at end of file diff --git a/src/Battling/EventHooks/EventData.hpp b/src/Battling/EventHooks/EventData.hpp index 6f00c82..d3e288a 100644 --- a/src/Battling/EventHooks/EventData.hpp +++ b/src/Battling/EventHooks/EventData.hpp @@ -1,8 +1,10 @@ #ifndef CREATURELIB_EVENTDATA_HPP #define CREATURELIB_EVENTDATA_HPP +#include #include "../Models/DamageSource.hpp" #include "EventDataKind.hpp" + namespace CreatureLib::Battling { // Predeclare some classes. class Creature; @@ -14,7 +16,7 @@ namespace CreatureLib::Battling { }; class DamageEvent : public EventData { - Creature* _creature; + ArbUt::BorrowedPtr _creature; DamageSource _damageSource; uint32_t _originalHealth; uint32_t _newHealth; @@ -23,33 +25,33 @@ namespace CreatureLib::Battling { DamageEvent(Creature* c, DamageSource s, uint32_t oHealth, uint32_t newHealth) noexcept : _creature(c), _damageSource(s), _originalHealth(oHealth), _newHealth(newHealth) {} EventDataKind GetKind() const noexcept override { return EventDataKind ::Damage; } - Creature* GetCreature() const noexcept { return _creature; } + const ArbUt::BorrowedPtr& GetCreature() const noexcept { return _creature; } DamageSource GetDamageSource() const noexcept { return _damageSource; } uint32_t GetOriginalHealth() const noexcept { return _originalHealth; } uint32_t GetNewHealth() const noexcept { return _newHealth; } }; class HealEvent : public EventData { - Creature* _creature; + ArbUt::BorrowedPtr _creature; uint32_t _originalHealth; uint32_t _newHealth; public: - HealEvent(Creature* c, uint32_t oHealth, uint32_t newHealth) noexcept + HealEvent(ArbUt::BorrowedPtr c, uint32_t oHealth, uint32_t newHealth) noexcept : _creature(c), _originalHealth(oHealth), _newHealth(newHealth) {} EventDataKind GetKind() const noexcept override { return EventDataKind ::Heal; } - Creature* GetCreature() const noexcept { return _creature; } + const ArbUt::BorrowedPtr& GetCreature() const noexcept { return _creature; } uint32_t GetOriginalHealth() const noexcept { return _originalHealth; } uint32_t GetNewHealth() const noexcept { return _newHealth; } }; class FaintEvent : public EventData { - Creature* _creature; + ArbUt::BorrowedPtr _creature; public: - FaintEvent(Creature* c) noexcept : _creature(c) {} + FaintEvent(ArbUt::BorrowedPtr c) noexcept : _creature(c) {} EventDataKind GetKind() const noexcept override { return EventDataKind ::Faint; } - Creature* GetCreature() const noexcept { return _creature; } + const ArbUt::BorrowedPtr& GetCreature() const noexcept { return _creature; } }; class DisplayTextEvent : public EventData { diff --git a/src/Battling/Models/BattleSide.cpp b/src/Battling/Models/BattleSide.cpp index 392038e..8b15930 100644 --- a/src/Battling/Models/BattleSide.cpp +++ b/src/Battling/Models/BattleSide.cpp @@ -36,7 +36,7 @@ void BattleSide::SetChoice(BaseTurnChoice* choice) { _choicesSet++; } -void BattleSide::SetCreature(Creature* creature, uint8_t index) { +void BattleSide::SetCreature(ArbUt::BorrowedPtr creature, uint8_t index) { auto old = _creatures[index]; if (old != nullptr) { old->SetOnBattleField(false); diff --git a/src/Battling/Models/BattleSide.hpp b/src/Battling/Models/BattleSide.hpp index 6553bdc..49a4cb9 100644 --- a/src/Battling/Models/BattleSide.hpp +++ b/src/Battling/Models/BattleSide.hpp @@ -43,7 +43,7 @@ namespace CreatureLib::Battling { void SetChoice(BaseTurnChoice* choice); void ResetChoices() noexcept; - void SetCreature(Creature* creature, uint8_t index); + void SetCreature(ArbUt::BorrowedPtr creature, uint8_t index); const ArbUt::BorrowedPtr& GetCreature(uint8_t index) const; bool CreatureOnSide(const ArbUt::BorrowedPtr& creature) const; diff --git a/src/Battling/Models/ExecutingAttack.hpp b/src/Battling/Models/ExecutingAttack.hpp index d224203..a8b8f1f 100644 --- a/src/Battling/Models/ExecutingAttack.hpp +++ b/src/Battling/Models/ExecutingAttack.hpp @@ -44,8 +44,9 @@ namespace CreatureLib::Battling { std::unique_ptr