From 0f012424c38e81660114dd3f0feb18e5203c56d4 Mon Sep 17 00:00:00 2001 From: Per Inge Mathisen Date: Sun, 6 Apr 2008 16:21:50 +0000 Subject: [PATCH] Restrict number of buildings that can be created from cheating and network to building limits, and make sure they are sane also for lassat and satlink. git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@4534 4a71c877-e1ca-e34f-864e-861f7616d084 --- src/droid.c | 2 -- src/hci.c | 4 ++++ src/multistruct.c | 4 +--- src/structure.c | 56 +++++++++++++---------------------------------- 4 files changed, 20 insertions(+), 46 deletions(-) diff --git a/src/droid.c b/src/droid.c index fb3f9ea5a..2e0fd34e6 100644 --- a/src/droid.c +++ b/src/droid.c @@ -1127,8 +1127,6 @@ BOOL droidStartBuild(DROID *psDroid) intBuildFinished(psDroid); return false; } - //add one to current quantity for this player - structLimit->currentQuantity++; //commented out for demo - 2/1/98 //ASSERT( droidNextToStruct(psDroid, (BASE_OBJECT *)psStruct), diff --git a/src/hci.c b/src/hci.c index ef8ff1036..65419528e 100644 --- a/src/hci.c +++ b/src/hci.c @@ -2093,6 +2093,10 @@ INT_RETVAL intRunWidgets(void) { psStructure = buildStructure(psBuilding, structX, structY, selectedPlayer, false); + if (!psStructure) + { + addConsoleMessage(_("Failed to create building"), LEFT_JUSTIFY, SYSTEM_MESSAGE); + } /* NOTE: if this was a regular buildprocess we would * have to call sendBuildStarted(psStructure, ); * In this case there is no droid working on the diff --git a/src/multistruct.c b/src/multistruct.c index e24437933..7870d799f 100644 --- a/src/multistruct.c +++ b/src/multistruct.c @@ -195,7 +195,6 @@ BOOL recvBuildFinished() UDWORD type,typeindex; UBYTE player; - NETbeginDecode(NET_BUILDFINISHED); NETuint32_t(&structId); // get the struct id. NETuint32_t(&type); // Kind of building. @@ -244,8 +243,7 @@ BOOL recvBuildFinished() } } // Build the structure - psStruct = buildStructure(&(asStructureStats[typeindex]), // Build the structure. - x, y, player,true); + psStruct = buildStructure(&(asStructureStats[typeindex]), x, y, player, true); if (psStruct) { diff --git a/src/structure.c b/src/structure.c index 6f4a9a1b0..259ae57d1 100644 --- a/src/structure.c +++ b/src/structure.c @@ -845,12 +845,19 @@ void initStructLimits(void) for (player = 0; player < MAX_PLAYERS; player++) { STRUCTURE_LIMITS *psStructLimits = asStructLimits[player]; + STRUCTURE_STATS *psStat = asStructureStats; - for (i=0; i < numStructureStats; i++) + for (i = 0; i < numStructureStats; i++) { psStructLimits[i].limit = LOTS_OF; psStructLimits[i].currentQuantity = 0; psStructLimits[i].globalLimit = LOTS_OF; + if (isLasSat(psStat) || psStat->type == REF_SAT_UPLINK) + { + psStructLimits[i].limit = 1; + psStructLimits[i].globalLimit = 1; + } + psStat++; } } } @@ -1571,45 +1578,12 @@ STRUCTURE* buildStructure(STRUCTURE_STATS* pStructureType, UDWORD x, UDWORD y, U ASSERT(!"invalid structure type", "buildStructure: Invalid structure type"); return NULL; } - - if (player == selectedPlayer) + // Don't allow more than interface limits + if (asStructLimits[player][max].currentQuantity + 1 > asStructLimits[player][max].limit) { - //don't allow more than interface limits of certain structures - if (pStructureType->type == REF_FACTORY || - pStructureType->type == REF_CYBORG_FACTORY || - pStructureType->type == REF_VTOL_FACTORY) - { - //NEVER EVER EVER WANT MORE THAN 5 FACTORIES - if (asStructLimits[selectedPlayer][max].currentQuantity > MAX_FACTORY) - { - ASSERT(!"attempting to construct too many factories", "buildStructure: trying to build too many factories (%d max)", MAX_FACTORY); - return NULL; - } - } - if (pStructureType->type == REF_RESEARCH) - { - //can only cope with MAX_OBJECTS research facilities - if (asStructLimits[selectedPlayer][max].currentQuantity > MAX_OBJECTS) - { - ASSERT(!"attempting to construct too many research facilities", "buildStructure: trying to build too many research facilities (%d max)", MAX_OBJECTS); - return NULL; - } - } - //HARD_CODE don't ever want more than one Las Sat structure - if (isLasSat(pStructureType) && getLasSatExists(selectedPlayer)) - { - ASSERT(!"attempting to build more than 1 Las Sat center", "buildStructure: trying to build too many Las Sat (1 max)"); - return NULL; - } - //HARD_CODE don't ever want more than one Sat Uplink structure - if (pStructureType->type == REF_SAT_UPLINK) - { - if (asStructLimits[selectedPlayer][max].currentQuantity > 0) - { - ASSERT(!"attempting to build more than 1 Sat Uplink", "buildStructure: trying to build too many Sat Uplinks (1 max)"); - return NULL; - } - } + debug(LOG_ERROR, "Player %u: Building %s could not be built due to building limits!", + player, pStructureType->pName); + return NULL; } // snap the coords to a tile @@ -1929,6 +1903,7 @@ STRUCTURE* buildStructure(STRUCTURE_STATS* pStructureType, UDWORD x, UDWORD y, U gridAddObject((BASE_OBJECT *)psBuilding); clustNewStruct(psBuilding); + asStructLimits[player][max].currentQuantity++; } else //its an upgrade { @@ -4846,8 +4821,7 @@ BOOL removeStruct(STRUCTURE *psDel, BOOL bDestroy) } //subtract one from the structLimits list so can build another - don't allow to go less than zero! - if (asStructLimits[psDel->player][psDel->pStructureType - asStructureStats]. - currentQuantity) + if (asStructLimits[psDel->player][psDel->pStructureType - asStructureStats].currentQuantity) { asStructLimits[psDel->player][psDel->pStructureType - asStructureStats].currentQuantity--; }