From 6bd09f6b98ed5d647544ef42c8153ce3f12a466e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= Date: Thu, 20 Jun 2019 19:58:56 +0200 Subject: [PATCH] Cancel concurrent peep pickups on placement (#29) --- src/openrct2/actions/PeepPickupAction.hpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/openrct2/actions/PeepPickupAction.hpp b/src/openrct2/actions/PeepPickupAction.hpp index 68ff20dd6e..dcabc0784b 100644 --- a/src/openrct2/actions/PeepPickupAction.hpp +++ b/src/openrct2/actions/PeepPickupAction.hpp @@ -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(); + } };