mirror of
https://github.com/nillerusr/source-engine.git
synced 2026-08-30 05:59:20 +00:00
upload "kind" alien swarm
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
@@ -19,15 +19,7 @@
|
||||
#include "props_shared.h"
|
||||
#include "func_breakablesurf.h"
|
||||
|
||||
#ifdef TERROR
|
||||
#include "func_elevator.h"
|
||||
#include "AmbientLight.h"
|
||||
#endif
|
||||
|
||||
#ifdef TF_DLL
|
||||
#include "tf_player.h"
|
||||
#include "bot/tf_bot.h"
|
||||
#endif
|
||||
|
||||
#include "Color.h"
|
||||
#include "collisionutils.h"
|
||||
@@ -39,311 +31,6 @@
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
BEGIN_DATADESC( CFuncNavCost )
|
||||
|
||||
// Inputs
|
||||
DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
|
||||
DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),
|
||||
DEFINE_KEYFIELD( m_iszTags, FIELD_STRING, "tags" ),
|
||||
DEFINE_KEYFIELD( m_team, FIELD_INTEGER, "team" ),
|
||||
DEFINE_KEYFIELD( m_isDisabled, FIELD_BOOLEAN, "start_disabled" ),
|
||||
|
||||
DEFINE_THINKFUNC( CostThink ),
|
||||
|
||||
END_DATADESC()
|
||||
|
||||
LINK_ENTITY_TO_CLASS( func_nav_avoid, CFuncNavAvoid );
|
||||
LINK_ENTITY_TO_CLASS( func_nav_prefer, CFuncNavPrefer );
|
||||
|
||||
CUtlVector< CHandle< CFuncNavCost > > CFuncNavCost::gm_masterCostVector;
|
||||
CountdownTimer CFuncNavCost::gm_dirtyTimer;
|
||||
|
||||
#define UPDATE_DIRTY_TIME 0.2f
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
void CFuncNavCost::Spawn( void )
|
||||
{
|
||||
BaseClass::Spawn();
|
||||
|
||||
gm_masterCostVector.AddToTail( this );
|
||||
gm_dirtyTimer.Start( UPDATE_DIRTY_TIME );
|
||||
|
||||
SetSolid( SOLID_BSP );
|
||||
AddSolidFlags( FSOLID_NOT_SOLID );
|
||||
|
||||
SetMoveType( MOVETYPE_NONE );
|
||||
SetModel( STRING( GetModelName() ) );
|
||||
AddEffects( EF_NODRAW );
|
||||
SetCollisionGroup( COLLISION_GROUP_NONE );
|
||||
|
||||
VPhysicsInitShadow( false, false );
|
||||
|
||||
SetThink( &CFuncNavCost::CostThink );
|
||||
SetNextThink( gpGlobals->curtime + UPDATE_DIRTY_TIME );
|
||||
|
||||
m_tags.RemoveAll();
|
||||
|
||||
const char *tags = STRING( m_iszTags );
|
||||
|
||||
// chop space-delimited string into individual tokens
|
||||
if ( tags )
|
||||
{
|
||||
char *buffer = new char [ strlen( tags ) + 1 ];
|
||||
Q_strcpy( buffer, tags );
|
||||
|
||||
for( char *token = strtok( buffer, " " ); token; token = strtok( NULL, " " ) )
|
||||
{
|
||||
m_tags.AddToTail( CFmtStr( "%s", token ) );
|
||||
}
|
||||
|
||||
delete [] buffer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
void CFuncNavCost::UpdateOnRemove( void )
|
||||
{
|
||||
gm_masterCostVector.FindAndFastRemove( this );
|
||||
BaseClass::UpdateOnRemove();
|
||||
|
||||
gm_dirtyTimer.Start( UPDATE_DIRTY_TIME );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
void CFuncNavCost::InputEnable( inputdata_t &inputdata )
|
||||
{
|
||||
m_isDisabled = false;
|
||||
gm_dirtyTimer.Start( UPDATE_DIRTY_TIME );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
void CFuncNavCost::InputDisable( inputdata_t &inputdata )
|
||||
{
|
||||
m_isDisabled = true;
|
||||
gm_dirtyTimer.Start( UPDATE_DIRTY_TIME );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
void CFuncNavCost::CostThink( void )
|
||||
{
|
||||
SetNextThink( gpGlobals->curtime + UPDATE_DIRTY_TIME );
|
||||
|
||||
if ( gm_dirtyTimer.HasStarted() && gm_dirtyTimer.IsElapsed() )
|
||||
{
|
||||
// one or more avoid entities have changed - update nav decoration
|
||||
gm_dirtyTimer.Invalidate();
|
||||
|
||||
UpdateAllNavCostDecoration();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
bool CFuncNavCost::HasTag( const char *groupname ) const
|
||||
{
|
||||
for( int i=0; i<m_tags.Count(); ++i )
|
||||
{
|
||||
if ( FStrEq( m_tags[i], groupname ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
// Return true if this cost applies to the given actor
|
||||
bool CFuncNavCost::IsApplicableTo( CBaseCombatCharacter *who ) const
|
||||
{
|
||||
if ( !who )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( m_team > 0 )
|
||||
{
|
||||
if ( who->GetTeamNumber() != m_team )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TF_DLL
|
||||
// TODO: Make group comparison efficient and move to base combat character
|
||||
CTFBot *bot = ToTFBot( who );
|
||||
if ( bot )
|
||||
{
|
||||
if ( bot->HasTheFlag() )
|
||||
{
|
||||
if ( HasTag( "bomb_carrier" ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// check custom bomb_carrier tags for this bot
|
||||
for( int i=0; i<m_tags.Count(); ++i )
|
||||
{
|
||||
const char* pszTag = m_tags[i];
|
||||
if ( V_stristr( pszTag, "bomb_carrier" ) )
|
||||
{
|
||||
if ( bot->HasTag( pszTag ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// the bomb carrier only pays attention to bomb_carrier costs
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( bot->HasMission( CTFBot::MISSION_DESTROY_SENTRIES ) )
|
||||
{
|
||||
if ( HasTag( "mission_sentry_buster" ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( bot->HasMission( CTFBot::MISSION_SNIPER ) )
|
||||
{
|
||||
if ( HasTag( "mission_sniper" ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( bot->HasMission( CTFBot::MISSION_SPY ) )
|
||||
{
|
||||
if ( HasTag( "mission_spy" ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( bot->HasMission( CTFBot::MISSION_REPROGRAMMED ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !bot->IsOnAnyMission() )
|
||||
{
|
||||
if ( HasTag( "common" ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( HasTag( bot->GetPlayerClass()->GetName() ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// check custom tags for this bot
|
||||
for( int i=0; i<m_tags.Count(); ++i )
|
||||
{
|
||||
if ( bot->HasTag( m_tags[i] ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// this cost doesn't apply to me
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
// Reevaluate all func_nav_cost entities and update the nav decoration accordingly.
|
||||
// This is required to handle overlapping func_nav_cost entities.
|
||||
void CFuncNavCost::UpdateAllNavCostDecoration( void )
|
||||
{
|
||||
int i, j;
|
||||
|
||||
// first, clear all avoid decoration from the mesh
|
||||
for( i=0; i<TheNavAreas.Count(); ++i )
|
||||
{
|
||||
TheNavAreas[i]->ClearAllNavCostEntities();
|
||||
}
|
||||
|
||||
// now, mark all areas with active cost entities overlapping them
|
||||
for( i=0; i<gm_masterCostVector.Count(); ++i )
|
||||
{
|
||||
CFuncNavCost *cost = gm_masterCostVector[i];
|
||||
|
||||
if ( !cost || !cost->IsEnabled() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Extent extent;
|
||||
extent.Init( cost );
|
||||
|
||||
CUtlVector< CNavArea * > overlapVector;
|
||||
TheNavMesh->CollectAreasOverlappingExtent( extent, &overlapVector );
|
||||
|
||||
Ray_t ray;
|
||||
trace_t tr;
|
||||
ICollideable *pCollide = cost->CollisionProp();
|
||||
|
||||
for( j=0; j<overlapVector.Count(); ++j )
|
||||
{
|
||||
ray.Init( overlapVector[j]->GetCenter(), overlapVector[j]->GetCenter() );
|
||||
|
||||
enginetrace->ClipRayToCollideable( ray, MASK_ALL, pCollide, &tr );
|
||||
|
||||
if ( tr.startsolid )
|
||||
{
|
||||
overlapVector[j]->AddFuncNavCostEntity( cost );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
// Return pathfind cost multiplier for the given actor
|
||||
float CFuncNavAvoid::GetCostMultiplier( CBaseCombatCharacter *who ) const
|
||||
{
|
||||
if ( IsApplicableTo( who ) )
|
||||
{
|
||||
return 25.0f;
|
||||
}
|
||||
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
// Return pathfind cost multiplier for the given actor
|
||||
float CFuncNavPrefer::GetCostMultiplier( CBaseCombatCharacter *who ) const
|
||||
{
|
||||
if ( IsApplicableTo( who ) )
|
||||
{
|
||||
return 0.04f; // 1/25th
|
||||
}
|
||||
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
BEGIN_DATADESC( CFuncNavBlocker )
|
||||
|
||||
@@ -450,7 +137,6 @@ void CFuncNavBlocker::Spawn( void )
|
||||
SetSolid( SOLID_NONE );
|
||||
AddSolidFlags( FSOLID_NOT_SOLID );
|
||||
CollisionProp()->WorldSpaceAABB( &m_CachedMins, &m_CachedMaxs );
|
||||
|
||||
if ( m_bDisabled )
|
||||
{
|
||||
UnblockNav();
|
||||
|
||||
Reference in New Issue
Block a user