Skip to content

Commit

Permalink
Add npc_get_to_enemy_nearest. Rename npc_nearest to npc_follow_nearest
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeSlave committed Jan 23, 2025
1 parent 9f11466 commit adf3ef6
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 16 deletions.
1 change: 1 addition & 0 deletions cl_dll/hl/hl_baseentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ bool CBaseMonster::CheckRangeAttack1( float flDot, float flDist ) { return false
bool CBaseMonster::CheckRangeAttack2( float flDot, float flDist ) { return false; }
bool CBaseMonster::CheckMeleeAttack1( float flDot, float flDist ) { return false; }
bool CBaseMonster::CheckMeleeAttack2( float flDot, float flDist ) { return false; }
bool CBaseMonster::WantsToGetCloseToEnemy() { return false; }
bool CBaseMonster::FCanCheckAttacks( void ) { return false; }
bool CBaseMonster::CheckEnemy( CBaseEntity *pEnemy ) { return false; }
void CBaseMonster::SetActivity( Activity NewActivity ) { }
Expand Down
1 change: 1 addition & 0 deletions dlls/basemonster.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class CBaseMonster : public CBaseToggle
virtual bool CheckRangeAttack2( float flDot, float flDist );
virtual bool CheckMeleeAttack1( float flDot, float flDist );
virtual bool CheckMeleeAttack2( float flDot, float flDist );
virtual bool WantsToGetCloseToEnemy();

bool FHaveSchedule( void );
bool FScheduleValid( void );
Expand Down
10 changes: 4 additions & 6 deletions dlls/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,9 +810,8 @@ cvar_t use_through_walls = { "use_through_walls", "1", FCVAR_SERVER };
cvar_t items_physics_fix = { "items_physics_fix", "0", FCVAR_SERVER };
cvar_t npc_tridepth = { "npc_tridepth", "1", FCVAR_SERVER };
cvar_t npc_tridepth_all = { "npc_tridepth_all", "0", FCVAR_SERVER };
#if FEATURE_NPC_NEAREST_CVAR
cvar_t npc_nearest = { "npc_nearest", "0", FCVAR_SERVER };
#endif
cvar_t npc_follow_nearest = { "npc_follow_nearest", "0", FCVAR_SERVER };
cvar_t npc_get_to_enemy_nearest = { "npc_get_to_enemy_nearest", "0", FCVAR_SERVER };
cvar_t npc_forget_enemy_time = { "npc_forget_enemy_time", "0", FCVAR_SERVER };
#if FEATURE_NPC_FIX_MELEE_DISTANCE_CVAR
cvar_t npc_fix_melee_distance = { "npc_fix_melee_distance", "0", FCVAR_SERVER };
Expand Down Expand Up @@ -1613,9 +1612,8 @@ void GameDLLInit( void )
CVAR_REGISTER( &items_physics_fix );
CVAR_REGISTER( &npc_tridepth );
CVAR_REGISTER( &npc_tridepth_all );
#if FEATURE_NPC_NEAREST_CVAR
CVAR_REGISTER( &npc_nearest );
#endif
CVAR_REGISTER( &npc_follow_nearest );
CVAR_REGISTER( &npc_get_to_enemy_nearest );
CVAR_REGISTER( &npc_forget_enemy_time );
#if FEATURE_NPC_FIX_MELEE_DISTANCE_CVAR
CVAR_REGISTER( &npc_fix_melee_distance );
Expand Down
14 changes: 8 additions & 6 deletions dlls/gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,12 +774,14 @@ bool AllowUseThroughWalls()

bool NpcFollowNearest()
{
#if FEATURE_NPC_NEAREST_CVAR
extern cvar_t npc_nearest;
return npc_nearest.value != 0;
#else
return false;
#endif
extern cvar_t npc_follow_nearest;
return npc_follow_nearest.value != 0;
}

bool NpcGetToEnemyNearest()
{
extern cvar_t npc_get_to_enemy_nearest;
return npc_get_to_enemy_nearest.value != 0;
}

float NpcForgetEnemyTime()
Expand Down
1 change: 1 addition & 0 deletions dlls/gamerules.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ int TridepthValue();
bool TridepthForAll();
bool AllowUseThroughWalls();
bool NpcFollowNearest();
bool NpcGetToEnemyNearest();
float NpcForgetEnemyTime();
bool NpcActiveAfterCombat();
bool NpcFollowOutOfPvs();
Expand Down
6 changes: 6 additions & 0 deletions dlls/houndeye.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class CHoundeye : public CSquadMonster
void SetActivity( Activity NewActivity );
const Visual* GetWaveVisual();
bool CheckRangeAttack1( float flDot, float flDist ) override;
bool WantsToGetCloseToEnemy() override;
bool FValidateHintType( short sHint ) override;
bool FCanActiveIdle( void ) override;
Schedule_t *GetScheduleOfType( int Type );
Expand Down Expand Up @@ -334,6 +335,11 @@ bool CHoundeye::CheckRangeAttack1( float flDot, float flDist )
return false;
}

bool CHoundeye::WantsToGetCloseToEnemy()
{
return true;
}

//=========================================================
// SetYawSpeed - allows each sequence to have a different
// turn rate associated with it.
Expand Down
17 changes: 15 additions & 2 deletions dlls/monsters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,11 @@ bool CBaseMonster::FCanCheckAttacks( void )
return false;
}

bool CBaseMonster::WantsToGetCloseToEnemy()
{
return !FBitSet(m_afCapability, bits_CAP_RANGE_ATTACK1|bits_CAP_RANGE_ATTACK2) && FBitSet(m_afCapability, bits_CAP_MELEE_ATTACK1|bits_CAP_MELEE_ATTACK1);
}

