Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 56 additions & 9 deletions src/game/server/neo/bot/behavior/neo_bot_seek_and_destroy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ ConVar sv_neo_bot_seek_and_destroy_combat_sound_detour_ratio( "sv_neo_bot_seek_a
"When racing for an objective, divert only if going via the combat sound costs at most this multiple of direct distance.", true, 0, false, 0 );
ConVar sv_neo_bot_seek_and_destroy_combat_sound_arrive_range( "sv_neo_bot_seek_and_destroy_combat_sound_arrive_range", "200.0", FCVAR_CHEAT,
"Combat sound close enough to count as investigated.", true, 0, false, 0 );
ConVar sv_neo_bot_seek_and_destroy_roam_goal_tries( "sv_neo_bot_seek_and_destroy_roam_goal_tries", "10", FCVAR_CHEAT,
"Random roam goals to try before settling on one the bot can already see.", true, 1, false, 0 );


//---------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -136,6 +138,21 @@ bool CNEOBotSeekAndDestroy::TryPathToRoamGoal( CNEOBot *me, const Vector &vGoal
}


//---------------------------------------------------------------------------------------------
// A place the bot can already see is not worth the walk, so pick an area outside of PVS
static bool IsRoamGoalInView( CNEOBot *me, const Vector &vGoal )
{
const CNavArea *pMyArea = me->GetLastKnownArea();
if ( !pMyArea )
{
return false;
}

const CNavArea *pGoalArea = TheNavMesh->GetNearestNavArea( vGoal );
return pGoalArea && pMyArea->IsPotentiallyVisible( pGoalArea );
}


//---------------------------------------------------------------------------------------------
CNEOBotSeekAndDestroy::CNEOBotSeekAndDestroy( float duration )
{
Expand Down Expand Up @@ -171,6 +188,12 @@ ActionResult< CNEOBot > CNEOBotSeekAndDestroy::OnStart( CNEOBot *me, Action< CNE
//---------------------------------------------------------------------------------------------
ActionResult< CNEOBot > CNEOBotSeekAndDestroy::Update( CNEOBot *me, float interval )
{
// Bots respawn mid-round in JGR, so the switch cannot wait for the pre-round freeze
if ( NEORules()->GetGameType() == NEO_GAME_TYPE_JGR )
{
return SuspendFor( new CNEOBotJgrSeek, "Switching to Juggernaut-related Seek and Destroy" );
}

// Check for Game Type Specific behaviors and suspend for them
if ( NEORules()->GetRemainingPreRoundFreezeTime( true ) > 0.0f )
{
Expand All @@ -184,10 +207,6 @@ ActionResult< CNEOBot > CNEOBotSeekAndDestroy::Update( CNEOBot *me, float interv
}

}
else if (NEORules()->GetGameType() == NEO_GAME_TYPE_JGR)
{
return SuspendFor( new CNEOBotJgrSeek, "Switching to Juggernaut-related Seek and Destroy" );
}

return Continue();
}
Expand Down Expand Up @@ -588,29 +607,57 @@ void CNEOBotSeekAndDestroy::RecomputeSeekPath( CNEOBot *me )
CBaseEntity* pSearch = NULL;
while ( ( pSearch = gEntList.FindEntityByClassname( pSearch, "info_player_*", &spawnFilter ) ) != NULL )
{
if ( pSearch && Q_strcmp(pSearch->GetEntityName().ToCStr(), "info_player_start"))
if ( pSearch && !FClassnameIs( pSearch, "info_player_start" ) )
{
pSpawns.AddToTail( pSearch );
}
}

// Don't wander between spawns if there aren't that many.
if ( pSpawns.Size() >= 3 )
{
for ( int i = 0; i < 10; i++ )
const int iTries = sv_neo_bot_seek_and_destroy_roam_goal_tries.GetInt();
for ( int i = 0; i < iTries; i++ )
{
m_hTargetEntity = pSpawns[RandomInt( 0, pSpawns.Size() - 1 )];
CBaseEntity *pSpawn = pSpawns[RandomInt( 0, pSpawns.Size() - 1 )];
const Vector vSpawn = pSpawn->WorldSpaceCenter();
if ( IsRoamGoalInView( me, vSpawn ) )
{
continue;
}

m_hTargetEntity = pSpawn;
m_bGoingToTargetEntity = true;
m_vGoalPos = m_hTargetEntity->WorldSpaceCenter();
m_vGoalPos = vSpawn;
if ( TryPathToRoamGoal( me, m_vGoalPos ) )
{
return;
}

// An unreachable spawn usually indicates a spawn protected area.
// Re-rolling would likely pick other spawn protected areas, so wander instead.
break;
}
}
}

for ( int i = 0; i < 10; i++ )
m_hTargetEntity = nullptr;
m_bGoingToTargetEntity = false;

const int iTries = sv_neo_bot_seek_and_destroy_roam_goal_tries.GetInt();
for ( int i = 0; i < iTries; i++ )
{
// No spawns we can get to? Just wander... somewhere!

Vector vWanderPoint = TheNavAreas[RandomInt( 0, TheNavAreas.Size() - 1 )]->GetCenter();

// The last try takes any point, so a bot that sees most of a small map still gets a path
const bool bLastTry = ( i == iTries - 1 );
if ( !bLastTry && IsRoamGoalInView( me, vWanderPoint ) )
{
continue;
}

m_vGoalPos = vWanderPoint;
if ( TryPathToRoamGoal( me, vWanderPoint ) )
return;
Expand Down
Loading