2019-10-31 11:02:23 +00:00
|
|
|
#include "TurnOrdering.hpp"
|
|
|
|
#include <algorithm>
|
2019-11-28 11:55:22 +00:00
|
|
|
#include "../Models/Battle.hpp"
|
|
|
|
#include "../TurnChoices/AttackTurnChoice.hpp"
|
2019-10-31 11:02:23 +00:00
|
|
|
|
2019-10-31 11:31:31 +00:00
|
|
|
using namespace CreatureLib;
|
|
|
|
using namespace Battling;
|
2019-10-31 11:02:23 +00:00
|
|
|
|
2020-04-22 19:20:07 +00:00
|
|
|
class ChoiceCompare {
|
|
|
|
public:
|
2020-04-22 21:03:16 +00:00
|
|
|
explicit ChoiceCompare() {}
|
2020-04-22 19:20:07 +00:00
|
|
|
bool operator()(const BaseTurnChoice* a, const BaseTurnChoice* b) {
|
|
|
|
auto aKind = a->GetKind();
|
|
|
|
auto bKind = b->GetKind();
|
|
|
|
if (aKind != bKind)
|
|
|
|
return aKind > bKind;
|
|
|
|
if (aKind == TurnChoiceKind::Attack) {
|
|
|
|
auto aPriority = dynamic_cast<const AttackTurnChoice*>(a)->GetPriority();
|
|
|
|
auto bPriority = dynamic_cast<const AttackTurnChoice*>(b)->GetPriority();
|
|
|
|
if (aPriority != bPriority)
|
|
|
|
return aPriority > bPriority;
|
|
|
|
}
|
|
|
|
auto aSpeed = a->GetUser()->GetBoostedStat(Library::Statistic::Speed);
|
|
|
|
auto bSpeed = b->GetUser()->GetBoostedStat(Library::Statistic::Speed);
|
|
|
|
if (aSpeed != bSpeed)
|
|
|
|
return aSpeed > bSpeed;
|
|
|
|
|
2020-04-22 21:09:54 +00:00
|
|
|
return a->__GetRandomValue() > b->__GetRandomValue();
|
2020-04-22 19:20:07 +00:00
|
|
|
}
|
|
|
|
};
|
2019-10-31 11:02:23 +00:00
|
|
|
|
2020-05-26 16:31:06 +00:00
|
|
|
void TurnOrdering::OrderChoices(std::vector<BaseTurnChoice*>& vec, ArbUt::Random& rand) {
|
2020-04-22 21:03:16 +00:00
|
|
|
std::sort(vec.begin(), vec.end(), ChoiceCompare());
|
2019-10-31 11:02:23 +00:00
|
|
|
}
|