From 3bc0d30be1b7f5b100975241362165f55d67e50c Mon Sep 17 00:00:00 2001 From: Freddie Witherden Date: Mon, 24 Dec 2007 14:47:44 +0000 Subject: [PATCH] Commit part two of patch #897 by Buginator along with some small changes by myself. git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@3156 4a71c877-e1ca-e34f-864e-861f7616d084 --- src/multiplay.c | 2 +- src/multiplay.h | 2 +- src/multirecv.h | 2 +- src/multistruct.c | 128 +++++++++++++++++++++++++++------------------- 4 files changed, 78 insertions(+), 56 deletions(-) diff --git a/src/multiplay.c b/src/multiplay.c index 49953f002..ea43c0f6d 100644 --- a/src/multiplay.c +++ b/src/multiplay.c @@ -670,7 +670,7 @@ BOOL recvMessage(void) recvBeacon(&msg); break; case NET_BUILD: // a build order has been sent. - recvBuildStarted(&msg); + recvBuildStarted(); break; case NET_BUILDFINISHED: // a building is complete recvBuildFinished(&msg); diff --git a/src/multiplay.h b/src/multiplay.h index 0ab4b47c7..fdcc34b06 100644 --- a/src/multiplay.h +++ b/src/multiplay.h @@ -234,7 +234,7 @@ extern BOOL multiplayerWinSequence(BOOL firstCall); // definitions of functions in multiplay's other c files. // Buildings . multistruct -extern BOOL sendBuildStarted (const STRUCTURE* psStruct, const DROID* psDroid); +extern BOOL sendBuildStarted (STRUCTURE *psStruct, DROID *psDroid); extern BOOL SendDestroyStructure(const STRUCTURE* s); extern BOOL SendBuildFinished (const STRUCTURE* psStruct); extern BOOL sendLasSat (UBYTE player, STRUCTURE *psStruct, BASE_OBJECT *psObj); diff --git a/src/multirecv.h b/src/multirecv.h index 9f2dc606c..6b3a28caa 100644 --- a/src/multirecv.h +++ b/src/multirecv.h @@ -34,7 +34,7 @@ extern BOOL recvDroidMove (NETMSG *pMsg); extern BOOL receiveWholeDroid (NETMSG *pMsg); extern BOOL recvDestroyStructure (NETMSG *pMsg); //extern BOOL RecvBuild (NETMSG *pMsg); -extern BOOL recvBuildStarted (NETMSG *pMsg); +extern BOOL recvBuildStarted (); extern BOOL recvBuildFinished (NETMSG *pMsg); //extern BOOL receiveWholeStructure (NETMSG *pMsg); extern BOOL recvTemplate (NETMSG *pMsg); diff --git a/src/multistruct.c b/src/multistruct.c index 4b3885526..aefec09c4 100644 --- a/src/multistruct.c +++ b/src/multistruct.c @@ -52,75 +52,97 @@ // //////////////////////////////////////////////////////////////////////////// // INFORM others that a building has been started, and base plate should be put down. -BOOL sendBuildStarted(const STRUCTURE* psStruct, const DROID* psDroid) +BOOL sendBuildStarted(STRUCTURE *psStruct, DROID *psDroid) { - NETMSG msg; - UDWORD zero=0; - UWORD player,order; - player = (UBYTE)psDroid->player; - order = (UBYTE)psDroid->order; - NetAdd(msg,0,player); //player - NetAdd(msg,1,psDroid->psTarStats->ref); //id of thing to build - NetAdd(msg,5,psDroid->orderX); // x - NetAdd(msg,7,psDroid->orderY); // y - NetAdd(msg,11,psDroid->id); // droid to order to build it - NetAdd(msg,15,psStruct->id); // building id to create - NetAdd(msg,19,order); // building id to create + DBCONPRINTF(ConsoleString,(ConsoleString,"sendBuildStarted() called")); + NETbeginEncode(NET_BUILD, NET_ALL_PLAYERS); + + // 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 + { + NETnull(); + } + + // Z coord + NETuint16_t(&psStruct->pos.z); - if (psDroid->psTarget && psDroid->psTarget->type == OBJ_STRUCTURE) - { - NetAdd(msg,20,((STRUCTURE*)psDroid->psTarget)->id); - } - else - { - NetAdd(msg,20,zero); - } - - NetAdd(msg,24,psStruct->pos.z); - - msg.size =28; - msg.type = NET_BUILD; - return (NETbcast(&msg,FALSE)); + return NETend(); } // //////////////////////////////////////////////////////////////////////////// // put down a base plate and start droid building it! -BOOL recvBuildStarted(NETMSG *pMsg) +BOOL recvBuildStarted() { - UDWORD targetId,order,droidId,structId,structStat; - UWORD x,z,y,player; STRUCTURE_STATS *psStats; DROID *psDroid; - UDWORD typeindex,actionX,actionY; + UDWORD actionX,actionY; + int typeIndex; + uint8_t player; + uint16_t x, y, z; + int32_t order; + uint32_t structRef, structId, targetId,droidID; - player = pMsg->body[0]; // decode message. - NetGet(pMsg,1,structStat); - NetGet(pMsg,5,x); - NetGet(pMsg,7,y); - NetGet(pMsg,11,droidId); - NetGet(pMsg,15,structId); - order = pMsg->body[19]; - NetGet(pMsg,20,targetId); - NetGet(pMsg,24,z); - for(typeindex=0; // find structure target - (typeindexorder = order; - if(psDroid->order == DORDER_LINEBUILD) + + if (psDroid->order == DORDER_LINEBUILD) { psDroid->order = DORDER_BUILD; } + psDroid->orderX = x; psDroid->orderY = y; psDroid->psTarStats = (BASE_STATS *) psStats; - if(targetId) + + if (targetId) { setDroidTarget(psDroid, IdToPointer(targetId, ANYPLAYER)); } @@ -138,16 +160,16 @@ BOOL recvBuildStarted(NETMSG *pMsg) droidStartBuild(psDroid); psDroid->action = DACTION_BUILD; } - } - if (psDroid->psTarget) //sync id's + // Sync IDs + if (psDroid->psTarget) { - ((STRUCTURE*)psDroid->psTarget)->id = structId; + ((STRUCTURE *) psDroid->psTarget)->id = structId; } } - - // order droid to start building it. + + NETend(); return TRUE; }