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.

827 lines
21 KiB

9 years ago
/***
*
* 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.
*
****/
//=========================================================
// monster template
//=========================================================
// UNDONE: Holster weapon?
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "talkmonster.h"
#include "schedule.h"
#include "defaultai.h"
#include "scripted.h"
#include "weapons.h"
#include "soundent.h"
//=========================================================
// Monster's Anim Events Go Here
//=========================================================
// first flag is barney dying for scripted sequences?
#define BARNEY_AE_DRAW ( 2 )
#define BARNEY_AE_SHOOT ( 3 )
#define BARNEY_AE_HOLSTER ( 4 )
#define BARNEY_BODY_GUNHOLSTERED 0
#define BARNEY_BODY_GUNDRAWN 1
9 years ago
#define BARNEY_BODY_GUNGONE 2
9 years ago
class CBarney : public CTalkMonster
{
public:
void Spawn( void );
void Precache( void );
void SetYawSpeed( void );
9 years ago
int ISoundMask( void );
9 years ago
void BarneyFirePistol( void );
void AlertSound( void );
9 years ago
int Classify( void );
9 years ago
void HandleAnimEvent( MonsterEvent_t *pEvent );
9 years ago
9 years ago
void RunTask( Task_t *pTask );
void StartTask( Task_t *pTask );
9 years ago
virtual int ObjectCaps( void ) { return CTalkMonster :: ObjectCaps() | FCAP_IMPULSE_USE; }
9 years ago
int TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType);
9 years ago
BOOL CheckRangeAttack1( float flDot, float flDist );
9 years ago
void DeclineFollowing( void );
// Override these to set behavior
9 years ago
Schedule_t *GetScheduleOfType( int Type );
Schedule_t *GetSchedule( void );
MONSTERSTATE GetIdealState( void );
9 years ago
void DeathSound( void );
void PainSound( void );
9 years ago
9 years ago
void TalkInit( void );
void TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType);
void Killed( entvars_t *pevAttacker, int iGib );
9 years ago
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
BOOL m_fGunDrawn;
float m_painTime;
float m_checkAttackTime;
BOOL m_lastAttackCheck;
9 years ago
// UNDONE: What is this for? It isn't used?
9 years ago
float m_flPlayerDamage;// how much pain has the player inflicted on me?
9 years ago
CUSTOM_SCHEDULES
9 years ago
};
LINK_ENTITY_TO_CLASS( monster_barney, CBarney )
9 years ago
9 years ago
TYPEDESCRIPTION CBarney::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CBarney, m_fGunDrawn, FIELD_BOOLEAN ),
DEFINE_FIELD( CBarney, m_painTime, FIELD_TIME ),
DEFINE_FIELD( CBarney, m_checkAttackTime, FIELD_TIME ),
DEFINE_FIELD( CBarney, m_lastAttackCheck, FIELD_BOOLEAN ),
DEFINE_FIELD( CBarney, m_flPlayerDamage, FIELD_FLOAT ),
};
IMPLEMENT_SAVERESTORE( CBarney, CTalkMonster )
9 years ago
//=========================================================
// AI Schedules Specific to this monster
//=========================================================
9 years ago
Task_t tlBaFollow[] =
9 years ago
{
9 years ago
{ TASK_MOVE_TO_TARGET_RANGE, (float)128 }, // Move within 128 of target ent (client)
{ TASK_SET_SCHEDULE, (float)SCHED_TARGET_FACE },
9 years ago
};
9 years ago
Schedule_t slBaFollow[] =
9 years ago
{
{
tlBaFollow,
9 years ago
ARRAYSIZE( tlBaFollow ),
bits_COND_NEW_ENEMY |
bits_COND_LIGHT_DAMAGE |
bits_COND_HEAVY_DAMAGE |
9 years ago
bits_COND_HEAR_SOUND |
bits_COND_PROVOKED,
bits_SOUND_DANGER,
"Follow"
},
};
//=========================================================
9 years ago
// BarneyDraw - much better looking draw schedule for when
9 years ago
// barney knows who he's gonna attack.
//=========================================================
9 years ago
Task_t tlBarneyEnemyDraw[] =
9 years ago
{
9 years ago
{ TASK_STOP_MOVING, 0 },
{ TASK_FACE_ENEMY, 0 },
{ TASK_PLAY_SEQUENCE_FACE_ENEMY, (float) ACT_ARM },
9 years ago
};
9 years ago
Schedule_t slBarneyEnemyDraw[] =
9 years ago
{
{
tlBarneyEnemyDraw,
9 years ago
ARRAYSIZE( tlBarneyEnemyDraw ),
9 years ago
0,
0,
"Barney Enemy Draw"
}
};
9 years ago
Task_t tlBaFaceTarget[] =
9 years ago
{
9 years ago
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_FACE_TARGET, (float)0 },
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_SET_SCHEDULE, (float)SCHED_TARGET_CHASE },
9 years ago
};
9 years ago
Schedule_t slBaFaceTarget[] =
9 years ago
{
{
tlBaFaceTarget,
9 years ago
ARRAYSIZE( tlBaFaceTarget ),
bits_COND_CLIENT_PUSH |
bits_COND_NEW_ENEMY |
bits_COND_LIGHT_DAMAGE |
bits_COND_HEAVY_DAMAGE |
9 years ago
bits_COND_HEAR_SOUND |
bits_COND_PROVOKED,
bits_SOUND_DANGER,
"FaceTarget"
},
};
9 years ago
Task_t tlIdleBaStand[] =
9 years ago
{
9 years ago
{ TASK_STOP_MOVING, 0 },
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_WAIT, (float)2 }, // repick IDLESTAND every two seconds.
{ TASK_TLK_HEADRESET, (float)0 }, // reset head position
9 years ago
};
9 years ago
Schedule_t slIdleBaStand[] =
9 years ago
{
9 years ago
{
9 years ago
tlIdleBaStand,
9 years ago
ARRAYSIZE( tlIdleBaStand ),
bits_COND_NEW_ENEMY |
bits_COND_LIGHT_DAMAGE |
bits_COND_HEAVY_DAMAGE |
bits_COND_HEAR_SOUND |
bits_COND_SMELL |
9 years ago
bits_COND_PROVOKED,
9 years ago
bits_SOUND_COMBAT |// sound flags - change these, and you'll break the talking code.
//bits_SOUND_PLAYER |
//bits_SOUND_WORLD |
bits_SOUND_DANGER |
bits_SOUND_MEAT |// scents
bits_SOUND_CARCASS |
9 years ago
bits_SOUND_GARBAGE,
"IdleStand"
},
};
DEFINE_CUSTOM_SCHEDULES( CBarney )
{
slBaFollow,
slBarneyEnemyDraw,
slBaFaceTarget,
slIdleBaStand,
};
IMPLEMENT_CUSTOM_SCHEDULES( CBarney, CTalkMonster )
9 years ago
9 years ago
void CBarney::StartTask( Task_t *pTask )
9 years ago
{
CTalkMonster::StartTask( pTask );
}
9 years ago
void CBarney::RunTask( Task_t *pTask )
9 years ago
{
9 years ago
switch( pTask->iTask )
9 years ago
{
case TASK_RANGE_ATTACK1:
if( m_hEnemy != 0 && ( m_hEnemy->IsPlayer() ) )
9 years ago
{
pev->framerate = 1.5;
}
CTalkMonster::RunTask( pTask );
break;
default:
CTalkMonster::RunTask( pTask );
break;
}
}
//=========================================================
// ISoundMask - returns a bit mask indicating which types
// of sounds this monster regards.
//=========================================================
9 years ago
int CBarney::ISoundMask( void)
9 years ago
{
9 years ago
return bits_SOUND_WORLD |
bits_SOUND_COMBAT |
bits_SOUND_CARCASS |
bits_SOUND_MEAT |
bits_SOUND_GARBAGE |
bits_SOUND_DANGER |
9 years ago
bits_SOUND_PLAYER;
}
//=========================================================
// Classify - indicates this monster's place in the
// relationship table.
//=========================================================
9 years ago
int CBarney::Classify( void )
9 years ago
{
9 years ago
return CLASS_PLAYER_ALLY;
9 years ago
}
//=========================================================
// ALertSound - barney says "Freeze!"
//=========================================================
9 years ago
void CBarney::AlertSound( void )
9 years ago
{
if( m_hEnemy != 0 )
9 years ago
{
9 years ago
if( FOkToSpeak() )
9 years ago
{
PlaySentence( "BA_ATTACK", RANDOM_FLOAT( 2.8f, 3.2f ), VOL_NORM, ATTN_IDLE );
9 years ago
}
}
}
9 years ago
//=========================================================
// SetYawSpeed - allows each sequence to have a different
// turn rate associated with it.
//=========================================================
9 years ago
void CBarney::SetYawSpeed( void )
9 years ago
{
int ys;
ys = 0;
switch ( m_Activity )
{
case ACT_IDLE:
ys = 70;
break;
case ACT_WALK:
ys = 70;
break;
case ACT_RUN:
ys = 90;
break;
default:
ys = 70;
break;
}
pev->yaw_speed = ys;
}
//=========================================================
// CheckRangeAttack1
//=========================================================
9 years ago
BOOL CBarney::CheckRangeAttack1( float flDot, float flDist )
9 years ago
{
if( flDist <= 1024.0f && flDot >= 0.5f )
9 years ago
{
9 years ago
if( gpGlobals->time > m_checkAttackTime )
9 years ago
{
TraceResult tr;
9 years ago
Vector shootOrigin = pev->origin + Vector( 0.0f, 0.0f, 55.0f );
9 years ago
CBaseEntity *pEnemy = m_hEnemy;
9 years ago
Vector shootTarget = ( ( pEnemy->BodyTarget( shootOrigin ) - pEnemy->pev->origin ) + m_vecEnemyLKP );
UTIL_TraceLine( shootOrigin, shootTarget, dont_ignore_monsters, ENT( pev ), &tr );
m_checkAttackTime = gpGlobals->time + 1.0f;
if( tr.flFraction == 1.0f || ( tr.pHit != NULL && CBaseEntity::Instance( tr.pHit ) == pEnemy ) )
9 years ago
m_lastAttackCheck = TRUE;
else
m_lastAttackCheck = FALSE;
m_checkAttackTime = gpGlobals->time + 1.5f;
9 years ago
}
return m_lastAttackCheck;
}
return FALSE;
}
//=========================================================
// BarneyFirePistol - shoots one round from the pistol at
// the enemy barney is facing.
//=========================================================
9 years ago
void CBarney::BarneyFirePistol( void )
9 years ago
{
Vector vecShootOrigin;
9 years ago
UTIL_MakeVectors( pev->angles );
9 years ago
vecShootOrigin = pev->origin + Vector( 0, 0, 55 );
Vector vecShootDir = ShootAtEnemy( vecShootOrigin );
Vector angDir = UTIL_VecToAngles( vecShootDir );
SetBlending( 0, angDir.x );
pev->effects = EF_MUZZLEFLASH;
9 years ago
FireBullets( 1, vecShootOrigin, vecShootDir, VECTOR_CONE_2DEGREES, 1024, BULLET_MONSTER_9MM );
9 years ago
int pitchShift = RANDOM_LONG( 0, 20 );
// Only shift about half the time
9 years ago
if( pitchShift > 10 )
9 years ago
pitchShift = 0;
else
pitchShift -= 5;
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, "barney/ba_attack2.wav", 1.0f, ATTN_NORM, 0, 100 + pitchShift );
9 years ago
CSoundEnt::InsertSound( bits_SOUND_COMBAT, pev->origin, 384, 0.3f );
9 years ago
// UNDONE: Reload?
m_cAmmoLoaded--;// take away a bullet!
}
9 years ago
9 years ago
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//
// Returns number of events handled, 0 if none.
//=========================================================
9 years ago
void CBarney::HandleAnimEvent( MonsterEvent_t *pEvent )
9 years ago
{
switch( pEvent->event )
{
case BARNEY_AE_SHOOT:
BarneyFirePistol();
break;
case BARNEY_AE_DRAW:
// barney's bodygroup switches here so he can pull gun from holster
pev->body = BARNEY_BODY_GUNDRAWN;
m_fGunDrawn = TRUE;
break;
case BARNEY_AE_HOLSTER:
// change bodygroup to replace gun in holster
pev->body = BARNEY_BODY_GUNHOLSTERED;
m_fGunDrawn = FALSE;
break;
default:
CTalkMonster::HandleAnimEvent( pEvent );
}
}
//=========================================================
// Spawn
//=========================================================
9 years ago
void CBarney::Spawn()
9 years ago
{
9 years ago
Precache();
9 years ago
9 years ago
SET_MODEL( ENT( pev ), "models/barney.mdl" );
UTIL_SetSize( pev, VEC_HUMAN_HULL_MIN, VEC_HUMAN_HULL_MAX );
9 years ago
9 years ago
pev->solid = SOLID_SLIDEBOX;
pev->movetype = MOVETYPE_STEP;
m_bloodColor = BLOOD_COLOR_RED;
pev->health = gSkillData.barneyHealth;
pev->view_ofs = Vector( 0.0f, 0.0f, 50.0f );// position of the eyes relative to monster's origin.
9 years ago
m_flFieldOfView = VIEW_FIELD_WIDE; // NOTE: we need a wide field of view so npc will notice player and say hello
m_MonsterState = MONSTERSTATE_NONE;
9 years ago
9 years ago
pev->body = 0; // gun in holster
m_fGunDrawn = FALSE;
9 years ago
9 years ago
m_afCapability = bits_CAP_HEAR | bits_CAP_TURN_HEAD | bits_CAP_DOORS_GROUP;
9 years ago
MonsterInit();
SetUse( &CTalkMonster::FollowerUse );
}
//=========================================================
// Precache - precaches all resources this monster needs
//=========================================================
9 years ago
void CBarney::Precache()
9 years ago
{
9 years ago
PRECACHE_MODEL( "models/barney.mdl" );
9 years ago
9 years ago
PRECACHE_SOUND( "barney/ba_attack1.wav" );
PRECACHE_SOUND( "barney/ba_attack2.wav" );
9 years ago
9 years ago
PRECACHE_SOUND( "barney/ba_pain1.wav" );
PRECACHE_SOUND( "barney/ba_pain2.wav" );
PRECACHE_SOUND( "barney/ba_pain3.wav" );
PRECACHE_SOUND( "barney/ba_die1.wav" );
PRECACHE_SOUND( "barney/ba_die2.wav" );
PRECACHE_SOUND( "barney/ba_die3.wav" );
9 years ago
// every new barney must call this, otherwise
// when a level is loaded, nobody will talk (time is reset to 0)
TalkInit();
CTalkMonster::Precache();
}
// Init talk data
9 years ago
void CBarney::TalkInit()
{
9 years ago
CTalkMonster::TalkInit();
// scientists speach group names (group names are in sentences.txt)
9 years ago
m_szGrp[TLK_ANSWER] = "BA_ANSWER";
9 years ago
m_szGrp[TLK_QUESTION] = "BA_QUESTION";
9 years ago
m_szGrp[TLK_IDLE] = "BA_IDLE";
m_szGrp[TLK_STARE] = "BA_STARE";
m_szGrp[TLK_USE] = "BA_OK";
m_szGrp[TLK_UNUSE] = "BA_WAIT";
m_szGrp[TLK_STOP] = "BA_STOP";
9 years ago
9 years ago
m_szGrp[TLK_NOSHOOT] = "BA_SCARED";
m_szGrp[TLK_HELLO] = "BA_HELLO";
9 years ago
9 years ago
m_szGrp[TLK_PLHURT1] = "!BA_CUREA";
m_szGrp[TLK_PLHURT2] = "!BA_CUREB";
m_szGrp[TLK_PLHURT3] = "!BA_CUREC";
9 years ago
9 years ago
m_szGrp[TLK_PHELLO] = NULL; //"BA_PHELLO"; // UNDONE
m_szGrp[TLK_PIDLE] = NULL; //"BA_PIDLE"; // UNDONE
9 years ago
m_szGrp[TLK_PQUESTION] = "BA_PQUEST"; // UNDONE
9 years ago
m_szGrp[TLK_SMELL] = "BA_SMELL";
9 years ago
9 years ago
m_szGrp[TLK_WOUND] = "BA_WOUND";
m_szGrp[TLK_MORTAL] = "BA_MORTAL";
9 years ago
// get voice for head - just one barney voice for now
m_voicePitch = 100;
}
static BOOL IsFacing( entvars_t *pevTest, const Vector &reference )
{
9 years ago
Vector vecDir = reference - pevTest->origin;
vecDir.z = 0.0f;
9 years ago
vecDir = vecDir.Normalize();
Vector forward, angle;
angle = pevTest->v_angle;
angle.x = 0.0f;
9 years ago
UTIL_MakeVectorsPrivate( angle, forward, NULL, NULL );
9 years ago
// He's facing me, he meant it
if( DotProduct( forward, vecDir ) > 0.96f ) // +/- 15 degrees or so
9 years ago
{
return TRUE;
}
return FALSE;
}
9 years ago
int CBarney::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
9 years ago
{
// make sure friends talk about it if player hurts talkmonsters...
9 years ago
int ret = CTalkMonster::TakeDamage( pevInflictor, pevAttacker, flDamage, bitsDamageType );
if( !IsAlive() || pev->deadflag == DEAD_DYING )
9 years ago
return ret;
9 years ago
if( m_MonsterState != MONSTERSTATE_PRONE && ( pevAttacker->flags & FL_CLIENT ) )
9 years ago
{
m_flPlayerDamage += flDamage;
// This is a heurstic to determine if the player intended to harm me
// If I have an enemy, we can't establish intent (may just be crossfire)
if( m_hEnemy == 0 )
9 years ago
{
// If the player was facing directly at me, or I'm already suspicious, get mad
9 years ago
if( ( m_afMemory & bits_MEMORY_SUSPICIOUS ) || IsFacing( pevAttacker, pev->origin ) )
9 years ago
{
// Alright, now I'm pissed!
PlaySentence( "BA_MAD", 4, VOL_NORM, ATTN_NORM );
Remember( bits_MEMORY_PROVOKED );
StopFollowing( TRUE );
}
else
{
// Hey, be careful with that
PlaySentence( "BA_SHOT", 4, VOL_NORM, ATTN_NORM );
Remember( bits_MEMORY_SUSPICIOUS );
}
}
9 years ago
else if( !( m_hEnemy->IsPlayer()) && pev->deadflag == DEAD_NO )
9 years ago
{
PlaySentence( "BA_SHOT", 4, VOL_NORM, ATTN_NORM );
}
}
return ret;
}
9 years ago
9 years ago
//=========================================================
// PainSound
//=========================================================
9 years ago
void CBarney::PainSound( void )
9 years ago
{
9 years ago
if( gpGlobals->time < m_painTime )
9 years ago
return;
m_painTime = gpGlobals->time + RANDOM_FLOAT( 0.5f, 0.75f );
9 years ago
switch( RANDOM_LONG( 0, 2 ) )
9 years ago
{
9 years ago
case 0:
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "barney/ba_pain1.wav", 1.0f, ATTN_NORM, 0, GetVoicePitch() );
9 years ago
break;
case 1:
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "barney/ba_pain2.wav", 1.0f, ATTN_NORM, 0, GetVoicePitch() );
9 years ago
break;
case 2:
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "barney/ba_pain3.wav", 1.0f, ATTN_NORM, 0, GetVoicePitch() );
9 years ago
break;
9 years ago
}
}
//=========================================================
// DeathSound
//=========================================================
9 years ago
void CBarney::DeathSound( void )
9 years ago
{
9 years ago
switch( RANDOM_LONG( 0, 2 ) )
9 years ago
{
9 years ago
case 0:
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "barney/ba_die1.wav", 1.0f, ATTN_NORM, 0, GetVoicePitch() );
9 years ago
break;
case 1:
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "barney/ba_die2.wav", 1.0f, ATTN_NORM, 0, GetVoicePitch() );
9 years ago
break;
case 2:
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "barney/ba_die3.wav", 1, ATTN_NORM, 0, GetVoicePitch() );
break;
9 years ago
}
}
9 years ago
void CBarney::TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType )
9 years ago
{
9 years ago
switch( ptr->iHitgroup )
9 years ago
{
case HITGROUP_CHEST:
case HITGROUP_STOMACH:
9 years ago
if (bitsDamageType & ( DMG_BULLET | DMG_SLASH | DMG_BLAST ) )
9 years ago
{
flDamage = flDamage * 0.5f;
9 years ago
}
break;
case 10:
9 years ago
if( bitsDamageType & ( DMG_BULLET | DMG_SLASH | DMG_CLUB ) )
9 years ago
{
flDamage -= 20.0f;
if( flDamage <= 0.0f )
9 years ago
{
UTIL_Ricochet( ptr->vecEndPos, 1.0f );
flDamage = 0.01f;
9 years ago
}
}
9 years ago
// always a head shot
ptr->iHitgroup = HITGROUP_HEAD;
break;
}
CTalkMonster::TraceAttack( pevAttacker, flDamage, vecDir, ptr, bitsDamageType );
}
void CBarney::Killed( entvars_t *pevAttacker, int iGib )
{
9 years ago
if( pev->body < BARNEY_BODY_GUNGONE )
{
// drop the gun!
9 years ago
Vector vecGunPos;
Vector vecGunAngles;
pev->body = BARNEY_BODY_GUNGONE;
GetAttachment( 0, vecGunPos, vecGunAngles );
9 years ago
DropItem( "weapon_bradnailer", vecGunPos, vecGunAngles );
9 years ago
}
SetUse( NULL );
CTalkMonster::Killed( pevAttacker, iGib );
}
//=========================================================
// AI Schedules Specific to this monster
//=========================================================
9 years ago
Schedule_t *CBarney::GetScheduleOfType( int Type )
9 years ago
{
Schedule_t *psched;
switch( Type )
{
case SCHED_ARM_WEAPON:
if( m_hEnemy != 0 )
9 years ago
{
// face enemy, then draw.
return slBarneyEnemyDraw;
}
break;
// Hook these to make a looping schedule
case SCHED_TARGET_FACE:
// call base class default so that barney will talk
// when 'used'
9 years ago
psched = CTalkMonster::GetScheduleOfType( Type );
9 years ago
9 years ago
if( psched == slIdleStand )
9 years ago
return slBaFaceTarget; // override this for different target face behavior
else
return psched;
case SCHED_TARGET_CHASE:
return slBaFollow;
case SCHED_IDLE_STAND:
// call base class default so that scientist will talk
// when standing during idle
9 years ago
psched = CTalkMonster::GetScheduleOfType( Type );
9 years ago
9 years ago
if( psched == slIdleStand )
9 years ago
{
// just look straight ahead.
return slIdleBaStand;
}
else
return psched;
}
return CTalkMonster::GetScheduleOfType( Type );
}
//=========================================================
// GetSchedule - Decides which type of schedule best suits
// the monster's current state and conditions. Then calls
// monster's member function to get a pointer to a schedule
// of the proper type.
//=========================================================
9 years ago
Schedule_t *CBarney::GetSchedule( void )
9 years ago
{
9 years ago
if( HasConditions( bits_COND_HEAR_SOUND ) )
9 years ago
{
CSound *pSound;
pSound = PBestSound();
ASSERT( pSound != NULL );
9 years ago
if( pSound && (pSound->m_iType & bits_SOUND_DANGER) )
9 years ago
return GetScheduleOfType( SCHED_TAKE_COVER_FROM_BEST_SOUND );
}
9 years ago
if( HasConditions( bits_COND_ENEMY_DEAD ) && FOkToSpeak() )
9 years ago
{
PlaySentence( "BA_KILL", 4, VOL_NORM, ATTN_NORM );
}
switch( m_MonsterState )
{
case MONSTERSTATE_COMBAT:
{
// dead enemy
9 years ago
if( HasConditions( bits_COND_ENEMY_DEAD ) )
9 years ago
{
// call base class, all code to handle dead enemies is centralized there.
9 years ago
return CBaseMonster::GetSchedule();
9 years ago
}
// always act surprized with a new enemy
9 years ago
if( HasConditions( bits_COND_NEW_ENEMY ) && HasConditions( bits_COND_LIGHT_DAMAGE ) )
9 years ago
return GetScheduleOfType( SCHED_SMALL_FLINCH );
9 years ago
9 years ago
// wait for one schedule to draw gun
9 years ago
if( !m_fGunDrawn )
9 years ago
return GetScheduleOfType( SCHED_ARM_WEAPON );
9 years ago
if( HasConditions( bits_COND_HEAVY_DAMAGE ) )
9 years ago
return GetScheduleOfType( SCHED_TAKE_COVER_FROM_ENEMY );
}
break;
case MONSTERSTATE_ALERT:
case MONSTERSTATE_IDLE:
9 years ago
if( HasConditions( bits_COND_LIGHT_DAMAGE | bits_COND_HEAVY_DAMAGE ) )
9 years ago
{
// flinch if hurt
return GetScheduleOfType( SCHED_SMALL_FLINCH );
}
if( m_hEnemy == 0 && IsFollowing() )
9 years ago
{
9 years ago
if( !m_hTargetEnt->IsAlive() )
9 years ago
{
// UNDONE: Comment about the recently dead player here?
StopFollowing( FALSE );
break;
}
else
{
9 years ago
if( HasConditions( bits_COND_CLIENT_PUSH ) )
9 years ago
{
return GetScheduleOfType( SCHED_MOVE_AWAY_FOLLOW );
}
return GetScheduleOfType( SCHED_TARGET_FACE );
}
}
9 years ago
if( HasConditions( bits_COND_CLIENT_PUSH ) )
9 years ago
{
return GetScheduleOfType( SCHED_MOVE_AWAY );
}
// try to say something about smells
TrySmellTalk();
break;
default:
break;
9 years ago
}
9 years ago
9 years ago
return CTalkMonster::GetSchedule();
}
9 years ago
MONSTERSTATE CBarney::GetIdealState( void )
9 years ago
{
return CTalkMonster::GetIdealState();
}
void CBarney::DeclineFollowing( void )
{
PlaySentence( "BA_POK", 2, VOL_NORM, ATTN_NORM );
}
//=========================================================
// DEAD BARNEY PROP
//
// Designer selects a pose in worldcraft, 0 through num_poses-1
// this value is added to what is selected as the 'first dead pose'
// among the monster's normal animations. All dead poses must
// appear sequentially in the model file. Be sure and set
// the m_iFirstPose properly!
//
//=========================================================
class CDeadBarney : public CBaseMonster
{
public:
void Spawn( void );
9 years ago
int Classify( void ) { return CLASS_PLAYER_ALLY; }
9 years ago
void KeyValue( KeyValueData *pkvd );
9 years ago
int m_iPose;// which sequence to display -- temporary, don't need to save
static const char *m_szPoses[3];
9 years ago
};
const char *CDeadBarney::m_szPoses[] = { "lying_on_back", "lying_on_side", "lying_on_stomach" };
9 years ago
void CDeadBarney::KeyValue( KeyValueData *pkvd )
{
9 years ago
if( FStrEq( pkvd->szKeyName, "pose" ) )
9 years ago
{
9 years ago
m_iPose = atoi( pkvd->szValue );
9 years ago
pkvd->fHandled = TRUE;
}
9 years ago
else
9 years ago
CBaseMonster::KeyValue( pkvd );
}
LINK_ENTITY_TO_CLASS( monster_barney_dead, CDeadBarney )
9 years ago
//=========================================================
// ********** DeadBarney SPAWN **********
//=========================================================
9 years ago
void CDeadBarney::Spawn()
9 years ago
{
9 years ago
PRECACHE_MODEL( "models/barney.mdl" );
SET_MODEL( ENT( pev ), "models/barney.mdl" );
9 years ago
9 years ago
pev->effects = 0;
pev->yaw_speed = 8;
pev->sequence = 0;
m_bloodColor = BLOOD_COLOR_RED;
9 years ago
pev->sequence = LookupSequence( m_szPoses[m_iPose] );
9 years ago
if( pev->sequence == -1 )
9 years ago
{
9 years ago
ALERT( at_console, "Dead barney with bad pose\n" );
9 years ago
}
// Corpses have less health
9 years ago
pev->health = 8;//gSkillData.barneyHealth;
9 years ago
MonsterInitDead();
}