Make the last couple classes use smart pointers.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
#ifndef CREATURELIB_EVENTDATA_HPP
|
||||
#define CREATURELIB_EVENTDATA_HPP
|
||||
|
||||
#include <Arbutils/Memory/BorrowedPtr.hpp>
|
||||
#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> _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<Creature>& 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> _creature;
|
||||
uint32_t _originalHealth;
|
||||
uint32_t _newHealth;
|
||||
|
||||
public:
|
||||
HealEvent(Creature* c, uint32_t oHealth, uint32_t newHealth) noexcept
|
||||
HealEvent(ArbUt::BorrowedPtr<Creature> 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<Creature>& 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> _creature;
|
||||
|
||||
public:
|
||||
FaintEvent(Creature* c) noexcept : _creature(c) {}
|
||||
FaintEvent(ArbUt::BorrowedPtr<Creature> c) noexcept : _creature(c) {}
|
||||
EventDataKind GetKind() const noexcept override { return EventDataKind ::Faint; }
|
||||
Creature* GetCreature() const noexcept { return _creature; }
|
||||
const ArbUt::BorrowedPtr<Creature>& GetCreature() const noexcept { return _creature; }
|
||||
};
|
||||
|
||||
class DisplayTextEvent : public EventData {
|
||||
|
||||
@@ -36,7 +36,7 @@ void BattleSide::SetChoice(BaseTurnChoice* choice) {
|
||||
_choicesSet++;
|
||||
}
|
||||
|
||||
void BattleSide::SetCreature(Creature* creature, uint8_t index) {
|
||||
void BattleSide::SetCreature(ArbUt::BorrowedPtr<Creature> creature, uint8_t index) {
|
||||
auto old = _creatures[index];
|
||||
if (old != nullptr) {
|
||||
old->SetOnBattleField(false);
|
||||
|
||||
@@ -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> creature, uint8_t index);
|
||||
|
||||
const ArbUt::BorrowedPtr<Creature>& GetCreature(uint8_t index) const;
|
||||
bool CreatureOnSide(const ArbUt::BorrowedPtr<Creature>& creature) const;
|
||||
|
||||
@@ -44,8 +44,9 @@ namespace CreatureLib::Battling {
|
||||
std::unique_ptr<Script> _script = nullptr;
|
||||
|
||||
public:
|
||||
ExecutingAttack(const ArbUt::List<ArbUt::BorrowedPtr<Creature>>& targets, uint8_t numberHits, Creature* user,
|
||||
const ArbUt::BorrowedPtr<LearnedAttack>& attack, const std::unique_ptr<Script>& script)
|
||||
ExecutingAttack(const ArbUt::List<ArbUt::BorrowedPtr<Creature>>& targets, uint8_t numberHits,
|
||||
ArbUt::BorrowedPtr<Creature> user, const ArbUt::BorrowedPtr<LearnedAttack>& attack,
|
||||
const std::unique_ptr<Script>& script)
|
||||
: _targets(targets.Count()), _numberHits(numberHits),
|
||||
_hits(std::make_unique<HitData[]>(targets.Count() * numberHits)), _user(user), _attack(attack) {
|
||||
AssertNotNull(user)
|
||||
|
||||
@@ -9,16 +9,16 @@ namespace CreatureLib::Battling {
|
||||
class Creature;
|
||||
|
||||
class BaseTurnChoice : public ScriptSource {
|
||||
Creature* _user;
|
||||
ArbUt::BorrowedPtr<Creature> _user;
|
||||
int32_t _randomValue;
|
||||
|
||||
protected:
|
||||
BaseTurnChoice(Creature* user) noexcept : _user(user){};
|
||||
BaseTurnChoice(ArbUt::BorrowedPtr<Creature> user) noexcept : _user(user){};
|
||||
|
||||
public:
|
||||
virtual ~BaseTurnChoice() = default;
|
||||
[[nodiscard]] virtual TurnChoiceKind GetKind() const noexcept = 0;
|
||||
[[nodiscard]] inline Creature* GetUser() const noexcept { return _user; }
|
||||
[[nodiscard]] inline const ArbUt::BorrowedPtr<Creature>& GetUser() const noexcept { return _user; }
|
||||
|
||||
inline void __SetRandomValue(int32_t val) noexcept { _randomValue = val; }
|
||||
inline int32_t __GetRandomValue() const noexcept { return _randomValue; }
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace CreatureLib::Battling {
|
||||
class FleeTurnChoice : public BaseTurnChoice {
|
||||
public:
|
||||
FleeTurnChoice(Creature* user) : BaseTurnChoice(user) {}
|
||||
FleeTurnChoice(ArbUt::BorrowedPtr<Creature> user) : BaseTurnChoice(user) {}
|
||||
|
||||
TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Flee; }
|
||||
size_t ScriptCount() const override { return GetUser()->ScriptCount(); }
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
namespace CreatureLib::Battling {
|
||||
class PassTurnChoice : public BaseTurnChoice {
|
||||
public:
|
||||
PassTurnChoice(Creature* c) : BaseTurnChoice(c) {}
|
||||
PassTurnChoice(ArbUt::BorrowedPtr<Creature> c) : BaseTurnChoice(c) {}
|
||||
|
||||
TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Pass; }
|
||||
size_t ScriptCount() const override { return GetUser()->ScriptCount(); }
|
||||
|
||||
@@ -4,15 +4,15 @@
|
||||
#include "BaseTurnChoice.hpp"
|
||||
namespace CreatureLib::Battling {
|
||||
class SwitchTurnChoice : public BaseTurnChoice {
|
||||
Creature* _newCreature;
|
||||
ArbUt::BorrowedPtr<Creature> _newCreature;
|
||||
|
||||
public:
|
||||
SwitchTurnChoice(Creature* user, Creature* newCreature) noexcept
|
||||
SwitchTurnChoice(ArbUt::BorrowedPtr<Creature> user, ArbUt::BorrowedPtr<Creature> newCreature) noexcept
|
||||
: BaseTurnChoice(user), _newCreature(newCreature) {}
|
||||
|
||||
TurnChoiceKind GetKind() const noexcept final { return TurnChoiceKind::Switch; }
|
||||
|
||||
inline Creature* GetNewCreature() const noexcept { return _newCreature; }
|
||||
inline const ArbUt::BorrowedPtr<Creature>& GetNewCreature() const noexcept { return _newCreature; }
|
||||
size_t ScriptCount() const override { return GetUser()->ScriptCount(); }
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user