From 4619e536ae98cd85c4cf8c87e893ad98d9ac6553 Mon Sep 17 00:00:00 2001 From: Night Owl Date: Tue, 26 Dec 2017 15:35:27 +0500 Subject: [PATCH] Add beheaded zombie with jumping headcrab. --- dlls/CAd/gonome.cpp | 6 ++++++ dlls/zombie.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ dlls/zombie.h | 1 + 3 files changed, 52 insertions(+) diff --git a/dlls/CAd/gonome.cpp b/dlls/CAd/gonome.cpp index 79d27e9f..a7412f60 100644 --- a/dlls/CAd/gonome.cpp +++ b/dlls/CAd/gonome.cpp @@ -156,6 +156,7 @@ public: Schedule_t *GetSchedule(); Schedule_t *GetScheduleOfType( int Type ); int TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType); + void Killed( entvars_t *pevAttacker, int iGib ); void SetActivity( Activity NewActivity ); @@ -300,6 +301,11 @@ void CGonome::SetActivity( Activity NewActivity ) } } +void CGonome::Killed( entvars_t *pevAttacker, int iGib ) +{ + CBaseMonster::Killed( pevAttacker, iGib ); +} + //========================================================= // TakeDamage - overridden for gonome so we can keep track // of how much time has passed since it was last injured diff --git a/dlls/zombie.cpp b/dlls/zombie.cpp index 10c26022..c9eb7c59 100644 --- a/dlls/zombie.cpp +++ b/dlls/zombie.cpp @@ -121,6 +121,49 @@ int CZombie::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float return CBaseMonster::TakeDamage( pevInflictor, pevAttacker, flDamage, bitsDamageType ); } +void CZombie::Killed( entvars_t *pevAttacker, int iGib ) +{ + if( !ShouldGibMonster( iGib ) ) + { + Vector vecSpawn = pev->origin; + vecSpawn.z = pev->origin.z + 72; + + pev->body = 1; + + CBaseEntity *pCrab = CBaseEntity::Create( "monster_headcrab", vecSpawn, pev->angles, edict() ); + pCrab->pev->spawnflags |= SF_MONSTER_FALL_TO_GROUND; + + Vector vecJumpDir; + UTIL_MakeVectors( pev->angles ); + + if( m_hEnemy != 0 ) + { + float gravity = CVAR_GET_FLOAT( "sv_gravity" ); + + float height = ( m_hEnemy->pev->origin.z + m_hEnemy->pev->view_ofs.z - pCrab->pev->origin.z ); + if( height < 4 ) + height = 4; + float speed = sqrt( 1.5 * gravity * height ); + float time = speed / gravity; + + vecJumpDir = ( m_hEnemy->pev->origin + m_hEnemy->pev->view_ofs - pCrab->pev->origin ); + vecJumpDir = vecJumpDir * ( 1.0 / time ); + + vecJumpDir.z = speed; + + float distance = vecJumpDir.Length(); + + if( distance > 100 ) + vecJumpDir = vecJumpDir * ( 100.0 / distance ); + } + else + vecJumpDir = Vector( gpGlobals->v_forward.x, gpGlobals->v_forward.y, gpGlobals->v_up.z ) * 20; + + pCrab->pev->velocity = vecJumpDir; + } + CBaseMonster::Killed( pevAttacker, iGib ); +} + void CZombie::PainSound( void ) { int pitch = 95 + RANDOM_LONG( 0, 9 ); @@ -286,6 +329,8 @@ void CZombie::Precache() for( i = 0; i < ARRAYSIZE( pPainSounds ); i++ ) PRECACHE_SOUND( pPainSounds[i] ); + + UTIL_PrecacheOther( "monster_headcrab" ); } //========================================================= diff --git a/dlls/zombie.h b/dlls/zombie.h index 7c47d396..893a8feb 100644 --- a/dlls/zombie.h +++ b/dlls/zombie.h @@ -25,6 +25,7 @@ public: int Classify( void ); virtual void HandleAnimEvent( MonsterEvent_t *pEvent ); int IgnoreConditions( void ); + virtual void Killed( entvars_t *pevAttacker, int iGib ); float m_flNextFlinch;