void CHL2MPRules::RestartGame()
{
	// bounds check
	if ( mp_timelimit.GetInt() < 0 )
	{
		mp_timelimit.SetValue( 0 );
	}
	m_flGameStartTime = gpGlobals->curtime;
	if ( !IsFinite( m_flGameStartTime.Get() ) )
	{
		Warning( "Trying to set a NaN game start time\n" );
		m_flGameStartTime.GetForModify() = 0.0f;
	}

	// Pre Map Cleanup
	for (int i = 1; i <= gpGlobals->maxClients; i++ )
	{
		CHL2MP_Player *pPlayer = (CHL2MP_Player*) UTIL_PlayerByIndex( i );

		if ( !pPlayer )
			continue;

		//Tony; if they aren't a spectator, make sure they get cleaned up before entities are removed!
		if ( pPlayer->GetTeamNumber() != TEAM_SPECTATOR )
		{
				// If they're in a vehicle, make sure they get out!
				if ( pPlayer->IsInAVehicle() )
					pPlayer->LeaveVehicle();

				QAngle angles = pPlayer->GetLocalAngles();

				angles.x = 0;
				angles.z = 0;

				pPlayer->SetLocalAngles( angles );
				CBaseCombatWeapon *pWeapon = (CBaseCombatWeapon*)pPlayer->GetActiveWeapon();
				if (pWeapon)
				{
					pPlayer->Weapon_Detach( pWeapon );
					UTIL_Remove( pWeapon );
				}
		}
		pPlayer->RemoveAllItems(true);
		pPlayer->ClearActiveWeapon();
		pPlayer->Reset();
	}

	CleanUpMap();
	
	// now that everything is cleaned up, respawn everyone.
	for (int i = 1; i <= gpGlobals->maxClients; i++ )
	{
		CHL2MP_Player *pPlayer = (CHL2MP_Player*) UTIL_PlayerByIndex( i );

		if ( !pPlayer )
			continue;

		//Tony; if they aren't a spectator, respawn them.
		if ( pPlayer->GetTeamNumber() != TEAM_SPECTATOR )
			pPlayer->Spawn();
	}

	CTeam *pRebels = GetGlobalTeam( TEAM_REBELS );
	CTeam *pCombine = GetGlobalTeam( TEAM_COMBINE );

	if ( pRebels )
	{
		pRebels->SetRoundScore( 0 );
	}

	if ( pCombine )
	{
		pCombine->SetRoundScore( 0 );
	}

	m_flIntermissionEndTime = 0;
	m_flRestartGameTime = 0.0;		
	m_bCompleteReset = false;

	IGameEvent * event = gameeventmanager->CreateEvent( "round_start" );
	if ( event )
	{
		event->SetInt("fraglimit", 0 );
		event->SetInt( "priority", 6 ); // HLTV event priority, not transmitted

		event->SetString("objective","DEATHMATCH");

		gameeventmanager->FireEvent( event );
	}
}
示例#2
0
//-----------------------------------------------------------------------------
// Can the player be set as the parent?
//-----------------------------------------------------------------------------
void CTriggerCTFCapture::StartTouch(CBaseEntity *pOther)
{
	if (!pOther->IsPlayer()) //Nothing else should trigger this.
		return;

	//Defines
	CHL2MP_Player *pPlayer = ToHL2MPPlayer(pOther);
	CtfFlag *pFlag = NULL;
	bool m_bHomeFlagTaken = false;

	if (!pPlayer || !pPlayer->IsAlive()) //Still alive?
		return;

	if (sv_ctf_capturestyle.GetInt() > 1)
	{
		while ((pFlag = static_cast<CtfFlag*>(gEntList.FindEntityByClassname(pFlag, "ctf_flag"))) != NULL)
		{
			if (pFlag->iTeam == pPlayer->GetTeamNumber()) //This flag is an enemy flag, we want the player's team's flag.
				continue;

			if (pFlag->GetAbsOrigin() != pFlag->FlagOrigin) //This flag belongs to the player's team. Is it at home?
				m_bHomeFlagTaken = true;
		}
	}


	while ((pFlag = static_cast<CtfFlag*>(gEntList.FindEntityByClassname(pFlag, "ctf_flag"))) != NULL)
	{
		if (pFlag->GetParent() && pFlag->GetParent() == pPlayer) //So the flag has a parent.. and it's the player who touched the trigger.
		{
			int TeamNumber = pPlayer->GetTeamNumber();

			//For team affected by the trigger.
			switch (m_iAffectedTeam)
			{
			case 0:
				iTeam = TeamNumber;
				break;
			case 1:
				iTeam = TEAM_BRITISH;
				break;
			case 2:
				iTeam = TEAM_AMERICANS;
				break;
			}

			if (TeamNumber != iTeam) //Trigger isn't for this player's team. Die.
				return;
			//

			if (m_bHomeFlagTaken) //The player's team's flag is taken. So we cannot cap an enemy flag.
			{
				ClientPrint(pPlayer, CTF_DENY_CAPTURE); //Let the player know.
				return; //Die here.
			}

			//Assuming we've made it thus far, you're probably carrying a flag that belongs to the enemy. Go ahead and cap it.
			pFlag->PlaySound(GetAbsOrigin(), m_iSound); //Play the capture sound.

			pFlag->ResetFlag();

			g_Teams[TeamNumber]->AddScore(m_iTeamBonus); //Adds the team score bonus.
			pPlayer->IncrementFragCount(m_iPlayerBonus); //Give the player the points.

			//reset the capturer's speed
			//pPlayer->SetSpeedModifier(0);
			pPlayer->RemoveSpeedModifier(ESpeedModID::Flag); //BG3 - Awesome - removed to more robust speed modifier system

			pFlag->PrintAlert(CTF_CAPTURE, pPlayer->GetPlayerName(), pFlag->cFlagName);

			//Do the log stuff.
			CTeam *team = pPlayer->GetTeam();

			UTIL_LogPrintf("\"%s<%i><%s><%s>\" triggered \"ctf_flag_capture\"\n",
				pPlayer->GetPlayerName(),
				pPlayer->GetUserID(),
				pPlayer->GetNetworkIDString(),
				team ? team->GetName() : "");
			//

			m_OnFlagCaptured.FireOutput(this, this); //Fire the OnFlagCaptured output, set it last just in case.
		}
	}
}