2019-10-17 12:33:25 +00:00
|
|
|
#include "BattleSide.hpp"
|
2019-10-31 12:26:56 +00:00
|
|
|
#include "../../Core/Exceptions/CreatureException.hpp"
|
2019-10-29 10:19:25 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
using namespace CreatureLib::Battling;
|
|
|
|
|
|
|
|
bool BattleSide::AllChoicesSet() const {
|
2019-11-06 17:08:21 +00:00
|
|
|
return _choicesSet == _creaturesPerSide;
|
2019-10-29 10:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BattleSide::ResetChoices() {
|
2019-11-06 17:08:21 +00:00
|
|
|
_choicesSet = 0;
|
2019-10-29 10:19:25 +00:00
|
|
|
for (uint8_t i = 0; i < _creaturesPerSide; i++){
|
|
|
|
_choices[i] = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<const BaseTurnChoice *>& BattleSide::GetChoices() const{
|
|
|
|
return _choices;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BattleSide::SetChoice(const BaseTurnChoice *choice) {
|
|
|
|
auto find = std::find(_creatures.begin(), _creatures.end(), choice->GetUser());
|
|
|
|
if (find ==_creatures.end())
|
2019-10-31 12:26:56 +00:00
|
|
|
throw CreatureException("User not found");
|
2019-10-29 10:19:25 +00:00
|
|
|
uint8_t index = std::distance(_creatures.begin(),find);
|
|
|
|
_choices[index] = choice;
|
2019-11-06 17:08:21 +00:00
|
|
|
_choicesSet++;
|
2019-10-29 10:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BattleSide::SetCreature(Creature *creature, uint8_t index) {
|
|
|
|
_creatures[index] = creature;
|
|
|
|
}
|
2019-11-02 12:57:43 +00:00
|
|
|
|
|
|
|
bool BattleSide::CreatureOnSide(const Creature *creature) const {
|
|
|
|
return std::find(_creatures.begin(), _creatures.end(), creature) != _creatures.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
Creature *BattleSide::GetCreature(uint8_t index) const {
|
|
|
|
return _creatures[index];
|
|
|
|
}
|