80 lines
2.4 KiB
C++
80 lines
2.4 KiB
C++
#include "BattleSide.hpp"
|
|
#include <algorithm>
|
|
#include "../../Library/Exceptions/CreatureException.hpp"
|
|
#include "Battle.hpp"
|
|
|
|
using namespace CreatureLib::Battling;
|
|
|
|
bool BattleSide::AllChoicesSet() const { return _choicesSet == _creaturesPerSide; }
|
|
|
|
bool BattleSide::AllPossibleSlotsFilled() const {
|
|
AssertNotNull(_battle)
|
|
for (size_t i = 0; i < _creatures.Count(); i++) {
|
|
auto c = _creatures[i];
|
|
if (c == nullptr || c->IsFainted()) {
|
|
if (_battle->CanSlotBeFilled(_index, i))
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void BattleSide::ResetChoices() {
|
|
_choicesSet = 0;
|
|
for (uint8_t i = 0; i < _creaturesPerSide; i++) {
|
|
_choices[i] = nullptr;
|
|
}
|
|
}
|
|
|
|
const List<BaseTurnChoice*>& BattleSide::GetChoices() const { return _choices; }
|
|
|
|
void BattleSide::SetChoice(BaseTurnChoice* choice) {
|
|
AssertNotNull(choice)
|
|
auto find = std::find(_creatures.begin(), _creatures.end(), choice->GetUser());
|
|
if (find == _creatures.end())
|
|
throw CreatureException("User not found");
|
|
uint8_t index = std::distance(_creatures.begin(), find);
|
|
_choices[index] = choice;
|
|
_choicesSet++;
|
|
}
|
|
|
|
void BattleSide::SetCreature(Creature* creature, uint8_t index) {
|
|
AssertNotNull(creature)
|
|
auto old = _creatures[index];
|
|
if (old != nullptr) {
|
|
old->SetOnBattleField(false);
|
|
}
|
|
_creatures[index] = creature;
|
|
creature->SetBattleData(_battle, this);
|
|
creature->SetOnBattleField(true);
|
|
if (_battle == nullptr)
|
|
return;
|
|
for (auto side : _battle->GetSides()) {
|
|
if (side == this)
|
|
continue;
|
|
for (auto c : side->GetCreatures()) {
|
|
if (c != nullptr) {
|
|
c->MarkOpponentAsSeen(creature);
|
|
creature->MarkOpponentAsSeen(c);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
bool BattleSide::CreatureOnSide(const Creature* creature) const {
|
|
AssertNotNull(creature)
|
|
return std::find(_creatures.begin(), _creatures.end(), creature) != _creatures.end();
|
|
}
|
|
|
|
Creature* BattleSide::GetCreature(uint8_t index) const { return _creatures[index]; }
|
|
|
|
void BattleSide::GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) {
|
|
scripts.Append(&_volatile);
|
|
_battle->GetActiveScripts(scripts);
|
|
}
|
|
uint8_t BattleSide::GetRandomCreatureIndex() {
|
|
// TODO: Consider adding parameter to only get index for available creatures.
|
|
AssertNotNull(_battle)
|
|
return _battle->GetRandom()->Get(_creaturesPerSide);
|
|
}
|