Use smart pointers for BattleSide.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2020-06-02 13:06:24 +02:00
parent 49e8ff055d
commit f898698f49
20 changed files with 86 additions and 107 deletions

View File

@@ -11,16 +11,16 @@ namespace CreatureLib::Battling {
class BattleSide : public ScriptSource {
uint8_t _index;
uint8_t _creaturesPerSide;
ArbUt::List<Creature*> _creatures;
ArbUt::List<BaseTurnChoice*> _choices;
ArbUt::List<ArbUt::BorrowedPtr<Creature>> _creatures;
ArbUt::List<std::shared_ptr<BaseTurnChoice>> _choices;
ArbUt::List<bool> _fillableSlots;
uint8_t _choicesSet = 0;
ScriptSet _volatile;
Battle* _battle;
ArbUt::BorrowedPtr<Battle> _battle;
bool _hasFled = false;
public:
BattleSide(uint8_t index, Battle* battle, uint8_t creaturesPerSide) noexcept
BattleSide(uint8_t index, ArbUt::BorrowedPtr<Battle> battle, uint8_t creaturesPerSide) noexcept
: _index(index), _creaturesPerSide(creaturesPerSide), _creatures(creaturesPerSide),
_choices(creaturesPerSide), _fillableSlots(creaturesPerSide), _battle(battle) {
for (size_t i = 0; i < creaturesPerSide; i++) {
@@ -34,7 +34,9 @@ namespace CreatureLib::Battling {
virtual ~BattleSide() = default;
[[nodiscard]] bool AllChoicesSet() const noexcept;
[[nodiscard]] const ArbUt::List<BaseTurnChoice*>& GetChoices() const noexcept;
[[nodiscard]] const ArbUt::List<std::shared_ptr<BaseTurnChoice>>& GetChoices() const noexcept {
return _choices;
}
[[nodiscard]] bool AllPossibleSlotsFilled() const;
@@ -43,24 +45,24 @@ namespace CreatureLib::Battling {
void SetCreature(Creature* creature, uint8_t index);
Creature* GetCreature(uint8_t index) const;
bool CreatureOnSide(const Creature* creature) const;
const ArbUt::BorrowedPtr<Creature>& GetCreature(uint8_t index) const;
bool CreatureOnSide(const ArbUt::BorrowedPtr<Creature>& creature) const;
size_t ScriptCount() const override;
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override;
const ArbUt::List<Creature*>& GetCreatures() { return _creatures; }
const ArbUt::List<ArbUt::BorrowedPtr<Creature>>& GetCreatures() { return _creatures; }
uint8_t GetSideIndex() noexcept { return _index; }
uint8_t GetCreatureIndex(Creature* c) {
uint8_t GetCreatureIndex(const ArbUt::BorrowedPtr<Creature>& c) {
for (size_t i = 0; i < _creatures.Count(); i++) {
if (c == _creatures[i])
if (_creatures[i] == c)
return i;
}
throw CreatureException("Unable to find creature on field.");
}
void MarkSlotAsUnfillable(Creature* creature) noexcept {
void MarkSlotAsUnfillable(const ArbUt::BorrowedPtr<Creature>& creature) noexcept {
for (uint8_t i = 0; i < _creaturesPerSide; i++) {
if (_creatures[i] == creature) {
_fillableSlots.At(i) = false;