Skip to content

Commit

Permalink
More accurate skeleton implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
nekonomicon committed Jan 3, 2024
1 parent a11a37f commit ca80620
Showing 1 changed file with 49 additions and 46 deletions.
95 changes: 49 additions & 46 deletions dlls/clcampaign/skeleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,18 @@
//=========================================================
// 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 SKELETON_AE_ATTACK_RIGHT 0x01
#define SKELETON_AE_ATTACK_LEFT 0x02
#define SKELETON_AE_ATTACK_BOTH 0x03

#define ZOMBIE_FLINCH_DELAY 2 // at most one flinch every n secs
#define SKELETON_FLINCH_DELAY 2 // at most one flinch every n secs

class CSkeleton : public CBaseMonster
{
public:
void Spawn( void );
void Precache( void );
void SetYawSpeed( void );
void DeathSound( void );
int Classify( void );
void HandleAnimEvent( MonsterEvent_t *pEvent );
int IgnoreConditions( void );
Expand All @@ -45,8 +44,9 @@ class CSkeleton : public CBaseMonster

void PainSound( void );


static const char *pPainSounds[];
static const char *pAttackHitSounds[];
static const char *pAttackMissSounds[];

// No range attacks
BOOL CheckRangeAttack1( float flDot, float flDist ) { return FALSE; }
Expand All @@ -59,9 +59,25 @@ LINK_ENTITY_TO_CLASS( monster_skeleton, CSkeleton )

const char *CSkeleton::pPainSounds[] =
{
"skeleton/s_pain1.wav",
"skeleton/s_pain2.wav",
"sleletons/s_pain3.wav"
"spooky/s_pain1.wav",
"spooky/s_pain2.wav",
"spooky/s_pain3.wav",
"spooky/s_die.wav",
"spooky/s_die2.wav",
"spooky/s_die3.wav",
};

const char *CSkeleton::pAttackHitSounds[] =
{
"zombie/claw_strike1.wav",
"zombie/claw_strike2.wav",
"zombie/claw_strike3.wav",
};

const char *CSkeleton::pAttackMissSounds[] =
{
"zombie/claw_miss1.wav",
"zombie/claw_miss2.wav",
};

//=========================================================
Expand All @@ -70,7 +86,7 @@ const char *CSkeleton::pPainSounds[] =
//=========================================================
int CSkeleton::Classify( void )
{
return CLASS_ALIEN_MONSTER;
return CLASS_ALIEN_MONSTER;
}

//=========================================================
Expand All @@ -95,43 +111,26 @@ int CSkeleton::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker,float
// Take 30% damage from bullets
if( bitsDamageType == DMG_BULLET )
{
Vector vecDir = pev->origin - (pevInflictor->absmin + pevInflictor->absmax) * 0.5;
Vector vecDir = pev->origin - (pevInflictor->absmin + pevInflictor->absmax) * 0.5f;
vecDir = vecDir.Normalize();
float flForce = DamageForce( 0 );
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);
return CBaseMonster::TakeDamage( pevInflictor, pevAttacker,flDamage, bitsDamageType );
}

void CSkeleton::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 );
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, RANDOM_SOUND_ARRAY( pPainSounds ), 1.0, ATTN_NORM, 0, pitch );
}
void CSkeleton::DeathSound( void )
{
switch( RANDOM_LONG( 0, 2 ) )
{
case 0:
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "spooky/s_die.wav", 1, ATTN_NORM );
break;
case 1:
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "spooky/s_die2.wav", 1, ATTN_NORM );
break;
case 2:
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "spooky/s_die3.wav", 1, ATTN_NORM );
break;
}
}




