Skip to content

Commit

Permalink
Fix monster seeing enemy as a blocker when the monster chooses to fol…
Browse files Browse the repository at this point in the history
…low enemy by node graph
  • Loading branch information
FreeSlave committed Feb 4, 2025
1 parent d11242d commit 7bb8add
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dlls/basemonster.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class CBaseMonster : public CBaseToggle
void PushEnemy(CBaseEntity *pEnemy, const Vector &vecLastKnownPos );
bool PopEnemy( void );

bool FGetNodeRoute( Vector vecDest );
bool FGetNodeRoute( Vector vecDest, int goalMoveFlag = 0 );

inline void TaskComplete( void ) { if ( !HasConditions( bits_COND_TASK_FAILED ) ) m_iTaskStatus = TASKSTATUS_COMPLETE; }
void MovementComplete( void );
Expand Down
52 changes: 43 additions & 9 deletions dlls/monsters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,8 @@ bool CBaseMonster::FRefreshRoute( int buildRouteFlags )
}
break;
case MOVEGOAL_ENEMY:
returnCode = BuildRoute( m_vecEnemyLKP, bits_MF_TO_ENEMY, m_hEnemy, buildRouteFlags );
case MOVEGOAL_ENEMY_NEAREST:
returnCode = BuildRoute( m_vecEnemyLKP, m_movementGoal, m_hEnemy, buildRouteFlags );
break;
case MOVEGOAL_LOCATION:
case MOVEGOAL_LOCATION_NEAREST:
Expand Down Expand Up @@ -1292,7 +1293,7 @@ bool CBaseMonster::CheckEnemy( CBaseEntity *pEnemy )
CheckAttacks( m_hEnemy, flDistToEnemy, flMeleeDist );
}

