From 8e1536d8677c368a8e8e69da3b43d608c133a212 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Sun, 30 Dec 2007 17:07:11 +0000 Subject: [PATCH] * Move the send/recv-DroidMove functions over to the new net primitives API (patch #905 by myself) git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@3239 4a71c877-e1ca-e34f-864e-861f7616d084 --- src/multibot.c | 73 +++++++++++++++++++++++++++---------------------- src/multiplay.c | 2 +- src/multiplay.h | 2 +- src/multirecv.h | 2 +- 4 files changed, 43 insertions(+), 36 deletions(-) diff --git a/src/multibot.c b/src/multibot.c index 213cdd825..ad9e361f7 100644 --- a/src/multibot.c +++ b/src/multibot.c @@ -317,60 +317,67 @@ BOOL recvDroidDisEmbark() // Droids // posibly Send an updated droid movement order. -BOOL SendDroidMove(DROID *pDroid, uint32_t x, uint32_t y, BOOL bFormation) +BOOL SendDroidMove(const DROID* psDroid, uint32_t x, uint32_t y, BOOL formation) { - NETMSG m; - // Don't allow a move to happen at all if it is not our responsibility - if (!myResponsibility(pDroid->player)) + if (!myResponsibility(psDroid->player)) { return FALSE; // Do not allow move } // If the unit has no actions or orders, allow it to happen but do not send - if (pDroid->action == DACTION_NONE || pDroid->order == DORDER_MOVE) + if (psDroid->action == DACTION_NONE || psDroid->order == DORDER_MOVE) { return TRUE; } - NetAdd(m,0,pDroid->id); //droid to move - NetAdd(m,4,x); //x pos - NetAdd(m,8,y); //y pos - NetAdd(m,12,pDroid->player); //owner of droid(for speed!) - NetAdd(m,13,bFormation); //use a formation? - m.size = 14; - m.type = NET_DROIDMOVE; - NETbcast(&m,FALSE); - - return TRUE; + NETbeginEncode(NET_DROIDMOVE, NET_ALL_PLAYERS); + { + uint8_t player = psDroid->player; + uint32_t droid = psDroid->id; + NETuint8_t(&player); + NETuint32_t(&droid); + NETuint32_t(&x); + NETuint32_t(&y); + NETbool(&formation); + } + return NETend(); } // recv and updated droid position -BOOL recvDroidMove(NETMSG *m) +BOOL recvDroidMove() { - UDWORD player,id,x,y; - DROID *psDroid; - UBYTE bFormation; + DROID* psDroid; + uint32_t x, y; + BOOL formation; - NetGet(m,0,id); - NetGet(m,4,x); - NetGet(m,8,y); - player = m->body[12]; - NetGet(m,13,bFormation); - - /* - * If we could not find the droid, request it. We can safely return here - * as when the droid is sent it will contain the updated movement position. - */ - if(!(IdToDroid(id,player,&psDroid))) + NETbeginDecode(); { - sendRequestDroid(id); - return TRUE; + uint8_t player; + uint32_t droid; + + NETuint8_t(&player); + NETuint32_t(&droid); + NETuint32_t(&x); + NETuint32_t(&y); + NETbool(&formation); + + NETend(); + + /* + * If we could not find the droid, request it. We can safely return here + * as when the droid is sent it will contain the updated movement position. + */ + if (!IdToDroid(droid, player, &psDroid)) + { + sendRequestDroid(droid); + return TRUE; + } } turnOffMultiMsg(TRUE); - if (bFormation) + if (formation) { moveDroidTo(psDroid, x, y); // Do the move } diff --git a/src/multiplay.c b/src/multiplay.c index 617e80374..05c7c46f8 100644 --- a/src/multiplay.c +++ b/src/multiplay.c @@ -646,7 +646,7 @@ BOOL recvMessage(void) recvDestroyExtra(&msg); // a generic destroy, complete wiht killer info. break; case NET_DROIDMOVE: // move a droid to x,y command. - recvDroidMove(&msg); + recvDroidMove(); break; case NET_GROUPORDER: // an order for more than 1 droid. recvGroupOrder(&msg); diff --git a/src/multiplay.h b/src/multiplay.h index b57a7a62c..b274935f2 100644 --- a/src/multiplay.h +++ b/src/multiplay.h @@ -245,7 +245,7 @@ extern BOOL SendDroid (const DROID_TEMPLATE* pTemplate, uint32_t x, uint32_t y extern BOOL SendDestroyDroid (const DROID* psDroid); extern BOOL SendDemolishFinished(STRUCTURE *psS,DROID *psD); extern BOOL SendDroidInfo (const DROID* psDroid, DROID_ORDER order, uint32_t x, uint32_t y, const BASE_OBJECT* psObj); -extern BOOL SendDroidMove (DROID *psDroid, UDWORD x, UDWORD y,BOOL bFormation); +extern BOOL SendDroidMove (const DROID* psDroid, uint32_t x, uint32_t y, BOOL formation); extern BOOL SendGroupOrderSelected (UBYTE player, UDWORD x, UDWORD y, BASE_OBJECT *psObj); extern BOOL SendCmdGroup (DROID_GROUP *psGroup, UWORD x, UWORD y, BASE_OBJECT *psObj); diff --git a/src/multirecv.h b/src/multirecv.h index 38f62b613..3272c62d2 100644 --- a/src/multirecv.h +++ b/src/multirecv.h @@ -30,7 +30,7 @@ extern BOOL recvDroid (void); extern BOOL recvDroidInfo (void); extern BOOL recvDestroyDroid (void); extern BOOL recvGroupOrder (NETMSG *pMsg); -extern BOOL recvDroidMove (NETMSG *pMsg); +extern BOOL recvDroidMove (void); extern BOOL receiveWholeDroid (NETMSG *pMsg); extern BOOL recvDestroyStructure (); //extern BOOL RecvBuild (NETMSG *pMsg);