Skip to content

Commit 01ad958

Browse files
committed
Fix ai_enemy_memory_fixes issues in npc_combine_s and npc_strider
1 parent 970887d commit 01ad958

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

sp/src/game/server/ai_basenpc_schedule.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extern ConVar ai_use_think_optimizations;
4646
ConVar ai_simulate_task_overtime( "ai_simulate_task_overtime", "0" );
4747

4848
#ifdef MAPBASE
49-
ConVar ai_enemy_memory_fixes( "ai_enemy_memory_fixes", "1", FCVAR_NONE, "Toggles Mapbase fixes for certain NPC AI not using enemy memory when it should." );
49+
ConVar ai_enemy_memory_fixes( "ai_enemy_memory_fixes", "0", FCVAR_NONE, "Toggles Mapbase fixes for certain NPC AI not using enemy memory when it should." );
5050
#endif
5151

5252
#define MAX_TASKS_RUN 10

sp/src/game/server/hl2/npc_combine.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -2551,6 +2551,24 @@ int CNPC_Combine::TranslateSchedule( int scheduleType )
25512551
}
25522552
}
25532553

2554+
#ifdef MAPBASE
2555+
extern ConVar ai_enemy_memory_fixes;
2556+
2557+
// SCHED_COMBINE_ESTABLISH_LINE_OF_FIRE uses TASK_GET_PATH_TO_ENEMY_LKP_LOS, a task with a mistake
2558+
// detailed in CAI_BaseNPC::StartTask and fixed by ai_enemy_memory_fixes.
2559+
//
2560+
// However, SCHED_COMBINE_ESTABLISH_LINE_OF_FIRE only stops being used once the NPC has LOS to its target.
2561+
// Since the fixed task now uses the enemy's last known position instead of the enemy's actual position,
2562+
// this schedule risks getting stuck in a loop.
2563+
//
2564+
// This code makes the soldier run up directly to the last known position if it's visible, allowing the AI
2565+
// to mark the enemy as eluded.
2566+
if ( ai_enemy_memory_fixes.GetBool() && FVisible( GetEnemyLKP() ) )
2567+
{
2568+
return SCHED_COMBINE_PRESS_ATTACK;
2569+
}
2570+
#endif
2571+
25542572
return SCHED_COMBINE_ESTABLISH_LINE_OF_FIRE;
25552573
}
25562574
break;

sp/src/game/server/hl2/npc_combine.h

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class CNPC_Combine : public CAI_BaseActor
6969
int RangeAttack2Conditions( float flDot, float flDist ); // For innate grenade attack
7070
int MeleeAttack1Conditions( float flDot, float flDist ); // For kick/punch
7171
bool FVisible( CBaseEntity *pEntity, int traceMask = MASK_BLOCKLOS, CBaseEntity **ppBlocker = NULL );
72+
bool FVisible( const Vector &vecTarget, int traceMask = MASK_BLOCKLOS, CBaseEntity **ppBlocker = NULL ) { return BaseClass::FVisible( vecTarget, traceMask, ppBlocker ); }
7273
virtual bool IsCurTaskContinuousMove();
7374

7475
virtual float GetJumpGravity() const { return 1.8f; }

sp/src/game/server/hl2/npc_strider.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,26 @@ int CNPC_Strider::TranslateSchedule( int scheduleType )
15111511
return SCHED_COMBAT_PATROL;
15121512
}
15131513
}
1514+
else
1515+
{
1516+
#ifdef MAPBASE
1517+
extern ConVar ai_enemy_memory_fixes;
1518+
1519+
// Striders convert TASK_GET_PATH_TO_ENEMY_LOS to TASK_GET_PATH_TO_ENEMY_LKP_LOS, a task which incorrectly
1520+
// acts identically to the former. This is detailed in CAI_BaseNPC::StartTask and fixed by ai_enemy_memory_fixes.
1521+
//
1522+
// However, SCHED_ESTABLISH_LINE_OF_FIRE only stops being used once the NPC has LOS to its target.
1523+
// Since the fixed task now uses the enemy's last known position instead of the enemy's actual position,
1524+
// this schedule risks getting stuck in a loop.
1525+
//
1526+
// This code chains back up to SCHED_ESTABLISH_LINE_OF_FIRE_FALLBACK, which is what's supposed to happen when a
1527+
// strider is eluded in this way.
1528+
if ( ai_enemy_memory_fixes.GetBool() && FVisible( GetEnemyLKP() ) )
1529+
{
1530+
return TranslateSchedule( SCHED_ESTABLISH_LINE_OF_FIRE_FALLBACK );
1531+
}
1532+
#endif
1533+
}
15141534

15151535
break;
15161536

sp/src/game/server/hl2/npc_strider.h

+1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ class CNPC_Strider : public CAI_BlendingHost<CAI_BaseNPC>,
188188
bool HasPass() { return m_PlayerFreePass.HasPass(); }
189189

190190
bool FVisible( CBaseEntity *pEntity, int traceMask = MASK_BLOCKLOS, CBaseEntity **ppBlocker = NULL );
191+
bool FVisible( const Vector &vecTarget, int traceMask = MASK_BLOCKLOS, CBaseEntity **ppBlocker = NULL ) { return BaseClass::FVisible( vecTarget, traceMask, ppBlocker ); }
191192
Vector BodyTarget( const Vector &posSrc, bool bNoisy );
192193

193194
bool IsValidEnemy( CBaseEntity *pTarget );

0 commit comments

Comments
 (0)