示例#1
0
void CSDKGameRules::CalculateSlowMoForPlayer(CSDKPlayer* pPlayer)
{
	if (!pPlayer)
		return;

	if (!pPlayer->IsAlive())
	{
		pPlayer->SetSlowMoType(SLOWMO_NONE);
		return;
	}

	// If I activated slow then I get to keep my slow level.
	if (pPlayer->GetSlowMoType() == SLOWMO_ACTIVATED)
		return;

	if (pPlayer->GetSlowMoType() == SLOWMO_STYLESKILL)
		return;

	// Players who haven't activated anything are at the whims of those who have.

	bool bOtherInSlow = false;

	CUtlVector<CSDKPlayer*> apOthersInPVS;

	CBaseEntity* pOther = NULL;

	while ((pOther = UTIL_EntitiesInPVS(pPlayer, pOther)) != NULL)
	{
		CSDKPlayer* pOtherPlayer = ToSDKPlayer(pOther);
		if (!pOtherPlayer)
			continue;

		if (pOtherPlayer == pPlayer)
			continue;

		apOthersInPVS.AddToTail(pOtherPlayer);
	}

	for (int i = 0; i < apOthersInPVS.Size(); i++)
	{
		CSDKPlayer* pOtherPlayer = apOthersInPVS[i];

		if (!pOtherPlayer->IsAlive())
			continue;

		if (pOtherPlayer->GetSlowMoType() != SLOWMO_NONE)
		{
			bOtherInSlow = true;
			break;
		}
	}

	// If any of these players are in slow then I'm in slow too.
	if (bOtherInSlow)
		pPlayer->SetSlowMoType(SLOWMO_PASSIVE);
	else
		pPlayer->SetSlowMoType(SLOWMO_NONE);
}
示例#2
0
void CSDKGameRules::GiveSlowMoToNearbyPlayers(CSDKPlayer* pPlayer)
{
	if (!pPlayer)
		return;

	if (!pPlayer->IsAlive())
	{
		pPlayer->SetSlowMoType(SLOWMO_NONE);
		return;
	}

	if (pPlayer->GetSlowMoType() == SLOWMO_NONE)
		return;

	// I have some slowmo on me. Pass it to other players nearby.

	CUtlVector<CSDKPlayer*> apOthersInPVS;

	CBaseEntity* pOther = NULL;

	while ((pOther = UTIL_EntitiesInPVS(pPlayer, pOther)) != NULL)
	{
		CSDKPlayer* pOtherPlayer = ToSDKPlayer(pOther);
		if (!pOtherPlayer)
			continue;

		if (pOtherPlayer == pPlayer)
			continue;

		// If they already have slow mo, we don't need to pass it to them.
		if (pOtherPlayer->GetSlowMoType() == SLOWMO_STYLESKILL)
			continue;

		if (pOtherPlayer->GetSlowMoType() == SLOWMO_ACTIVATED)
			continue;

		if (pOtherPlayer->GetSlowMoType() == SLOWMO_PASSIVE)
			continue;

		apOthersInPVS.AddToTail(pOtherPlayer);
	}

	for (int i = 0; i < apOthersInPVS.Size(); i++)
	{
		CSDKPlayer* pOtherPlayer = apOthersInPVS[i];

		// It could have been already done by a previous iteration of the recursion below.
		if (pOtherPlayer->GetSlowMoType() != SLOWMO_NONE)
			continue;

		pOtherPlayer->SetSlowMoType(SLOWMO_PASSIVE);
		GiveSlowMoToNearbyPlayers(pOtherPlayer);
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CItem_DynamicResupply::FindPotentialItems( int nCount, DynamicResupplyItems_t *pItems, int iDebug, SpawnInfo_t *pSpawnInfo )
{
	int i;
	for ( i = 0; i < nCount; ++i )
	{
		pSpawnInfo[i].m_iPotentialItems = 0;
	}

	// Count the potential addition of items in the PVS
	CBaseEntity *pEntity = NULL;
	while ( (pEntity = UTIL_EntitiesInPVS( this, pEntity )) != NULL )
	{
		if ( pEntity->WorldSpaceCenter().DistToSqr( WorldSpaceCenter() ) > (POTENTIAL_ITEM_RADIUS * POTENTIAL_ITEM_RADIUS) )
			continue;

		for ( i = 0; i < nCount; ++i )
		{
			if ( !FClassnameIs( pEntity, pItems[i].sEntityName ) )
				continue;

			if ( iDebug == 2 )
			{
				NDebugOverlay::Line( WorldSpaceCenter(), pEntity->WorldSpaceCenter(), 0,255,0, true, 20.0 );
			}

			++pSpawnInfo[i].m_iPotentialItems;
			break;
		}
	}

	if ( iDebug )
	{
		Msg("Searching the PVS:\n");
		for ( int i = 0; i < nCount; i++ )
		{
			Msg("   Found %d '%s' in the PVS.\n", pSpawnInfo[i].m_iPotentialItems, pItems[i].sEntityName );
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : &data - 
//-----------------------------------------------------------------------------
void CItem_DynamicResupply::InputCalculateType( inputdata_t &data )
{{
	#ifdef SecobMod__Enable_Fixed_Multiplayer_AI
		// spawn gear for the nearest player 
		CBasePlayer *pNearest = UTIL_GetNearestPlayer(GetAbsOrigin()); 
		if ( pNearest != NULL ) 
			SpawnDynamicItem( pNearest ); 
	#else
		CBasePlayer *pPlayer = UTIL_GetLocalPlayer();
		SpawnDynamicItem( pPlayer );
	#endif //SecobMod__Enable_Fixed_Multiplayer_AI
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : &data - 
//-----------------------------------------------------------------------------
void CItem_DynamicResupply::InputBecomeMaster( inputdata_t &data )
{
	if ( g_MasterResupply )
		g_MasterResupply->m_bIsMaster = false;

	g_MasterResupply = this;
	m_bIsMaster = true;

	// Stop thinking now that I am the master.
	SetThink( NULL );
}


//-----------------------------------------------------------------------------
// Chooses an item when the player is full
//-----------------------------------------------------------------------------
void CItem_DynamicResupply::SpawnFullItem( CItem_DynamicResupply *pMaster, CBasePlayer *pPlayer, int iDebug )
{
	// Can we not actually spawn the item?
	if ( !HasSpawnFlags(SF_DYNAMICRESUPPLY_ALWAYS_SPAWN) )
		return;

	float flRatio[NUM_AMMO_ITEMS];
	int i;
	float flTotalProb = 0.0f;
	for ( i = 0; i < NUM_AMMO_ITEMS; ++i )
	{
		int iAmmoType = GetAmmoDef()->Index( g_DynamicResupplyAmmoItems[i].sAmmoDef );
		bool bCanSpawn = pPlayer->Weapon_GetWpnForAmmo( iAmmoType ) != NULL;

		if ( bCanSpawn && ( g_DynamicResupplyAmmoItems[i].flFullProbability != 0 ) && ( pMaster->m_flDesiredAmmo[i] != 0.0f ) )
		{
			flTotalProb += g_DynamicResupplyAmmoItems[i].flFullProbability;
			flRatio[i] = flTotalProb;
		}
		else
		{
			flRatio[i] = -1.0f;
		}
	}

	if ( flTotalProb == 0.0f )
	{
		// If we're supposed to fallback to just a health vial, do that and finish.
		if ( pMaster->HasSpawnFlags(SF_DYNAMICRESUPPLY_FALLBACK_TO_VIAL) )
		{
			CBaseEntity::Create( "item_healthvial", GetAbsOrigin(), GetAbsAngles(), this );

			if ( iDebug )
			{
				Msg("Player is full, spawning item_healthvial due to spawnflag.\n");
			}
			return;
		}

		// Otherwise, spawn the first ammo item in the list
		flRatio[0] = 1.0f;
		flTotalProb = 1.0f;
	}
	
	float flChoice = random->RandomFloat( 0.0f, flTotalProb ); 
	for ( i = 0; i < NUM_AMMO_ITEMS; ++i )
	{
		if ( flChoice <= flRatio[i] )
		{
			CBaseEntity::Create( g_DynamicResupplyAmmoItems[i].sEntityName, GetAbsOrigin(), GetAbsAngles(), this );

			if ( iDebug )
			{
				Msg("Player is full, spawning %s \n", g_DynamicResupplyAmmoItems[i].sEntityName );
			}
			return;
		}
	}

	if ( iDebug )
	{
		Msg("Player is full on all health + ammo, is not spawning.\n" );
	}
}


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CItem_DynamicResupply::FindPotentialItems( int nCount, DynamicResupplyItems_t *pItems, int iDebug, SpawnInfo_t *pSpawnInfo )
{
	int i;
	for ( i = 0; i < nCount; ++i )
	{
		pSpawnInfo[i].m_iPotentialItems = 0;
	}

	// Count the potential addition of items in the PVS
	CBaseEntity *pEntity = NULL;
	while ( (pEntity = UTIL_EntitiesInPVS( this, pEntity )) != NULL )
	{
		if ( pEntity->WorldSpaceCenter().DistToSqr( WorldSpaceCenter() ) > (POTENTIAL_ITEM_RADIUS * POTENTIAL_ITEM_RADIUS) )
			continue;

		for ( i = 0; i < nCount; ++i )
		{
			if ( !FClassnameIs( pEntity, pItems[i].sEntityName ) )
				continue;

			if ( iDebug == 2 )
			{
				NDebugOverlay::Line( WorldSpaceCenter(), pEntity->WorldSpaceCenter(), 0,255,0, true, 20.0 );
			}

			++pSpawnInfo[i].m_iPotentialItems;
			break;
		}
	}

	if ( iDebug )
	{
		Msg("Searching the PVS:\n");
		for ( int i = 0; i < nCount; i++ )
		{
			Msg("   Found %d '%s' in the PVS.\n", pSpawnInfo[i].m_iPotentialItems, pItems[i].sEntityName );
		}
	}
}