Skip to content

Commit

Permalink
Fix duplicate structure IDs by removing GAME_BUILD message type.
Browse files Browse the repository at this point in the history
The only remaining purpose of GAME_BUILD was to hackishly change structure IDs around, which is not useful since structure IDs are already synchronised.

Changelog: Fix inability to select or target some structures due to duplicate structure IDs.
  • Loading branch information
Cyp committed Nov 7, 2010
1 parent c53a59b commit be5285f
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 158 deletions.
5 changes: 2 additions & 3 deletions lib/netplay/netplay.c
Expand Up @@ -166,9 +166,9 @@ unsigned NET_PlayerConnectionStatus[CONNECTIONSTATUS_NORMAL][MAX_PLAYERS];
** ie ("trunk", "2.1.3", "3.0", ...)
************************************************************************************
**/
char VersionString[VersionStringSize] = "master, netcode 4.1004";
char VersionString[VersionStringSize] = "master, netcode 4.1005";
static int NETCODE_VERSION_MAJOR = 4;
static int NETCODE_VERSION_MINOR = 1004;
static int NETCODE_VERSION_MINOR = 1005;

bool NETisCorrectVersion(uint32_t game_version_major, uint32_t game_version_minor)
{
Expand Down Expand Up @@ -3179,7 +3179,6 @@ const char *messageTypeToString(unsigned messageType_)
case GAME_TEMPLATE: return "GAME_TEMPLATE";
case GAME_TEMPLATEDEST: return "GAME_TEMPLATEDEST";
case GAME_FEATUREDEST: return "GAME_FEATUREDEST";
case GAME_BUILD: return "GAME_BUILD";
case GAME_RESEARCH: return "GAME_RESEARCH";
case GAME_FEATURES: return "GAME_FEATURES";
case GAME_SECONDARY: return "GAME_SECONDARY";
Expand Down
1 change: 0 additions & 1 deletion lib/netplay/netplay.h
Expand Up @@ -100,7 +100,6 @@ typedef enum
GAME_TEMPLATE, ///< a new template
GAME_TEMPLATEDEST, ///< remove template
GAME_FEATUREDEST, ///< destroy a game feature.
GAME_BUILD, ///< build a new structure
GAME_RESEARCH, ///< Research has been completed.
GAME_FEATURES, ///< information regarding features.
GAME_SECONDARY, ///< set a droids secondary order
Expand Down
9 changes: 0 additions & 9 deletions src/droid.c
Expand Up @@ -1001,15 +1001,6 @@ BOOL droidStartBuild(DROID *psDroid)
return false;
}
psStruct->body /= 10; // structures start at 10% health

