示例#1
0
文件: Team.cpp 项目: Dmytry/spring
void CTeam::GiveEverythingTo(const unsigned toTeam)
{
	CTeam* target = teamHandler->Team(toTeam);

	if (!target) {
		logOutput.Print("Team %i does not exist, can't give units", toTeam);
		return;
	}

	if (!luaRules || luaRules->AllowResourceTransfer(teamNum, toTeam, "m", metal)) {
		target->metal += metal;
		metal = 0;
	}
	if (!luaRules || luaRules->AllowResourceTransfer(teamNum, toTeam, "e", energy)) {
		target->energy += energy;
		energy = 0;
	}

	for (CUnitSet::iterator ui = units.begin(); ui != units.end(); ) {
		// must pass the normal checks, isDead, unit count restrictions, luaRules, etc...
		CUnitSet::iterator next = ui; ++next;
		(*ui)->ChangeTeam(toTeam, CUnit::ChangeGiven);
		ui = next;
	}

	Died();
}
示例#2
0
void CTeam::SelfDestruct()
{
	for (CUnitSet::iterator ui = units.begin(); ui != units.end(); ++ui) {
		CUnit* unit = (*ui);
		if (unit != NULL && unit->unitDef->canSelfD) {
			if (unit->beingBuilt) {
				unit->KillUnit(false, true, NULL); // kill units under construction without explosion
			} else {
				unit->KillUnit(true, false, NULL);
			}
		}
	}
	Died();
}
示例#3
0
文件: Team.cpp 项目: Dmytry/spring
void CTeam::RemoveUnit(CUnit* unit,RemoveType type)
{
	units.erase(unit);
	switch (type) {
		case RemoveDied: {
			currentStats.unitsDied++;
			break;
		}
		case RemoveGiven: {
			currentStats.unitsSent++;
			break;
		}
		case RemoveCaptured: {
			currentStats.unitsOutCaptured++;
			break;
		}
	}

	if (units.empty() && !gaia) {
		Died();
	}
}
示例#4
0
/*
===================
=
= GameLoop
=
===================

This function controls the flow between states of the game.

It loads previous saved games, setup levels states, controls the
flow between levels, including when player loses or when completes the game,
and checks if the result of the current game is a highscore.

The "real" game loop (player actions in like moving, killing, etc.) is in the
PlayLoop function.
*/
void GameLoop (void)
{
	int i,xl,yl,xh,yh;
	char num[20];
	boolean	died;
#ifdef MYPROFILE
	/* clock_t type variables
	   may register times, 
		start and and times 
		could be used to measure 
		the speed of the graphics system.
		Speed is measured in fps- frames per second.
*/
	clock_t start,end;
#endif

restartgame:
	ClearMemory (); 
	SETFONTCOLOR(0,15);
	DrawPlayScreen ();
	died = false;
restart:
	do
	{
		if (!loadedgame)
		  gamestate.score = gamestate.oldscore;
		DrawScore();

		startgame = false;
		if (loadedgame)
			loadedgame = false;
		else
			SetupGameLevel ();

#ifdef SPEAR
		if (gamestate.mapon == 20)	// give them the key allways
		{
			gamestate.keys |= 1;
			DrawKeys ();
		}
#endif

		ingame = true;
		StartMusic ();
		PM_CheckMainMem ();
		if (!died)
			PreloadGraphics ();
		else
			died = false;

		fizzlein = true;
		DrawLevel ();

startplayloop:
		PlayLoop ();

#ifdef SPEAR
		if (spearflag)
		{
			SD_StopSound();
			SD_PlaySound(GETSPEARSND);
			if (DigiMode != sds_Off)
			{
				long lasttimecount = TimeCount;

				while(TimeCount < lasttimecount+150)
				//while(DigiPlaying!=false)
					SD_Poll();
			}
			else
				SD_WaitSoundDone();

			ClearMemory ();
			gamestate.oldscore = gamestate.score;
			gamestate.mapon = 20;
			SetupGameLevel ();
			StartMusic ();
			PM_CheckMainMem ();
			player->x = spearx;
			player->y = speary;
			player->angle = spearangle;
			spearflag = false;
			Thrust (0,0);
			goto startplayloop;
		}
#endif

		StopMusic ();
		ingame = false;

		if (demorecord && playstate != ex_warped)
			FinishDemoRecord ();

		if (startgame || loadedgame)
			goto restartgame;

		switch (playstate)
		{
		case ex_completed:
		case ex_secretlevel:
			gamestate.keys = 0;
			DrawKeys ();
			VW_FadeOut ();

			ClearMemory ();

			LevelCompleted ();		// do the intermission
#ifdef SPEARDEMO
			if (gamestate.mapon == 1)
			{
				died = true;			// don't "get psyched!"

				VW_FadeOut ();

				ClearMemory ();

				CheckHighScore (gamestate.score,gamestate.mapon+1);

				#pragma warn -sus
				#ifndef JAPAN
				_fstrcpy(MainMenu[viewscores].string,STR_VS);
				#endif
				MainMenu[viewscores].routine = CP_ViewScores;
				#pragma warn +sus

				return;
			}
#endif

#ifdef JAPDEMO
			if (gamestate.mapon == 3)
			{
				died = true;			// don't "get psyched!"

				VW_FadeOut ();

				ClearMemory ();

				CheckHighScore (gamestate.score,gamestate.mapon+1);

				#pragma warn -sus
				#ifndef JAPAN
				_fstrcpy(MainMenu[viewscores].string,STR_VS);
				#endif
				MainMenu[viewscores].routine = CP_ViewScores;
				#pragma warn +sus

				return;
			}
#endif

			gamestate.oldscore = gamestate.score;

#ifndef SPEAR
			//
			// COMING BACK FROM SECRET LEVEL
			//
			if (gamestate.mapon == 9)
				gamestate.mapon = ElevatorBackTo[gamestate.episode];	// back from secret
			else
			//
			// GOING TO SECRET LEVEL
			//
			if (playstate == ex_secretlevel)
				gamestate.mapon = 9;
#else

#define FROMSECRET1		3
#define FROMSECRET2		11

			//
			// GOING TO SECRET LEVEL
			//
			if (playstate == ex_secretlevel)
				switch(gamestate.mapon)
				{
				 case FROMSECRET1: gamestate.mapon = 18; break;
				 case FROMSECRET2: gamestate.mapon = 19; break;
				}
			else
			//
			// COMING BACK FROM SECRET LEVEL
			//
			if (gamestate.mapon == 18 || gamestate.mapon == 19)
				switch(gamestate.mapon)
				{
				 case 18: gamestate.mapon = FROMSECRET1+1; break;
				 case 19: gamestate.mapon = FROMSECRET2+1; break;
				}
#endif
			else
			//
			// GOING TO NEXT LEVEL
			//
				gamestate.mapon++;


			break;

		case ex_died:
			Died ();
			died = true;			// don't "get psyched!"

			if (gamestate.lives > -1)
				break;				// more lives left

			VW_FadeOut ();

			ClearMemory ();

			CheckHighScore (gamestate.score,gamestate.mapon+1);

			#pragma warn -sus
			#ifndef JAPAN
			_fstrcpy(MainMenu[viewscores].string,STR_VS);
			#endif
			MainMenu[viewscores].routine = CP_ViewScores;
			#pragma warn +sus

			return;

		case ex_victorious:

#ifndef SPEAR
			VW_FadeOut ();
#else
			VL_FadeOut (0,255,0,17,17,300);
#endif
			ClearMemory ();

			Victory ();

			ClearMemory ();

			CheckHighScore (gamestate.score,gamestate.mapon+1);

			#pragma warn -sus
			#ifndef JAPAN
			_fstrcpy(MainMenu[viewscores].string,STR_VS);
			#endif
			MainMenu[viewscores].routine = CP_ViewScores;
			#pragma warn +sus

			return;

		default:
			ClearMemory ();
			break;
		}

	} while (1);

}
示例#5
0
void byoSnake::Move()
{
    if ( IsPaused() )
    {
        Refresh();
        m_Timer.Start(-1,true);
        return;
    }

    // Calculating new position

    if ( m_InitialSlowdownCnt )
    {
        m_InitialSlowdownCnt--;
        m_Timer.Start(-1,true);
        return;
    }

    int newX = m_SnakeX[0];
    int newY = m_SnakeY[0];

    switch ( m_Direction )
    {
        case dLeft:  newX--; break;
        case dRight: newX++; break;
        case dUp:    newY--; break;
        case dDown:  newY++; break;
    }

    bool valid = true;
    if ( newX<0 || newX>=m_FieldHoriz ) valid = false;
    if ( newY<0 || newY>=m_FieldVert  ) valid = false;

    for ( int i=0; valid && i<m_SnakeLen-1; i++ )
    {
        if ( m_SnakeX[i] == newX && m_SnakeY[i] == newY ) valid = false;
    }

    if ( !valid )
    {
        if ( ++m_KillCnt >= m_MaxKillCnt )
        {
            Died();
        }
        else
        {
            m_Timer.Start(-1,true);
        }
        Refresh();
        return;
    }

    m_KillCnt = 0;

    if ( newX == m_AppleX && newY == m_AppleY )
    {
        GetsBigger();
    }

    // Shifting snake
    for ( int i=m_SnakeLen; i-->0;  )
    {
        m_SnakeX[i] = m_SnakeX[i-1];
        m_SnakeY[i] = m_SnakeY[i-1];
    }

    m_SnakeX[0] = newX;
    m_SnakeY[0] = newY;

    RebuildField();
    if ( newX == m_AppleX && newY == m_AppleY )
    {
        RandomizeApple();
    }
    else
    {
        m_Score -= m_Delay / 10;
        if ( m_Score <0 ) m_Score = 0;
    }

    Refresh();

    m_Timer.Start(-1,true);
}