Beispiel #1
0
/** Receive droid and transporter loading information
 *
 *  \sa sendDroidEmbark(),sendDroidDisEmbark(),recvDroidDisEmbark()
 */
BOOL recvDroidEmbark(NETQUEUE queue)
{
	DROID* psDroid;
	DROID* psTransporterDroid;
	BOOL bDroidRemoved;

	NETbeginDecode(queue, GAME_DROIDEMBARK);
	{
		uint8_t player;
		uint32_t droidID;
		uint32_t transporterID;

		NETuint8_t(&player);
		NETuint32_t(&droidID);
		NETuint32_t(&transporterID);

		// we have to find the droid on our (local) list first.
		if (!IdToDroid(droidID, player, &psDroid))
		{
			NETend();
			// Possible it already died? (sync error?)
			debug(LOG_WARNING, "player's %d droid %d wasn't found?", player,droidID);
			return false;
		}
		if (!IdToDroid(transporterID, player, &psTransporterDroid))
		{
			NETend();
			// Possible it already died? (sync error?)
			debug(LOG_WARNING, "player's %d transport droid %d wasn't found?", player,transporterID);
			return false;
		}

		if (psDroid == NULL)
		{
			// how can this happen?
			return true;
		}

		// Take it out of the world without destroying it (just removes it from the droid list)
		bDroidRemoved = droidRemove(psDroid, apsDroidLists);

		// Init the order for when disembark
		psDroid->order = DORDER_NONE;
		setDroidTarget(psDroid, NULL);
		psDroid->psTarStats = NULL;

		if (bDroidRemoved)
		{
			// and now we need to add it to their transporter group!
			grpJoin(psTransporterDroid->psGroup, psDroid);
		}
		else
		{
			// possible sync error?
			debug(LOG_WARNING, "Eh? Where did unit %d go? Couldn't load droid onto transporter.", droidID);
		}
	}
	NETend();
	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;
}