* 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
master
Giel van Schijndel 2007-12-30 17:07:11 +00:00
parent ed2ac88c21
commit 8e1536d867
4 changed files with 43 additions and 36 deletions

View File

@ -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
}

View File

@ -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);

View File

@ -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);

View File

@ -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);