if (bMultiMessages)
{
if(myResponsibility(psDroid->player) )
{
// This message doesn't actually do anything, unless out of synch.
sendBuildStarted(psStruct, psDroid);
}
}
}
else
{
Expand Down
6 changes: 0 additions & 6 deletions src/hci.c
Expand Up @@ -2133,12 +2133,6 @@ INT_RETVAL intRunWidgets(void)
{
addConsoleMessage(_("Failed to create building"), LEFT_JUSTIFY, SYSTEM_MESSAGE);
}
/* NOTE: if this was a regular buildprocess we would
* have to call sendBuildStarted(psStructure, <droid>);
* In this case there is no droid working on the
* building though. So we cannot fill out the <droid>
* part.
*/
}
if (psStructure)
{
Expand Down
3 changes: 0 additions & 3 deletions src/multiplay.c
Expand Up @@ -691,9 +691,6 @@ BOOL recvMessage(void)
case NET_BEACONMSG: //beacon (blip) message
recvBeacon(queue);
break;
case GAME_BUILD: // a build order has been sent.
recvBuildStarted(queue);
break;
case GAME_BUILDFINISHED: // a building is complete
recvBuildFinished(queue);
break;
Expand Down
1 change: 0 additions & 1 deletion src/multiplay.h
Expand Up @@ -172,7 +172,6 @@ extern BOOL multiplayerWinSequence(BOOL firstCall);
// definitions of functions in multiplay's other c files.

// Buildings . multistruct
extern BOOL sendBuildStarted (STRUCTURE *psStruct, DROID *psDroid);
extern BOOL SendDestroyStructure(STRUCTURE *s);
extern BOOL SendBuildFinished (STRUCTURE *psStruct);
extern BOOL sendLasSat (UBYTE player, STRUCTURE *psStruct, BASE_OBJECT *psObj);
Expand Down
1 change: 0 additions & 1 deletion src/multirecv.h
Expand Up @@ -37,7 +37,6 @@ extern BOOL recvDroidInfo (NETQUEUE queue);
extern BOOL recvDestroyDroid (NETQUEUE queue);
extern BOOL recvDroidMove (NETQUEUE queue);
extern BOOL recvDestroyStructure (NETQUEUE queue);
extern BOOL recvBuildStarted (NETQUEUE queue);
extern BOOL recvBuildFinished (NETQUEUE queue);
extern BOOL recvTemplate (NETQUEUE queue);
extern BOOL recvDestroyFeature (NETQUEUE queue);
Expand Down
134 changes: 0 additions & 134 deletions src/multistruct.c
Expand Up @@ -51,140 +51,6 @@
// ////////////////////////////////////////////////////////////////////////////
// structures

// ////////////////////////////////////////////////////////////////////////////
// INFORM others that a building has been started, and base plate should be put down.
BOOL sendBuildStarted(STRUCTURE *psStruct, DROID *psDroid)
{
NETbeginEncode(NETgameQueue(selectedPlayer), GAME_BUILD);

// Who is building it
NETuint8_t(&psDroid->player);

// What they are building
NETuint32_t(&psDroid->psTarStats->ref);

// Where it is being built
NETuint16_t(&psDroid->orderX);
NETuint16_t(&psDroid->orderY);

// The droid building it
NETuint32_t(&psDroid->id);

// The ID assigned to the structure being built
NETuint32_t(&psStruct->id);

// The droids order
NETint32_t(&psDroid->order);

if (psDroid->psTarget
&& psDroid->psTarget->type == OBJ_STRUCTURE)
{
// The ID of the droids target (== psStruct->id ?)
NETuint32_t(&psDroid->psTarget->id);
}
else
{
uint32_t zero = 0;
NETuint32_t(&zero);
}

return NETend();
}

// ////////////////////////////////////////////////////////////////////////////
// put down a base plate and start droid building it!
BOOL recvBuildStarted(NETQUEUE queue)
{
STRUCTURE_STATS *psStats;
DROID *psDroid;
unsigned int typeIndex;
uint8_t player;
uint16_t x, y;
int32_t order;
uint32_t structRef, structId, targetId,droidID;

NETbeginDecode(queue, GAME_BUILD);
NETuint8_t(&player);
NETuint32_t(&structRef);
NETuint16_t(&x);
NETuint16_t(&y);
NETuint32_t(&droidID);
NETuint32_t(&structId);
NETint32_t(&order);
NETuint32_t(&targetId);
NETend();

// Find structure target
for (typeIndex = 0;
typeIndex < numStructureStats && asStructureStats[typeIndex].ref != structRef;
typeIndex++);

psStats = &asStructureStats[typeIndex];

if (IdToDroid(droidID, player, &psDroid))
{
if (psDroid->psTarget)
{
// Sync IDs
debug(LOG_SYNC, "GAME_BUILD: Changing structureId %u to %u. (TODO: Remove this.)", ((STRUCTURE *)psDroid->psTarget)->id, structId);
((STRUCTURE *)psDroid->psTarget)->id = structId;
return true;
}
debug(LOG_SYNC, "Droid %u was not building structure %u. But that's ok, it was probably destroyed before this message arrived.", droidID, structId);

// TODO The following may be causing crashes, figure out whether to fix or remove it. (Shouldn't be needed with the new code.)
// sync |11:57:00: [recvBuildStarted] Synch error, droid 162496 was not building structure 165480.
// error |11:57:00: [buildStructureDir] Player 0 (Human): is building Emplacement-MortarPit01 at (42, 43) but found Emplacement-MortarPit01 already at (42, 43)
// error |11:57:00: [droidUpdateBuild] Trying to update a construction, but no target!
// error |11:57:00: [droidUpdateBuild] Assert in Warzone: ../../src/droid.c:1098 (psDroid->psTarget), last script event: '0 (CALL_DROID_REACH_LOCATION)'
#if 0
UDWORD actionX, actionY;
// Tell the droid to go to where it needs to in order to build the struct
if (getDroidDestination((BASE_STATS *) psStats, x, y, &actionX, &actionY))
{
psDroid->order = order;

if (psDroid->order == DORDER_LINEBUILD)
{
psDroid->order = DORDER_BUILD;
}

psDroid->orderX = x;
psDroid->orderY = y;
psDroid->psTarStats = (BASE_STATS *) psStats;

if (targetId)
{
setDroidTarget(psDroid, IdToPointer(targetId, ANYPLAYER));
}
else
{
setDroidTarget(psDroid, NULL);
}

if (IsStatExpansionModule(psStats))
{
setUpBuildModule(psDroid);
}
else
{
droidStartBuild(psDroid);
psDroid->action = DACTION_BUILD;
}
}
#endif

// Sync IDs
// TODO Synch IDs, without resorting to an ugly hack like this.
if (psDroid->psTarget)
{
((STRUCTURE *) psDroid->psTarget)->id = structId;
}
}

return true;
}

// ////////////////////////////////////////////////////////////////////////////
// INFORM others that a building has been completed.
BOOL SendBuildFinished(STRUCTURE *psStruct)
Expand Down

0 comments on commit be5285f

Please sign in to comment.