Fully handle turn ordering
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,18 +1,36 @@
|
||||
#include "TurnOrdering.hpp"
|
||||
#include "../TurnChoices/AttackTurnChoice.hpp"
|
||||
#include "../Models/Creature.hpp"
|
||||
#include "../Models/Battle.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using namespace CreatureLib::Battling;
|
||||
using namespace CreatureLib;
|
||||
using namespace Battling;
|
||||
|
||||
bool ___ChoiceOrderFunc(const BaseTurnChoice* a, const BaseTurnChoice* b){
|
||||
bool ___ChoiceOrderFunc(const BaseTurnChoice* a, const BaseTurnChoice* b, Core::Random& rand){
|
||||
auto aKind = a->GetKind();
|
||||
auto bKind = b->GetKind();
|
||||
if (aKind != bKind)
|
||||
return aKind > bKind;
|
||||
//FIXME: choices need to be ordered when they're the same type
|
||||
throw 1;
|
||||
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;
|
||||
}
|
||||
|
||||
void TurnOrdering::OrderChoices(std::vector<const BaseTurnChoice *> &vec) {
|
||||
std::sort(vec.begin(), vec.end(), ___ChoiceOrderFunc);
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user