when assigning a unit to a player, remove it from the previous owner (if there is one)

This commit is contained in:
Tim Felgentreff 2020-09-28 10:26:30 +02:00
parent 4abc6041a5
commit 696e8bccd7

View file

@ -825,7 +825,13 @@ void CPlayer::Clear()
void CPlayer::AddUnit(CUnit &unit)
{
Assert(unit.Player != this);
if (unit.Player == this) {
return;
}
if (unit.PlayerSlot != static_cast<size_t>(-1)) {
// unit is registered with another player
unit.Player->RemoveUnit(unit);
}
Assert(unit.PlayerSlot == static_cast<size_t>(-1));
unit.PlayerSlot = this->Units.size();
this->Units.push_back(&unit);