//=========================================================
// CheckEnemy - part of the Condition collection process,
// gets and stores data and conditions pertaining to a monster's
Expand Down Expand Up @@ -1282,7 +1287,7 @@ bool CBaseMonster::CheckEnemy( CBaseEntity *pEnemy )
{
for( int i = m_iRouteIndex; i < ROUTE_SIZE; i++ )
{
if( m_Route[i].iType == ( bits_MF_IS_GOAL | bits_MF_TO_ENEMY ) )
if( m_Route[i].iType == (bits_MF_IS_GOAL|bits_MF_TO_ENEMY) || m_Route[i].iType == (bits_MF_IS_GOAL|bits_MF_TO_ENEMY|bits_MF_NEAREST_PATH) )
{
// UNDONE: Should we allow monsters to override this distance (80?)
if( ( m_Route[i].vecLocation - m_vecEnemyLKP ).Length() > 80.0f )
Expand Down Expand Up @@ -1686,7 +1691,11 @@ int CBaseMonster::RouteClassify( int iMoveFlag )
movementGoal = MOVEGOAL_TARGETENT_NEAREST;
}
else if( iMoveFlag & bits_MF_TO_ENEMY )
{
movementGoal = MOVEGOAL_ENEMY;
if( iMoveFlag & bits_MF_NEAREST_PATH )
movementGoal = MOVEGOAL_ENEMY_NEAREST;
}
else if( iMoveFlag & bits_MF_TO_PATHCORNER )
movementGoal = MOVEGOAL_PATHCORNER;
else if( iMoveFlag & bits_MF_TO_NODE )
Expand Down Expand Up @@ -1793,6 +1802,9 @@ bool CBaseMonster::BuildRoute( const Vector &vecGoal, int iMoveFlag, CBaseEntity

m_vecMoveGoal = localMoveNearest;

// Prevent playing walk/run animation while standing in place
const float distToMoveStraight = (localMoveNearest - pev->origin).Length2D();

Vector apex;
const Vector triangulatedNearest = FTriangulateToNearest(pev->origin, vecGoal, flDist, pTarget, apex);

Expand All @@ -1814,8 +1826,9 @@ bool CBaseMonster::BuildRoute( const Vector &vecGoal, int iMoveFlag, CBaseEntity
RouteSimplify( pTarget );
}
m_vecMoveGoal = triangulatedNearest;
return true;
}
return true;
return distToMoveStraight >= 1.0f;
}

// b0rk
Expand Down
7 changes: 6 additions & 1 deletion dlls/schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,12 @@ void CBaseMonster::StartTask( Task_t *pTask )
return;
}

if( BuildRoute( pEnemy->pev->origin, bits_MF_TO_ENEMY, pEnemy ) )
int routeFlags = bits_MF_TO_ENEMY;
if (NpcGetToEnemyNearest() && WantsToGetCloseToEnemy())
{
routeFlags |= bits_MF_NEAREST_PATH;
}
if( BuildRoute( pEnemy->pev->origin, routeFlags, pEnemy ) )
{
TaskComplete();
}
Expand Down
1 change: 1 addition & 0 deletions dlls/schedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ struct WayPoint_t
#define MOVEGOAL_NODE (bits_MF_TO_NODE)
#define MOVEGOAL_TARGETENT_NEAREST (bits_MF_TO_TARGETENT|bits_MF_NEAREST_PATH)
#define MOVEGOAL_LOCATION_NEAREST (bits_MF_TO_LOCATION|bits_MF_NEAREST_PATH)
#define MOVEGOAL_ENEMY_NEAREST (MOVEGOAL_ENEMY|bits_MF_NEAREST_PATH)

#define BUILDROUTE_NO_NODEROUTE ( 1 << 0 )
#define BUILDROUTE_NODEROUTE_ONLY ( 1 << 1 )
Expand Down
3 changes: 3 additions & 0 deletions features/featureful_exec.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ npc_forget_enemy_time "0"
// If set to 1, monsters will wander around a bit after the combat ends.
npc_active_after_combat "0"

// In original Half-Life melee-only monsters can't get path to enemy (e.g. player) if he stays on some small elevation like a table. Set this to 1 to allow monsters find a path to the enemy on the elevation. This is experimental.
npc_get_to_enemy_nearest "0"

// Attempt to fix item_ and ammo_ entities falling physics. This is experimental as some values lead to other bugs.
// 0 - default Half-Life behavior (items fall through thin shelves)
// 1 - items dropped from func_breakable boxes placed on thin shelves don't fall through. Items still fall through if box is in the air.
Expand Down
1 change: 0 additions & 1 deletion game_shared/mod_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
#define FEATURE_EXPERIMENTAL_CVARS 1

#define FEATURE_USE_THROUGH_WALLS_CVAR (0 || FEATURE_EXPERIMENTAL_CVARS)
#define FEATURE_NPC_NEAREST_CVAR (0 || FEATURE_EXPERIMENTAL_CVARS)
#define FEATURE_GRENADE_JUMP_CVAR (0 || FEATURE_EXPERIMENTAL_CVARS)
#define FEATURE_NPC_FIX_MELEE_DISTANCE_CVAR (0 || FEATURE_EXPERIMENTAL_CVARS)
#define FEATURE_NPC_FOLLOW_OUT_OF_PVS_CVAR (0 || FEATURE_EXPERIMENTAL_CVARS)
Expand Down

0 comments on commit adf3ef6

Please sign in to comment.