Use smart pointers for BattleSide.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2020-06-02 13:06:24 +02:00
parent 49e8ff055d
commit f898698f49
20 changed files with 86 additions and 107 deletions

View File

@@ -9,14 +9,14 @@ using namespace Battling;
class ChoiceCompare {
public:
explicit ChoiceCompare() {}
bool operator()(const BaseTurnChoice* a, const BaseTurnChoice* b) {
bool operator()(const std::shared_ptr<BaseTurnChoice>& a, const std::shared_ptr<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();
auto aPriority = dynamic_cast<const AttackTurnChoice*>(a.get())->GetPriority();
auto bPriority = dynamic_cast<const AttackTurnChoice*>(b.get())->GetPriority();
if (aPriority != bPriority)
return aPriority > bPriority;
}
@@ -29,6 +29,6 @@ public:
}
};
void TurnOrdering::OrderChoices(std::vector<BaseTurnChoice*>& vec, ArbUt::Random& rand) {
void TurnOrdering::OrderChoices(std::vector<std::shared_ptr<BaseTurnChoice>>& vec, ArbUt::Random& rand) {
std::sort(vec.begin(), vec.end(), ChoiceCompare());
}