Skip to content

Minor npc_zombie improvements #312

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

Merged
merged 6 commits into from
Jan 9, 2025
Merged
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
21 changes: 19 additions & 2 deletions sp/src/game/server/hl2/npc_BaseZombie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ BEGIN_DATADESC( CNPC_BaseZombie )
DEFINE_FIELD( m_fIsTorso, FIELD_BOOLEAN ),
#ifdef MAPBASE
DEFINE_KEYFIELD( m_fIsHeadless, FIELD_BOOLEAN, "Headless" ),
DEFINE_KEYFIELD( m_flMeleeReach, FIELD_FLOAT, "MeleeReach" ),
DEFINE_KEYFIELD( m_flMaxDistToSwat, FIELD_FLOAT, "MaxDistToSwat" ),
DEFINE_KEYFIELD( m_iMaxObjMassToSwat, FIELD_INTEGER, "MaxObjMassToSwat" ),
#else
DEFINE_FIELD( m_fIsHeadless, FIELD_BOOLEAN ),
#endif
Expand Down Expand Up @@ -256,6 +259,12 @@ CNPC_BaseZombie::CNPC_BaseZombie()
// moan loop.
m_iMoanSound = g_numZombies;

#ifdef MAPBASE
m_flMeleeReach = ZOMBIE_MELEE_REACH;
m_flMaxDistToSwat = ZOMBIE_PLAYER_MAX_SWAT_DIST;
m_iMaxObjMassToSwat = ZOMBIE_MAX_PHYSOBJ_MASS;
#endif

g_numZombies++;
}

Expand Down Expand Up @@ -295,7 +304,11 @@ bool CNPC_BaseZombie::FindNearestPhysicsObject( int iMaxMass )
float dist = VectorNormalize(vecDirToEnemy);
vecDirToEnemy.z = 0;

if( dist > ZOMBIE_PLAYER_MAX_SWAT_DIST )
#ifndef MAPBASE
if (dist > ZOMBIE_PLAYER_MAX_SWAT_DIST)
#else
if (dist > m_flMaxDistToSwat)
#endif
{
// Player is too far away. Don't bother
// trying to swat anything at them until
Expand Down Expand Up @@ -786,7 +799,7 @@ bool CNPC_BaseZombie::ShouldBecomeTorso( const CTakeDamageInfo &info, float flDa
HeadcrabRelease_t CNPC_BaseZombie::ShouldReleaseHeadcrab( const CTakeDamageInfo &info, float flDamageThreshold )
{
#ifdef MAPBASE
if ( m_iHealth <= 0 && !m_fIsHeadless )
if ( m_iHealth <= 0 && !m_fIsHeadless && !HasSpawnFlags(SF_ZOMBIE_NO_HEADCRAB_SPAWN))
#else
if ( m_iHealth <= 0 )
#endif
Expand Down Expand Up @@ -2154,7 +2167,11 @@ void CNPC_BaseZombie::GatherConditions( void )
// between him and the object he's heading for already.
if( gpGlobals->curtime >= m_flNextSwatScan && (m_hPhysicsEnt == NULL) )
{
#ifdef MAPBASE
FindNearestPhysicsObject(m_iMaxObjMassToSwat);
#else
FindNearestPhysicsObject( ZOMBIE_MAX_PHYSOBJ_MASS );
#endif
m_flNextSwatScan = gpGlobals->curtime + 2.0;
}
}
Expand Down
18 changes: 16 additions & 2 deletions sp/src/game/server/hl2/npc_BaseZombie.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ extern int AE_ZOMBIE_POUND;
#define ZOMBIE_BLOOD_BITE 3

#ifdef MAPBASE
#define SF_ZOMBIE_NO_TORSO ( 1 << 15 )
#define SF_ZOMBIE_NO_TORSO ( 1 << 15 )
#define SF_ZOMBIE_NO_HEADCRAB_SPAWN ( 1 << 16 )
#endif


Expand Down Expand Up @@ -141,7 +142,14 @@ abstract_class CNPC_BaseZombie : public CAI_BaseZombieBase
}

int MeleeAttack1Conditions ( float flDot, float flDist );
virtual float GetClawAttackRange() const { return ZOMBIE_MELEE_REACH; }
virtual float GetClawAttackRange() const
{
#ifdef MAPBASE
return m_flMeleeReach;
#else
return ZOMBIE_MELEE_REACH;
#endif
}

// No range attacks
int RangeAttack1Conditions ( float flDot, float flDist ) { return( 0 ); }
Expand Down Expand Up @@ -257,6 +265,12 @@ abstract_class CNPC_BaseZombie : public CAI_BaseZombieBase

float m_flNextFlinch;

#ifdef MAPBASE
float m_flMeleeReach;
float m_flMaxDistToSwat;
int m_iMaxObjMassToSwat;
#endif

bool m_bHeadShot; // Used to determine the survival of our crab beyond our death.

//
Expand Down
Loading