From 3da5952483bb0f0f35d5b41474f1c26c1458b9ef Mon Sep 17 00:00:00 2001 From: Cyp Date: Fri, 19 Nov 2010 15:16:37 +0100 Subject: [PATCH] Fix broken check for giving too many trucks to a player. Caused desynchs due to players not agreeing who owned what. The check against selectedPlayer was incorrect, it caused clients with max trucks + 1 to not believe anyone could give trucks to anyone else. Introduced in d6b47d1122f751dea01680d3598041e374a21590. Changelog: Really fix truck limit when giving trucks. --- src/droid.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/droid.c b/src/droid.c index cb2869c89..b0958edf6 100644 --- a/src/droid.c +++ b/src/droid.c @@ -4306,20 +4306,41 @@ DROID * giftSingleDroid(DROID *psD, UDWORD to) if (bMultiPlayer) { int i; + bool tooMany = false; + + incNumDroids(to); + tooMany = tooMany || getNumDroids(to) > getMaxDroids(to); + if (psD->droidType == DROID_CYBORG_CONSTRUCT || psD->droidType == DROID_CONSTRUCT) + { + incNumConstructorDroids(to); + tooMany = tooMany || getNumConstructorDroids(to) > MAX_CONSTRUCTOR_DROIDS; + } + else if (psD->droidType == DROID_COMMAND) + { + incNumCommandDroids(to); + tooMany = tooMany || getNumCommandDroids(to) > MAX_COMMAND_DROIDS; + } + + if (tooMany) + { + if (to == selectedPlayer) + { + CONPRINTF(ConsoleString, (ConsoleString, _("%s wanted to give you a %s but you have too many!"), getPlayerName(psD->player), psD->aName)); + } + else if(psD->player == selectedPlayer) + { + CONPRINTF(ConsoleString, (ConsoleString, _("You wanted to give %s a %s but they have too many!"), getPlayerName(to), psD->aName)); + } + return NULL; + } // reset order orderDroid(psD, DORDER_STOP, ModeQueue); + visRemoveVisibility((BASE_OBJECT *)psD); + if (droidRemove(psD, apsDroidLists)) // remove droid from one list { - if (psD->droidType == DROID_CYBORG_CONSTRUCT || psD->droidType == DROID_CONSTRUCT) - { - if (getNumConstructorDroids(selectedPlayer) > MAX_CONSTRUCTOR_DROIDS) - { - CONPRINTF(ConsoleString, (ConsoleString, _("%s wanted to give you a %s but you have too many!"), getPlayerName(psD->player), psD->aName)); - return NULL; - } - } if (!isHumanPlayer(psD->player)) { droidSetName(psD, "Enemy Unit");