From 618d5214073cf7d72a1e4617b4c04341a422fc36 Mon Sep 17 00:00:00 2001 From: Victor Luchits Date: Mon, 11 May 2020 18:03:37 +0300 Subject: [PATCH] Fix CMP_stack to follow strict weak ordering of elements --- lib/battle/BattleInfo.cpp | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/lib/battle/BattleInfo.cpp b/lib/battle/BattleInfo.cpp index f7005ea3e..1e63fda03 100644 --- a/lib/battle/BattleInfo.cpp +++ b/lib/battle/BattleInfo.cpp @@ -1071,14 +1071,14 @@ bool CMP_stack::operator()(const battle::Unit * a, const battle::Unit * b) int as = a->getInitiative(turn), bs = b->getInitiative(turn); if(as != bs) return as > bs; - else - { - if(a->unitSide() == b->unitSide()) - return a->unitSlot() < b->unitSlot(); - else - return a->unitSide() == side ? false : true; - } + + if (a->unitSide() == b->unitSide()) + return a->unitSlot() < b->unitSlot(); + else if (a->unitSide() == side || b->unitSide() == side) + return a->unitSide() != side; //FIXME: what about summoned stacks + + return std::addressof(a) > std::addressof(b); } case 2: //fastest last, upper slot first case 3: //fastest last, upper slot first @@ -1086,18 +1086,21 @@ bool CMP_stack::operator()(const battle::Unit * a, const battle::Unit * b) int as = a->getInitiative(turn), bs = b->getInitiative(turn); if(as != bs) return as > bs; - else - { - if(a->unitSide() == b->unitSide()) - return a->unitSlot() < b->unitSlot(); - else - return a->unitSide() == side ? false : true; - } + + if(a->unitSide() == b->unitSide()) + return a->unitSlot() < b->unitSlot(); + else if (a->unitSide() == side || b->unitSide() == side) + return a->unitSide() != side; + + return std::addressof(a) > std::addressof(b); } default: - assert(0); + assert(false); return false; } + + assert(false); + return false; } CMP_stack::CMP_stack(int Phase, int Turn, uint8_t Side)