//=========================================================
// HandleAnimEvent - catches the monster-specific messages
Expand All @@ -141,7 +140,7 @@ void CSkeleton::HandleAnimEvent( MonsterEvent_t *pEvent )
{
switch( pEvent->event )
{
case ZOMBIE_AE_ATTACK_RIGHT:
case SKELETON_AE_ATTACK_RIGHT:
{
// do stuff for this event.
//ALERT( at_console, "Slash right!\n" );
Expand All @@ -154,10 +153,13 @@ void CSkeleton::HandleAnimEvent( MonsterEvent_t *pEvent )
pHurt->pev->punchangle.x = 5;
pHurt->pev->velocity = pHurt->pev->velocity - gpGlobals->v_right * 100;
}
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, RANDOM_SOUND_ARRAY( pAttackHitSounds ), 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
}
else
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, RANDOM_SOUND_ARRAY( pAttackMissSounds ), 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
}
break;
case ZOMBIE_AE_ATTACK_LEFT:
case SKELETON_AE_ATTACK_LEFT:
{
// do stuff for this event.
//ALERT( at_console, "Slash left!\n" );
Expand All @@ -170,10 +172,13 @@ void CSkeleton::HandleAnimEvent( MonsterEvent_t *pEvent )
pHurt->pev->punchangle.x = 5;
pHurt->pev->velocity = pHurt->pev->velocity + gpGlobals->v_right * 100;
}
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, RANDOM_SOUND_ARRAY( pAttackHitSounds ), 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
}
else
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, RANDOM_SOUND_ARRAY( pAttackMissSounds ), 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
}
break;
case ZOMBIE_AE_ATTACK_BOTH:
case SKELETON_AE_ATTACK_BOTH:
{
// do stuff for this event.
CBaseEntity *pHurt = CheckTraceHullAttack( 70, gSkillData.zombieDmgBothSlash, DMG_SLASH );
Expand All @@ -184,7 +189,10 @@ void CSkeleton::HandleAnimEvent( MonsterEvent_t *pEvent )
pHurt->pev->punchangle.x = 5;
pHurt->pev->velocity = pHurt->pev->velocity + gpGlobals->v_forward * -100;
}
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, RANDOM_SOUND_ARRAY( pAttackHitSounds ), 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
}
else
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, RANDOM_SOUND_ARRAY( pAttackMissSounds ), 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
}
break;
default:
Expand All @@ -205,10 +213,10 @@ void CSkeleton::Spawn()

pev->solid = SOLID_SLIDEBOX;
pev->movetype = MOVETYPE_STEP;
pev->health = 80;
pev->health = gSkillData.zombieHealth;
pev->view_ofs = VEC_VIEW;// position of the eyes relative to monster's origin.
m_bloodColor = DONT_BLEED;
m_flFieldOfView = 0;// indicates the width of this monster's forward view cone ( as a dotproduct result )
m_flFieldOfView = 0.5f;// indicates the width of this monster's forward view cone ( as a dotproduct result )
m_MonsterState = MONSTERSTATE_NONE;
m_afCapability = bits_CAP_DOORS_GROUP;

Expand All @@ -220,15 +228,10 @@ void CSkeleton::Spawn()
//=========================================================
void CSkeleton::Precache()
{
int i;

PRECACHE_MODEL( "models/skellington.mdl" );
PRECACHE_SOUND( "spooky/s_die.wav" );
PRECACHE_SOUND( "spooky/s_die2.wav" );
PRECACHE_SOUND( "spooky/s_die3.wav" );

for( i = 0; i < ARRAYSIZE( pPainSounds ); i++ )
PRECACHE_SOUND( (char *)pPainSounds[i] );
PRECACHE_SOUND_ARRAY( pPainSounds );
PRECACHE_SOUND_ARRAY( pAttackHitSounds );
PRECACHE_SOUND_ARRAY( pAttackMissSounds );
}

//=========================================================
Expand All @@ -253,7 +256,7 @@ int CSkeleton::IgnoreConditions( void )
if( ( m_Activity == ACT_SMALL_FLINCH ) || ( m_Activity == ACT_BIG_FLINCH ) )
{
if( m_flNextFlinch < gpGlobals->time )
m_flNextFlinch = gpGlobals->time + ZOMBIE_FLINCH_DELAY;
m_flNextFlinch = gpGlobals->time + SKELETON_FLINCH_DELAY;
}

return iIgnore;
Expand Down

0 comments on commit ca80620

Please sign in to comment.