upload "kind" alien swarm

This commit is contained in:
nillerusr
2023-10-03 17:23:56 +03:00
parent b7bd94c52e
commit 7d3c0d8b5a
4229 changed files with 462903 additions and 495158 deletions

View File

@@ -1,14 +1,14 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: Precaches and defs for entities and other data that must always be available.
//
// $NoKeywords: $
//===========================================================================//
//===========================================================================
#include "cbase.h"
#include "soundent.h"
#include "client.h"
#include "decals.h"
#include "editor_sendcommand.h"
#include "EnvMessage.h"
#include "player.h"
#include "gamerules.h"
@@ -31,6 +31,11 @@
#include "engine/IStaticPropMgr.h"
#include "particle_parse.h"
#include "globalstate.h"
#include "cvisibilitymonitor.h"
#include "model_types.h"
#include "vscript/ivscript.h"
#include "vscript_server.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
@@ -43,6 +48,104 @@ extern CUtlMemoryPool g_EntityListPool;
#define SF_DECAL_NOTINDEATHMATCH 2048
#if !defined( CLIENT_DLL )
#define SF_GAME_EVENT_PROXY_AUTO_VISIBILITY 1
//=========================================================
// Allows level designers to generate certain game events
// from entity i/o.
//=========================================================
class CInfoGameEventProxy : public CPointEntity
{
private:
string_t m_iszEventName;
float m_flRange;
public:
DECLARE_CLASS( CInfoGameEventProxy, CPointEntity );
void Spawn();
int UpdateTransmitState();
void InputGenerateGameEvent( inputdata_t &inputdata );
static bool GameEventProxyCallback( CBaseEntity *pProxy, CBasePlayer *pViewingPlayer );
DECLARE_DATADESC();
};
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CInfoGameEventProxy::Spawn()
{
BaseClass::Spawn();
m_flRange *= 12.0f; // Convert feet to inches
if( GetSpawnFlags() & SF_GAME_EVENT_PROXY_AUTO_VISIBILITY )
{
VisibilityMonitor_AddEntity( this, m_flRange, &CInfoGameEventProxy::GameEventProxyCallback, NULL );
}
}
//-----------------------------------------------------------------------------
// Purpose: Always transmitted to clients
//-----------------------------------------------------------------------------
int CInfoGameEventProxy::UpdateTransmitState()
{
return SetTransmitState( FL_EDICT_ALWAYS );
}
//---------------------------------------------------------
//---------------------------------------------------------
void CInfoGameEventProxy::InputGenerateGameEvent( inputdata_t &inputdata )
{
CBasePlayer *pActivator = ToBasePlayer( inputdata.pActivator );
IGameEvent *event = gameeventmanager->CreateEvent( m_iszEventName.ToCStr() );
if ( event )
{
if ( pActivator )
{
event->SetInt( "userid", pActivator->GetUserID() );
}
event->SetInt( "subject", entindex() );
gameeventmanager->FireEvent( event );
}
}
//---------------------------------------------------------
// Callback for the visibility monitor.
//---------------------------------------------------------
bool CInfoGameEventProxy::GameEventProxyCallback( CBaseEntity *pProxy, CBasePlayer *pViewingPlayer )
{
CInfoGameEventProxy *pProxyPtr = dynamic_cast <CInfoGameEventProxy *>(pProxy);
if( !pProxyPtr )
return true;
IGameEvent * event = gameeventmanager->CreateEvent( pProxyPtr->m_iszEventName.ToCStr() );
if ( event )
{
event->SetInt( "userid", pViewingPlayer->GetUserID() );
event->SetInt( "subject", pProxyPtr->entindex() );
gameeventmanager->FireEvent( event );
}
return false;
}
LINK_ENTITY_TO_CLASS( info_game_event_proxy, CInfoGameEventProxy );
BEGIN_DATADESC( CInfoGameEventProxy )
DEFINE_KEYFIELD( m_iszEventName, FIELD_STRING, "event_name" ),
DEFINE_KEYFIELD( m_flRange, FIELD_FLOAT, "range" ),
DEFINE_INPUTFUNC( FIELD_STRING, "GenerateGameEvent", InputGenerateGameEvent ),
END_DATADESC()
#endif
class CDecal : public CPointEntity
{
public:
@@ -59,11 +162,14 @@ public:
// Input handlers.
void InputActivate( inputdata_t &inputdata );
CBaseEntity *GetDecalEntityAndPosition( Vector *pPosition, bool bStatic );
DECLARE_DATADESC();
public:
int m_nTexture;
bool m_bLowPriority;
string_t m_entityName;
private:
@@ -74,6 +180,7 @@ BEGIN_DATADESC( CDecal )
DEFINE_FIELD( m_nTexture, FIELD_INTEGER ),
DEFINE_KEYFIELD( m_bLowPriority, FIELD_BOOLEAN, "LowPriority" ), // Don't mark as FDECAL_PERMANENT so not save/restored and will be reused on the client preferentially
DEFINE_KEYFIELD( m_entityName, FIELD_STRING, "ApplyEntity" ), // Force apply to this entity instead of tracing
// Function pointers
DEFINE_FUNCTION( StaticDecal ),
@@ -112,6 +219,87 @@ void CDecal::Activate()
}
}
class CTraceFilterValidForDecal : public CTraceFilterSimple
{
public:
CTraceFilterValidForDecal(const IHandleEntity *passentity, int collisionGroup )
: CTraceFilterSimple( passentity, collisionGroup )
{
}
virtual bool ShouldHitEntity( IHandleEntity *pServerEntity, int contentsMask )
{
static const char *ppszIgnoredClasses[] =
{
"weapon_*",
"item_*",
"prop_ragdoll",
"prop_dynamic",
"prop_static",
"prop_physics",
"npc_bullseye", // Tracker 15335
};
CBaseEntity *pEntity = EntityFromEntityHandle( pServerEntity );
// Tracker 15335: Never impact decals against entities which are not rendering, either.
if ( pEntity->IsEffectActive( EF_NODRAW ) )
return false;
for ( int i = 0; i < ARRAYSIZE(ppszIgnoredClasses); i++ )
{
if ( pEntity->ClassMatches( ppszIgnoredClasses[i] ) )
return false;
}
if ( modelinfo->GetModelType( pEntity->GetModel() ) != mod_brush )
return false;
return CTraceFilterSimple::ShouldHitEntity( pServerEntity, contentsMask );
}
};
CBaseEntity *CDecal::GetDecalEntityAndPosition( Vector *pPosition, bool bStatic )
{
CBaseEntity *pEntity = NULL;
if ( !m_entityName )
{
trace_t trace;
Vector start = GetAbsOrigin();
Vector direction(1,1,1);
if ( GetAbsAngles() == vec3_angle )
{
start -= direction * 5;
}
else
{
GetVectors( &direction, NULL, NULL );
}
Vector end = start + direction * 10;
if ( bStatic )
{
CTraceFilterValidForDecal traceFilter( this, COLLISION_GROUP_NONE );
UTIL_TraceLine( start, end, MASK_SOLID, &traceFilter, &trace );
}
else
{
UTIL_TraceLine( start, end, MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &trace );
}
if ( trace.DidHitNonWorldEntity() )
{
*pPosition = trace.endpos;
return trace.m_pEnt;
}
}
else
{
pEntity = gEntList.FindEntityByName( NULL, m_entityName );
}
*pPosition = GetAbsOrigin();
return pEntity;
}
void CDecal::TriggerDecal ( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
// this is set up as a USE function for info_decals that have targetnames, so that the
@@ -119,14 +307,13 @@ void CDecal::TriggerDecal ( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_T
trace_t trace;
int entityIndex;
UTIL_TraceLine( GetAbsOrigin() - Vector(5,5,5), GetAbsOrigin() + Vector(5,5,5), MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &trace );
entityIndex = trace.m_pEnt ? trace.m_pEnt->entindex() : 0;
Vector position;
CBaseEntity *pEntity = GetDecalEntityAndPosition(&position, false);
entityIndex = pEntity ? pEntity->entindex() : 0;
CBroadcastRecipientFilter filter;
te->BSPDecal( filter, 0.0,
&GetAbsOrigin(), entityIndex, m_nTexture );
te->BSPDecal( filter, 0.0, &position, entityIndex, m_nTexture );
SetThink( &CDecal::SUB_Remove );
SetNextThink( gpGlobals->curtime + 0.1f );
@@ -141,77 +328,24 @@ void CDecal::InputActivate( inputdata_t &inputdata )
void CDecal::StaticDecal( void )
{
class CTraceFilterValidForDecal : public CTraceFilterSimple
Vector position;
CBaseEntity *pEntity = GetDecalEntityAndPosition(&position, true);
int entityIndex = 0;
int modelIndex = 0;
if ( pEntity )
{
public:
CTraceFilterValidForDecal(const IHandleEntity *passentity, int collisionGroup )
: CTraceFilterSimple( passentity, collisionGroup )
{
}
virtual bool ShouldHitEntity( IHandleEntity *pServerEntity, int contentsMask )
{
static const char *ppszIgnoredClasses[] =
{
"weapon_*",
"item_*",
"prop_ragdoll",
"prop_dynamic",
"prop_static",
"prop_physics",
"npc_bullseye", // Tracker 15335
};
CBaseEntity *pEntity = EntityFromEntityHandle( pServerEntity );
// Tracker 15335: Never impact decals against entities which are not rendering, either.
if ( pEntity->IsEffectActive( EF_NODRAW ) )
return false;
for ( int i = 0; i < ARRAYSIZE(ppszIgnoredClasses); i++ )
{
if ( pEntity->ClassMatches( ppszIgnoredClasses[i] ) )
return false;
}
return CTraceFilterSimple::ShouldHitEntity( pServerEntity, contentsMask );
}
};
trace_t trace;
CTraceFilterValidForDecal traceFilter( this, COLLISION_GROUP_NONE );
int entityIndex, modelIndex = 0;
Vector position = GetAbsOrigin();
UTIL_TraceLine( position - Vector(5,5,5), position + Vector(5,5,5), MASK_SOLID, &traceFilter, &trace );
bool canDraw = true;
entityIndex = trace.m_pEnt ? (short)trace.m_pEnt->entindex() : 0;
if ( entityIndex )
entityIndex = pEntity->entindex();
modelIndex = pEntity->GetModelIndex();
Vector worldspace = position;
VectorITransform( worldspace, pEntity->EntityToWorldTransform(), position );
}
else
{
CBaseEntity *ent = trace.m_pEnt;
if ( ent )
{
modelIndex = ent->GetModelIndex();
VectorITransform( GetAbsOrigin(), ent->EntityToWorldTransform(), position );
canDraw = ( modelIndex != 0 );
if ( !canDraw )
{
Warning( "Suppressed StaticDecal which would have hit entity %i (class:%s, name:%s) with modelindex = 0\n",
ent->entindex(),
ent->GetClassname(),
STRING( ent->GetEntityName() ) );
}
}
position = GetAbsOrigin();
}
if ( canDraw )
{
engine->StaticDecal( position, m_nTexture, entityIndex, modelIndex, m_bLowPriority );
}
engine->StaticDecal( position, m_nTexture, entityIndex, modelIndex, m_bLowPriority );
SUB_Remove();
}
@@ -380,6 +514,9 @@ BEGIN_DATADESC( CWorld )
DEFINE_KEYFIELD( m_bDisplayTitle, FIELD_BOOLEAN, "gametitle" ),
DEFINE_FIELD( m_WorldMins, FIELD_VECTOR ),
DEFINE_FIELD( m_WorldMaxs, FIELD_VECTOR ),
// DEFINE_FIELD( m_flMaxOccludeeArea, FIELD_CLASSCHECK_IGNORE ) // do this or else we get a warning about multiply-defined fields
// DEFINE_FIELD( m_flMinOccluderArea, FIELD_CLASSCHECK_IGNORE ) // do this or else we get a warning about multiply-defined fields
#ifdef _X360
DEFINE_KEYFIELD( m_flMaxOccludeeArea, FIELD_FLOAT, "maxoccludeearea_x360" ),
DEFINE_KEYFIELD( m_flMinOccluderArea, FIELD_FLOAT, "minoccluderarea_x360" ),
@@ -441,6 +578,10 @@ bool CWorld::KeyValue( const char *szKeyName, const char *szValue )
sscanf( szValue, "%f %f %f", &vec.x, &vec.y, &vec.z );
m_WorldMaxs = vec;
}
else if ( FStrEq(szKeyName, "timeofday" ) )
{
SetTimeOfDay( atoi( szValue ) );
}
else
return BaseClass::KeyValue( szKeyName, szValue );
@@ -449,7 +590,7 @@ bool CWorld::KeyValue( const char *szKeyName, const char *szValue )
extern bool g_fGameOver;
static CWorld *g_WorldEntity = NULL;
CWorld *g_WorldEntity = NULL;
CWorld* GetWorldEntity()
{
@@ -467,10 +608,20 @@ CWorld::CWorld( )
SetMoveType( MOVETYPE_NONE );
m_bColdWorld = false;
// Set this in the constructor for legacy maps (sjb)
m_iTimeOfDay = TIME_MIDNIGHT;
}
CWorld::~CWorld( )
CWorld::~CWorld()
{
// If in edit mode tell Hammer I'm ending my session. This re-enables
// the Hammer UI so they can continue editing the map.
#ifdef _WIN32
Editor_EndSession(false);
#endif
EventList_Free();
ActivityList_Free();
if ( g_pGameRules )
@@ -484,9 +635,7 @@ CWorld::~CWorld( )
//------------------------------------------------------------------------------
// Purpose : Add a decal to the world
// Input :
// Output :
// Add a decal to the world
//------------------------------------------------------------------------------
void CWorld::DecalTrace( trace_t *pTrace, char const *decalName)
{
@@ -574,14 +723,24 @@ const char *GetDefaultLightstyleString( int styleIndex )
return "m";
}
//-----------------------------------------------------------------------------
string_t g_iszFuncBrushClassname = NULL_STRING;
void CWorld::Precache( void )
{
COM_TimestampedLog( "CWorld::Precache - Start" );
g_WorldEntity = this;
g_fGameOver = false;
g_pLastSpawn = NULL;
g_Language.SetValue( LANGUAGE_ENGLISH ); // TODO use VGUI to get current language
#ifndef INFESTED_DLL
ConVarRef stepsize( "sv_stepsize" );
stepsize.SetValue( 18 );
#endif
ConVarRef roomtype( "room_type" );
roomtype.SetValue( 0 );
@@ -599,13 +758,6 @@ void CWorld::Precache( void )
CSoundEnt::InitSoundEnt();
// Only allow precaching between LevelInitPreEntity and PostEntity
CBaseEntity::SetAllowPrecache( true );
IGameSystem::LevelInitPreEntityAllSystems( STRING( GetModelName() ) );
// Create the player resource
g_pGameRules->CreateStandardEntities();
// UNDONE: Make most of these things server systems or precache_registers
// =================================================
// Activities
@@ -616,41 +768,44 @@ void CWorld::Precache( void )
EventList_Free();
RegisterSharedEvents();
InitBodyQue();
// init sentence group playback stuff from sentences.txt.
// ok to call this multiple times, calls after first are ignored.
// Only allow precaching between LevelInitPreEntity and PostEntity
CBaseEntity::SetAllowPrecache( true );
COM_TimestampedLog( "IGameSystem::LevelInitPreEntityAllSystems" );
IGameSystem::LevelInitPreEntityAllSystems( STRING( GetModelName() ) );
COM_TimestampedLog( "g_pGameRules->CreateStandardEntities()" );
// Create the player resource
g_pGameRules->CreateStandardEntities();
COM_TimestampedLog( "InitBodyQue()" );
InitBodyQue();
COM_TimestampedLog( "SENTENCEG_Init()" );
// init sentence group playback stuff from sentences.txt.
// ok to call this multiple times, calls after first are ignored.
SENTENCEG_Init();
COM_TimestampedLog( "PrecacheStandardParticleSystems()" );
// Precache standard particle systems
PrecacheStandardParticleSystems( );
// the area based ambient sounds MUST be the first precache_sounds
// the area based ambient sounds MUST be the first precache_sounds
// player precaches
COM_TimestampedLog( "W_Precache()" );
// player precaches
W_Precache (); // get weapon precaches
COM_TimestampedLog( "ClientPrecache()" );
ClientPrecache();
g_pGameRules->Precache();
COM_TimestampedLog( "PrecacheTempEnts()" );
// precache all temp ent stuff
CBaseTempEntity::PrecacheTempEnts();
g_Language.SetValue( LANGUAGE_ENGLISH ); // TODO use VGUI to get current language
if ( g_Language.GetInt() == LANGUAGE_GERMAN )
{
PrecacheModel( "models/germangibs.mdl" );
}
else
{
PrecacheModel( "models/gibs/hgibs.mdl" );
}
PrecacheScriptSound( "BaseEntity.EnterWater" );
PrecacheScriptSound( "BaseEntity.ExitWater" );
//
// Setup light animation tables. 'a' is total darkness, 'z' is maxbright.
//
COM_TimestampedLog( "LightStyles" );
//
// Setup light animation tables. 'a' is total darkness, 'z' is maxbright.
//
for ( int i = 0; i < ARRAYSIZE(g_DefaultLightstyles); i++ )
{
engine->LightStyle( i, GetDefaultLightstyleString(i) );
@@ -661,6 +816,7 @@ void CWorld::Precache( void )
// 63 testing
engine->LightStyle(63, "a");
COM_TimestampedLog( "InitializeAINetworks" );
// =================================================
// Load and Init AI Networks
// =================================================
@@ -668,16 +824,20 @@ void CWorld::Precache( void )
// =================================================
// Load and Init AI Schedules
// =================================================
COM_TimestampedLog( "LoadAllSchedules" );
g_AI_SchedulesManager.LoadAllSchedules();
// =================================================
// Initialize NPC Relationships
// =================================================
COM_TimestampedLog( "InitDefaultAIRelationships" );
g_pGameRules->InitDefaultAIRelationships();
COM_TimestampedLog( "InitInteractionSystem" );
CBaseCombatCharacter::InitInteractionSystem();
// Call all registered precachers.
CPrecacheRegister::Precache();
COM_TimestampedLog( "g_pGameRules->Precache" );
// Call the gamerules precache after the AI precache so that games can precache NPCs that are always loaded
g_pGameRules->Precache();
if ( m_iszChapterTitle != NULL_STRING )
{
DevMsg( 2, "Chapter title: %s\n", STRING(m_iszChapterTitle) );
@@ -695,6 +855,20 @@ void CWorld::Precache( void )
}
g_iszFuncBrushClassname = AllocPooledString("func_brush");
if ( m_iszDetailSpriteMaterial.Get() != NULL_STRING )
{
PrecacheMaterial( STRING( m_iszDetailSpriteMaterial.Get() ) );
}
COM_TimestampedLog( "CWorld::Precache - Finish" );
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CWorld::UpdateOnRemove( void )
{
BaseClass::UpdateOnRemove();
}
//-----------------------------------------------------------------------------
@@ -703,7 +877,7 @@ void CWorld::Precache( void )
//-----------------------------------------------------------------------------
float GetRealTime()
{
return engine->Time();
return Plat_FloatTime();
}
@@ -731,3 +905,13 @@ bool CWorld::IsColdWorld( void )
{
return m_bColdWorld;
}
int CWorld::GetTimeOfDay() const
{
return m_iTimeOfDay;
}
void CWorld::SetTimeOfDay( int iTimeOfDay )
{
m_iTimeOfDay = iTimeOfDay;
}