From 696e8bccd764093c2b4e7028e99c41e668852fe1 Mon Sep 17 00:00:00 2001 From: Tim Felgentreff <timfelgentreff@gmail.com> Date: Mon, 28 Sep 2020 10:26:30 +0200 Subject: [PATCH] when assigning a unit to a player, remove it from the previous owner (if there is one) --- src/stratagus/player.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/stratagus/player.cpp b/src/stratagus/player.cpp index f5a54f2a4..9d16f132b 100644 --- a/src/stratagus/player.cpp +++ b/src/stratagus/player.cpp @@ -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);