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 462900 additions and 495155 deletions
+14 -315
View File
@@ -1,4 +1,4 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
@@ -16,20 +16,15 @@
#include "fmtstr.h"
#include "utlbuffer.h"
#include "tier0/vprof.h"
#ifdef TERROR
#include "func_simpleladder.h"
#endif
#include "functorutils.h"
//#include "shared_util.h"
#ifdef NEXT_BOT
#include "NextBot/NavMeshEntities/func_nav_prerequisite.h"
#endif
#include "functorutils.h"
// NOTE: This has to be the last file included!
#include "tier0/memdbgon.h"
#define DrawLine( from, to, duration, red, green, blue ) NDebugOverlay::Line( from, to, red, green, blue, true, NDEBUG_PERSIST_TILL_NEXT_SERVER )
#define DrawLine( from, to, duration, red, green, blue ) NDebugOverlay::Line( from, to, red, green, blue, true, 0.1f )
/**
@@ -42,9 +37,6 @@ ConVar nav_quicksave( "nav_quicksave", "1", FCVAR_GAMEDLL | FCVAR_CHEAT, "Set to
ConVar nav_show_approach_points( "nav_show_approach_points", "0", FCVAR_GAMEDLL | FCVAR_CHEAT, "Show Approach Points in the Navigation Mesh." );
ConVar nav_show_danger( "nav_show_danger", "0", FCVAR_GAMEDLL | FCVAR_CHEAT, "Show current 'danger' levels." );
ConVar nav_show_player_counts( "nav_show_player_counts", "0", FCVAR_GAMEDLL | FCVAR_CHEAT, "Show current player counts in each area." );
ConVar nav_show_func_nav_avoid( "nav_show_func_nav_avoid", "0", FCVAR_GAMEDLL | FCVAR_CHEAT, "Show areas of designer-placed bot avoidance due to func_nav_avoid entities" );
ConVar nav_show_func_nav_prefer( "nav_show_func_nav_prefer", "0", FCVAR_GAMEDLL | FCVAR_CHEAT, "Show areas of designer-placed bot preference due to func_nav_prefer entities" );
ConVar nav_show_func_nav_prerequisite( "nav_show_func_nav_prerequisite", "0", FCVAR_GAMEDLL | FCVAR_CHEAT, "Show areas of designer-placed bot preference due to func_nav_prerequisite entities" );
ConVar nav_max_vis_delta_list_length( "nav_max_vis_delta_list_length", "64", FCVAR_CHEAT );
extern ConVar nav_show_potentially_visible;
@@ -69,7 +61,7 @@ CNavMesh::CNavMesh( void )
LoadPlaceDatabase();
ListenForGameEvent( "round_start" );
// ListenForGameEvent( "round_start_pre_entity" );
ListenForGameEvent( "round_start_pre_entity" );
ListenForGameEvent( "break_prop" );
ListenForGameEvent( "break_breakable" );
ListenForGameEvent( "teamplay_round_start" );
@@ -120,8 +112,6 @@ void CNavMesh::Reset( void )
m_markedLadder = NULL;
m_selectedLadder = NULL;
m_updateBlockedAreasTimer.Invalidate();
if (m_spawnName)
{
delete [] m_spawnName;
@@ -158,7 +148,6 @@ void CNavMesh::DestroyNavigationMesh( bool incremental )
{
m_blockedAreas.RemoveAll();
m_avoidanceObstacleAreas.RemoveAll();
m_transientAreas.RemoveAll();
if ( !incremental )
{
@@ -256,13 +245,6 @@ void CNavMesh::Update( void )
return; // don't bother trying to draw stuff while we're generating
}
// Test all of the areas for blocked status
if ( m_updateBlockedAreasTimer.HasStarted() && m_updateBlockedAreasTimer.IsElapsed() )
{
TestAllAreasForBlockedStatus();
m_updateBlockedAreasTimer.Invalidate();
}
UpdateBlockedAreas();
UpdateAvoidanceObstacleAreas();
@@ -295,23 +277,6 @@ void CNavMesh::Update( void )
DrawPlayerCounts();
}
if ( nav_show_func_nav_avoid.GetBool() )
{
DrawFuncNavAvoid();
}
if ( nav_show_func_nav_prefer.GetBool() )
{
DrawFuncNavPrefer();
}
#ifdef NEXT_BOT
if ( nav_show_func_nav_prerequisite.GetBool() )
{
DrawFuncNavPrerequisite();
}
#endif
if ( nav_show_potentially_visible.GetBool() )
{
CBasePlayer *player = UTIL_GetListenServerHost();
@@ -579,40 +544,6 @@ void CNavMesh::OnServerActivate( void )
}
}
#ifdef NEXT_BOT
//--------------------------------------------------------------------------------------------------------------
class CRegisterPrerequisite
{
public:
CRegisterPrerequisite( CFuncNavPrerequisite *prereq )
{
m_prereq = prereq;
}
bool operator() ( CNavArea *area )
{
area->AddPrerequisite( m_prereq );
return true;
}
CFuncNavPrerequisite *m_prereq;
};
#endif
//--------------------------------------------------------------------------------------------------------------
/**
* Test all areas for blocked status
*/
void CNavMesh::TestAllAreasForBlockedStatus( void )
{
FOR_EACH_VEC( TheNavAreas, pit )
{
CNavArea *area = TheNavAreas[ pit ];
area->UpdateBlocked( true );
}
}
//--------------------------------------------------------------------------------------------------------------
/**
@@ -620,28 +551,12 @@ void CNavMesh::TestAllAreasForBlockedStatus( void )
*/
void CNavMesh::OnRoundRestart( void )
{
m_updateBlockedAreasTimer.Start( 1.0f );
#ifdef NEXT_BOT
// test all areas for blocked status
FOR_EACH_VEC( TheNavAreas, pit )
{
CNavArea *area = TheNavAreas[ pit ];
area->RemoveAllPrerequisites();
area->UpdateBlocked( true );
}
// attach prerequisites
for ( int i=0; i<IFuncNavPrerequisiteAutoList::AutoList().Count(); ++i )
{
CFuncNavPrerequisite *prereq = static_cast< CFuncNavPrerequisite* >( IFuncNavPrerequisiteAutoList::AutoList()[i] );
Extent prereqExtent;
prereqExtent.Init( prereq );
CRegisterPrerequisite apply( prereq );
ForAllAreasOverlappingExtent( apply, prereqExtent );
}
#endif
}
@@ -779,7 +694,7 @@ CNavArea *CNavMesh::GetNavArea( CBaseEntity *pEntity, int nFlags, float flBeneat
continue;
// don't consider blocked areas
if ( bSkipBlockedAreas && pArea->IsBlocked( pEntity->GetTeamNumber() ) )
if ( bSkipBlockedAreas && pArea->IsBlocked( TEAM_ANY ) )
continue;
// project position onto area to get Z
@@ -821,7 +736,7 @@ CNavArea *CNavMesh::GetNavArea( CBaseEntity *pEntity, int nFlags, float flBeneat
* Used to find initial area if we start off of the mesh.
* @todo Make sure area is not on the other side of the wall from goal.
*/
CNavArea *CNavMesh::GetNearestNavArea( const Vector &pos, bool anyZ, float maxDist, bool checkLOS, bool checkGround, int team ) const
CNavArea *CNavMesh::GetNearestNavArea( const Vector &pos, bool anyZ, float maxDist, bool checkLOS, bool checkGround ) const
{
VPROF_BUDGET( "CNavMesh::GetNearestNavArea", "NextBot" );
@@ -916,7 +831,7 @@ CNavArea *CNavMesh::GetNearestNavArea( const Vector &pos, bool anyZ, float maxDi
continue;
// don't consider blocked areas
if ( area->IsBlocked( team ) )
if ( area->IsBlocked( TEAM_ANY ) )
continue;
// mark as visited
@@ -1011,7 +926,7 @@ CNavArea *CNavMesh::GetNearestNavArea( CBaseEntity *pEntity, int nFlags, float m
bool bCheckLOS = ( nFlags & GETNAVAREA_CHECK_LOS ) != 0;
bool bCheckGround = ( nFlags & GETNAVAREA_CHECK_GROUND ) != 0;
return GetNearestNavArea( pEntity->GetAbsOrigin(), false, maxDist, bCheckLOS, bCheckGround, pEntity->GetTeamNumber() );
return GetNearestNavArea( pEntity->GetAbsOrigin(), false, maxDist, bCheckLOS, bCheckGround );
}
@@ -1082,38 +997,7 @@ void CNavMesh::LoadPlaceDatabase( void )
{
m_placeCount = 0;
#ifdef TERROR
// TODO: LoadPlaceDatabase happens during the constructor, so we can't override it!
// Population.txt holds all the info we need for place names in Left4Dead, so let's not
// make Phil edit yet another text file.
KeyValues *populationData = new KeyValues( "population" );
if ( populationData->LoadFromFile( filesystem, "scripts/population.txt" ) )
{
CUtlVector< char * > placeNames;
for ( KeyValues *key = populationData->GetFirstTrueSubKey(); key != NULL; key = key->GetNextTrueSubKey() )
{
if ( FStrEq( key->GetName(), "default" ) ) // default population is the undefined place
continue;
placeNames.AddToTail( CloneString( key->GetName() ) );
}
m_placeCount = placeNames.Count();
// allocate place name array
m_placeName = new char * [ m_placeCount ];
for ( unsigned int i=0; i<m_placeCount; ++i )
{
m_placeName[i] = placeNames[i];
}
populationData->deleteThis();
return;
}
populationData->deleteThis();
#endif
CUtlBuffer buf( 0, 0, CUtlBuffer::TEXT_BUFFER );
filesystem->ReadFile("NavPlace.db", "GAME", buf);
@@ -1137,7 +1021,7 @@ void CNavMesh::LoadPlaceDatabase( void )
int len = V_strlen( buffer );
if ( len >= 2 )
{
if ( buffer[len-1] == '\n' || buffer[len-1] == '\r' )
if ( buffer[len-1] == '\n' )
buffer[len-1] = 0;
if ( buffer[len-2] == '\r' )
@@ -1436,68 +1320,12 @@ void CNavMesh::DrawPlayerCounts( void ) const
if (area->GetPlayerCount() > 0)
{
NDebugOverlay::Text( area->GetCenter(), msg.sprintf( "%d (%d/%d)", area->GetPlayerCount(), area->GetPlayerCount(1), area->GetPlayerCount(2) ), false, NDEBUG_PERSIST_TILL_NEXT_SERVER );
NDebugOverlay::Text( area->GetCenter(), msg.sprintf( "%d (%d/%d)", area->GetPlayerCount(), area->GetPlayerCount(1), area->GetPlayerCount(2) ), false, 0.1f );
}
}
}
//--------------------------------------------------------------------------------------------------------------
/**
* Draw bot avoidance areas from func_nav_avoid entities
*/
void CNavMesh::DrawFuncNavAvoid( void ) const
{
FOR_EACH_VEC( TheNavAreas, it )
{
CNavArea *area = TheNavAreas[ it ];
if ( area->HasFuncNavAvoid() )
{
area->DrawFilled( 255, 0, 0, 255 );
}
}
}
//--------------------------------------------------------------------------------------------------------------
/**
* Draw bot preference areas from func_nav_prefer entities
*/
void CNavMesh::DrawFuncNavPrefer( void ) const
{
FOR_EACH_VEC( TheNavAreas, it )
{
CNavArea *area = TheNavAreas[ it ];
if ( area->HasFuncNavPrefer() )
{
area->DrawFilled( 0, 255, 0, 255 );
}
}
}
#ifdef NEXT_BOT
//--------------------------------------------------------------------------------------------------------------
/**
* Draw bot preference areas from func_nav_prerequisite entities
*/
void CNavMesh::DrawFuncNavPrerequisite( void ) const
{
FOR_EACH_VEC( TheNavAreas, it )
{
CNavArea *area = TheNavAreas[ it ];
if ( area->HasPrerequisite() )
{
area->DrawFilled( 0, 0, 255, 255 );
}
}
}
#endif
//--------------------------------------------------------------------------------------------------------------
/**
* Increase the danger of nav areas containing and near the given position
@@ -1695,95 +1523,6 @@ void CommandNavClearSelectedSet( void )
static ConCommand nav_clear_selected_set( "nav_clear_selected_set", CommandNavClearSelectedSet, "Clear the selected set.", FCVAR_GAMEDLL | FCVAR_CHEAT );
//----------------------------------------------------------------------------------
CON_COMMAND_F( nav_dump_selected_set_positions, "Write the (x,y,z) coordinates of the centers of all selected nav areas to a file.", FCVAR_GAMEDLL | FCVAR_CHEAT )
{
const NavAreaVector &selectedSet = TheNavMesh->GetSelectedSet();
CUtlBuffer fileBuffer( 4096, 1024*1024, CUtlBuffer::TEXT_BUFFER );
for( int i=0; i<selectedSet.Count(); ++i )
{
const Vector &center = selectedSet[i]->GetCenter();
fileBuffer.Printf( "%f %f %f\n", center.x, center.y, center.z );
}
// filename is local to game dir for Steam, so we need to prepend game dir for regular file save
char gamePath[256];
engine->GetGameDir( gamePath, 256 );
char filename[256];
Q_snprintf( filename, sizeof( filename ), "%s\\maps\\%s_xyz.txt", gamePath, STRING( gpGlobals->mapname ) );
if ( !filesystem->WriteFile( filename, "MOD", fileBuffer ) )
{
Warning( "Unable to save %d bytes to %s\n", fileBuffer.Size(), filename );
}
else
{
DevMsg( "Write %d nav area center positions to '%s'.\n", selectedSet.Count(), filename );
}
};
//----------------------------------------------------------------------------------
CON_COMMAND_F( nav_show_dumped_positions, "Show the (x,y,z) coordinate positions of the given dump file.", FCVAR_GAMEDLL | FCVAR_CHEAT )
{
CUtlBuffer fileBuffer( 4096, 1024*1024, CUtlBuffer::TEXT_BUFFER );
// filename is local to game dir for Steam, so we need to prepend game dir for regular file save
char gamePath[256];
engine->GetGameDir( gamePath, 256 );
char filename[256];
Q_snprintf( filename, sizeof( filename ), "%s\\maps\\%s_xyz.txt", gamePath, STRING( gpGlobals->mapname ) );
if ( !filesystem->ReadFile( filename, "MOD", fileBuffer ) )
{
Warning( "Unable to read %s\n", filename );
}
else
{
while( true )
{
Vector center;
if ( fileBuffer.Scanf( "%f %f %f", &center.x, &center.y, &center.z ) <= 0 )
{
break;
}
NDebugOverlay::Cross3D( center, 5.0f, 255, 255, 0, true, 99999.9f );
}
}
};
//----------------------------------------------------------------------------------
CON_COMMAND_F( nav_select_larger_than, "Select nav areas where both dimensions are larger than the given size.", FCVAR_GAMEDLL | FCVAR_CHEAT )
{
if ( args.ArgC() > 1 )
{
float minSize = atof( args[1] );
int selectedCount = 0;
for( int i=0; i<TheNavAreas.Count(); ++i )
{
CNavArea *area = TheNavAreas[i];
if ( area->GetSizeX() > minSize && area->GetSizeY() > minSize )
{
TheNavMesh->AddToSelectedSet( area );
++selectedCount;
}
}
DevMsg( "Selected %d areas with dimensions larger than %3.2f units.\n", selectedCount, minSize );
}
}
//--------------------------------------------------------------------------------------------------------------
void CommandNavBeginSelecting( void )
{
@@ -2021,16 +1760,6 @@ CON_COMMAND_F( nav_select_stairs, "Adds all stairway areas to the selected set",
}
//--------------------------------------------------------------------------------------------------------------
CON_COMMAND_F( nav_select_orphans, "Adds all orphan areas to the selected set (highlight a valid area first).", FCVAR_CHEAT )
{
if ( !UTIL_IsCommandIssuedByServerAdmin() )
return;
TheNavMesh->CommandNavSelectOrphans();
}
//--------------------------------------------------------------------------------------------------------------
void CommandNavSplit( void )
{
@@ -2130,17 +1859,6 @@ void CommandNavDisconnect( void )
static ConCommand nav_disconnect( "nav_disconnect", CommandNavDisconnect, "To disconnect two Areas, mark an Area, highlight a second Area, then invoke the disconnect command. This will remove all connections between the two Areas.", FCVAR_GAMEDLL | FCVAR_CHEAT );
//--------------------------------------------------------------------------------------------------------------
void CommandNavDisconnectOutgoingOneWays( void )
{
if ( !UTIL_IsCommandIssuedByServerAdmin() )
return;
TheNavMesh->CommandNavDisconnectOutgoingOneWays();
}
static ConCommand nav_disconnect_outgoing_oneways( "nav_disconnect_outgoing_oneways", CommandNavDisconnectOutgoingOneWays, "For each area in the selected set, disconnect all outgoing one-way connections.", FCVAR_GAMEDLL | FCVAR_CHEAT );
//--------------------------------------------------------------------------------------------------------------
void CommandNavSplice( void )
{
@@ -2724,23 +2442,7 @@ static ConCommand nav_compress_id( "nav_compress_id", CommandNavCompressID, "Re-
//--------------------------------------------------------------------------------------------------------------
#ifdef TERROR
void CommandNavShowLadderBounds( void )
{
if ( !UTIL_IsCommandIssuedByServerAdmin() )
return;
CFuncSimpleLadder *ladder = NULL;
while( (ladder = dynamic_cast< CFuncSimpleLadder * >(gEntList.FindEntityByClassname( ladder, "func_simpleladder" ))) != NULL )
{
Vector mins, maxs;
ladder->CollisionProp()->WorldSpaceSurroundingBounds( &mins, &maxs );
ladder->m_debugOverlays |= OVERLAY_TEXT_BIT | OVERLAY_ABSBOX_BIT;
NDebugOverlay::Box( vec3_origin, mins, maxs, 0, 255, 0, 0, 600 );
}
}
static ConCommand nav_show_ladder_bounds( "nav_show_ladder_bounds", CommandNavShowLadderBounds, "Draws the bounding boxes of all func_ladders in the map.", FCVAR_GAMEDLL | FCVAR_CHEAT );
#endif
//--------------------------------------------------------------------------------------------------------------
void CommandNavBuildLadder( void )
@@ -2799,10 +2501,7 @@ NavAttributeLookup TheNavAttributeTable[] =
{ "NO_MERGE", NAV_MESH_NO_MERGE },
{ "OBSTACLE_TOP", NAV_MESH_OBSTACLE_TOP },
{ "CLIFF", NAV_MESH_CLIFF },
#ifdef TERROR
{ "PLAYERCLIP", (NavAttributeType)CNavArea::NAV_PLAYERCLIP },
{ "BREAKABLEWALL", (NavAttributeType)CNavArea::NAV_BREAKABLEWALL },
#endif
{ NULL, NAV_MESH_INVALID }
};