2019-10-31 11:02:23 +00:00
|
|
|
#include "TurnOrdering.hpp"
|
2019-10-31 11:31:31 +00:00
|
|
|
#include "../TurnChoices/AttackTurnChoice.hpp"
|
|
|
|
#include "../Models/Creature.hpp"
|
|
|
|
#include "../Models/Battle.hpp"
|
2019-10-31 11:02:23 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2019-10-31 11:31:31 +00:00
|
|
|
using namespace CreatureLib;
|
|
|
|
using namespace Battling;
|
2019-10-31 11:02:23 +00:00
|
|
|
|
2019-10-31 11:31:31 +00:00
|
|
|
bool ___ChoiceOrderFunc(const BaseTurnChoice* a, const BaseTurnChoice* b, Core::Random& rand){
|
2019-10-31 11:02:23 +00:00
|
|
|
auto aKind = a->GetKind();
|
|
|
|
auto bKind = b->GetKind();
|
|
|
|
if (aKind != bKind)
|
|
|
|
return aKind > bKind;
|
2019-10-31 11:31:31 +00:00
|
|
|
if (aKind == TurnChoiceKind::Attack){
|
|
|
|
auto aPriority = static_cast<const AttackTurnChoice*>(a)->GetPriority();
|
|
|
|
auto bPriority = static_cast<const AttackTurnChoice*>(b)->GetPriority();
|
|
|
|
if (aPriority != bPriority)
|
|
|
|
return aPriority > bPriority;
|
|
|
|
}
|
|
|
|
auto aSpeed = a->GetUser()->GetBoostedStat(Core::Statistic::Speed);
|
|
|
|
auto bSpeed = b->GetUser()->GetBoostedStat(Core::Statistic::Speed);
|
|
|
|
if (aSpeed != bSpeed)
|
|
|
|
return aSpeed > bSpeed;
|
|
|
|
|
|
|
|
auto randomValue = rand.Get(2);
|
|
|
|
return randomValue == 0;
|
2019-10-31 11:02:23 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 11:31:31 +00:00
|
|
|
void TurnOrdering::OrderChoices(std::vector<const BaseTurnChoice *> &vec, Core::Random& rand) {
|
|
|
|
auto comp = [&](const BaseTurnChoice * a,const BaseTurnChoice * b)-> bool {
|
|
|
|
return ___ChoiceOrderFunc(a,b,rand);
|
|
|
|
};
|
|
|
|
std::sort(vec.begin(), vec.end(), comp);
|
2019-10-31 11:02:23 +00:00
|
|
|
}
|