Files
CreatureLib/src/Battling/Models/Battle.cpp
Deukhoofd 42c1623985
All checks were successful
continuous-integration/drone/push Build is passing
Fully handle turn ordering
2019-10-31 12:31:31 +01:00

57 lines
1.5 KiB
C++

#include "Battle.hpp"
#include "../Flow/TurnHandler.hpp"
#include "../TurnChoices/AttackTurnChoice.hpp"
#include "../Flow/TurnOrdering.hpp"
using namespace CreatureLib;
using namespace CreatureLib::Battling;
const BattleLibrary *Battle::GetLibrary() const {
return _library;
}
bool Battle::CanUse(BaseTurnChoice *choice) {
if (choice->GetKind() == TurnChoiceKind::Attack){
//HOOK: change number of uses needed.
return static_cast<AttackTurnChoice*>(choice)->GetAttack()->GetRemainingUses() > 1;
}
return true;
}
bool Battle::TrySetChoice(BaseTurnChoice *choice) {
if (!CanUse(choice))
return false;
choice->GetUser()->GetBattleSide()->SetChoice(choice);
CheckChoicesSetAndRun();
return true;
}
void Battle::CheckChoicesSetAndRun() {
for (auto side: _sides){
if (!side->AllChoicesSet()){
return;
}
}
auto choices = std::vector<const BaseTurnChoice*>(_numberOfSides * _creaturesPerSide);
auto i = 0;
for (auto side: _sides){
for (auto choice: side->GetChoices()){
choices[i] = choice;
i++;
}
}
TurnOrdering::OrderChoices(choices, _random);
auto choiceQueue = ChoiceQueue(choices);
this->_currentTurnQueue = &choiceQueue;
TurnHandler::RunTurn(choiceQueue);
this->_currentTurnQueue = nullptr;
}
ChoiceQueue* Battle::GetCurrentTurnQueue() const {
return _currentTurnQueue;
}
Core::Random &Battle::GetRandom(){
return _random;
}