if( m_movementGoal == MOVEGOAL_ENEMY )
if( m_movementGoal == MOVEGOAL_ENEMY || m_movementGoal == MOVEGOAL_ENEMY_NEAREST )
{
for( int i = m_iRouteIndex; i < ROUTE_SIZE; i++ )
{
Expand Down Expand Up @@ -1845,7 +1846,7 @@ bool CBaseMonster::BuildRoute( const Vector &vecGoal, int iMoveFlag, CBaseEntity
}

// last ditch, try nodes
if( !FBitSet(buildRouteFlags, BUILDROUTE_NO_NODEROUTE) && FGetNodeRoute( vecGoal ) )
if( !FBitSet(buildRouteFlags, BUILDROUTE_NO_NODEROUTE) && FGetNodeRoute( vecGoal, iMoveFlag & (bits_MF_TO_TARGETENT|bits_MF_TO_ENEMY) ) )
{
//ALERT( at_console, "Can get there on nodes\n" );
m_vecMoveGoal = vecGoal;
Expand Down Expand Up @@ -2294,12 +2295,12 @@ void CBaseMonster::Move( float flInterval )
flCheckDist = DIST_TO_CHECK;
}

if( ( m_Route[m_iRouteIndex].iType & ( ~bits_MF_NOT_TO_MASK ) ) == bits_MF_TO_ENEMY )
if( ( m_Route[m_iRouteIndex].iType & ( ~(bits_MF_NOT_TO_MASK|bits_MF_NEAREST_PATH) ) ) == bits_MF_TO_ENEMY )
{
// only on a PURE move to enemy ( i.e., ONLY MF_TO_ENEMY set, not MF_TO_ENEMY and DETOUR )
pTargetEnt = m_hEnemy;
}
else if( ( m_Route[m_iRouteIndex].iType & ~bits_MF_NOT_TO_MASK ) & bits_MF_TO_TARGETENT )
else if( ( m_Route[m_iRouteIndex].iType & ~(bits_MF_NOT_TO_MASK|bits_MF_NEAREST_PATH) ) == bits_MF_TO_TARGETENT )
{
pTargetEnt = m_hTargetEnt;
}
Expand Down Expand Up @@ -2365,7 +2366,7 @@ void CBaseMonster::Move( float flInterval )
}
else
{
if (m_movementGoal == MOVEGOAL_ENEMY && pBlocker && pBlocker == m_hEnemy)
if ((m_movementGoal == MOVEGOAL_ENEMY || m_movementGoal == MOVEGOAL_ENEMY_NEAREST) && pBlocker && pBlocker == m_hEnemy)
{
Remember(bits_MEMORY_BLOCKER_IS_ENEMY);
}
Expand Down Expand Up @@ -3280,7 +3281,7 @@ Vector CBaseMonster::GetGunPosition()
// succeeds (path is valid) or false if failed (no path
// exists )
//=========================================================
bool CBaseMonster::FGetNodeRoute( Vector vecDest )
bool CBaseMonster::FGetNodeRoute( Vector vecDest, int goalMoveFlag )
{
int iPath[ MAX_PATH_SIZE ];
int iSrcNode, iDestNode;
Expand Down Expand Up @@ -3362,7 +3363,7 @@ bool CBaseMonster::FGetNodeRoute( Vector vecDest )
if( iNumToCopy < ROUTE_SIZE )
{
m_Route[iNumToCopy].vecLocation = vecDest;
m_Route[iNumToCopy].iType |= bits_MF_IS_GOAL;
m_Route[iNumToCopy].iType |= goalMoveFlag|bits_MF_IS_GOAL;
}

return true;
Expand Down Expand Up @@ -3442,6 +3443,28 @@ const char* CBaseMonster::MonsterStateDisplayString(MONSTERSTATE monsterState)
}
}

static void ReportRouteType(ALERT_TYPE level, int routeType)
{
if (routeType & bits_MF_TO_TARGETENT)
ALERT(level, "To TargetEnt; ");
if (routeType & bits_MF_TO_ENEMY)
ALERT(level, "To Enemy; ");
if (routeType & bits_MF_TO_DETOUR)
ALERT(level, "Detour; ");
if (routeType & bits_MF_TO_PATHCORNER)
ALERT(level, "Path Corner; ");
if (routeType & bits_MF_TO_NODE)
ALERT(level, "Node; ");
if (routeType & bits_MF_TO_LOCATION)
ALERT(level, "Location; ");
if (routeType & bits_MF_IS_GOAL)
ALERT(level, "Goal; ");
if (routeType & bits_MF_DONT_SIMPLIFY)
ALERT(level, "Don't simplify; ");
if (routeType & bits_MF_NEAREST_PATH)
ALERT(level, "Nearest; ");
}

void CBaseMonster::ReportAIState( ALERT_TYPE level )
{
const bool shouldReportRoute = DeveloperModeLevel() >= 3;
Expand Down Expand Up @@ -3531,7 +3554,7 @@ void CBaseMonster::ReportAIState( ALERT_TYPE level )
{
ALERT( level, "Moving" );
if( m_flMoveWaitFinished > gpGlobals->time )
ALERT( level, ": Stopped for %.2f", (double)(m_flMoveWaitFinished - gpGlobals->time) );
ALERT( level, ": Stopped for %.2f", m_flMoveWaitFinished - gpGlobals->time );
else if( m_IdealActivity == GetStoppedActivity() )
ALERT( level, ": In stopped anim" );
ALERT( level, ". " );
Expand Down Expand Up @@ -3625,6 +3648,17 @@ void CBaseMonster::ReportAIState( ALERT_TYPE level )
{
ALERT(level, "No nearest node. ");
}

if (!FRouteClear())
{
ALERT(level, "\nRoute:\n");
for (int j = 0; m_Route[j].iType && j < ARRAYSIZE(m_Route); ++j)
{
ALERT(level, "%d: ", j);
ReportRouteType(level, m_Route[j].iType);
ALERT(level, "\n");
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion dlls/schedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +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 MOVEGOAL_ENEMY_NEAREST (bits_MF_TO_ENEMY|bits_MF_NEAREST_PATH)

#define BUILDROUTE_NO_NODEROUTE ( 1 << 0 )
#define BUILDROUTE_NODEROUTE_ONLY ( 1 << 1 )
Expand Down

0 comments on commit 7bb8add

Please sign in to comment.