#include "TurnOrdering.hpp" #include #include "../Models/Battle.hpp" #include "../TurnChoices/AttackTurnChoice.hpp" using namespace CreatureLib; using namespace Battling; class ChoiceCompare { public: explicit ChoiceCompare() {} 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(a)->GetPriority(); auto bPriority = dynamic_cast(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; return a->__GetRandomValue() > b->__GetRandomValue(); } }; void TurnOrdering::OrderChoices(std::vector& vec, ArbUt::Random& rand) { std::sort(vec.begin(), vec.end(), ChoiceCompare()); }