Cleanup
This commit is contained in:
@@ -6,29 +6,32 @@
|
||||
using namespace CreatureLib;
|
||||
using namespace Battling;
|
||||
|
||||
bool ___ChoiceOrderFunc(const BaseTurnChoice* a, const BaseTurnChoice* b, Arbutils::Random& rand) {
|
||||
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;
|
||||
class ChoiceCompare {
|
||||
Arbutils::Random& _rand;
|
||||
|
||||
auto randomValue = rand.Get(2);
|
||||
return randomValue == 0;
|
||||
}
|
||||
public:
|
||||
explicit ChoiceCompare(Arbutils::Random& rand) : _rand(rand) {}
|
||||
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;
|
||||
|
||||
auto randomValue = _rand.Get(2);
|
||||
return randomValue == 0;
|
||||
}
|
||||
};
|
||||
|
||||
void TurnOrdering::OrderChoices(std::vector<BaseTurnChoice*>& vec, Arbutils::Random& rand) {
|
||||
auto comp = [&](const BaseTurnChoice* a, const BaseTurnChoice* b) -> bool {
|
||||
return ___ChoiceOrderFunc(a, b, rand);
|
||||
};
|
||||
std::sort(vec.begin(), vec.end(), comp);
|
||||
std::sort(vec.begin(), vec.end(), ChoiceCompare(rand));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user