Example #1
0
// ////////////////////////////////////////////////////////////////////////////
// put down a base plate and start droid building it!
BOOL recvBuildStarted(NETMSG *pMsg)
{
	//UDWORD			targetId,order,droidId,structId,x,z,y,structStat,player;
	UDWORD			targetId,order,droidId,structId,structStat;
	UWORD			x,z,y,player;
	STRUCTURE_STATS *psStats;
	DROID			*psDroid;
	UDWORD			typeindex,actionX,actionY;

	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
	(typeindex<numStructureStats ) && (asStructureStats[typeindex].ref != structStat);
	typeindex++);  

	psStats = &asStructureStats[typeindex];
	
	if(IdToDroid(droidId,player, &psDroid))
	{
		if (getDroidDestination( (BASE_STATS *)psStats ,x,y, &actionX,&actionY))				
		{
			psDroid->order = order;
			if(psDroid->order == DORDER_LINEBUILD)
			{
				psDroid->order = DORDER_BUILD;
			}
			psDroid->orderX = x;
			psDroid->orderY = y;
			psDroid->psTarStats = (BASE_STATS *) psStats;
			if(targetId)
			{
				psDroid->psTarget = IdToPointer(targetId,ANYPLAYER);
			}
			else
			{
				psDroid->psTarget = 0;
			}

			if (IsStatExpansionModule(psStats))
			{
				setUpBuildModule(psDroid);
			}
			else
			{
				droidStartBuild(psDroid);
				psDroid->action = DACTION_BUILD;
			}
			
		}


		if (psDroid->psTarget)									//sync id's 
		{
			((STRUCTURE*)psDroid->psTarget)->id = structId; 
		}
	}

	// order droid to start building it.
	return TRUE;
}
// ////////////////////////////////////////////////////////////////////////////
// put down a base plate and start droid building it!
BOOL recvBuildStarted()
{
    STRUCTURE_STATS *psStats;
    DROID			*psDroid;
    UDWORD			actionX,actionY;
    unsigned int typeIndex;
    uint8_t			player;
    uint16_t		x, y, z;
    int32_t			order;
    uint32_t		structRef, structId, targetId,droidID;

    NETbeginDecode(NET_BUILD);
    NETuint8_t(&player);
    NETuint32_t(&structRef);
    NETuint16_t(&x);
    NETuint16_t(&y);
    NETuint32_t(&droidID);
    NETuint32_t(&structId);
    NETint32_t(&order);
    NETuint32_t(&targetId);
    NETuint16_t(&z);
    NETend();
    // Find structure target
    for (typeIndex = 0;
            typeIndex < numStructureStats && asStructureStats[typeIndex].ref != structRef;
            typeIndex++);

    psStats = &asStructureStats[typeIndex];

    if (IdToDroid(droidID, player, &psDroid))
    {
        // Tell the droid to go to where it needs to in order to build the struct
        if (getDroidDestination((BASE_STATS *) psStats, x, y, &actionX, &actionY))
        {
            psDroid->order = order;

            if (psDroid->order == DORDER_LINEBUILD)
            {
                psDroid->order = DORDER_BUILD;
            }

            psDroid->orderX = x;
            psDroid->orderY = y;
            psDroid->psTarStats = (BASE_STATS *) psStats;

            if (targetId)
            {
                setDroidTarget(psDroid, IdToPointer(targetId, ANYPLAYER));
            }
            else
            {
                setDroidTarget(psDroid, NULL);
            }

            if (IsStatExpansionModule(psStats))
            {
                setUpBuildModule(psDroid);
            }
            else
            {
                droidStartBuild(psDroid);
                psDroid->action = DACTION_BUILD;
            }
        }

        // Sync IDs
        if (psDroid->psTarget)
        {
            ((STRUCTURE *) psDroid->psTarget)->id = structId;
        }
    }

    return true;
}