1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Merge pull request #643 from viciious/fix_cmp_stack

Fix CMP_stack to follow strict weak ordering of elements
This commit is contained in:
Alexander Shishkin 2020-05-11 20:04:54 +03:00 committed by GitHub
commit f05d2b6586
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)