#ifndef CREATURELIB_BATTLESIDE_HPP #define CREATURELIB_BATTLESIDE_HPP #include #include #include #include "../TurnChoices/BaseTurnChoice.hpp" #include "Creature.hpp" using namespace Arbutils::Collections; namespace CreatureLib::Battling { class BattleSide : public ScriptSource { uint8_t _index; uint8_t _creaturesPerSide; List _creatures; List _choices; List _fillableSlots; uint8_t _choicesSet = 0; ScriptSet _volatile; Battle* _battle; bool _hasFled = false; public: BattleSide(uint8_t index, 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++) { _creatures[i] = nullptr; _choices[i] = nullptr; _fillableSlots[i] = true; } ResetChoices(); } virtual ~BattleSide() = default; [[nodiscard]] bool AllChoicesSet() const noexcept; [[nodiscard]] const List& GetChoices() const noexcept; [[nodiscard]] bool AllPossibleSlotsFilled() const; void SetChoice(BaseTurnChoice* choice); void ResetChoices() noexcept; void SetCreature(Creature* creature, uint8_t index); Creature* GetCreature(uint8_t index) const; bool CreatureOnSide(const Creature* creature) const; void GetActiveScripts(Arbutils::Collections::List& scripts) override; const List& GetCreatures() { return _creatures; } uint8_t GetSideIndex() noexcept { return _index; } uint8_t GetCreatureIndex(Creature* c) { for (size_t i = 0; i < _creatures.Count(); i++) { if (c == _creatures[i]) return i; } throw CreatureException("Unable to find creature on field."); } void MarkSlotAsUnfillable(Creature* creature) noexcept { for (uint8_t i = 0; i < _creaturesPerSide; i++) { if (_creatures[i] == creature) { _fillableSlots.At(i) = false; return; } } } bool IsDefeated() noexcept { for (auto b : _fillableSlots) { if (b) return false; } return true; } bool HasFled() noexcept { return _hasFled; } void MarkAsFled() noexcept { _hasFled = true; } uint8_t GetRandomCreatureIndex(); }; } #endif // CREATURELIB_BATTLESIDE_HPP