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.
 
 
 
 
 
 

345 lines
9.2 KiB

/***
*
* Copyright (c) 1996-2001, 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.
*
****/
// 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 DIABLO_AE_ATTACK_RIGHT 0x01
#define DIABLO_AE_ATTACK_LEFT 0x02
#define DIABLO_AE_ATTACK_BOTH 0x03
#define DIABLO_FLINCH_DELAY 2 // at most one flinch every n secs
class CDiablo : public CBaseMonster
{
public:
void Spawn(void);
void Precache(void);
void SetYawSpeed(void);
int Classify(void);
void HandleAnimEvent(MonsterEvent_t *pEvent);
int IgnoreConditions(void);
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
BOOL CheckRangeAttack1(float flDot, float flDist) { return FALSE; }
BOOL CheckRangeAttack2(float flDot, float flDist) { return FALSE; }
int TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType);
void SetActivity(Activity NewActivity);
};
LINK_ENTITY_TO_CLASS(monster_diablo, CDiablo);
const char *CDiablo::pAttackHitSounds[] =
{
"diablo/diablo_claw1.wav",
"diablo/diablo_claw2.wav",
"diablo/diablo_claw3.wav",
};
const char *CDiablo::pAttackMissSounds[] =
{
"diablo/diablo_claw_miss1.wav",
"diablo/diablo_claw_miss2.wav",
};
const char *CDiablo::pAttackSounds[] =
{
"diablo/diablo_attack1.wav",
"diablo/diablo_attack2.wav",
};
const char *CDiablo::pIdleSounds[] =
{
"diablo/diablo_idle1.wav",
"diablo/diablo_idle2.wav",
"diablo/diablo_idle3.wav",
};
const char *CDiablo::pAlertSounds[] =
{
"diablo/diablo_alert10.wav",
"diablo/diablo_alert20.wav",
"diablo/diablo_alert30.wav",
};
const char *CDiablo::pPainSounds[] =
{
"diablo/diablo_pain1.wav",
"diablo/diablo_pain2.wav",
};
//=========================================================
// Classify - indicates this monster's place in the
// relationship table.
//=========================================================
int CDiablo::Classify(void)
{
return CLASS_ALIEN_PREDATOR;
}
//=========================================================
// SetYawSpeed - allows each sequence to have a different
// turn rate associated with it.
//=========================================================
void CDiablo::SetYawSpeed(void)
{
int ys;
ys = 240; // 120
#if 0
switch (m_Activity)
{
}
#endif
pev->yaw_speed = ys;
}
int CDiablo::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.5;
vecDir = vecDir.Normalize();
float flForce = DamageForce(flDamage);
pev->velocity = pev->velocity + vecDir * flForce;
flDamage *= 0.3;
}
// HACK HACK -- until we fix this.
if (IsAlive())
PainSound();
return CBaseMonster::TakeDamage(pevInflictor, pevAttacker, flDamage, bitsDamageType);
}
void CDiablo::PainSound(void)
{
int pitch = 95 + RANDOM_LONG(0, 9);
if (RANDOM_LONG(0, 5) < 2)
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, RANDOM_SOUND_ARRAY(pPainSounds), 1.0, ATTN_NORM, 0, pitch);
}
void CDiablo::AlertSound(void)
{
int pitch = 95 + RANDOM_LONG(0, 9);
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, RANDOM_SOUND_ARRAY(pAlertSounds), 1.0, ATTN_NORM, 0, pitch);
}
void CDiablo::IdleSound(void)
{
int pitch = 100 + RANDOM_LONG(-5, 5);
// Play a random idle sound
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, RANDOM_SOUND_ARRAY(pIdleSounds), 1.0, ATTN_NORM, 0, pitch);
}
void CDiablo::AttackSound(void)
{
int pitch = 100 + RANDOM_LONG(-5, 5);
// Play a random attack sound
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, RANDOM_SOUND_ARRAY(pAttackSounds), 1.0, ATTN_NORM, 0, pitch);
}
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//=========================================================
void CDiablo::HandleAnimEvent(MonsterEvent_t *pEvent)
{
switch (pEvent->event)
{
case DIABLO_AE_ATTACK_RIGHT:
{
// do stuff for this event.
// ALERT( at_console, "Slash right!\n" );
CBaseEntity *pHurt = CheckTraceHullAttack(70, gSkillData.diabloDmgOneSlash * 3 + RANDOM_LONG( 0, 9 ), 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, RANDOM_SOUND_ARRAY(pAttackHitSounds), 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG(-5, 5));
}
else // Play a random attack miss sound
EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, RANDOM_SOUND_ARRAY(pAttackMissSounds), 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG(-5, 5));
if (RANDOM_LONG(0, 1))
AttackSound();
}
break;
case DIABLO_AE_ATTACK_LEFT:
{
// do stuff for this event.
// ALERT( at_console, "Slash left!\n" );
CBaseEntity *pHurt = CheckTraceHullAttack(70, gSkillData.diabloDmgOneSlash * 3 + RANDOM_LONG( 0, 9 ), 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, 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));
if (RANDOM_LONG(0, 1))
AttackSound();
}
break;
case DIABLO_AE_ATTACK_BOTH:
{
// do stuff for this event.
CBaseEntity *pHurt = CheckTraceHullAttack(70, gSkillData.diabloDmgBothSlash * 2.2f + RANDOM_LONG( 0, 9 ), 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, 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));
if (RANDOM_LONG(0, 1))
AttackSound();
}
break;
default:
CBaseMonster::HandleAnimEvent(pEvent);
break;
}
}
//=========================================================
// Spawn
//=========================================================
void CDiablo::Spawn()
{
Precache();
SET_MODEL(ENT(pev), "models/diablo.mdl");
UTIL_SetSize(pev, VEC_HUMAN_HULL_MIN, VEC_HUMAN_HULL_MAX);
pev->solid = SOLID_SLIDEBOX;
pev->movetype = MOVETYPE_STEP;
m_bloodColor = BLOOD_COLOR_RED;
pev->health = gSkillData.diabloHealth * 4.0f;
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 CDiablo::Precache()
{
PRECACHE_MODEL("models/diablo.mdl");
PRECACHE_SOUND_ARRAY(pAttackHitSounds);
PRECACHE_SOUND_ARRAY(pAttackMissSounds);
PRECACHE_SOUND_ARRAY(pAttackSounds);
PRECACHE_SOUND_ARRAY(pIdleSounds);
PRECACHE_SOUND_ARRAY(pAlertSounds);
PRECACHE_SOUND_ARRAY(pPainSounds);
}
void CDiablo::SetActivity(Activity newActivity)
{
if (m_MonsterState == MONSTERSTATE_COMBAT)
{
if (newActivity == ACT_WALK)
newActivity = ACT_RUN;
}
CBaseMonster::SetActivity(newActivity);
}
//=========================================================
// AI Schedules Specific to this monster
//=========================================================
int CDiablo::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 + DIABLO_FLINCH_DELAY;
}
return iIgnore;
}