Cancel concurrent peep pickups on placement (#29)

This commit is contained in:
ζeh Matt 2019-06-20 19:58:56 +02:00 committed by duncanspumpkin
parent b896f07687
commit 6bd09f6b98
1 changed files with 23 additions and 0 deletions

View File

@ -178,6 +178,7 @@ public:
{
return MakeResult(GA_ERROR::UNKNOWN, STR_ERR_CANT_PLACE_PERSON_HERE, gGameCommandErrorText);
}
CancelConcurrentPickups(peep);
break;
default:
log_error("Invalid pickup type: %u", _type);
@ -186,4 +187,26 @@ public:
}
return res;
}
private:
void CancelConcurrentPickups(Peep * pickedPeep) const
{
// This part is only relevant in multiplayer games.
if (network_get_mode() == NETWORK_MODE_NONE)
return;
// Not relevant for owner, owner gets to place it normally.
NetworkPlayerId_t currentPlayerId = network_get_current_player_id();
if (currentPlayerId == _owner)
return;
Peep* peep = network_get_pickup_peep(network_get_current_player_id());
if (peep != pickedPeep)
return;
// By assigning the peep to null before calling tool_cancel we can avoid
// resetting the peep to the initial position.
network_set_pickup_peep(currentPlayerId, nullptr);
tool_cancel();
}
};