* Move the send/recv-GroupOrder functions over to the new net primitives API (patch #905 by myself)
git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@3242 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
352246e652
commit
6d19aa6473
318
src/multibot.c
318
src/multibot.c
|
@ -514,184 +514,194 @@ typedef enum {
|
||||||
* Droid Group/selection orders.
|
* Droid Group/selection orders.
|
||||||
* Minimises comms by sending orders for whole groups, rather than each droid
|
* Minimises comms by sending orders for whole groups, rather than each droid
|
||||||
*/
|
*/
|
||||||
BOOL SendGroupOrderSelected(uint8_t player, uint32_t x, uint32_t y, BASE_OBJECT *psObj)
|
BOOL SendGroupOrderSelected(uint8_t player, uint32_t x, uint32_t y, const BASE_OBJECT* psObj)
|
||||||
{
|
{
|
||||||
NETMSG m;
|
NETbeginEncode(NET_GROUPORDER, NET_ALL_PLAYERS);
|
||||||
DROID *pDroid;
|
|
||||||
uint16_t droidCount = 0;
|
|
||||||
DROID_ORDER order = UNKNOWN;
|
|
||||||
NET_ORDER_SUBTYPE subType = (psObj) ? NET_ORDER_SUBTYPE_OBJECT : NET_ORDER_SUBTYPE_POSITION;
|
|
||||||
BOOL cmdOrder = FALSE;
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
switch (subType)
|
|
||||||
{
|
{
|
||||||
|
DROID_ORDER order = UNKNOWN;
|
||||||
|
BOOL subType = (psObj) ? TRUE : FALSE, cmdOrder = FALSE;
|
||||||
|
DROID* psDroid;
|
||||||
|
uint8_t droidCount;
|
||||||
|
|
||||||
|
NETenum(&order);
|
||||||
|
NETbool(&cmdOrder);
|
||||||
|
NETbool(&subType);
|
||||||
|
|
||||||
// If they are being ordered to `goto' an object
|
// If they are being ordered to `goto' an object
|
||||||
case NET_ORDER_SUBTYPE_OBJECT:
|
if (subType)
|
||||||
NetAdd(m,0, psObj->id);
|
|
||||||
NetAdd(m,4, psObj->type);
|
|
||||||
break;
|
|
||||||
// If the droids are being ordered to `goto' a specific position
|
|
||||||
case NET_ORDER_SUBTYPE_POSITION:
|
|
||||||
NetAdd(m,0,x);
|
|
||||||
NetAdd(m,4,y);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
assert(!"Unexpected droid-order-targettype!");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
m.body[8] = subType;
|
|
||||||
|
|
||||||
m.body[10] = cmdOrder; // not a cmd order.
|
|
||||||
|
|
||||||
m.body[12] = order; // set the order.
|
|
||||||
|
|
||||||
m.size = 13;
|
|
||||||
|
|
||||||
// Work out the number of droids to send
|
|
||||||
for (pDroid = apsDroidLists[player]; pDroid; pDroid = pDroid->psNext)
|
|
||||||
{
|
|
||||||
if (pDroid->selected)
|
|
||||||
droidCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there are less than 2 droids don't bother (to allow individual orders)
|
|
||||||
if (droidCount < 2)
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the droids to the message (break when reached droidCount, as the rest must be unselected droids)
|
|
||||||
for (i = 0, pDroid = apsDroidLists[player]; i < droidCount && pDroid; pDroid = pDroid->psNext)
|
|
||||||
{
|
|
||||||
if (pDroid->selected)
|
|
||||||
{
|
{
|
||||||
NetAdd(m,m.size,pDroid->id);
|
uint32_t id = psObj->id;
|
||||||
m.size += sizeof(UDWORD);
|
uint32_t type = psObj->type;
|
||||||
i++;
|
|
||||||
|
NETuint32_t(&id);
|
||||||
|
NETenum(&type);
|
||||||
|
}
|
||||||
|
// Else if the droids are being ordered to `goto' a specific position
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NETuint32_t(&x);
|
||||||
|
NETuint32_t(&y);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Work out the number of droids to send
|
||||||
|
for (psDroid = apsDroidLists[player], droidCount = 0; psDroid; psDroid = psDroid->psNext)
|
||||||
|
{
|
||||||
|
if (psDroid->selected)
|
||||||
|
++droidCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there are less than 2 droids don't bother (to allow individual orders)
|
||||||
|
if (droidCount < 2)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the number of droids to the message
|
||||||
|
NETuint8_t(&droidCount);
|
||||||
|
|
||||||
|
// Add the droids to the message
|
||||||
|
for (psDroid = apsDroidLists[player]; psDroid && droidCount; psDroid = psDroid->psNext)
|
||||||
|
{
|
||||||
|
if (psDroid->selected)
|
||||||
|
{
|
||||||
|
NETuint32_t(&psDroid->id);
|
||||||
|
--droidCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return NETend();
|
||||||
// Add the number of droids to the message
|
|
||||||
NetAdd(m,9,droidCount);
|
|
||||||
m.type = NET_GROUPORDER;
|
|
||||||
NETbcast(&m,FALSE);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL SendGroupOrderGroup(DROID_GROUP *psGroup, DROID_ORDER order, uint32_t x, uint32_t y, BASE_OBJECT *psObj)
|
BOOL SendGroupOrderGroup(const DROID_GROUP* psGroup, DROID_ORDER order, uint32_t x, uint32_t y, const BASE_OBJECT* psObj)
|
||||||
{
|
{
|
||||||
NETMSG m;
|
NETbeginEncode(NET_GROUPORDER, NET_ALL_PLAYERS);
|
||||||
DROID *pDroid;
|
|
||||||
uint16_t droidCount = 0;
|
|
||||||
NET_ORDER_SUBTYPE subType = (psObj) ? NET_ORDER_SUBTYPE_OBJECT : NET_ORDER_SUBTYPE_POSITION;
|
|
||||||
BOOL cmdOrder = FALSE;
|
|
||||||
|
|
||||||
switch (subType)
|
|
||||||
{
|
{
|
||||||
|
BOOL subType = (psObj) ? TRUE : FALSE, cmdOrder = FALSE;
|
||||||
|
DROID* psDroid;
|
||||||
|
uint8_t droidCount;
|
||||||
|
|
||||||
|
NETenum(&order);
|
||||||
|
NETbool(&cmdOrder);
|
||||||
|
NETbool(&subType);
|
||||||
|
|
||||||
// If they are being ordered to `goto' an object
|
// If they are being ordered to `goto' an object
|
||||||
case NET_ORDER_SUBTYPE_OBJECT:
|
if (subType)
|
||||||
NetAdd(m,0, psObj->id);
|
{
|
||||||
NetAdd(m,4, psObj->type);
|
uint32_t id = psObj->id;
|
||||||
break;
|
uint32_t type = psObj->type;
|
||||||
// If the droids are being ordered to `goto' a specific position
|
|
||||||
case NET_ORDER_SUBTYPE_POSITION:
|
NETuint32_t(&id);
|
||||||
NetAdd(m,0,x);
|
NETenum(&type);
|
||||||
NetAdd(m,4,y);
|
}
|
||||||
break;
|
// Else if the droids are being ordered to `goto' a specific position
|
||||||
default:
|
else
|
||||||
assert(!"Unexpected droid-order-targettype!");
|
{
|
||||||
break;
|
NETuint32_t(&x);
|
||||||
|
NETuint32_t(&y);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Work out the number of droids to send
|
||||||
|
for (psDroid = psGroup->psList, droidCount = 0; psDroid; psDroid = psDroid->psGrpNext)
|
||||||
|
{
|
||||||
|
++droidCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the number of droids to the message
|
||||||
|
NETuint8_t(&droidCount);
|
||||||
|
|
||||||
|
// Add the droids to the message
|
||||||
|
for (psDroid = psGroup->psList; psDroid; psDroid = psDroid->psGrpNext)
|
||||||
|
{
|
||||||
|
NETuint32_t(&psDroid->id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return NETend();
|
||||||
m.body[8] = subType;
|
|
||||||
|
|
||||||
m.body[10] = cmdOrder; // not a cmd order.
|
|
||||||
|
|
||||||
m.body[12] = order; // set the order.
|
|
||||||
|
|
||||||
m.size = 13;
|
|
||||||
|
|
||||||
// Work out the number of droids to send
|
|
||||||
for (pDroid = psGroup->psList; pDroid; pDroid = pDroid->psGrpNext)
|
|
||||||
{
|
|
||||||
droidCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the droids to the message
|
|
||||||
for (pDroid = psGroup->psList; pDroid; pDroid = pDroid->psGrpNext)
|
|
||||||
{
|
|
||||||
NetAdd(m,m.size,pDroid->id);
|
|
||||||
m.size += sizeof(UDWORD);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the number of droids to the message
|
|
||||||
NetAdd(m,9,droidCount);
|
|
||||||
m.type = NET_GROUPORDER;
|
|
||||||
NETbcast(&m,FALSE);
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ////////////////////////////////////////////////////////////////////////////
|
// ////////////////////////////////////////////////////////////////////////////
|
||||||
// receive a group order.
|
// receive a group order.
|
||||||
BOOL recvGroupOrder(NETMSG *pMsg)
|
BOOL recvGroupOrder()
|
||||||
{
|
{
|
||||||
uint32_t x = 0, y = 0, id = 0, destid = 0;
|
NETbeginDecode();
|
||||||
DROID *psDroid = NULL;
|
|
||||||
OBJECT_TYPE desttype = OBJ_DROID;
|
|
||||||
DROID_ORDER order = pMsg->body[12];
|
|
||||||
NET_ORDER_SUBTYPE subType = pMsg->body[8];
|
|
||||||
BOOL cmdOrder = pMsg->body[10];
|
|
||||||
uint16_t droidCount;
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
// Get the droid count
|
|
||||||
NetGet(pMsg,9,droidCount);
|
|
||||||
|
|
||||||
switch (subType)
|
|
||||||
{
|
{
|
||||||
// It's target is an object
|
DROID_ORDER order;
|
||||||
case NET_ORDER_SUBTYPE_OBJECT:
|
BOOL subType, cmdOrder;
|
||||||
NetGet(pMsg,0,destid);
|
|
||||||
NetGet(pMsg,4,desttype);
|
|
||||||
break;
|
|
||||||
// It's target is a position
|
|
||||||
case NET_ORDER_SUBTYPE_POSITION:
|
|
||||||
NetGet(pMsg,0,x);
|
|
||||||
NetGet(pMsg,4,y);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
assert(!"Unexpected droid-order-targettype!");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// for each droid
|
uint32_t destId, x, y;
|
||||||
for (i = 0; i < droidCount; i++)
|
OBJECT_TYPE destType;
|
||||||
{
|
|
||||||
NetGet(pMsg, 13 + i * sizeof(UDWORD), id);
|
uint8_t droidCount;
|
||||||
IdToDroid(id, ANYPLAYER, &psDroid); // find the droid
|
|
||||||
if (psDroid == NULL)
|
NETenum(&order);
|
||||||
|
NETbool(&cmdOrder);
|
||||||
|
NETbool(&subType);
|
||||||
|
|
||||||
|
// If they are being ordered to `goto' an object
|
||||||
|
if (subType)
|
||||||
{
|
{
|
||||||
sendRequestDroid(id); //droid not found, request it.
|
NETuint32_t(&destId);
|
||||||
return FALSE;
|
NETenum(&destType);
|
||||||
|
}
|
||||||
|
// Else if the droids are being ordered to `goto' a specific position
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NETuint32_t(&x);
|
||||||
|
NETuint32_t(&y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Get the droid count
|
||||||
* If the current order not is a command order and we are not a
|
NETuint8_t(&droidCount);
|
||||||
* commander yet are in the commander group remove us from it.
|
|
||||||
*/
|
|
||||||
if (!cmdOrder && psDroid->droidType != DROID_COMMAND
|
|
||||||
&& psDroid->psGroup != NULL && psDroid->psGroup->type == GT_COMMAND)
|
|
||||||
{
|
|
||||||
grpLeave(psDroid->psGroup, psDroid);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process the droids order
|
// Retrieve the droids from the message
|
||||||
ProcessDroidOrder(psDroid,order,x,y,desttype,destid); // process the order.
|
for (; droidCount; --droidCount)
|
||||||
|
{
|
||||||
|
uint32_t id;
|
||||||
|
DROID* psDroid;
|
||||||
|
|
||||||
|
// Retrieve the id number for the current droid
|
||||||
|
if (!NETuint32_t(&id))
|
||||||
|
{
|
||||||
|
// If somehow we fail assume the message got truncated prematurely
|
||||||
|
debug(LOG_NET, "recvGroupOrder: error retrieving droid ID number; while there are (supposed to be) still %hhu droids left", droidCount);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!IdToDroid(id, ANYPLAYER, &psDroid))
|
||||||
|
{
|
||||||
|
// If the droid's not found, request it
|
||||||
|
sendRequestDroid(id);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the current order not is a command order and we are not a
|
||||||
|
* commander yet are in the commander group remove us from it.
|
||||||
|
*/
|
||||||
|
if (!cmdOrder && psDroid->droidType != DROID_COMMAND
|
||||||
|
&& psDroid->psGroup != NULL && psDroid->psGroup->type == GT_COMMAND)
|
||||||
|
{
|
||||||
|
grpLeave(psDroid->psGroup, psDroid);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process the droid's order
|
||||||
|
if (subType)
|
||||||
|
{
|
||||||
|
/* If they are being ordered to `goto' an object then we don't
|
||||||
|
* have any X and Y coordinate.
|
||||||
|
*/
|
||||||
|
ProcessDroidOrder(psDroid, order, 0, 0, destType, destId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Otherwise if the droids are being ordered to `goto' a
|
||||||
|
* specific position. Then we don't have any destination info
|
||||||
|
*/
|
||||||
|
ProcessDroidOrder(psDroid, order, x, y, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
NETend();
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -649,7 +649,7 @@ BOOL recvMessage(void)
|
||||||
recvDroidMove();
|
recvDroidMove();
|
||||||
break;
|
break;
|
||||||
case NET_GROUPORDER: // an order for more than 1 droid.
|
case NET_GROUPORDER: // an order for more than 1 droid.
|
||||||
recvGroupOrder(&msg);
|
recvGroupOrder();
|
||||||
break;
|
break;
|
||||||
case NET_CHECK_DROID: // droid damage and position checks
|
case NET_CHECK_DROID: // droid damage and position checks
|
||||||
recvDroidCheck();
|
recvDroidCheck();
|
||||||
|
|
|
@ -246,10 +246,10 @@ extern BOOL SendDestroyDroid (const DROID* psDroid);
|
||||||
extern BOOL SendDemolishFinished(STRUCTURE *psS,DROID *psD);
|
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 SendDroidInfo (const DROID* psDroid, DROID_ORDER order, uint32_t x, uint32_t y, const BASE_OBJECT* psObj);
|
||||||
extern BOOL SendDroidMove (const DROID* psDroid, uint32_t x, uint32_t y, BOOL formation);
|
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 SendGroupOrderSelected(uint8_t player, uint32_t x, uint32_t y, const BASE_OBJECT* psObj);
|
||||||
extern BOOL SendCmdGroup (DROID_GROUP *psGroup, UWORD x, UWORD y, BASE_OBJECT *psObj);
|
extern BOOL SendCmdGroup (DROID_GROUP *psGroup, UWORD x, UWORD y, BASE_OBJECT *psObj);
|
||||||
|
|
||||||
extern BOOL SendGroupOrderGroup(DROID_GROUP *psGroup, DROID_ORDER order,UDWORD x,UDWORD y,BASE_OBJECT *psObj);
|
extern BOOL SendGroupOrderGroup(const DROID_GROUP* psGroup, DROID_ORDER order, uint32_t x, uint32_t y, const BASE_OBJECT* psObj);
|
||||||
|
|
||||||
|
|
||||||
extern BOOL sendDroidSecondary (const DROID* psDroid, SECONDARY_ORDER sec, SECONDARY_STATE state);
|
extern BOOL sendDroidSecondary (const DROID* psDroid, SECONDARY_ORDER sec, SECONDARY_STATE state);
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
extern BOOL recvDroid (void);
|
extern BOOL recvDroid (void);
|
||||||
extern BOOL recvDroidInfo (void);
|
extern BOOL recvDroidInfo (void);
|
||||||
extern BOOL recvDestroyDroid (void);
|
extern BOOL recvDestroyDroid (void);
|
||||||
extern BOOL recvGroupOrder (NETMSG *pMsg);
|
extern BOOL recvGroupOrder (void);
|
||||||
extern BOOL recvDroidMove (void);
|
extern BOOL recvDroidMove (void);
|
||||||
extern BOOL receiveWholeDroid (NETMSG *pMsg);
|
extern BOOL receiveWholeDroid (NETMSG *pMsg);
|
||||||
extern BOOL recvDestroyStructure ();
|
extern BOOL recvDestroyStructure ();
|
||||||
|
|
Loading…
Reference in New Issue