From 7e9b1086457b759b96cce5125d5f7018a07eaefb Mon Sep 17 00:00:00 2001 From: Freddie Witherden Date: Mon, 24 Dec 2007 15:10:34 +0000 Subject: [PATCH] Commit part 4 of patch #897 (send/recv structure demolished messages. git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@3159 4a71c877-e1ca-e34f-864e-861f7616d084 --- src/multiplay.c | 2 +- src/multirecv.h | 2 +- src/multistruct.c | 44 +++++++++++++++++++++++++------------------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/multiplay.c b/src/multiplay.c index 05a9cb3da..b649dce2c 100644 --- a/src/multiplay.c +++ b/src/multiplay.c @@ -729,7 +729,7 @@ BOOL recvMessage(void) recvPing(&msg); break; case NET_DEMOLISH: // structure demolished. - recvDemolishFinished(&msg); + recvDemolishFinished(); break; case NET_RESEARCH: // some research has been done. recvResearch(&msg); diff --git a/src/multirecv.h b/src/multirecv.h index 51c5685e8..f5af8c2f1 100644 --- a/src/multirecv.h +++ b/src/multirecv.h @@ -39,7 +39,7 @@ extern BOOL recvBuildFinished (); //extern BOOL receiveWholeStructure (NETMSG *pMsg); extern BOOL recvTemplate (NETMSG *pMsg); extern BOOL recvDestroyFeature (NETMSG *pMsg); -extern BOOL recvDemolishFinished (NETMSG *pMsg); +extern BOOL recvDemolishFinished (); extern BOOL recvPing (NETMSG *pMsg); extern BOOL recvRequestDroid (NETMSG *pMsg); extern BOOL recvTextMessage (NETMSG *pMsg); diff --git a/src/multistruct.c b/src/multistruct.c index 30a135238..6cd126d14 100644 --- a/src/multistruct.c +++ b/src/multistruct.c @@ -275,43 +275,49 @@ BOOL recvBuildFinished() // //////////////////////////////////////////////////////////////////////////// // demolish message. -BOOL SendDemolishFinished( STRUCTURE *psStruct,DROID *psDroid) +BOOL SendDemolishFinished(STRUCTURE *psStruct, DROID *psDroid) { - NETMSG m; + DBCONPRINTF(ConsoleString,(ConsoleString,"SendDemolishFinished() called")); + NETbeginEncode(NET_DEMOLISH, NET_ALL_PLAYERS); + + // Send what is being demolish and who is doing it + NETuint32_t(&psStruct->id); + NETuint32_t(&psDroid->id); - NetAdd(m,0,psStruct->id); - NetAdd(m,4,psDroid->id); - - m.size = 2*sizeof(UDWORD); - m.type = NET_DEMOLISH; - return( NETbcast(&m,FALSE)); + return NETend(); } -BOOL recvDemolishFinished(NETMSG *m) +BOOL recvDemolishFinished() { STRUCTURE *psStruct; - UDWORD s,d; DROID *psDroid; + uint32_t structID,droidID; - NetGet(m,0,s); - NetGet(m,4,d); + DBCONPRINTF(ConsoleString,(ConsoleString,"recvDemolishFinished() called")); + NETbeginDecode(); - psStruct = IdToStruct(s,ANYPLAYER); - IdToDroid(d,ANYPLAYER,&psDroid); + NETuint32_t(&structID); + NETuint32_t(&droidID); - if(psStruct) + psStruct = IdToStruct(structID, ANYPLAYER); + IdToDroid(droidID, ANYPLAYER, &psDroid); + + if (psStruct) { - removeStruct( psStruct, TRUE ); // demolish it. - if(psDroid && psDroid->psTarStats) + // Demolish it + removeStruct(psStruct, TRUE); + if (psDroid && psDroid->psTarStats) { - psDroid->psTarStats = NULL; // update droid if reqd. + // Update droid if reqd + psDroid->psTarStats = NULL; } } + + NETend(); return TRUE; } - // //////////////////////////////////////////////////////////////////////////// // Inform others that a structure has been destroyed BOOL SendDestroyStructure(const STRUCTURE* s)