Exemplo n.º 1
0
BOOL recvDemolishFinished(NETQUEUE queue)
{
	STRUCTURE	*psStruct;
	DROID		*psDroid;
	uint32_t	structID, droidID;

	NETbeginDecode(queue, GAME_DEMOLISH);
		NETuint32_t(&structID);
		NETuint32_t(&droidID);
	NETend();

	psStruct = IdToStruct(structID, ANYPLAYER);
	if (!IdToDroid(droidID, ANYPLAYER, &psDroid))
	{
		debug(LOG_ERROR, "recvDemolishFinished: Packet with bad droid ID received. Discarding!");
		return false;
	}

	if (psStruct)
	{
		// Demolish it
		// Should never get here, if in synch.
		removeStruct(psStruct, true);
		if (psDroid && psDroid->psTarStats)
		{
			// Update droid if reqd
			psDroid->psTarStats = NULL;
		}
	}

	return true;
}
Exemplo n.º 2
0
int main(void){
	
    struct node *list;
    short int exit = 0;
    char input;
	
    list = malloc( sizeof(struct node) * 1);
    list->name = NULL;
    list->age = -1;
    list->nextName = NULL;
    list->nextAge = NULL;
	
    do {
		
        printf("1. Add Structure\n2. Remove Structure\n3. Print names\n4. Print ages\n5. Exit\n\nOption: ");
		
        do {
            input = getchar();
        } while (input == '\n');
        while(getchar() != '\n');
		
        switch (input){
            case '1':
                addStruct(list);
                break;
            case '2':
                removeStruct(list);
                break;
            case '3':
                printListByName(list);
                break;
            case '4':
                printListByAge(list);
                break;
            case '5':
                exit = 1;
                break;
        }
		
        printf("\n");
		
    } while (exit == 0);
	
	
    /* Free all by name.  It doesn't matter whether we progress
	 through the list by age or name, as long as we make sure we
	 go all the way through the list. */
    struct node *next;
	
    do {
        next = list->nextName;
        if (list->name != NULL) free(list->name);
        free(list);
        list = next;
    } while (list != NULL);
	
    return 0;
}
Exemplo n.º 3
0
/*
** when a remote player leaves an arena game do this!
**
** @param player -- the one we need to clear
** @param quietly -- true means without any visible effects
*/
void clearPlayer(UDWORD player,bool quietly)
{
	UDWORD			i;
	STRUCTURE		*psStruct,*psNext;

	debug(LOG_NET, "R.I.P. %s (%u). quietly is %s", getPlayerName(player), player, quietly ? "true":"false");

	ingame.JoiningInProgress[player] = false;	// if they never joined, reset the flag
	ingame.DataIntegrity[player] = false;

	(void)setPlayerName(player,"");				//clear custom player name (will use default instead)

	for(i = 0;i<MAX_PLAYERS;i++)				// remove alliances
	{
		alliances[player][i]	= ALLIANCE_BROKEN;
		alliances[i][player]	= ALLIANCE_BROKEN;
	}

	debug(LOG_DEATH, "killing off all droids for player %d", player);
	while(apsDroidLists[player])				// delete all droids
	{
		if(quietly)			// don't show effects
		{
			killDroid(apsDroidLists[player]);
		}
		else				// show effects
		{
			destroyDroid(apsDroidLists[player], gameTime);
		}
	}

	debug(LOG_DEATH, "killing off all structures for player %d", player);
	psStruct = apsStructLists[player];
	while(psStruct)				// delete all structs
	{
		psNext = psStruct->psNext;

		// FIXME: look why destroyStruct() doesn't put back the feature like removeStruct() does
		if(quietly || psStruct->pStructureType->type == REF_RESOURCE_EXTRACTOR)		// don't show effects
		{
			removeStruct(psStruct, true);
		}
		else			// show effects
		{
			destroyStruct(psStruct, gameTime);
		}

		psStruct = psNext;
	}

	return;
}
Exemplo n.º 4
0
BOOL recvDemolishFinished(NETMSG *m)
{
	STRUCTURE	*psStruct;
	UDWORD		s,d;
	DROID		*psDroid;

	NetGet(m,0,s);					
	NetGet(m,4,d);							

	psStruct = IdToStruct(s,ANYPLAYER);
	IdToDroid(d,ANYPLAYER,&psDroid);

	if(psStruct)
	{
		removeStruct( psStruct, TRUE );				// demolish it.
		if(psDroid && psDroid->psTarStats)
		{
			psDroid->psTarStats = NULL;		// update droid if reqd.
		}
	}
	return TRUE;
}
Exemplo n.º 5
0
// ////////////////////////////////////////////////////////////////////////////
// remove structures from map before campaign play.
static BOOL cleanMap(UDWORD player)
{
    DROID		*psD,*psD2;
    STRUCTURE	*psStruct;
    BOOL		firstFact,firstRes;

    bMultiPlayer = false;
    bMultiMessages = false;

    firstFact = true;
    firstRes = true;

    switch(game.base)
    {
    case CAMP_CLEAN:									//clean map
        while(apsStructLists[player])					//strip away structures.
        {
            removeStruct(apsStructLists[player], true);
        }
        psD = apsDroidLists[player];					// remove all but construction droids.
        while(psD)
        {
            psD2=psD->psNext;
            if (psD->droidType != DROID_CONSTRUCT && psD->droidType != DROID_CYBORG_CONSTRUCT)
            {
                killDroid(psD);
            }
            psD = psD2;
        }
        break;

    case CAMP_BASE:												//just structs, no walls
        psStruct = apsStructLists[player];
        while(psStruct)
        {
            if ( (psStruct->pStructureType->type == REF_WALL)
                    ||(psStruct->pStructureType->type == REF_WALLCORNER)
                    ||(psStruct->pStructureType->type == REF_DEFENSE)
                    ||(psStruct->pStructureType->type == REF_BLASTDOOR)
                    ||(psStruct->pStructureType->type == REF_GATE)
                    ||(psStruct->pStructureType->type == REF_CYBORG_FACTORY)
                    ||(psStruct->pStructureType->type == REF_COMMAND_CONTROL))
            {
                removeStruct(psStruct, true);
                psStruct= apsStructLists[player];			//restart,(list may have changed).
            }
            else if( (psStruct->pStructureType->type == REF_FACTORY)
                     ||(psStruct->pStructureType->type == REF_RESEARCH)
                     ||(psStruct->pStructureType->type == REF_POWER_GEN))
            {
                if(psStruct->pStructureType->type == REF_FACTORY )
                {
                    if(firstFact == true)
                    {
                        firstFact = false;
                        removeStruct(psStruct, true);
                        psStruct= apsStructLists[player];
                    }
                    else	// don't delete, just rejig!
                    {
                        if(((FACTORY*)psStruct->pFunctionality)->capacity != 0)
                        {
                            ((FACTORY*)psStruct->pFunctionality)->capacity = 0;
                            ((FACTORY*)psStruct->pFunctionality)->productionOutput = (UBYTE)((PRODUCTION_FUNCTION*)psStruct->pStructureType->asFuncList[0])->productionOutput;

                            psStruct->sDisplay.imd	= psStruct->pStructureType->pIMD;
                            psStruct->body			= (UWORD)(structureBody(psStruct));

                        }
                        psStruct				= psStruct->psNext;
                    }
                }
                else if(psStruct->pStructureType->type == REF_RESEARCH)
                {
                    if(firstRes == true)
                    {
                        firstRes = false;
                        removeStruct(psStruct, true);
                        psStruct= apsStructLists[player];
                    }
                    else
                    {
                        if(((RESEARCH_FACILITY*)psStruct->pFunctionality)->capacity != 0)
                        {   // downgrade research
                            ((RESEARCH_FACILITY*)psStruct->pFunctionality)->capacity = 0;
                            ((RESEARCH_FACILITY*)psStruct->pFunctionality)->researchPoints = ((RESEARCH_FUNCTION*)psStruct->pStructureType->asFuncList[0])->researchPoints;
                            psStruct->sDisplay.imd	= psStruct->pStructureType->pIMD;
                            psStruct->body			= (UWORD)(structureBody(psStruct));
                        }
                        psStruct=psStruct->psNext;
                    }
                }
                else if(psStruct->pStructureType->type == REF_POWER_GEN)
                {
                    if(((POWER_GEN*)psStruct->pFunctionality)->capacity != 0)
                    {   // downgrade powergen.
                        ((POWER_GEN*)psStruct->pFunctionality)->capacity = 0;

                        psStruct->sDisplay.imd	= psStruct->pStructureType->pIMD;
                        psStruct->body			= (UWORD)(structureBody(psStruct));
                    }
                    structurePowerUpgrade(psStruct);
                    psStruct=psStruct->psNext;
                }
            }

            else
            {
                psStruct=psStruct->psNext;
            }
        }
        break;


    case CAMP_WALLS:												//everything.
        break;
    default:
        debug( LOG_FATAL, "Unknown Campaign Style" );
        abort();
        break;
    }

    bMultiPlayer = true;
    bMultiMessages = true;
    return true;
}