Skip to content

Add ability to override NPC Jump Variables #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
29 changes: 29 additions & 0 deletions sp/src/game/server/ai_basenpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12429,6 +12429,12 @@ BEGIN_DATADESC( CAI_BaseNPC )

DEFINE_KEYFIELD( m_flSpeedModifier, FIELD_FLOAT, "BaseSpeedModifier" ),
DEFINE_FIELD( m_FakeSequenceGestureLayer, FIELD_INTEGER ),

// Jump override keyvalues
DEFINE_KEYFIELD( m_jumpUpOverride, FIELD_FLOAT, "JumpUpOverride" ),
DEFINE_KEYFIELD( m_jumpDownOverride, FIELD_FLOAT, "JumpDownOverride" ),
DEFINE_KEYFIELD( m_jumpDistOverride, FIELD_FLOAT, "JumpDistOverride" ),

#endif

// Satisfy classcheck
Expand Down Expand Up @@ -12539,6 +12545,11 @@ BEGIN_DATADESC( CAI_BaseNPC )
DEFINE_OUTPUT( m_OnStateChange, "OnStateChange" ),
#endif

// Change jump height
DEFINE_INPUTFUNC( FIELD_FLOAT, "SetMaxJumpUp", InputSetJumpUp ),
DEFINE_INPUTFUNC( FIELD_FLOAT, "SetMaxJumpDown", InputSetJumpDown ),
DEFINE_INPUTFUNC( FIELD_FLOAT, "SetMaxJumpDist", InputSetJumpDist ),

// Function pointers
DEFINE_USEFUNC( NPCUse ),
DEFINE_THINKFUNC( CallNPCThink ),
Expand Down Expand Up @@ -17047,3 +17058,21 @@ bool CAI_BaseNPC::IsInChoreo() const
{
return m_bInChoreo;
}

//-----------------------------------------------------------------------------
// Purpose: Override the NPC's default jump values
//-----------------------------------------------------------------------------
void CAI_BaseNPC::InputSetJumpUp( inputdata_t& inputdata )
{
m_jumpUpOverride = inputdata.value.Float();
}

void CAI_BaseNPC::InputSetJumpDown( inputdata_t& inputdata )
{
m_jumpDownOverride = inputdata.value.Float();
}

void CAI_BaseNPC::InputSetJumpDist( inputdata_t& inputdata )
{
m_jumpDistOverride = inputdata.value.Float();
}
11 changes: 11 additions & 0 deletions sp/src/game/server/ai_basenpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2132,6 +2132,11 @@ class CAI_BaseNPC : public CBaseCombatCharacter,
void InputIgnoreDangerSounds( inputdata_t &inputdata );
void InputUpdateEnemyMemory( inputdata_t &inputdata );

// Overwrite jump height
void InputSetJumpUp( inputdata_t& inputdata );
void InputSetJumpDown( inputdata_t& inputdata );
void InputSetJumpDist( inputdata_t& inputdata );

//---------------------------------

virtual void NotifyDeadFriend( CBaseEntity *pFriend ) { return; }
Expand Down Expand Up @@ -2488,6 +2493,12 @@ class CAI_BaseNPC : public CBaseCombatCharacter,
void GetPlayerAvoidBounds( Vector *pMins, Vector *pMaxs );

void StartPingEffect( void ) { m_flTimePingEffect = gpGlobals->curtime + 2.0f; DispatchUpdateTransmitState(); }

protected: // Jump override variables
float m_jumpUpOverride = 0.0f;
float m_jumpDownOverride = 0.0f;
float m_jumpDistOverride = 0.0f;

};


Expand Down
13 changes: 9 additions & 4 deletions sp/src/game/server/ai_basenpc_movement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,21 @@ bool CAI_BaseNPC::CanStandOn( CBaseEntity *pSurface ) const
bool CAI_BaseNPC::IsJumpLegal( const Vector &startPos, const Vector &apex, const Vector &endPos,
float maxUp, float maxDown, float maxDist ) const
{
if ((endPos.z - startPos.z) > maxUp + 0.1)
// Always use the jump override values
float localMaxUp = m_jumpUpOverride > 0.0 ? m_jumpUpOverride : maxUp;
float localMaxDown = m_jumpDownOverride > 0.0 ? m_jumpDownOverride : maxDown;
float localMaxDist = m_jumpDistOverride > 0.0 ? m_jumpDistOverride : maxDist;

if ((endPos.z - startPos.z) > localMaxUp + 0.1 )
return false;
if ((startPos.z - endPos.z) > maxDown + 0.1)
if ((startPos.z - endPos.z) > localMaxDown + 0.1 )
return false;

if ((apex.z - startPos.z) > maxUp * 1.25 )
if ((apex.z - startPos.z) > localMaxUp * 1.25 )
return false;

float dist = (startPos - endPos).Length();
if ( dist > maxDist + 0.1)
if ( dist > localMaxDist + 0.1 )
return false;
return true;
}
Expand Down
4 changes: 3 additions & 1 deletion sp/src/game/server/hl2/npc_monk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,9 @@ int CNPC_Monk::SelectFailSchedule( int failedSchedule, int failedTask, AI_TaskFa
//-----------------------------------------------------------------------------
bool CNPC_Monk::IsJumpLegal( const Vector &startPos, const Vector &apex, const Vector &endPos ) const
{
if ( startPos.z - endPos.z < 0 )
// `startPos.z - endPos.z < 0` disables jumping up (probably to hack around some silly behavior Valve found in d1_town_02a)
// If the mapper is setting jumpUpOverride, they probably want father to jump up
if ( startPos.z - endPos.z < 0 && m_jumpUpOverride < 0 )
return false;
return BaseClass::IsJumpLegal( startPos, apex, endPos );
}
Expand Down