You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
362 lines
10 KiB
362 lines
10 KiB
/*** |
|
* |
|
* Copyright (c) 1996-2002, Valve LLC. All rights reserved. |
|
* |
|
* This product contains software technology licensed from Id |
|
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. |
|
* All Rights Reserved. |
|
* |
|
* This source code contains proprietary and confidential information of |
|
* Valve LLC and its suppliers. Access to this code is restricted to |
|
* persons who have executed a written SDK license with Valve. Any access, |
|
* use or distribution of this code by or to any unlicensed person is illegal. |
|
* |
|
****/ |
|
//========================================================= |
|
// Zombie |
|
//========================================================= |
|
|
|
// UNDONE: Don't flinch every time you get hit |
|
|
|
#include "extdll.h" |
|
#include "util.h" |
|
#include "cbase.h" |
|
#include "monsters.h" |
|
#include "schedule.h" |
|
#include "zombie.h" |
|
|
|
//========================================================= |
|
// Monster's Anim Events Go Here |
|
//========================================================= |
|
#define ZOMBIE_AE_ATTACK_RIGHT 0x01 |
|
#define ZOMBIE_AE_ATTACK_LEFT 0x02 |
|
#define ZOMBIE_AE_ATTACK_BOTH 0x03 |
|
|
|
#define ZOMBIE_FLINCH_DELAY 2 // at most one flinch every n secs |
|
|
|
LINK_ENTITY_TO_CLASS( monster_zombie, CZombie ) |
|
LINK_ENTITY_TO_CLASS( monster_zombie_barney, CZombie ) |
|
|
|
const char *CZombie::pAttackHitSounds[] = |
|
{ |
|
"zombie/claw_strike1.wav", |
|
"zombie/claw_strike2.wav", |
|
"zombie/claw_strike3.wav", |
|
}; |
|
|
|
const char *CZombie::pAttackMissSounds[] = |
|
{ |
|
"zombie/claw_miss1.wav", |
|
"zombie/claw_miss2.wav", |
|
}; |
|
|
|
const char *CZombie::pAttackSounds[] = |
|
{ |
|
"zombie/zo_attack1.wav", |
|
"zombie/zo_attack2.wav", |
|
}; |
|
|
|
const char *CZombie::pIdleSounds[] = |
|
{ |
|
"zombie/zo_idle1.wav", |
|
"zombie/zo_idle2.wav", |
|
"zombie/zo_idle3.wav", |
|
"zombie/zo_idle4.wav", |
|
}; |
|
|
|
const char *CZombie::pAlertSounds[] = |
|
{ |
|
"zombie/zo_alert10.wav", |
|
"zombie/zo_alert20.wav", |
|
"zombie/zo_alert30.wav", |
|
}; |
|
|
|
const char *CZombie::pPainSounds[] = |
|
{ |
|
"zombie/zo_pain1.wav", |
|
"zombie/zo_pain2.wav", |
|
}; |
|
|
|
//========================================================= |
|
// Classify - indicates this monster's place in the |
|
// relationship table. |
|
//========================================================= |
|
int CZombie::Classify( void ) |
|
{ |
|
return CLASS_ALIEN_MONSTER; |
|
} |
|
|
|
//========================================================= |
|
// SetYawSpeed - allows each sequence to have a different |
|
// turn rate associated with it. |
|
//========================================================= |
|
void CZombie::SetYawSpeed( void ) |
|
{ |
|
int ys; |
|
|
|
ys = 120; |
|
#if 0 |
|
switch ( m_Activity ) |
|
{ |
|
} |
|
#endif |
|
pev->yaw_speed = ys; |
|
} |
|
|
|
int CZombie::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType ) |
|
{ |
|
// Take 30% damage from bullets |
|
if( bitsDamageType == DMG_BULLET ) |
|
{ |
|
Vector vecDir = pev->origin - ( pevInflictor->absmin + pevInflictor->absmax ) * 0.5f; |
|
vecDir = vecDir.Normalize(); |
|
float flForce = DamageForce( flDamage ); |
|
pev->velocity = pev->velocity + vecDir * flForce; |
|
flDamage *= 0.3f; |
|
} |
|
|
|
// HACK HACK -- until we fix this. |
|
if( IsAlive() ) |
|
PainSound(); |
|
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 ); |
|
|
|
if( RANDOM_LONG( 0, 5 ) < 2 ) |
|
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, pPainSounds[RANDOM_LONG( 0, ARRAYSIZE( pPainSounds ) - 1 )], 1.0, ATTN_NORM, 0, pitch ); |
|
} |
|
|
|
void CZombie::AlertSound( void ) |
|
{ |
|
int pitch = 95 + RANDOM_LONG( 0, 9 ); |
|
|
|
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, pAlertSounds[ RANDOM_LONG( 0, ARRAYSIZE( pAlertSounds ) - 1 )], 1.0, ATTN_NORM, 0, pitch ); |
|
} |
|
|
|
void CZombie::IdleSound( void ) |
|
{ |
|
int pitch = 95 + RANDOM_LONG( 0, 9 ); |
|
|
|
// Play a random idle sound |
|
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, pIdleSounds[RANDOM_LONG( 0, ARRAYSIZE( pIdleSounds ) -1 )], 1.0, ATTN_NORM, 0, pitch ); |
|
} |
|
|
|
void CZombie::AttackSound( void ) |
|
{ |
|
int pitch = 95 + RANDOM_LONG( 0, 9 ); |
|
|
|
// Play a random attack sound |
|
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, pAttackSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackSounds ) - 1 )], 1.0, ATTN_NORM, 0, pitch ); |
|
} |
|
|
|
//========================================================= |
|
// HandleAnimEvent - catches the monster-specific messages |
|
// that occur when tagged animation frames are played. |
|
//========================================================= |
|
void CZombie::HandleAnimEvent( MonsterEvent_t *pEvent ) |
|
{ |
|
switch( pEvent->event ) |
|
{ |
|
case ZOMBIE_AE_ATTACK_RIGHT: |
|
{ |
|
// do stuff for this event. |
|
//ALERT( at_console, "Slash right!\n" ); |
|
CBaseEntity *pHurt = CheckTraceHullAttack( 70, gSkillData.zombieDmgOneSlash, DMG_SLASH ); |
|
if( pHurt ) |
|
{ |
|
if( pHurt->pev->flags & ( FL_MONSTER | FL_CLIENT ) ) |
|
{ |
|
pHurt->pev->punchangle.z = -18; |
|
pHurt->pev->punchangle.x = 5; |
|
pHurt->pev->velocity = pHurt->pev->velocity - gpGlobals->v_right * 100; |
|
} |
|
// Play a random attack hit sound |
|
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackHitSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackHitSounds ) - 1 )], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5 , 5 ) ); |
|
} |
|
else // Play a random attack miss sound |
|
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackMissSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackMissSounds ) - 1 )], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) ); |
|
|
|
if( RANDOM_LONG( 0, 1 ) ) |
|
AttackSound(); |
|
} |
|
break; |
|
case ZOMBIE_AE_ATTACK_LEFT: |
|
{ |
|
// do stuff for this event. |
|
//ALERT( at_console, "Slash left!\n" ); |
|
CBaseEntity *pHurt = CheckTraceHullAttack( 70, gSkillData.zombieDmgOneSlash, DMG_SLASH ); |
|
if( pHurt ) |
|
{ |
|
if( pHurt->pev->flags & ( FL_MONSTER | FL_CLIENT ) ) |
|
{ |
|
pHurt->pev->punchangle.z = 18; |
|
pHurt->pev->punchangle.x = 5; |
|
pHurt->pev->velocity = pHurt->pev->velocity + gpGlobals->v_right * 100; |
|
} |
|
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackHitSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackHitSounds ) - 1 )], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) ); |
|
} |
|
else |
|
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackMissSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackMissSounds ) - 1 )], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) ); |
|
|
|
if( RANDOM_LONG( 0, 1 ) ) |
|
AttackSound(); |
|
} |
|
break; |
|
case ZOMBIE_AE_ATTACK_BOTH: |
|
{ |
|
// do stuff for this event. |
|
CBaseEntity *pHurt = CheckTraceHullAttack( 70, gSkillData.zombieDmgBothSlash, DMG_SLASH ); |
|
if( pHurt ) |
|
{ |
|
if( pHurt->pev->flags & ( FL_MONSTER | FL_CLIENT ) ) |
|
{ |
|
pHurt->pev->punchangle.x = 5; |
|
pHurt->pev->velocity = pHurt->pev->velocity + gpGlobals->v_forward * -100; |
|
} |
|
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackHitSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackHitSounds ) - 1 )], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) ); |
|
} |
|
else |
|
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackMissSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackMissSounds ) - 1 )], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) ); |
|
|
|
if( RANDOM_LONG( 0, 1 ) ) |
|
AttackSound(); |
|
} |
|
break; |
|
default: |
|
CBaseMonster::HandleAnimEvent( pEvent ); |
|
break; |
|
} |
|
} |
|
|
|
//========================================================= |
|
// Spawn |
|
//========================================================= |
|
void CZombie::Spawn() |
|
{ |
|
Precache(); |
|
|
|
if( FClassnameIs( pev, "monster_zombie_barney" ) ) |
|
SET_MODEL( ENT( pev ), "models/zombie_barney.mdl" ); |
|
else |
|
SET_MODEL( ENT( pev ), "models/zombie.mdl" ); |
|
|
|
UTIL_SetSize( pev, VEC_HUMAN_HULL_MIN, VEC_HUMAN_HULL_MAX ); |
|
|
|
pev->solid = SOLID_SLIDEBOX; |
|
pev->movetype = MOVETYPE_STEP; |
|
m_bloodColor = BLOOD_COLOR_GREEN; |
|
pev->health = gSkillData.zombieHealth; |
|
pev->view_ofs = VEC_VIEW;// position of the eyes relative to monster's origin. |
|
m_flFieldOfView = 0.5;// indicates the width of this monster's forward view cone ( as a dotproduct result ) |
|
m_MonsterState = MONSTERSTATE_NONE; |
|
m_afCapability = bits_CAP_DOORS_GROUP; |
|
|
|
MonsterInit(); |
|
} |
|
|
|
//========================================================= |
|
// Precache - precaches all resources this monster needs |
|
//========================================================= |
|
void CZombie::Precache() |
|
{ |
|
size_t i; |
|
|
|
if( FClassnameIs( pev, "monster_zombie_barney" ) ) |
|
PRECACHE_MODEL( "models/zombie_barney.mdl" ); |
|
else |
|
PRECACHE_MODEL( "models/zombie.mdl" ); |
|
|
|
for( i = 0; i < ARRAYSIZE( pAttackHitSounds ); i++ ) |
|
PRECACHE_SOUND( pAttackHitSounds[i] ); |
|
|
|
for( i = 0; i < ARRAYSIZE( pAttackMissSounds ); i++ ) |
|
PRECACHE_SOUND( pAttackMissSounds[i] ); |
|
|
|
for( i = 0; i < ARRAYSIZE( pAttackSounds ); i++ ) |
|
PRECACHE_SOUND( pAttackSounds[i] ); |
|
|
|
for( i = 0; i < ARRAYSIZE( pIdleSounds ); i++ ) |
|
PRECACHE_SOUND( pIdleSounds[i] ); |
|
|
|
for( i = 0; i < ARRAYSIZE( pAlertSounds ); i++ ) |
|
PRECACHE_SOUND( pAlertSounds[i] ); |
|
|
|
for( i = 0; i < ARRAYSIZE( pPainSounds ); i++ ) |
|
PRECACHE_SOUND( pPainSounds[i] ); |
|
|
|
UTIL_PrecacheOther( "monster_headcrab" ); |
|
} |
|
|
|
//========================================================= |
|
// AI Schedules Specific to this monster |
|
//========================================================= |
|
|
|
int CZombie::IgnoreConditions( void ) |
|
{ |
|
int iIgnore = CBaseMonster::IgnoreConditions(); |
|
|
|
if( ( m_Activity == ACT_MELEE_ATTACK1 ) || ( m_Activity == ACT_MELEE_ATTACK1 ) ) |
|
{ |
|
#if 0 |
|
if( pev->health < 20 ) |
|
iIgnore |= ( bits_COND_LIGHT_DAMAGE| bits_COND_HEAVY_DAMAGE ); |
|
else |
|
#endif |
|
if( m_flNextFlinch >= gpGlobals->time ) |
|
iIgnore |= ( bits_COND_LIGHT_DAMAGE | bits_COND_HEAVY_DAMAGE ); |
|
} |
|
|
|
if( ( m_Activity == ACT_SMALL_FLINCH ) || ( m_Activity == ACT_BIG_FLINCH ) ) |
|
{ |
|
if( m_flNextFlinch < gpGlobals->time ) |
|
m_flNextFlinch = gpGlobals->time + ZOMBIE_FLINCH_DELAY; |
|
} |
|
|
|
return iIgnore; |
|
}
|
|
|