mirror of https://github.com/FWGS/hlsdk-xash3d
495 lines
15 KiB
C++
Executable File
495 lines
15 KiB
C++
Executable File
/***
|
|
*
|
|
* Copyright (c) 1999, 2000 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.
|
|
*
|
|
****/
|
|
//=========================================================
|
|
// Wolf
|
|
//=========================================================
|
|
|
|
// 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 "soundent.h"
|
|
#include "game.h"
|
|
|
|
#define WEREWOLF_IMMUNE (DMG_BULLET|DMG_SLASH|DMG_CLUB)
|
|
|
|
//=========================================================
|
|
// Monster's Anim Events Go Here
|
|
//=========================================================
|
|
#define WEREWOLF_AE_ATTACK1 0x01
|
|
#define WEREWOLF_AE_ATTACK2 0x02
|
|
#define WEREWOLF_AE_ATTACK_RAGE1 0x03
|
|
#define WEREWOLF_AE_ATTACK_RAGE2 0x04
|
|
#define WEREWOLF_AE_LEAP 0x05
|
|
#define WEREWOLF_AE_LEAP_ATTACK 0x06
|
|
|
|
#define WEREWOLF_FLINCH_DELAY 6 // at most one flinch every n secs
|
|
|
|
#define WEREWOLF_GREY 0
|
|
#define WEREWOLF_BLACK 1
|
|
#define WEREWOLF_SILVERMANE 2
|
|
#define WEREWOLF_BROWN 3
|
|
#define WEREWOLF_WHITE 4
|
|
#define WEREWOLF_WINTER 5
|
|
#define NUM_WEREWOLF_BODIES 6
|
|
|
|
|
|
#include "werewolf.h"
|
|
|
|
|
|
LINK_ENTITY_TO_CLASS( monster_werewolf, CWerewolf );
|
|
|
|
const char *CWerewolf::pAttackHitSounds[] =
|
|
{
|
|
"zombie/claw_strike1.wav",
|
|
"zombie/claw_strike2.wav",
|
|
"zombie/claw_strike3.wav",
|
|
};
|
|
|
|
const char *CWerewolf::pAttackMissSounds[] =
|
|
{
|
|
"zombie/claw_miss1.wav",
|
|
"zombie/claw_miss2.wav",
|
|
};
|
|
|
|
const char *CWerewolf::pAttackSounds[] =
|
|
{
|
|
"ghoul/gh_attack1.wav",
|
|
// "ghoul/gh_attack2.wav",
|
|
};
|
|
|
|
const char *CWerewolf::pIdleSounds[] =
|
|
{
|
|
"ghoul/gh_idle1.wav",
|
|
"ghoul/gh_idle2.wav",
|
|
"ghoul/gh_idle3.wav",
|
|
// "ghoul/gh_idle4.wav",
|
|
};
|
|
|
|
const char *CWerewolf::pAlertSounds[] =
|
|
{
|
|
"ghoul/gh_alert1.wav",
|
|
// "ghoul/gh_alert20.wav",
|
|
// "ghoul/gh_alert30.wav",
|
|
};
|
|
|
|
const char *CWerewolf::pPainSounds[] =
|
|
{
|
|
"ghoul/gh_pain1.wav",
|
|
// "ghoul/gh_pain2.wav",
|
|
};
|
|
|
|
//=========================================================
|
|
// Classify - indicates this monster's place in the
|
|
// relationship table.
|
|
//=========================================================
|
|
int CWerewolf :: Classify ( void )
|
|
{
|
|
return m_iClass?m_iClass:CLASS_ALIEN_PREDATOR;
|
|
}
|
|
|
|
//=========================================================
|
|
// ISoundMask - returns a bit mask indicating which types
|
|
// of sounds this monster regards. In the base class implementation,
|
|
// monsters care about all sounds, but no scents.
|
|
//=========================================================
|
|
int CWerewolf :: ISoundMask ( void )
|
|
{
|
|
return bits_SOUND_WORLD |
|
|
bits_SOUND_COMBAT |
|
|
bits_SOUND_CARCASS |
|
|
bits_SOUND_MEAT |
|
|
bits_SOUND_GARBAGE |
|
|
bits_SOUND_PLAYER;
|
|
}
|
|
|
|
//=========================================================
|
|
// IRelationship - overridden.
|
|
//=========================================================
|
|
int CWerewolf::IRelationship ( CBaseEntity *pTarget )
|
|
{
|
|
if ( FClassnameIs( pTarget->pev, "monster_wolf" ) )
|
|
{
|
|
return R_AL;
|
|
}
|
|
|
|
return CBaseMonster :: IRelationship( pTarget );
|
|
}
|
|
|
|
//=========================================================
|
|
// SetYawSpeed - allows each sequence to have a different
|
|
// turn rate associated with it.
|
|
//=========================================================
|
|
void CWerewolf :: SetYawSpeed ( void )
|
|
{
|
|
int ys;
|
|
|
|
ys = 120;
|
|
|
|
pev->yaw_speed = ys;
|
|
}
|
|
|
|
//=========================================================
|
|
// CheckRangeAttack1
|
|
//=========================================================
|
|
BOOL CWerewolf :: CheckRangeAttack1 ( float flDot, float flDist )
|
|
{
|
|
// Decent fix to keep folks from kicking/punching hornets and snarks is to check the onground flag(sjb)
|
|
//int iGround = FBitSet ( m_hEnemy->pev->flags, FL_ONGROUND );
|
|
|
|
// Cthulhu: but this stops the monster from hitting flying monsters that are
|
|
// melee attacking it (e.g. nightgaunt)
|
|
// Solution: explicitly check for monster types that we cannot hit
|
|
|
|
BOOL bHit = TRUE; // we can hit by default
|
|
if (m_hEnemy)
|
|
{
|
|
if (FClassnameIs( m_hEnemy->pev, "hornet")) bHit = FALSE;
|
|
if (FClassnameIs( m_hEnemy->pev, "monster_snark")) bHit = FALSE;
|
|
}
|
|
|
|
if ( flDist >= 96 && flDist <= 312 && flDot >= 0.7 && m_hEnemy != NULL && bHit )
|
|
{
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
int CWerewolf :: TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
|
|
{
|
|
if ( (bitsDamageType & WEREWOLF_IMMUNE) != 0 ) return 0;
|
|
|
|
// HACK HACK -- until we fix this.
|
|
if ( IsAlive() )
|
|
PainSound();
|
|
return CBaseMonster::TakeDamage( pevInflictor, pevAttacker, flDamage, bitsDamageType );
|
|
}
|
|
|
|
void CWerewolf :: 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 CWerewolf :: 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 CWerewolf :: 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) ], 0.2, ATTN_NORM, 0, pitch );
|
|
}
|
|
|
|
void CWerewolf :: 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) ], 0.5, ATTN_NORM, 0, pitch );
|
|
}
|
|
|
|
|
|
//=========================================================
|
|
// HandleAnimEvent - catches the monster-specific messages
|
|
// that occur when tagged animation frames are played.
|
|
//=========================================================
|
|
void CWerewolf :: HandleAnimEvent( MonsterEvent_t *pEvent )
|
|
{
|
|
switch( pEvent->event )
|
|
{
|
|
case WEREWOLF_AE_ATTACK1:
|
|
{
|
|
// 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.z = -20;
|
|
pHurt->pev->punchangle.x = 20;
|
|
pHurt->pev->velocity = pHurt->pev->velocity + gpGlobals->v_forward * 100;
|
|
pHurt->pev->velocity = pHurt->pev->velocity + gpGlobals->v_up * 200;
|
|
}
|
|
// 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 WEREWOLF_AE_ATTACK2:
|
|
{
|
|
// do stuff for this event.
|
|
CBaseEntity *pHurt = CheckTraceHullAttack( 70, gSkillData.bullsquidDmgBite, DMG_SLASH );
|
|
if ( pHurt )
|
|
{
|
|
if ( pHurt->pev->flags & (FL_MONSTER|FL_CLIENT) )
|
|
{
|
|
pHurt->pev->punchangle.z = -20;
|
|
pHurt->pev->punchangle.x = 20;
|
|
pHurt->pev->velocity = pHurt->pev->velocity + gpGlobals->v_forward * 50;
|
|
pHurt->pev->velocity = pHurt->pev->velocity + gpGlobals->v_up * 10;
|
|
}
|
|
// 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 WEREWOLF_AE_ATTACK_RAGE1:
|
|
{
|
|
// do stuff for this event.
|
|
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 WEREWOLF_AE_ATTACK_RAGE2:
|
|
{
|
|
// do stuff for this event.
|
|
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 WEREWOLF_AE_LEAP:
|
|
{
|
|
ClearBits( pev->flags, FL_ONGROUND );
|
|
|
|
UTIL_SetOrigin (this, pev->origin + Vector ( 0 , 0 , 1) );// take him off ground so engine doesn't instantly reset onground
|
|
UTIL_MakeVectors ( pev->angles );
|
|
|
|
Vector vecJumpDir;
|
|
if (m_hEnemy != NULL)
|
|
{
|
|
float gravity = g_psv_gravity->value;
|
|
if (gravity <= 1)
|
|
gravity = 1;
|
|
|
|
// How fast does the headcrab need to travel to reach that height given gravity?
|
|
float height = (m_hEnemy->pev->origin.z + m_hEnemy->pev->view_ofs.z - pev->origin.z);
|
|
if (height < 16)
|
|
height = 16;
|
|
float speed = sqrt( 2 * gravity * height );
|
|
float time = speed / gravity;
|
|
|
|
// Scale the sideways velocity to get there at the right time
|
|
vecJumpDir = (m_hEnemy->pev->origin + m_hEnemy->pev->view_ofs - pev->origin);
|
|
vecJumpDir = vecJumpDir * ( 1.0 / time );
|
|
|
|
// Speed to offset gravity at the desired height
|
|
vecJumpDir.z = speed;
|
|
|
|
// Don't jump too far/fast
|
|
float distance = vecJumpDir.Length();
|
|
|
|
if (distance > 650)
|
|
{
|
|
vecJumpDir = vecJumpDir * ( 650.0 / distance );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// jump hop, don't care where
|
|
vecJumpDir = Vector( gpGlobals->v_forward.x, gpGlobals->v_forward.y, gpGlobals->v_up.z ) * 350;
|
|
}
|
|
|
|
pev->velocity = vecJumpDir;
|
|
}
|
|
break;
|
|
|
|
case WEREWOLF_AE_LEAP_ATTACK:
|
|
{
|
|
// do stuff for this event.
|
|
CBaseEntity *pHurt = CheckTraceHullAttack( 70, gSkillData.bullsquidDmgBite, DMG_SLASH );
|
|
if ( pHurt )
|
|
{
|
|
if ( pHurt->pev->flags & (FL_MONSTER|FL_CLIENT) )
|
|
{
|
|
pHurt->pev->punchangle.z = -20;
|
|
pHurt->pev->punchangle.x = 20;
|
|
pHurt->pev->velocity = pHurt->pev->velocity + gpGlobals->v_forward * 50;
|
|
pHurt->pev->velocity = pHurt->pev->velocity + gpGlobals->v_up * 10;
|
|
}
|
|
// 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;
|
|
|
|
default:
|
|
CBaseMonster::HandleAnimEvent( pEvent );
|
|
break;
|
|
}
|
|
}
|
|
|
|
//=========================================================
|
|
// Spawn
|
|
//=========================================================
|
|
void CWerewolf :: Spawn()
|
|
{
|
|
Precache( );
|
|
|
|
if (pev->model)
|
|
SET_MODEL(ENT(pev), STRING(pev->model)); //LRC
|
|
else
|
|
SET_MODEL(ENT(pev), "models/monsters/werewolf.mdl");
|
|
UTIL_SetSize( pev, Vector( -16, -16, 0 ), Vector( 16, 16, 72 ) );
|
|
|
|
pev->solid = SOLID_SLIDEBOX;
|
|
pev->movetype = MOVETYPE_STEP;
|
|
m_bloodColor = BLOOD_COLOR_RED;
|
|
if (pev->health == 0)
|
|
pev->health = gSkillData.agruntHealth; // use this one
|
|
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 | bits_CAP_HEAR | bits_CAP_JUMP;
|
|
|
|
if ( pev->body == -1 )
|
|
{// -1 chooses a random body
|
|
pev->body = RANDOM_LONG(0, NUM_WEREWOLF_BODIES-1);// pick a body, any body
|
|
}
|
|
|
|
MonsterInit();
|
|
}
|
|
|
|
//=========================================================
|
|
// Precache - precaches all resources this monster needs
|
|
//=========================================================
|
|
void CWerewolf :: Precache()
|
|
{
|
|
int i;
|
|
|
|
if (pev->model)
|
|
PRECACHE_MODEL((char*)STRING(pev->model)); //LRC
|
|
else
|
|
PRECACHE_MODEL("models/monsters/werewolf.mdl");
|
|
|
|
for ( i = 0; i < ARRAYSIZE( pAttackHitSounds ); i++ )
|
|
PRECACHE_SOUND((char *)pAttackHitSounds[i]);
|
|
|
|
for ( i = 0; i < ARRAYSIZE( pAttackMissSounds ); i++ )
|
|
PRECACHE_SOUND((char *)pAttackMissSounds[i]);
|
|
|
|
for ( i = 0; i < ARRAYSIZE( pAttackSounds ); i++ )
|
|
PRECACHE_SOUND((char *)pAttackSounds[i]);
|
|
|
|
for ( i = 0; i < ARRAYSIZE( pIdleSounds ); i++ )
|
|
PRECACHE_SOUND((char *)pIdleSounds[i]);
|
|
|
|
for ( i = 0; i < ARRAYSIZE( pAlertSounds ); i++ )
|
|
PRECACHE_SOUND((char *)pAlertSounds[i]);
|
|
|
|
for ( i = 0; i < ARRAYSIZE( pPainSounds ); i++ )
|
|
PRECACHE_SOUND((char *)pPainSounds[i]);
|
|
}
|
|
|
|
//=========================================================
|
|
// AI Schedules Specific to this monster
|
|
//=========================================================
|
|
|
|
int CWerewolf::IgnoreConditions ( void )
|
|
{
|
|
int iIgnore = CBaseMonster::IgnoreConditions();
|
|
|
|
if ((m_Activity == ACT_MELEE_ATTACK1) || (m_Activity == ACT_MELEE_ATTACK2))
|
|
{
|
|
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 + WEREWOLF_FLINCH_DELAY;
|
|
}
|
|
|
|
return iIgnore;
|
|
|
|
}
|
|
|
|
void CWerewolf::TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType )
|
|
{
|
|
//ALERT( at_aiconsole, "CWerewolf::TraceAttack\n");
|
|
|
|
if ( !IsAlive() )
|
|
{
|
|
CBaseMonster::TraceAttack( pevAttacker, flDamage, vecDir, ptr, bitsDamageType );
|
|
return;
|
|
}
|
|
|
|
if ((bitsDamageType & WEREWOLF_IMMUNE) != 0) return;
|
|
|
|
CBaseMonster::TraceAttack( pevAttacker, flDamage, vecDir, ptr, bitsDamageType );
|
|
|
|
}
|
|
|