Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
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.

301 lines
8.7 KiB

7 years ago
/***
*
* 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
//=========================================================
#include "zombie.h"
7 years ago
LINK_ENTITY_TO_CLASS( monster_zombie, CZombie )
7 years ago
const char *CZombie::pAttackHitSounds[] =
7 years ago
{
"zombie/claw_strike1.wav",
"zombie/claw_strike2.wav",
"zombie/claw_strike3.wav",
};
const char *CZombie::pAttackMissSounds[] =
7 years ago
{
"zombie/claw_miss1.wav",
"zombie/claw_miss2.wav",
};
const char *CZombie::pAttackSounds[] =
7 years ago
{
"zombie/zo_attack1.wav",
"zombie/zo_attack2.wav",
};
const char *CZombie::pIdleSounds[] =
7 years ago
{
"zombie/zo_idle1.wav",
"zombie/zo_idle2.wav",
"zombie/zo_idle3.wav",
"zombie/zo_idle4.wav",
};
const char *CZombie::pAlertSounds[] =
7 years ago
{
"zombie/zo_alert10.wav",
"zombie/zo_alert20.wav",
"zombie/zo_alert30.wav",
};
const char *CZombie::pPainSounds[] =
7 years ago
{
"zombie/zo_pain1.wav",
"zombie/zo_pain2.wav",
};
//=========================================================
// Classify - indicates this monster's place in the
// relationship table.
//=========================================================
8 years ago
int CZombie::Classify( void )
7 years ago
{
return m_iClass?m_iClass:CLASS_ALIEN_MONSTER;
}
//=========================================================
// SetYawSpeed - allows each sequence to have a different
// turn rate associated with it.
//=========================================================
8 years ago
void CZombie::SetYawSpeed( void )
7 years ago
{
int ys;
ys = 120;
#if 0
switch ( m_Activity )
{
}
#endif
pev->yaw_speed = ys;
}
8 years ago
int CZombie::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
7 years ago
{
// Take 30% damage from bullets
8 years ago
if( bitsDamageType == DMG_BULLET )
7 years ago
{
Vector vecDir = pev->origin - ( pevInflictor->absmin + pevInflictor->absmax ) * 0.5f;
7 years ago
vecDir = vecDir.Normalize();
float flForce = DamageForce( flDamage );
pev->velocity = pev->velocity + vecDir * flForce;
flDamage *= 0.3f;
7 years ago
}
// HACK HACK -- until we fix this.
8 years ago
if( IsAlive() )
7 years ago
PainSound();
return CBaseMonster::TakeDamage( pevInflictor, pevAttacker, flDamage, bitsDamageType );
}
8 years ago
void CZombie::PainSound( void )
7 years ago
{
8 years ago
int pitch = 95 + RANDOM_LONG( 0, 9 );
7 years ago
8 years ago
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 );
7 years ago
}
8 years ago
void CZombie::AlertSound( void )
7 years ago
{
8 years ago
int pitch = 95 + RANDOM_LONG( 0, 9 );
7 years ago
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, pAlertSounds[ RANDOM_LONG( 0, ARRAYSIZE( pAlertSounds ) - 1 )], 1.0, ATTN_NORM, 0, pitch );
7 years ago
}
8 years ago
void CZombie::IdleSound( void )
7 years ago
{
8 years ago
int pitch = 95 + RANDOM_LONG( 0, 9 );
7 years ago
// 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 );
7 years ago
}
8 years ago
void CZombie::AttackSound( void )
7 years ago
{
int pitch = 95 + RANDOM_LONG( 0, 9 );
7 years ago
// 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 );
7 years ago
}
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//=========================================================
8 years ago
void CZombie::HandleAnimEvent( MonsterEvent_t *pEvent )
7 years ago
{
switch( pEvent->event )
{
case ZOMBIE_AE_ATTACK_RIGHT:
{
// do stuff for this event.
//ALERT( at_console, "Slash right!\n" );
7 years ago
CBaseEntity *pHurt = CheckTraceHullAttack( 70, gSkillData.zombieDmgOneSlash, DMG_SLASH );
8 years ago
if( pHurt )
7 years ago
{
8 years ago
if( pHurt->pev->flags & ( FL_MONSTER | FL_CLIENT ) )
7 years ago
{
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
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackHitSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackHitSounds ) - 1 )], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5 , 5 ) );
7 years ago
}
else // Play a random attack miss sound
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackMissSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackMissSounds ) - 1 )], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
7 years ago
8 years ago
if( RANDOM_LONG( 0, 1 ) )
7 years ago
AttackSound();
}
break;
case ZOMBIE_AE_ATTACK_LEFT:
{
// do stuff for this event.
//ALERT( at_console, "Slash left!\n" );
7 years ago
CBaseEntity *pHurt = CheckTraceHullAttack( 70, gSkillData.zombieDmgOneSlash, DMG_SLASH );
8 years ago
if( pHurt )
7 years ago
{
8 years ago
if( pHurt->pev->flags & ( FL_MONSTER | FL_CLIENT ) )
7 years ago
{
pHurt->pev->punchangle.z = 18;
pHurt->pev->punchangle.x = 5;
pHurt->pev->velocity = pHurt->pev->velocity + gpGlobals->v_right * 100;
}
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackHitSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackHitSounds ) - 1 )], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
7 years ago
}
else
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackMissSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackMissSounds ) - 1 )], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
7 years ago
8 years ago
if( RANDOM_LONG( 0, 1 ) )
7 years ago
AttackSound();
}
break;
case ZOMBIE_AE_ATTACK_BOTH:
{
// do stuff for this event.
CBaseEntity *pHurt = CheckTraceHullAttack( 70, gSkillData.zombieDmgBothSlash, DMG_SLASH );
8 years ago
if( pHurt )
7 years ago
{
8 years ago
if( pHurt->pev->flags & ( FL_MONSTER | FL_CLIENT ) )
7 years ago
{
pHurt->pev->punchangle.x = 5;
pHurt->pev->velocity = pHurt->pev->velocity + gpGlobals->v_forward * -100;
}
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackHitSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackHitSounds ) - 1 )], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
7 years ago
}
else
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackMissSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackMissSounds ) - 1 )], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
7 years ago
8 years ago
if( RANDOM_LONG( 0, 1 ) )
7 years ago
AttackSound();
}
break;
default:
CBaseMonster::HandleAnimEvent( pEvent );
break;
}
}
//=========================================================
// Spawn
//=========================================================
8 years ago
void CZombie::Spawn()
7 years ago
{
8 years ago
Precache();
7 years ago
if (pev->model)
SET_MODEL(ENT(pev), STRING(pev->model)); //LRC
else
SET_MODEL( ENT( pev ), "models/zombie.mdl" );
7 years ago
UTIL_SetSize( pev, VEC_HUMAN_HULL_MIN, VEC_HUMAN_HULL_MAX );
8 years ago
pev->solid = SOLID_SLIDEBOX;
7 years ago
pev->movetype = MOVETYPE_STEP;
m_bloodColor = BLOOD_COLOR_RED;
7 years ago
if (pev->health == 0)
pev->health = gSkillData.zombieHealth;
7 years ago
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
//=========================================================
8 years ago
void CZombie::Precache()
7 years ago
{
size_t i;
7 years ago
if (pev->model)
PRECACHE_MODEL(STRING(pev->model)); //LRC
7 years ago
else
PRECACHE_MODEL( "models/zombie.mdl" );
7 years ago
8 years ago
for( i = 0; i < ARRAYSIZE( pAttackHitSounds ); i++ )
PRECACHE_SOUND( pAttackHitSounds[i] );
7 years ago
8 years ago
for( i = 0; i < ARRAYSIZE( pAttackMissSounds ); i++ )
PRECACHE_SOUND( pAttackMissSounds[i] );
7 years ago
8 years ago
for( i = 0; i < ARRAYSIZE( pAttackSounds ); i++ )
PRECACHE_SOUND( pAttackSounds[i] );
7 years ago
8 years ago
for( i = 0; i < ARRAYSIZE( pIdleSounds ); i++ )
PRECACHE_SOUND( pIdleSounds[i] );
7 years ago
8 years ago
for( i = 0; i < ARRAYSIZE( pAlertSounds ); i++ )
PRECACHE_SOUND( pAlertSounds[i] );
7 years ago
8 years ago
for( i = 0; i < ARRAYSIZE( pPainSounds ); i++ )
PRECACHE_SOUND( pPainSounds[i] );
}
7 years ago
//=========================================================
// AI Schedules Specific to this monster
//=========================================================
8 years ago
int CZombie::IgnoreConditions( void )
7 years ago
{
int iIgnore = CBaseMonster::IgnoreConditions();
8 years ago
if( ( m_Activity == ACT_MELEE_ATTACK1 ) || ( m_Activity == ACT_MELEE_ATTACK1 ) )
7 years ago
{
#if 0
8 years ago
if( pev->health < 20 )
iIgnore |= ( bits_COND_LIGHT_DAMAGE| bits_COND_HEAVY_DAMAGE );
7 years ago
else
8 years ago
#endif
if( m_flNextFlinch >= gpGlobals->time )
iIgnore |= ( bits_COND_LIGHT_DAMAGE | bits_COND_HEAVY_DAMAGE );
7 years ago
}
8 years ago
if( ( m_Activity == ACT_SMALL_FLINCH ) || ( m_Activity == ACT_BIG_FLINCH ) )
7 years ago
{
8 years ago
if( m_flNextFlinch < gpGlobals->time )
7 years ago
m_flNextFlinch = gpGlobals->time + ZOMBIE_FLINCH_DELAY;
}
return iIgnore;
}