game_shared/gamerules.cpp
3132333435363738394041424344454647484950515253
ConVar g_Language( "g_Language", "0", FCVAR_REPLICATED );
static CViewVectors g_DefaultViewVectors(
Vector( 0, 0, 64 ),
Vector(-16, -16, 0 ),
Vector( 16, 16, 72 ),
Vector(-16, -16, 0 ),
Vector( 16, 16, 36 ),
Vector( 0, 0, 28 ),
Vector(-10, -10, -10 ),
Vector( 10, 10, 10 ),
Vector( 0, 0, 14 )
);
// ------------------------------------------------------------------------------------ //
// CGameRulesProxy implementation.
// ------------------------------------------------------------------------------------ //
313233343536373839404142434445464748495051525354555657585960616263646566676869
ConVar g_Language( "g_Language", "0", FCVAR_REPLICATED );
// --> Mirv: Changed some of the values
//static CViewVectors g_DefaultViewVectors(
// Vector( 0, 0, 64 ), // m_vView
//
// Vector(-16, -16, 0 ), // m_vHullMin
// Vector( 16, 16, 72 ), // m_vHullMax
//
// Vector(-16, -16, 0 ), // m_vDuckHullMin
// Vector( 16, 16, 36 ), // m_vDuckHullMax
// Vector( 0, 0, 28 ), // m_vDuckView
//
// Vector(-10, -10, -10 ), // m_vObsHullMin
// Vector( 10, 10, 10 ), // m_vObsHullMax
//
// Vector( 0, 0, 14 ) // m_vDeadViewHeight
//);
static CViewVectors g_DefaultViewVectors(
Vector( 0, 0, 28 ), // m_vView
Vector(-16, -16, -36 ), // m_vHullMin
Vector( 16, 16, 36 ), // m_vHullMax
Vector(-16, -16, -18 ), // m_vDuckHullMin
Vector( 16, 16, 18 ), // m_vDuckHullMax
Vector( 0, 0, 12 ), // m_vDuckView // |-- Mirv: Changed from 28
Vector(-10, -10, -10 ), // m_vObsHullMin
Vector( 10, 10, 10 ), // m_vObsHullMax
Vector( 0, 0, -2 ) // m_vDeadViewHeight
);
// <-- Mirv: Changed some of the values
// ------------------------------------------------------------------------------------ //
// CGameRulesProxy implementation.
// ------------------------------------------------------------------------------------ //
99100101102103104105
CGameRules::CGameRules() : CAutoGameSystemPerFrame( "CGameRules" )
{
Assert( !g_pGameRules );
g_pGameRules = this;
}
#else //}{
115116117118119120121122123
CGameRules::CGameRules() : CAutoGameSystemPerFrame( "CGameRules" )
{
Assert( !g_pGameRules );
#ifndef FF_BETA_TEST_COMPILE
g_pGameRules = this;
#endif
}
#else //}{
156157158159160161162
CBaseEntity *pSpawnSpot = pPlayer->EntSelectSpawnPoint();
Assert( pSpawnSpot );
pPlayer->SetLocalOrigin( pSpawnSpot->GetAbsOrigin() + Vector(0,0,1) );
pPlayer->SetAbsVelocity( vec3_origin );
pPlayer->SetLocalAngles( pSpawnSpot->GetLocalAngles() );
pPlayer->m_Local.m_vecPunchAngle = vec3_angle;
174175176177178179180181182183184
CBaseEntity *pSpawnSpot = pPlayer->EntSelectSpawnPoint();
Assert( pSpawnSpot );
Vector vecSpawnOrigin = pSpawnSpot->GetAbsOrigin() + Vector(0,0,37);
Vector vecSpawnOriginOffset = GetPlayerSpawnSpotOffset( pPlayer, vecSpawnOrigin, Vector(16,16,0), Vector(16,16,72) );
//pPlayer->SetLocalOrigin( pSpawnSpot->GetAbsOrigin() + Vector(0,0,1 + 36) ); // |-- Mirv: Added 36 for shift in position
pPlayer->SetLocalOrigin( vecSpawnOrigin + vecSpawnOriginOffset );
pPlayer->SetAbsVelocity( vec3_origin );
pPlayer->SetLocalAngles( pSpawnSpot->GetLocalAngles() );
pPlayer->m_Local.m_vecPunchAngle = vec3_angle;
166167168169170171
return pSpawnSpot;
}
// checks if the spot is clear of players
bool CGameRules::IsSpawnPointValid( CBaseEntity *pSpot, CBasePlayer *pPlayer )
{
188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
return pSpawnSpot;
}
// this is not a cheat
ConVar sv_spawnoffsetattempts( "sv_spawnoffsetattempts" , "5", 0, "4 rotations PER this value. It keeps trying offset positions while less than this value. Oh and also, attempt 0 just checks the original spawn location so there are no rotations.", true, 0, true, 9);
// for moving the spawn spot around the original spawn spot if other players are inside it
Vector CGameRules::GetPlayerSpawnSpotOffset( const CBasePlayer *pPlayer, const Vector vecOrigin, const Vector vecPlayerBoundsMins, const Vector vecPlayerBoundsMaxs )
{
if ( pPlayer->GetTeamNumber() < TEAM_BLUE )
return Vector(0,0,0);
Vector vecOffset = Vector(0,0,0);
// only try this X times (first attempt is actually just for checking the original spawn location)
for (int i = 0; i < sv_spawnoffsetattempts.GetInt(); i++)
{
// keep track of how many directions are blocked, so we know when to give up
int iNumBlockedDirections = 0;
// for rotating 90 degrees at least 4 times (it's likely/hopeful that this will only happen once)
for (int j = 0; j < 4; j++)
{
// don't do all this crazy rotating, tracing, and other stuff on the first attempt
if (i > 0)
{
// update and/or rotate the offset
// VectorYawRotate seems to be broken?
// VectorYawRotate(Vector(i * 34, 0, 0), 90.0f, vecOffset);
if ( j == 0 )
vecOffset = Vector(i * 34, 0, 0);
else if ( j == 1 )
vecOffset = Vector(0, i * 34, 0);
else if ( j == 2 )
vecOffset = Vector(i * -34, 0, 0);
else
vecOffset = Vector(0, i * -34, 0);
// for tracing out to detect a wall
Vector vecOffsetNormalized = vecOffset;
VectorNormalizeFast(vecOffsetNormalized);
// make sure a wall or something solid like that isn't in the way
trace_t tr;
int iTraceLength = (i * 34) + 16;
UTIL_TraceLine( vecOrigin, vecOrigin + (vecOffsetNormalized * iTraceLength), MASK_SOLID_BRUSHONLY, NULL, COLLISION_GROUP_NONE, &tr );
// something's in the way, so don't waste anymore time...just move on to the next rotation
if ( tr.DidHitWorld() )
{
// another direction cockblocked
iNumBlockedDirections++;
continue;
}
}
// check for players in this offset spawn location
CBaseEntity *pList[ 128 ];
int count = UTIL_EntitiesInBox( pList, 128, ( vecOrigin + vecOffset ) - vecPlayerBoundsMins, ( vecOrigin + vecOffset ) + vecPlayerBoundsMaxs, FL_CLIENT | FL_NPC | FL_FAKECLIENT );
// nothing in the way, so return this offset
if ( count == 0 )
return vecOffset;
// only try once at the original location
if (i == 0)
break;
}
// all 4 directions are blocked (you're spawning in a small cube of death?), so don't waste anymore time
if (iNumBlockedDirections > 3)
break;
}
// No offset found, so let's telefrag the players in the way and return a 0 offset
CBaseEntity *pList[ 128 ];
int count = UTIL_EntitiesInBox( pList, 128, vecOrigin - vecPlayerBoundsMins, vecOrigin + vecPlayerBoundsMaxs, FL_CLIENT | FL_NPC | FL_FAKECLIENT );
if( count )
{
// Iterate through the list and check the results
for( int i = 0; i < count; i++ )
{
CBaseEntity *ent = pList[ i ];
if( ent )
{
if( ent->IsPlayer() )
{
if( ( ent != pPlayer ) && ent->IsAlive() )
ent->TakeDamage( CTakeDamageInfo( GetContainingEntity( INDEXENT( 0 ) ), GetContainingEntity( INDEXENT( 0 ) ), 6969, DMG_GENERIC ) );
}
else
{
// TODO: Remove objects - buildables/grenades/projectiles - on the spawn point?
}
}
}
}
// Just spawn already, DAMN!
return Vector(0,0,0);
}
// checks if the spot is clear of players
bool CGameRules::IsSpawnPointValid( CBaseEntity *pSpot, CBasePlayer *pPlayer )
{
221222223224225226
//=========================================================
void CGameRules::RefreshSkillData ( bool forceUpdate )
{
#ifndef CLIENT_DLL
if ( !forceUpdate )
{
342343344345346347348349
//=========================================================
void CGameRules::RefreshSkillData ( bool forceUpdate )
{
// We don't care about this stuff, do we? -- Mulch
/*
#ifndef CLIENT_DLL
if ( !forceUpdate )
{
248249250251252253
engine->ServerExecute();
#endif // HL2_DLL
#endif // CLIENT_DLL
}
371372373374375376377
engine->ServerExecute();
#endif // HL2_DLL
#endif // CLIENT_DLL
*/
}
645646647648649650651652653654655656657658659660
return false;
// Projectiles hit everything but debris, weapons, + other projectiles
if ( collisionGroup1 == COLLISION_GROUP_PROJECTILE )
{
if ( collisionGroup0 == COLLISION_GROUP_DEBRIS ||
collisionGroup0 == COLLISION_GROUP_WEAPON ||
collisionGroup0 == COLLISION_GROUP_PROJECTILE )
{
return false;
}
}
// Don't let vehicles collide with weapons
// Don't let players collide with weapons...
// Don't let NPCs collide with weapons
769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
return false;
// Projectiles hit everything but debris, weapons, + other projectiles
// Adding so projectiles dont collide with players -GreenMushy
if ( collisionGroup1 == COLLISION_GROUP_PROJECTILE )
{
if ( collisionGroup0 == COLLISION_GROUP_DEBRIS ||
collisionGroup0 == COLLISION_GROUP_PLAYER ||
collisionGroup0 == COLLISION_GROUP_WEAPON ||
collisionGroup0 == COLLISION_GROUP_ROCKET ||
collisionGroup0 == COLLISION_GROUP_PROJECTILE )
{
return false;
}
}
//COLLISION_GROUP_ROCKET hits the same stuff as "projectiles" but hits players
if ( collisionGroup1 == COLLISION_GROUP_ROCKET )
{
if ( collisionGroup0 == COLLISION_GROUP_DEBRIS ||
collisionGroup0 == COLLISION_GROUP_WEAPON ||
collisionGroup0 == COLLISION_GROUP_ROCKET )
{
return false;
}
}
//Let buildables collide with mostly everything atm
//Adding this buildable collision group so we can better customize exceptions later on -Green Mushy
if( collisionGroup1 == COLLISION_GROUP_BUILDABLE )
{
if( collisionGroup0 == COLLISION_GROUP_DEBRIS ||
collisionGroup0 == COLLISION_GROUP_INTERACTIVE_DEBRIS)
{
return false;
}
}
// Don't let vehicles collide with weapons
// Don't let players collide with weapons...
// Don't let NPCs collide with weapons