CreatureLib/src/Battling/Models/BattleSide.hpp

90 lines
2.7 KiB
C++
Raw Normal View History

2019-10-17 12:33:25 +00:00
#ifndef CREATURELIB_BATTLESIDE_HPP
#define CREATURELIB_BATTLESIDE_HPP
2020-03-22 12:42:26 +00:00
#include <Arbutils/Assert.hpp>
#include <Arbutils/Collections/List.hpp>
2019-10-17 12:33:25 +00:00
#include <vector>
#include "../TurnChoices/BaseTurnChoice.hpp"
#include "Creature.hpp"
2019-10-17 12:33:25 +00:00
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;
2019-12-15 10:52:10 +00:00
bool _hasFled = false;
public:
explicit BattleSide(uint8_t index, Battle* battle, uint8_t creaturesPerSide)
2020-03-22 12:42:26 +00:00
: _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;
[[nodiscard]] const List<BaseTurnChoice*>& GetChoices() const;
[[nodiscard]] bool AllPossibleSlotsFilled() const;
void SetChoice(BaseTurnChoice* choice);
void ResetChoices();
void SetCreature(Creature* creature, uint8_t index);
2019-11-02 12:57:43 +00:00
Creature* GetCreature(uint8_t index) const;
bool CreatureOnSide(const Creature* creature) const;
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) final;
const List<Creature*>& GetCreatures() { return _creatures; }
2019-12-14 11:40:50 +00:00
2019-12-07 21:52:43 +00:00
uint8_t GetSideIndex() { return _index; }
uint8_t GetCreatureIndex(Creature* c) {
for (size_t i = 0; i < _creatures.Count(); i++) {
2019-12-07 21:52:43 +00:00
if (c == _creatures[i])
return i;
}
throw CreatureException("Unable to find creature on field.");
}
void MarkSlotAsUnfillable(Creature* creature) {
for (uint8_t i = 0; i < _creaturesPerSide; i++) {
if (_creatures[i] == creature) {
_fillableSlots.At(i) = false;
return;
}
}
}
2019-12-07 21:52:43 +00:00
bool IsDefeated() {
for (auto b : _fillableSlots) {
if (b)
return false;
}
return true;
}
2019-12-15 10:52:10 +00:00
bool HasFled() { return _hasFled; }
void MarkAsFled() { _hasFled = true; }
uint8_t GetRandomCreatureIndex();
2019-10-17 12:33:25 +00:00
};
}
#endif // CREATURELIB_BATTLESIDE_HPP