91 lines
2.8 KiB
C++
91 lines
2.8 KiB
C++
#ifndef CREATURELIB_BATTLESIDE_HPP
|
|
#define CREATURELIB_BATTLESIDE_HPP
|
|
|
|
#include <Arbutils/Assert.hpp>
|
|
#include <Arbutils/Collections/List.hpp>
|
|
#include <vector>
|
|
#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<Creature*> _creatures;
|
|
List<BaseTurnChoice*> _choices;
|
|
List<bool> _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.Append(nullptr);
|
|
_choices.Append(nullptr);
|
|
_fillableSlots.Append(true);
|
|
}
|
|
ResetChoices();
|
|
}
|
|
|
|
virtual ~BattleSide() = default;
|
|
|
|
[[nodiscard]] bool AllChoicesSet() const noexcept;
|
|
[[nodiscard]] const List<BaseTurnChoice*>& 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;
|
|
|
|
size_t ScriptCount() const override;
|
|
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override;
|
|
|
|
const List<Creature*>& 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
|