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.
245 lines
6.5 KiB
245 lines
6.5 KiB
/*** |
|
* |
|
* 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. |
|
* |
|
****/ |
|
//========================================================= |
|
// Grinman - unexplained entity. |
|
//========================================================= |
|
#include "extdll.h" |
|
#include "util.h" |
|
#include "cbase.h" |
|
#include "monsters.h" |
|
#include "schedule.h" |
|
#include "weapons.h" |
|
|
|
//========================================================= |
|
// Monster's Anim Events Go Here |
|
//========================================================= |
|
|
|
class CGrinman : public CBaseMonster |
|
{ |
|
public: |
|
void Spawn( void ); |
|
void Precache( void ); |
|
void SetYawSpeed( void ); |
|
int Classify ( void ); |
|
void HandleAnimEvent( MonsterEvent_t *pEvent ); |
|
int ISoundMask ( void ); |
|
|
|
void DeclineFollowing( void ); |
|
|
|
int Save( CSave &save ); |
|
int Restore( CRestore &restore ); |
|
static TYPEDESCRIPTION m_SaveData[]; |
|
|
|
void StartTask( Task_t *pTask ); |
|
void RunTask( Task_t *pTask ); |
|
int TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType ); |
|
void TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType); |
|
|
|
void PlayScriptedSentence( const char *pszSentence, float duration, float volume, float attenuation, BOOL bConcurrent, CBaseEntity *pListener ); |
|
|
|
EHANDLE m_hPlayer; |
|
EHANDLE m_hTalkTarget; |
|
float m_flTalkTime; |
|
}; |
|
LINK_ENTITY_TO_CLASS( monster_grinman, CGrinman ); |
|
|
|
|
|
TYPEDESCRIPTION CGrinman::m_SaveData[] = |
|
{ |
|
DEFINE_FIELD( CGrinman, m_hTalkTarget, FIELD_EHANDLE ), |
|
DEFINE_FIELD( CGrinman, m_flTalkTime, FIELD_TIME ), |
|
}; |
|
IMPLEMENT_SAVERESTORE( CGrinman, CBaseMonster ); |
|
|
|
|
|
//========================================================= |
|
// Classify - indicates this monster's place in the |
|
// relationship table. |
|
//========================================================= |
|
int CGrinman :: Classify ( void ) |
|
{ |
|
return CLASS_NONE; |
|
} |
|
|
|
//========================================================= |
|
// SetYawSpeed - allows each sequence to have a different |
|
// turn rate associated with it. |
|
//========================================================= |
|
void CGrinman :: SetYawSpeed ( void ) |
|
{ |
|
int ys; |
|
|
|
switch ( m_Activity ) |
|
{ |
|
case ACT_IDLE: |
|
default: |
|
ys = 90; |
|
} |
|
|
|
pev->yaw_speed = ys; |
|
} |
|
|
|
//========================================================= |
|
// HandleAnimEvent - catches the monster-specific messages |
|
// that occur when tagged animation frames are played. |
|
//========================================================= |
|
void CGrinman :: HandleAnimEvent( MonsterEvent_t *pEvent ) |
|
{ |
|
switch( pEvent->event ) |
|
{ |
|
case 0: |
|
default: |
|
CBaseMonster::HandleAnimEvent( pEvent ); |
|
break; |
|
} |
|
} |
|
|
|
//========================================================= |
|
// ISoundMask - generic monster can't hear. |
|
//========================================================= |
|
int CGrinman :: ISoundMask ( void ) |
|
{ |
|
return 0; |
|
} |
|
|
|
//========================================================= |
|
// Spawn |
|
//========================================================= |
|
void CGrinman :: Spawn() |
|
{ |
|
Precache(); |
|
|
|
SET_MODEL( ENT(pev), "models/gman.mdl" ); |
|
UTIL_SetSize(pev, VEC_HUMAN_HULL_MIN, VEC_HUMAN_HULL_MAX); |
|
|
|
pev->solid = SOLID_SLIDEBOX; |
|
pev->movetype = MOVETYPE_STEP; |
|
m_bloodColor = DONT_BLEED; |
|
pev->health = 100; |
|
m_flFieldOfView = -1;// 360 degrees, he sees all. |
|
m_MonsterState = MONSTERSTATE_NONE; |
|
|
|
MonsterInit(); |
|
} |
|
|
|
//========================================================= |
|
// Precache - precaches all resources this monster needs |
|
//========================================================= |
|
void CGrinman :: Precache() |
|
{ |
|
PRECACHE_MODEL( "models/gman.mdl" ); |
|
} |
|
|
|
|
|
//========================================================= |
|
// AI Schedules Specific to this monster |
|
//========================================================= |
|
|
|
|
|
void CGrinman :: StartTask( Task_t *pTask ) |
|
{ |
|
switch( pTask->iTask ) |
|
{ |
|
case TASK_WAIT: |
|
if (m_hPlayer == 0) |
|
{ |
|
m_hPlayer = UTIL_FindEntityByClassname( NULL, "player" ); |
|
} |
|
break; |
|
} |
|
CBaseMonster::StartTask( pTask ); |
|
} |
|
|
|
void CGrinman :: RunTask( Task_t *pTask ) |
|
{ |
|
switch( pTask->iTask ) |
|
{ |
|
case TASK_WAIT: |
|
// look at who I'm talking to |
|
if (m_flTalkTime > gpGlobals->time && m_hTalkTarget != 0) |
|
{ |
|
float yaw = VecToYaw(m_hTalkTarget->pev->origin - pev->origin) - pev->angles.y; |
|
|
|
if (yaw > 180) yaw -= 360; |
|
if (yaw < -180) yaw += 360; |
|
|
|
// turn towards vector |
|
SetBoneController( 0, yaw ); |
|
} |
|
// look at player, but only if playing a "safe" idle animation |
|
else if (m_hPlayer != 0 && pev->sequence == 0) |
|
{ |
|
float yaw = VecToYaw(m_hPlayer->pev->origin - pev->origin) - pev->angles.y; |
|
|
|
if (yaw > 180) yaw -= 360; |
|
if (yaw < -180) yaw += 360; |
|
|
|
// turn towards vector |
|
SetBoneController( 0, yaw ); |
|
} |
|
else |
|
{ |
|
SetBoneController( 0, 0 ); |
|
} |
|
CBaseMonster::RunTask( pTask ); |
|
break; |
|
default: |
|
SetBoneController( 0, 0 ); |
|
CBaseMonster::RunTask( pTask ); |
|
break; |
|
} |
|
} |
|
|
|
|
|
//========================================================= |
|
// Override all damage |
|
//========================================================= |
|
int CGrinman :: TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType ) |
|
{ |
|
pev->health = pev->max_health / 2; // always trigger the 50% damage aitrigger |
|
|
|
if ( flDamage > 0 ) |
|
{ |
|
SetConditions(bits_COND_LIGHT_DAMAGE); |
|
} |
|
|
|
if ( flDamage >= 20 ) |
|
{ |
|
SetConditions(bits_COND_HEAVY_DAMAGE); |
|
} |
|
return TRUE; |
|
} |
|
|
|
|
|
void CGrinman::TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType) |
|
{ |
|
switch (RANDOM_LONG(1,3)) |
|
{ |
|
case 1:UTIL_Sparks( ptr->vecEndPos ); break; |
|
case 2:UTIL_Ricochet( ptr->vecEndPos, 2 ); break; |
|
case 3:UTIL_BloodStream( ptr->vecEndPos, UTIL_RandomBloodVector(), 330, RANDOM_LONG(50,150)); break; |
|
} |
|
|
|
AddMultiDamage( pevAttacker, this, flDamage, bitsDamageType ); |
|
} |
|
|
|
|
|
void CGrinman::PlayScriptedSentence( const char *pszSentence, float duration, float volume, float attenuation, BOOL bConcurrent, CBaseEntity *pListener ) |
|
{ |
|
CBaseMonster::PlayScriptedSentence( pszSentence, duration, volume, attenuation, bConcurrent, pListener ); |
|
|
|
m_flTalkTime = gpGlobals->time + duration; |
|
m_hTalkTarget = pListener; |
|
}
|
|
|