hlsdk-xash3d/dlls/zombie.cpp

339 lines
9.8 KiB
C++
Raw Normal View History

2016-06-04 15:24:23 +02:00
/***
*
* 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"
//=========================================================
// Monster's Anim Events Go Here
//=========================================================
#define ZOMBIE_AE_ATTACK_RIGHT 0x01
#define ZOMBIE_AE_ATTACK_LEFT 0x02
#define ZOMBIE_AE_ATTACK_BOTH 0x03
2016-07-31 15:48:50 +02:00
#define ZOMBIE_FLINCH_DELAY 2 // at most one flinch every n secs
2016-06-04 15:24:23 +02:00
class CZombie : public CBaseMonster
{
public:
void Spawn( void );
void Precache( void );
void SetYawSpeed( void );
2016-07-31 15:48:50 +02:00
int Classify( void );
2016-06-04 15:24:23 +02:00
void HandleAnimEvent( MonsterEvent_t *pEvent );
2016-07-31 15:48:50 +02:00
int IgnoreConditions( void );
2016-06-04 15:24:23 +02:00
float m_flNextFlinch;
void PainSound( void );
void AlertSound( void );
void IdleSound( void );
void AttackSound( void );
static const char *pAttackSounds[];
static const char *pIdleSounds[];
static const char *pAlertSounds[];
static const char *pPainSounds[];
static const char *pAttackHitSounds[];
static const char *pAttackMissSounds[];
// No range attacks
2016-07-31 15:48:50 +02:00
BOOL CheckRangeAttack1( float flDot, float flDist ) { return FALSE; }
BOOL CheckRangeAttack2( float flDot, float flDist ) { return FALSE; }
2016-06-04 15:24:23 +02:00
int TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType );
};
LINK_ENTITY_TO_CLASS( monster_zombie, CZombie )
2016-06-04 15:24:23 +02:00
const char *CZombie::pAttackHitSounds[] =
2016-06-04 15:24:23 +02:00
{
"zombie/claw_strike1.wav",
"zombie/claw_strike2.wav",
"zombie/claw_strike3.wav",
};
const char *CZombie::pAttackMissSounds[] =
2016-06-04 15:24:23 +02:00
{
"zombie/claw_miss1.wav",
"zombie/claw_miss2.wav",
};
const char *CZombie::pAttackSounds[] =
2016-06-04 15:24:23 +02:00
{
"zombie/zo_attack1.wav",
"zombie/zo_attack2.wav",
};
const char *CZombie::pIdleSounds[] =
2016-06-04 15:24:23 +02:00
{
"zombie/zo_idle1.wav",
"zombie/zo_idle2.wav",
"zombie/zo_idle3.wav",
"zombie/zo_idle4.wav",
};
const char *CZombie::pAlertSounds[] =
2016-06-04 15:24:23 +02:00
{
"zombie/zo_alert10.wav",
"zombie/zo_alert20.wav",
"zombie/zo_alert30.wav",
};
const char *CZombie::pPainSounds[] =
2016-06-04 15:24:23 +02:00
{
"zombie/zo_pain1.wav",
"zombie/zo_pain2.wav",
};
//=========================================================
// Classify - indicates this monster's place in the
// relationship table.
//=========================================================
2016-07-31 15:48:50 +02:00
int CZombie::Classify( void )
2016-06-04 15:24:23 +02:00
{
return CLASS_ALIEN_MONSTER;
}
//=========================================================
// SetYawSpeed - allows each sequence to have a different
// turn rate associated with it.
//=========================================================
2016-07-31 15:48:50 +02:00
void CZombie::SetYawSpeed( void )
2016-06-04 15:24:23 +02:00
{
int ys;
ys = 120;
#if 0
switch ( m_Activity )
{
}
#endif
pev->yaw_speed = ys;
}
2016-07-31 15:48:50 +02:00
int CZombie::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
2016-06-04 15:24:23 +02:00
{
// Take 30% damage from bullets
2016-07-31 15:48:50 +02:00
if( bitsDamageType == DMG_BULLET )
2016-06-04 15:24:23 +02:00
{
Vector vecDir = pev->origin - (pevInflictor->absmin + pevInflictor->absmax) * 0.5;
vecDir = vecDir.Normalize();
float flForce = DamageForce( flDamage );
pev->velocity = pev->velocity + vecDir * flForce;
flDamage *= 0.3;
}
// HACK HACK -- until we fix this.
2016-07-31 15:48:50 +02:00
if( IsAlive() )
2016-06-04 15:24:23 +02:00
PainSound();
return CBaseMonster::TakeDamage( pevInflictor, pevAttacker, flDamage, bitsDamageType );
}
2016-07-31 15:48:50 +02:00
void CZombie::PainSound( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
int pitch = 95 + RANDOM_LONG( 0, 9 );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
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 );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
void CZombie::AlertSound( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
int pitch = 95 + RANDOM_LONG( 0, 9 );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, pAlertSounds[ RANDOM_LONG( 0, ARRAYSIZE( pAlertSounds ) - 1 )], 1.0, ATTN_NORM, 0, pitch );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
void CZombie::IdleSound( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
int pitch = 95 + RANDOM_LONG( 0, 9 );
2016-06-04 15:24:23 +02:00
// 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 );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
void CZombie::AttackSound( void )
2016-06-04 15:24:23 +02:00
{
int pitch = 95 + RANDOM_LONG( 0, 9 );
2016-06-04 15:24:23 +02:00
// 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 );
2016-06-04 15:24:23 +02:00
}
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//=========================================================
2016-07-31 15:48:50 +02:00
void CZombie::HandleAnimEvent( MonsterEvent_t *pEvent )
2016-06-04 15:24:23 +02:00
{
switch( pEvent->event )
{
case ZOMBIE_AE_ATTACK_RIGHT:
{
// do stuff for this event.
//ALERT( at_console, "Slash right!\n" );
2016-06-04 15:24:23 +02:00
CBaseEntity *pHurt = CheckTraceHullAttack( 70, gSkillData.zombieDmgOneSlash, DMG_SLASH );
2016-07-31 15:48:50 +02:00
if( pHurt )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pHurt->pev->flags & ( FL_MONSTER | FL_CLIENT ) )
2016-06-04 15:24:23 +02:00
{
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
2016-07-31 15:48:50 +02:00
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackHitSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackHitSounds ) - 1 )], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5 , 5 ) );
2016-06-04 15:24:23 +02:00
}
else // Play a random attack miss sound
2016-07-31 15:48:50 +02:00
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackMissSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackMissSounds ) - 1 )], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( RANDOM_LONG( 0, 1 ) )
2016-06-04 15:24:23 +02:00
AttackSound();
}
break;
case ZOMBIE_AE_ATTACK_LEFT:
{
// do stuff for this event.
//ALERT( at_console, "Slash left!\n" );
2016-06-04 15:24:23 +02:00
CBaseEntity *pHurt = CheckTraceHullAttack( 70, gSkillData.zombieDmgOneSlash, DMG_SLASH );
2016-07-31 15:48:50 +02:00
if( pHurt )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pHurt->pev->flags & ( FL_MONSTER | FL_CLIENT ) )
2016-06-04 15:24:23 +02:00
{
pHurt->pev->punchangle.z = 18;
pHurt->pev->punchangle.x = 5;
pHurt->pev->velocity = pHurt->pev->velocity + gpGlobals->v_right * 100;
}
2016-07-31 15:48:50 +02:00
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackHitSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackHitSounds ) - 1 )], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
2016-06-04 15:24:23 +02:00
}
else
2016-07-31 15:48:50 +02:00
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackMissSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackMissSounds ) - 1 )], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( RANDOM_LONG( 0, 1 ) )
2016-06-04 15:24:23 +02:00
AttackSound();
}
break;
case ZOMBIE_AE_ATTACK_BOTH:
{
// do stuff for this event.
CBaseEntity *pHurt = CheckTraceHullAttack( 70, gSkillData.zombieDmgBothSlash, DMG_SLASH );
2016-07-31 15:48:50 +02:00
if( pHurt )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pHurt->pev->flags & ( FL_MONSTER | FL_CLIENT ) )
2016-06-04 15:24:23 +02:00
{
pHurt->pev->punchangle.x = 5;
pHurt->pev->velocity = pHurt->pev->velocity + gpGlobals->v_forward * -100;
}
2016-07-31 15:48:50 +02:00
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackHitSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackHitSounds ) - 1 )], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
2016-06-04 15:24:23 +02:00
}
else
2016-07-31 15:48:50 +02:00
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackMissSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackMissSounds ) - 1 )], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( RANDOM_LONG( 0, 1 ) )
2016-06-04 15:24:23 +02:00
AttackSound();
}
break;
default:
CBaseMonster::HandleAnimEvent( pEvent );
break;
}
}
//=========================================================
// Spawn
//=========================================================
2016-07-31 15:48:50 +02:00
void CZombie::Spawn()
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
Precache();
2016-06-04 15:24:23 +02:00
2017-07-23 23:24:55 +02:00
SET_MODEL( ENT( pev ), "models/zombie.mdl" );
2016-06-04 15:24:23 +02:00
UTIL_SetSize( pev, VEC_HUMAN_HULL_MIN, VEC_HUMAN_HULL_MAX );
2016-07-31 15:48:50 +02:00
pev->solid = SOLID_SLIDEBOX;
2016-06-04 15:24:23 +02:00
pev->movetype = MOVETYPE_STEP;
m_bloodColor = BLOOD_COLOR_GREEN;
2016-07-31 15:48:50 +02:00
pev->health = gSkillData.zombieHealth;
2016-06-04 15:24:23 +02:00
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
//=========================================================
2016-07-31 15:48:50 +02:00
void CZombie::Precache()
2016-06-04 15:24:23 +02:00
{
2017-06-29 15:56:03 +02:00
size_t i;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
PRECACHE_MODEL( "models/zombie.mdl" );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
for( i = 0; i < ARRAYSIZE( pAttackHitSounds ); i++ )
2017-07-23 23:24:55 +02:00
PRECACHE_SOUND( pAttackHitSounds[i] );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
for( i = 0; i < ARRAYSIZE( pAttackMissSounds ); i++ )
2017-07-23 23:24:55 +02:00
PRECACHE_SOUND( pAttackMissSounds[i] );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
for( i = 0; i < ARRAYSIZE( pAttackSounds ); i++ )
2017-07-23 23:24:55 +02:00
PRECACHE_SOUND( pAttackSounds[i] );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
for( i = 0; i < ARRAYSIZE( pIdleSounds ); i++ )
2017-07-23 23:24:55 +02:00
PRECACHE_SOUND( pIdleSounds[i] );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
for( i = 0; i < ARRAYSIZE( pAlertSounds ); i++ )
2017-07-23 23:24:55 +02:00
PRECACHE_SOUND( pAlertSounds[i] );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
for( i = 0; i < ARRAYSIZE( pPainSounds ); i++ )
2017-07-23 23:24:55 +02:00
PRECACHE_SOUND( pPainSounds[i] );
}
2016-06-04 15:24:23 +02:00
//=========================================================
// AI Schedules Specific to this monster
//=========================================================
2016-07-31 15:48:50 +02:00
int CZombie::IgnoreConditions( void )
2016-06-04 15:24:23 +02:00
{
int iIgnore = CBaseMonster::IgnoreConditions();
2016-07-31 15:48:50 +02:00
if( ( m_Activity == ACT_MELEE_ATTACK1 ) || ( m_Activity == ACT_MELEE_ATTACK1 ) )
2016-06-04 15:24:23 +02:00
{
#if 0
2016-07-31 15:48:50 +02:00
if( pev->health < 20 )
iIgnore |= ( bits_COND_LIGHT_DAMAGE| bits_COND_HEAVY_DAMAGE );
2016-06-04 15:24:23 +02:00
else
2016-07-31 15:48:50 +02:00
#endif
if( m_flNextFlinch >= gpGlobals->time )
iIgnore |= ( bits_COND_LIGHT_DAMAGE | bits_COND_HEAVY_DAMAGE );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
if( ( m_Activity == ACT_SMALL_FLINCH ) || ( m_Activity == ACT_BIG_FLINCH ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_flNextFlinch < gpGlobals->time )
2016-06-04 15:24:23 +02:00
m_flNextFlinch = gpGlobals->time + ZOMBIE_FLINCH_DELAY;
}
return iIgnore;
}