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.

1207 lines
32 KiB

7 years ago
/***
*
9 years ago
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
7 years ago
*
* 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.
*
****/
//=========================================================
// Agrunt - Dominant, warlike alien grunt monster
//=========================================================
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "schedule.h"
#include "squadmonster.h"
#include "weapons.h"
#include "soundent.h"
#include "hornet.h"
#include "scripted.h"
//=========================================================
// monster-specific schedule types
//=========================================================
enum
{
SCHED_AGRUNT_SUPPRESS = LAST_COMMON_SCHEDULE + 1,
SCHED_AGRUNT_THREAT_DISPLAY
7 years ago
};
//=========================================================
// monster-specific tasks
//=========================================================
enum
{
TASK_AGRUNT_SETUP_HIDE_ATTACK = LAST_COMMON_TASK + 1,
TASK_AGRUNT_GET_PATH_TO_ENEMY_CORPSE
7 years ago
};
int iAgruntMuzzleFlash;
//=========================================================
// Monster's Anim Events Go Here
//=========================================================
#define AGRUNT_AE_HORNET1 ( 1 )
#define AGRUNT_AE_HORNET2 ( 2 )
#define AGRUNT_AE_HORNET3 ( 3 )
#define AGRUNT_AE_HORNET4 ( 4 )
#define AGRUNT_AE_HORNET5 ( 5 )
// some events are set up in the QC file that aren't recognized by the code yet.
#define AGRUNT_AE_PUNCH ( 6 )
#define AGRUNT_AE_BITE ( 7 )
#define AGRUNT_AE_LEFT_FOOT ( 10 )
#define AGRUNT_AE_RIGHT_FOOT ( 11 )
#define AGRUNT_AE_LEFT_PUNCH ( 12 )
#define AGRUNT_AE_RIGHT_PUNCH ( 13 )
#define AGRUNT_MELEE_DIST 100.0f
7 years ago
//LRC - body definitions for the Agrunt model
#define AGRUNT_BODY_HASGUN 0
#define AGRUNT_BODY_NOGUN 1
class CAGrunt : public CSquadMonster
{
public:
void Spawn( void );
void Precache( void );
8 years ago
void SetYawSpeed( void );
int Classify( void );
int ISoundMask( void );
7 years ago
void HandleAnimEvent( MonsterEvent_t *pEvent );
void SetObjectCollisionBox( void )
{
pev->absmin = pev->origin + Vector( -32.0f, -32.0f, 0.0f );
pev->absmax = pev->origin + Vector( 32.0f, 32.0f, 85.0f );
7 years ago
}
8 years ago
Schedule_t *GetSchedule( void );
Schedule_t *GetScheduleOfType( int Type );
BOOL FCanCheckAttacks( void );
BOOL CheckMeleeAttack1( float flDot, float flDist );
BOOL CheckRangeAttack1( float flDot, float flDist );
void StartTask( Task_t *pTask );
7 years ago
void AlertSound( void );
8 years ago
void DeathSound( void );
void PainSound( void );
void AttackSound( void );
void PrescheduleThink( void );
void TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType );
7 years ago
int IRelationship( CBaseEntity *pTarget );
8 years ago
void StopTalking( void );
7 years ago
BOOL ShouldSpeak( void );
CUSTOM_SCHEDULES
7 years ago
virtual void Killed( entvars_t *pevAttacker, int iGib );
8 years ago
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
7 years ago
static const char *pAttackHitSounds[];
static const char *pAttackMissSounds[];
static const char *pAttackSounds[];
static const char *pDieSounds[];
static const char *pPainSounds[];
static const char *pIdleSounds[];
static const char *pAlertSounds[];
8 years ago
BOOL m_fCanHornetAttack;
float m_flNextHornetAttackCheck;
7 years ago
float m_flNextPainTime;
// three hacky fields for speech stuff. These don't really need to be saved.
8 years ago
float m_flNextSpeakTime;
float m_flNextWordTime;
int m_iLastWord;
7 years ago
};
LINK_ENTITY_TO_CLASS( monster_alien_grunt, CAGrunt )
9 years ago
8 years ago
TYPEDESCRIPTION CAGrunt::m_SaveData[] =
7 years ago
{
DEFINE_FIELD( CAGrunt, m_fCanHornetAttack, FIELD_BOOLEAN ),
DEFINE_FIELD( CAGrunt, m_flNextHornetAttackCheck, FIELD_TIME ),
DEFINE_FIELD( CAGrunt, m_flNextPainTime, FIELD_TIME ),
DEFINE_FIELD( CAGrunt, m_flNextSpeakTime, FIELD_TIME ),
DEFINE_FIELD( CAGrunt, m_flNextWordTime, FIELD_TIME ),
DEFINE_FIELD( CAGrunt, m_iLastWord, FIELD_INTEGER ),
};
IMPLEMENT_SAVERESTORE( CAGrunt, CSquadMonster )
7 years ago
8 years ago
const char *CAGrunt::pAttackHitSounds[] =
7 years ago
{
"zombie/claw_strike1.wav",
"zombie/claw_strike2.wav",
"zombie/claw_strike3.wav",
};
8 years ago
const char *CAGrunt::pAttackMissSounds[] =
7 years ago
{
"zombie/claw_miss1.wav",
"zombie/claw_miss2.wav",
};
const char *CAGrunt::pAttackSounds[] =
{
"agrunt/ag_attack1.wav",
"agrunt/ag_attack2.wav",
"agrunt/ag_attack3.wav",
};
const char *CAGrunt::pDieSounds[] =
{
"agrunt/ag_die1.wav",
"agrunt/ag_die4.wav",
"agrunt/ag_die5.wav",
};
const char *CAGrunt::pPainSounds[] =
{
"agrunt/ag_pain1.wav",
"agrunt/ag_pain2.wav",
"agrunt/ag_pain3.wav",
"agrunt/ag_pain4.wav",
"agrunt/ag_pain5.wav",
};
const char *CAGrunt::pIdleSounds[] =
{
"agrunt/ag_idle1.wav",
"agrunt/ag_idle2.wav",
"agrunt/ag_idle3.wav",
"agrunt/ag_idle4.wav",
};
const char *CAGrunt::pAlertSounds[] =
{
"agrunt/ag_alert1.wav",
"agrunt/ag_alert3.wav",
"agrunt/ag_alert4.wav",
"agrunt/ag_alert5.wav",
};
//=========================================================
// IRelationship - overridden because Human Grunts are
// Alien Grunt's nemesis.
//=========================================================
8 years ago
int CAGrunt::IRelationship( CBaseEntity *pTarget )
7 years ago
{
8 years ago
if( FClassnameIs( pTarget->pev, "monster_human_grunt" ) )
7 years ago
{
return R_NM;
}
8 years ago
return CSquadMonster::IRelationship( pTarget );
7 years ago
}
//=========================================================
// ISoundMask
//=========================================================
8 years ago
int CAGrunt::ISoundMask( void )
7 years ago
{
8 years ago
return ( bits_SOUND_WORLD | bits_SOUND_COMBAT | bits_SOUND_PLAYER | bits_SOUND_DANGER );
7 years ago
}
//=========================================================
// TraceAttack
//=========================================================
8 years ago
void CAGrunt::TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType )
7 years ago
{
8 years ago
if( ptr->iHitgroup == 10 && ( bitsDamageType & ( DMG_BULLET | DMG_SLASH | DMG_CLUB ) ) )
7 years ago
{
// hit armor
8 years ago
if( pev->dmgtime != gpGlobals->time || ( RANDOM_LONG( 0, 10 ) < 1 ) )
7 years ago
{
UTIL_Ricochet( ptr->vecEndPos, RANDOM_FLOAT( 1.0f, 2.0f ) );
7 years ago
pev->dmgtime = gpGlobals->time;
}
8 years ago
if( RANDOM_LONG( 0, 1 ) == 0 )
7 years ago
{
Vector vecTracerDir = vecDir;
vecTracerDir.x += RANDOM_FLOAT( -0.3f, 0.3f );
vecTracerDir.y += RANDOM_FLOAT( -0.3f, 0.3f );
vecTracerDir.z += RANDOM_FLOAT( -0.3f, 0.3f );
7 years ago
vecTracerDir = vecTracerDir * -512.0f;
7 years ago
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, ptr->vecEndPos );
WRITE_BYTE( TE_TRACER );
WRITE_COORD( ptr->vecEndPos.x );
WRITE_COORD( ptr->vecEndPos.y );
WRITE_COORD( ptr->vecEndPos.z );
WRITE_COORD( vecTracerDir.x );
WRITE_COORD( vecTracerDir.y );
WRITE_COORD( vecTracerDir.z );
MESSAGE_END();
}
flDamage -= 20.0f;
if( flDamage <= 0.0f )
flDamage = 0.1f;// don't hurt the monster much, but allow bits_COND_LIGHT_DAMAGE to be generated
7 years ago
}
else
{
8 years ago
SpawnBlood( ptr->vecEndPos, BloodColor(), flDamage );// a little surface blood.
7 years ago
TraceBleed( flDamage, vecDir, ptr, bitsDamageType );
}
AddMultiDamage( pevAttacker, this, flDamage, bitsDamageType );
}
//=========================================================
// StopTalking - won't speak again for 10-20 seconds.
//=========================================================
void CAGrunt::StopTalking( void )
{
m_flNextWordTime = m_flNextSpeakTime = gpGlobals->time + 10.0f + RANDOM_LONG( 0, 10 );
7 years ago
}
//=========================================================
// ShouldSpeak - Should this agrunt be talking?
//=========================================================
BOOL CAGrunt::ShouldSpeak( void )
{
8 years ago
if( m_flNextSpeakTime > gpGlobals->time )
7 years ago
{
// my time to talk is still in the future.
return FALSE;
}
8 years ago
if( pev->spawnflags & SF_MONSTER_GAG )
7 years ago
{
8 years ago
if( m_MonsterState != MONSTERSTATE_COMBAT )
7 years ago
{
// if gagged, don't talk outside of combat.
// if not going to talk because of this, put the talk time
// into the future a bit, so we don't talk immediately after
// going into combat
m_flNextSpeakTime = gpGlobals->time + 3.0f;
7 years ago
return FALSE;
}
}
return TRUE;
}
//=========================================================
// PrescheduleThink
//=========================================================
8 years ago
void CAGrunt::PrescheduleThink( void )
7 years ago
{
8 years ago
if( ShouldSpeak() )
7 years ago
{
8 years ago
if( m_flNextWordTime < gpGlobals->time )
7 years ago
{
int num = -1;
do
{
8 years ago
num = RANDOM_LONG( 0, ARRAYSIZE( pIdleSounds ) - 1 );
7 years ago
} while( num == m_iLastWord );
m_iLastWord = num;
// play a new sound
EMIT_SOUND( ENT( pev ), CHAN_VOICE, pIdleSounds[num], 1.0f, ATTN_NORM );
7 years ago
// is this word our last?
8 years ago
if( RANDOM_LONG( 1, 10 ) <= 1 )
7 years ago
{
// stop talking.
StopTalking();
}
else
{
m_flNextWordTime = gpGlobals->time + RANDOM_FLOAT( 0.5f, 1.0f );
7 years ago
}
}
}
}
//=========================================================
// DieSound
//=========================================================
8 years ago
void CAGrunt::DeathSound( void )
7 years ago
{
StopTalking();
EMIT_SOUND( ENT( pev ), CHAN_VOICE, pDieSounds[RANDOM_LONG( 0, ARRAYSIZE( pDieSounds ) - 1 )], 1.0f, ATTN_NORM );
7 years ago
}
//=========================================================
// AlertSound
//=========================================================
8 years ago
void CAGrunt::AlertSound( void )
7 years ago
{
StopTalking();
EMIT_SOUND( ENT( pev ), CHAN_VOICE, pAlertSounds[RANDOM_LONG( 0, ARRAYSIZE( pAlertSounds ) - 1 )], 1.0f, ATTN_NORM );
7 years ago
}
//=========================================================
// AttackSound
//=========================================================
8 years ago
void CAGrunt::AttackSound( void )
7 years ago
{
StopTalking();
EMIT_SOUND( ENT( pev ), CHAN_VOICE, pAttackSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackSounds ) - 1 )], 1.0f, ATTN_NORM );
7 years ago
}
//=========================================================
// PainSound
//=========================================================
8 years ago
void CAGrunt::PainSound( void )
7 years ago
{
8 years ago
if( m_flNextPainTime > gpGlobals->time )
7 years ago
{
return;
}
m_flNextPainTime = gpGlobals->time + 0.6f;
7 years ago
StopTalking();
EMIT_SOUND( ENT( pev ), CHAN_VOICE, pPainSounds[RANDOM_LONG( 0, ARRAYSIZE( pPainSounds ) - 1 )], 1.0f, ATTN_NORM );
7 years ago
}
//=========================================================
8 years ago
// Classify - indicates this monster's place in the
7 years ago
// relationship table.
//=========================================================
8 years ago
int CAGrunt::Classify( void )
7 years ago
{
return m_iClass?m_iClass:CLASS_ALIEN_MILITARY;
}
//=========================================================
// SetYawSpeed - allows each sequence to have a different
// turn rate associated with it.
//=========================================================
8 years ago
void CAGrunt::SetYawSpeed( void )
7 years ago
{
int ys;
8 years ago
switch( m_Activity )
7 years ago
{
case ACT_TURN_LEFT:
case ACT_TURN_RIGHT:
ys = 110;
break;
8 years ago
default:
ys = 100;
break;
7 years ago
}
pev->yaw_speed = ys;
}
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//
// Returns number of events handled, 0 if none.
//=========================================================
8 years ago
void CAGrunt::HandleAnimEvent( MonsterEvent_t *pEvent )
7 years ago
{
switch( pEvent->event )
{
case AGRUNT_AE_HORNET1:
case AGRUNT_AE_HORNET2:
case AGRUNT_AE_HORNET3:
case AGRUNT_AE_HORNET4:
case AGRUNT_AE_HORNET5:
{
// m_vecEnemyLKP should be center of enemy body
Vector vecArmPos, vecArmDir;
Vector vecDirToEnemy;
Vector angDir;
8 years ago
if( HasConditions( bits_COND_SEE_ENEMY ) )
7 years ago
{
vecDirToEnemy = ( ( m_vecEnemyLKP ) - pev->origin );
angDir = UTIL_VecToAngles( vecDirToEnemy );
vecDirToEnemy = vecDirToEnemy.Normalize();
}
else
{
angDir = pev->angles;
UTIL_MakeAimVectors( angDir );
vecDirToEnemy = gpGlobals->v_forward;
}
pev->effects = EF_MUZZLEFLASH;
// make angles +-180
if( angDir.x > 180.0f )
7 years ago
{
angDir.x = angDir.x - 360.0f;
7 years ago
}
SetBlending( 0, angDir.x );
GetAttachment( 0, vecArmPos, vecArmDir );
vecArmPos = vecArmPos + vecDirToEnemy * 32.0f;
7 years ago
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecArmPos );
WRITE_BYTE( TE_SPRITE );
WRITE_COORD( vecArmPos.x ); // pos
WRITE_COORD( vecArmPos.y );
WRITE_COORD( vecArmPos.z );
WRITE_SHORT( iAgruntMuzzleFlash ); // model
WRITE_BYTE( 6 ); // size * 10
WRITE_BYTE( 128 ); // brightness
MESSAGE_END();
CBaseEntity *pHornet = CBaseEntity::Create( "hornet", vecArmPos, UTIL_VecToAngles( vecDirToEnemy ), edict() );
UTIL_MakeVectors( pHornet->pev->angles );
pHornet->pev->velocity = gpGlobals->v_forward * 300.0f;
7 years ago
CBaseMonster *pHornetMonster = pHornet->MyMonsterPointer();
//LRC - hornets have the same allegiance as their creators
pHornetMonster->m_iPlayerReact = m_iPlayerReact;
pHornetMonster->m_iClass = m_iClass;
if (m_afMemory & bits_MEMORY_PROVOKED) // if I'm mad at the player, so are my hornets
pHornetMonster->Remember(bits_MEMORY_PROVOKED);
8 years ago
if( pHornetMonster )
7 years ago
{
if (m_pCine && m_pCine->PreciseAttack()) //LRC- are we doing a scripted action?
pHornetMonster->m_hEnemy = m_hTargetEnt;
else
9 years ago
pHornetMonster->m_hEnemy = m_hEnemy;
7 years ago
}
}
break;
case AGRUNT_AE_LEFT_FOOT:
8 years ago
switch( RANDOM_LONG( 0, 1 ) )
7 years ago
{
// left foot
8 years ago
case 0:
EMIT_SOUND_DYN( ENT( pev ), CHAN_BODY, "player/pl_ladder2.wav", 1, ATTN_NORM, 0, 70 );
break;
case 1:
EMIT_SOUND_DYN( ENT( pev ), CHAN_BODY, "player/pl_ladder4.wav", 1, ATTN_NORM, 0, 70 );
break;
7 years ago
}
break;
case AGRUNT_AE_RIGHT_FOOT:
// right foot
8 years ago
switch( RANDOM_LONG( 0, 1 ) )
7 years ago
{
8 years ago
case 0:
EMIT_SOUND_DYN( ENT( pev ), CHAN_BODY, "player/pl_ladder1.wav", 1, ATTN_NORM, 0, 70 );
break;
case 1:
EMIT_SOUND_DYN( ENT( pev ), CHAN_BODY, "player/pl_ladder3.wav", 1, ATTN_NORM, 0, 70 );
8 years ago
break;
7 years ago
}
break;
case AGRUNT_AE_LEFT_PUNCH:
{
CBaseEntity *pHurt = CheckTraceHullAttack( AGRUNT_MELEE_DIST, gSkillData.agruntDmgPunch, DMG_CLUB );
8 years ago
if( pHurt )
7 years ago
{
pHurt->pev->punchangle.y = -25.0f;
pHurt->pev->punchangle.x = 8.0f;
7 years ago
// OK to use gpGlobals without calling MakeVectors, cause CheckTraceHullAttack called it above.
8 years ago
if( pHurt->IsPlayer() )
7 years ago
{
// this is a player. Knock him around.
pHurt->pev->velocity = pHurt->pev->velocity + gpGlobals->v_right * 250.0f;
7 years ago
}
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackHitSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackHitSounds ) - 1 )], 1.0f, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
7 years ago
Vector vecArmPos, vecArmAng;
GetAttachment( 0, vecArmPos, vecArmAng );
8 years ago
SpawnBlood( vecArmPos, pHurt->BloodColor(), 25 );// a little surface blood.
7 years ago
}
else
{
// Play a random attack miss sound
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackMissSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackMissSounds ) - 1 )], 1.0f, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
7 years ago
}
}
break;
case AGRUNT_AE_RIGHT_PUNCH:
{
CBaseEntity *pHurt = CheckTraceHullAttack( AGRUNT_MELEE_DIST, gSkillData.agruntDmgPunch, DMG_CLUB );
8 years ago
if( pHurt )
7 years ago
{
pHurt->pev->punchangle.y = 25.0f;
pHurt->pev->punchangle.x = 8.0f;
7 years ago
// OK to use gpGlobals without calling MakeVectors, cause CheckTraceHullAttack called it above.
8 years ago
if( pHurt->IsPlayer() )
7 years ago
{
// this is a player. Knock him around.
pHurt->pev->velocity = pHurt->pev->velocity + gpGlobals->v_right * -250.0f;
7 years ago
}
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackHitSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackHitSounds ) - 1 )], 1.0f, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
7 years ago
Vector vecArmPos, vecArmAng;
GetAttachment( 0, vecArmPos, vecArmAng );
8 years ago
SpawnBlood( vecArmPos, pHurt->BloodColor(), 25 );// a little surface blood.
7 years ago
}
else
{
// Play a random attack miss sound
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, pAttackMissSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackMissSounds ) - 1 )], 1.0f, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
7 years ago
}
}
break;
default:
CSquadMonster::HandleAnimEvent( pEvent );
break;
}
}
//=========================================================
// Spawn
//=========================================================
8 years ago
void CAGrunt::Spawn()
7 years ago
{
8 years ago
Precache();
7 years ago
if (pev->model)
SET_MODEL(ENT(pev), STRING(pev->model)); //LRC
else
SET_MODEL( ENT( pev ), "models/agrunt.mdl" );
UTIL_SetSize( pev, Vector( -32.0f, -32.0f, 0.0f ), Vector( 32.0f, 32.0f, 64.0f ) );
7 years ago
8 years ago
pev->solid = SOLID_SLIDEBOX;
pev->movetype = MOVETYPE_STEP;
m_bloodColor = DONT_BLEED;
8 years ago
pev->effects = 0;
7 years ago
if (pev->health == 0)
pev->health = gSkillData.agruntHealth;
m_flFieldOfView = 0.2f;// indicates the width of this monster's forward view cone ( as a dotproduct result )
8 years ago
m_MonsterState = MONSTERSTATE_NONE;
m_afCapability = 0;
m_afCapability |= bits_CAP_SQUAD;
7 years ago
m_HackedGunPos = Vector( 24.0f, 64.0f, 48.0f );
7 years ago
m_flNextSpeakTime = m_flNextWordTime = gpGlobals->time + 10.0f + RANDOM_LONG( 0, 10 );
7 years ago
MonsterInit();
}
//=========================================================
// Precache - precaches all resources this monster needs
//=========================================================
8 years ago
void CAGrunt::Precache()
7 years ago
{
size_t i;
7 years ago
if (pev->model)
PRECACHE_MODEL(STRING(pev->model)); //LRC
7 years ago
else
PRECACHE_MODEL( "models/agrunt.mdl" );
7 years ago
8 years ago
for( i = 0; i < ARRAYSIZE( pAttackHitSounds ); i++ )
PRECACHE_SOUND( pAttackHitSounds[i] );
7 years ago
8 years ago
for( i = 0; i < ARRAYSIZE( pAttackMissSounds ); i++ )
PRECACHE_SOUND( pAttackMissSounds[i] );
7 years ago
8 years ago
for( i = 0; i < ARRAYSIZE( pIdleSounds ); i++ )
PRECACHE_SOUND( pIdleSounds[i] );
7 years ago
8 years ago
for( i = 0; i < ARRAYSIZE( pDieSounds ); i++ )
PRECACHE_SOUND( pDieSounds[i] );
7 years ago
8 years ago
for( i = 0; i < ARRAYSIZE( pPainSounds ); i++ )
PRECACHE_SOUND( pPainSounds[i] );
7 years ago
8 years ago
for( i = 0; i < ARRAYSIZE( pAttackSounds ); i++ )
PRECACHE_SOUND( pAttackSounds[i] );
7 years ago
8 years ago
for( i = 0; i < ARRAYSIZE( pAlertSounds ); i++ )
PRECACHE_SOUND( pAlertSounds[i] );
7 years ago
PRECACHE_SOUND( "hassault/hw_shoot1.wav" );
iAgruntMuzzleFlash = PRECACHE_MODEL( "sprites/muz4.spr" );
UTIL_PrecacheOther( "hornet" );
8 years ago
}
7 years ago
//=========================================================
// AI Schedules Specific to this monster
//=========================================================
//=========================================================
// Fail Schedule
//=========================================================
8 years ago
Task_t tlAGruntFail[] =
7 years ago
{
8 years ago
{ TASK_STOP_MOVING, 0 },
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_WAIT, 2.0f },
{ TASK_WAIT_PVS, 0.0f },
7 years ago
};
8 years ago
Schedule_t slAGruntFail[] =
7 years ago
{
{
tlAGruntFail,
8 years ago
ARRAYSIZE( tlAGruntFail ),
bits_COND_CAN_RANGE_ATTACK1 |
7 years ago
bits_COND_CAN_MELEE_ATTACK1,
0,
"AGrunt Fail"
},
};
//=========================================================
// Combat Fail Schedule
//=========================================================
8 years ago
Task_t tlAGruntCombatFail[] =
7 years ago
{
8 years ago
{ TASK_STOP_MOVING, 0 },
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_WAIT_FACE_ENEMY, 2.0f },
{ TASK_WAIT_PVS, 0.0f },
7 years ago
};
8 years ago
Schedule_t slAGruntCombatFail[] =
7 years ago
{
{
tlAGruntCombatFail,
8 years ago
ARRAYSIZE( tlAGruntCombatFail ),
bits_COND_CAN_RANGE_ATTACK1 |
7 years ago
bits_COND_CAN_MELEE_ATTACK1,
0,
"AGrunt Combat Fail"
},
};
//=========================================================
// Standoff schedule. Used in combat when a monster is
// hiding in cover or the enemy has moved out of sight.
// Should we look around in this schedule?
//=========================================================
8 years ago
Task_t tlAGruntStandoff[] =
7 years ago
{
{ TASK_STOP_MOVING, 0.0f },
8 years ago
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_WAIT_FACE_ENEMY, 2.0f },
7 years ago
};
8 years ago
Schedule_t slAGruntStandoff[] =
7 years ago
{
{
tlAGruntStandoff,
8 years ago
ARRAYSIZE( tlAGruntStandoff ),
bits_COND_CAN_RANGE_ATTACK1 |
bits_COND_CAN_MELEE_ATTACK1 |
bits_COND_SEE_ENEMY |
bits_COND_NEW_ENEMY |
7 years ago
bits_COND_HEAR_SOUND,
bits_SOUND_DANGER,
"Agrunt Standoff"
}
};
//=========================================================
// Suppress
//=========================================================
8 years ago
Task_t tlAGruntSuppressHornet[] =
7 years ago
{
{ TASK_STOP_MOVING, 0.0f },
{ TASK_RANGE_ATTACK1, 0.0f },
7 years ago
};
Schedule_t slAGruntSuppress[] =
{
{
tlAGruntSuppressHornet,
8 years ago
ARRAYSIZE( tlAGruntSuppressHornet ),
7 years ago
0,
0,
"AGrunt Suppress Hornet",
},
};
//=========================================================
// primary range attacks
//=========================================================
8 years ago
Task_t tlAGruntRangeAttack1[] =
7 years ago
{
{ TASK_STOP_MOVING, 0.0f },
{ TASK_FACE_ENEMY, 0.0f },
{ TASK_RANGE_ATTACK1, 0.0f },
7 years ago
};
8 years ago
Schedule_t slAGruntRangeAttack1[] =
7 years ago
{
8 years ago
{
7 years ago
tlAGruntRangeAttack1,
8 years ago
ARRAYSIZE( tlAGruntRangeAttack1 ),
bits_COND_NEW_ENEMY |
bits_COND_ENEMY_DEAD |
7 years ago
bits_COND_HEAVY_DAMAGE,
0,
"AGrunt Range Attack1"
},
};
8 years ago
Task_t tlAGruntHiddenRangeAttack1[] =
7 years ago
{
8 years ago
{ TASK_SET_FAIL_SCHEDULE, (float)SCHED_STANDOFF },
{ TASK_AGRUNT_SETUP_HIDE_ATTACK, 0 },
{ TASK_STOP_MOVING, 0 },
{ TASK_FACE_IDEAL, 0 },
{ TASK_RANGE_ATTACK1_NOTURN, (float)0 },
7 years ago
};
8 years ago
Schedule_t slAGruntHiddenRangeAttack[] =
7 years ago
{
8 years ago
{
7 years ago
tlAGruntHiddenRangeAttack1,
8 years ago
ARRAYSIZE ( tlAGruntHiddenRangeAttack1 ),
bits_COND_NEW_ENEMY |
bits_COND_HEAVY_DAMAGE |
7 years ago
bits_COND_HEAR_SOUND,
bits_SOUND_DANGER,
"AGrunt Hidden Range Attack1"
},
};
//=========================================================
8 years ago
// Take cover from enemy! Tries lateral cover before node
// cover!
7 years ago
//=========================================================
8 years ago
Task_t tlAGruntTakeCoverFromEnemy[] =
7 years ago
{
{ TASK_STOP_MOVING, 0.0f },
{ TASK_WAIT, 0.2f },
{ TASK_FIND_COVER_FROM_ENEMY, 0.0f },
{ TASK_RUN_PATH, 0.0f },
{ TASK_WAIT_FOR_MOVEMENT, 0.0f },
8 years ago
{ TASK_REMEMBER, (float)bits_MEMORY_INCOVER },
{ TASK_FACE_ENEMY, 0.0f },
7 years ago
};
8 years ago
Schedule_t slAGruntTakeCoverFromEnemy[] =
7 years ago
{
8 years ago
{
7 years ago
tlAGruntTakeCoverFromEnemy,
8 years ago
ARRAYSIZE( tlAGruntTakeCoverFromEnemy ),
7 years ago
bits_COND_NEW_ENEMY,
0,
"AGruntTakeCoverFromEnemy"
},
};
//=========================================================
// Victory dance!
//=========================================================
8 years ago
Task_t tlAGruntVictoryDance[] =
7 years ago
{
{ TASK_STOP_MOVING, 0.0f },
8 years ago
{ TASK_SET_FAIL_SCHEDULE, (float)SCHED_AGRUNT_THREAT_DISPLAY },
{ TASK_WAIT, 0.2f },
{ TASK_AGRUNT_GET_PATH_TO_ENEMY_CORPSE, 0.0f },
{ TASK_WALK_PATH, 0.0f },
{ TASK_WAIT_FOR_MOVEMENT, 0.0f },
{ TASK_FACE_ENEMY, 0.0f },
8 years ago
{ TASK_PLAY_SEQUENCE, (float)ACT_CROUCH },
{ TASK_PLAY_SEQUENCE, (float)ACT_VICTORY_DANCE },
{ TASK_PLAY_SEQUENCE, (float)ACT_VICTORY_DANCE },
{ TASK_PLAY_SEQUENCE, (float)ACT_STAND },
{ TASK_PLAY_SEQUENCE, (float)ACT_THREAT_DISPLAY },
{ TASK_PLAY_SEQUENCE, (float)ACT_CROUCH },
{ TASK_PLAY_SEQUENCE, (float)ACT_VICTORY_DANCE },
{ TASK_PLAY_SEQUENCE, (float)ACT_VICTORY_DANCE },
{ TASK_PLAY_SEQUENCE, (float)ACT_VICTORY_DANCE },
{ TASK_PLAY_SEQUENCE, (float)ACT_VICTORY_DANCE },
{ TASK_PLAY_SEQUENCE, (float)ACT_VICTORY_DANCE },
{ TASK_PLAY_SEQUENCE, (float)ACT_STAND },
7 years ago
};
8 years ago
Schedule_t slAGruntVictoryDance[] =
7 years ago
{
8 years ago
{
7 years ago
tlAGruntVictoryDance,
8 years ago
ARRAYSIZE( tlAGruntVictoryDance ),
bits_COND_NEW_ENEMY |
bits_COND_LIGHT_DAMAGE |
7 years ago
bits_COND_HEAVY_DAMAGE,
0,
"AGruntVictoryDance"
},
};
//=========================================================
//=========================================================
8 years ago
Task_t tlAGruntThreatDisplay[] =
7 years ago
{
{ TASK_STOP_MOVING, 0.0f },
{ TASK_FACE_ENEMY, 0.0f },
8 years ago
{ TASK_PLAY_SEQUENCE, (float)ACT_THREAT_DISPLAY },
7 years ago
};
8 years ago
Schedule_t slAGruntThreatDisplay[] =
7 years ago
{
8 years ago
{
7 years ago
tlAGruntThreatDisplay,
8 years ago
ARRAYSIZE( tlAGruntThreatDisplay ),
bits_COND_NEW_ENEMY |
bits_COND_LIGHT_DAMAGE |
7 years ago
bits_COND_HEAVY_DAMAGE,
8 years ago
bits_SOUND_PLAYER |
bits_SOUND_COMBAT |
7 years ago
bits_SOUND_WORLD,
"AGruntThreatDisplay"
},
};
DEFINE_CUSTOM_SCHEDULES( CAGrunt )
{
slAGruntFail,
slAGruntCombatFail,
slAGruntStandoff,
slAGruntSuppress,
slAGruntRangeAttack1,
slAGruntHiddenRangeAttack,
slAGruntTakeCoverFromEnemy,
slAGruntVictoryDance,
slAGruntThreatDisplay,
};
IMPLEMENT_CUSTOM_SCHEDULES( CAGrunt, CSquadMonster )
7 years ago
//=========================================================
// FCanCheckAttacks - this is overridden for alien grunts
// because they can use their smart weapons against unseen
// enemies. Base class doesn't attack anyone it can't see.
//=========================================================
8 years ago
BOOL CAGrunt::FCanCheckAttacks( void )
7 years ago
{
8 years ago
if( !HasConditions( bits_COND_ENEMY_TOOFAR ) )
7 years ago
{
return TRUE;
}
else
{
return FALSE;
}
}
//=========================================================
// CheckMeleeAttack1 - alien grunts zap the crap out of
// any enemy that gets too close.
//=========================================================
8 years ago
BOOL CAGrunt::CheckMeleeAttack1( float flDot, float flDist )
7 years ago
{
/*if( HasConditions( bits_COND_SEE_ENEMY ) && flDist <= AGRUNT_MELEE_DIST && flDot >= 0.6 && m_hEnemy != 0 )
7 years ago
{
return TRUE;
}*/
7 years ago
return FALSE;
}
//=========================================================
// CheckRangeAttack1
//
// !!!LATER - we may want to load balance this. Several
// tracelines are done, so we may not want to do this every
// server frame. Definitely not while firing.
//=========================================================
8 years ago
BOOL CAGrunt::CheckRangeAttack1( float flDot, float flDist )
7 years ago
{
8 years ago
if( gpGlobals->time < m_flNextHornetAttackCheck )
7 years ago
{
return m_fCanHornetAttack;
}
if( HasConditions( bits_COND_SEE_ENEMY ) && flDist >= AGRUNT_MELEE_DIST && flDist <= 1024.0f && flDot >= 0.5f && NoFriendlyFire() )
7 years ago
{
8 years ago
TraceResult tr;
7 years ago
Vector vecArmPos, vecArmDir;
// verify that a shot fired from the gun will hit the enemy before the world.
// !!!LATER - we may wish to do something different for projectile weapons as opposed to instant-hit
UTIL_MakeVectors( pev->angles );
GetAttachment( 0, vecArmPos, vecArmDir );
//UTIL_TraceLine( vecArmPos, vecArmPos + gpGlobals->v_forward * 256.0f, ignore_monsters, ENT( pev ), &tr );
8 years ago
UTIL_TraceLine( vecArmPos, m_hEnemy->BodyTarget( vecArmPos ), dont_ignore_monsters, ENT( pev ), &tr );
7 years ago
if( tr.flFraction == 1.0f || tr.pHit == m_hEnemy->edict() )
7 years ago
{
m_flNextHornetAttackCheck = gpGlobals->time + RANDOM_FLOAT( 2.0f, 5.0f );
7 years ago
m_fCanHornetAttack = TRUE;
return m_fCanHornetAttack;
}
}
8 years ago
m_flNextHornetAttackCheck = gpGlobals->time + 0.2f;// don't check for half second if this check wasn't successful
7 years ago
m_fCanHornetAttack = FALSE;
return m_fCanHornetAttack;
}
//=========================================================
// StartTask
//=========================================================
8 years ago
void CAGrunt::StartTask( Task_t *pTask )
7 years ago
{
8 years ago
switch( pTask->iTask )
7 years ago
{
case TASK_AGRUNT_GET_PATH_TO_ENEMY_CORPSE:
{
UTIL_MakeVectors( pev->angles );
if( BuildRoute( m_vecEnemyLKP - gpGlobals->v_forward * 50.0f, bits_MF_TO_LOCATION, NULL ) )
7 years ago
{
TaskComplete();
}
else
{
8 years ago
ALERT( at_aiconsole, "AGruntGetPathToEnemyCorpse failed!!\n" );
7 years ago
TaskFail();
}
}
break;
case TASK_AGRUNT_SETUP_HIDE_ATTACK:
// alien grunt shoots hornets back out into the open from a concealed location.
// try to find a spot to throw that gives the smart weapon a good chance of finding the enemy.
// ideally, this spot is along a line that is perpendicular to a line drawn from the agrunt to the enemy.
CBaseMonster *pEnemyMonsterPtr;
pEnemyMonsterPtr = m_hEnemy->MyMonsterPointer();
8 years ago
if( pEnemyMonsterPtr )
7 years ago
{
8 years ago
Vector vecCenter;
TraceResult tr;
BOOL fSkip;
7 years ago
fSkip = FALSE;
vecCenter = Center();
UTIL_VecToAngles( m_vecEnemyLKP - pev->origin );
UTIL_TraceLine( Center() + gpGlobals->v_forward * 128.0f, m_vecEnemyLKP, ignore_monsters, ENT( pev ), &tr );
if( tr.flFraction == 1.0f )
7 years ago
{
MakeIdealYaw( pev->origin + gpGlobals->v_right * 128.0f );
7 years ago
fSkip = TRUE;
TaskComplete();
}
8 years ago
if( !fSkip )
7 years ago
{
UTIL_TraceLine( Center() - gpGlobals->v_forward * 128.0f, m_vecEnemyLKP, ignore_monsters, ENT( pev ), &tr );
if( tr.flFraction == 1.0f )
7 years ago
{
MakeIdealYaw( pev->origin - gpGlobals->v_right * 128.0f );
7 years ago
fSkip = TRUE;
TaskComplete();
}
}
8 years ago
if( !fSkip )
7 years ago
{
UTIL_TraceLine( Center() + gpGlobals->v_forward * 256.0f, m_vecEnemyLKP, ignore_monsters, ENT( pev ), &tr );
if( tr.flFraction == 1.0f )
7 years ago
{
MakeIdealYaw( pev->origin + gpGlobals->v_right * 256.0f );
7 years ago
fSkip = TRUE;
TaskComplete();
}
}
8 years ago
if( !fSkip )
7 years ago
{
UTIL_TraceLine( Center() - gpGlobals->v_forward * 256.0f, m_vecEnemyLKP, ignore_monsters, ENT( pev ), &tr );
if( tr.flFraction == 1.0f )
7 years ago
{
MakeIdealYaw( pev->origin - gpGlobals->v_right * 256.0f );
7 years ago
fSkip = TRUE;
TaskComplete();
}
}
8 years ago
if( !fSkip )
7 years ago
{
TaskFail();
}
}
else
{
8 years ago
ALERT( at_aiconsole, "AGRunt - no enemy monster ptr!!!\n" );
7 years ago
TaskFail();
}
break;
default:
8 years ago
CSquadMonster::StartTask( pTask );
7 years ago
break;
}
}
//=========================================================
// 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.
//=========================================================
8 years ago
Schedule_t *CAGrunt::GetSchedule( void )
7 years ago
{
8 years ago
if( HasConditions( bits_COND_HEAR_SOUND ) )
7 years ago
{
CSound *pSound;
pSound = PBestSound();
ASSERT( pSound != NULL );
8 years ago
if( pSound && ( pSound->m_iType & bits_SOUND_DANGER ) )
7 years ago
{
// dangerous sound nearby!
return GetScheduleOfType( SCHED_TAKE_COVER_FROM_BEST_SOUND );
}
}
8 years ago
switch( m_MonsterState )
7 years ago
{
case MONSTERSTATE_COMBAT:
{
// dead enemy
8 years ago
if( HasConditions( bits_COND_ENEMY_DEAD ) )
7 years ago
{
// call base class, all code to handle dead enemies is centralized there.
8 years ago
return CBaseMonster::GetSchedule();
7 years ago
}
8 years ago
if( HasConditions( bits_COND_NEW_ENEMY ) )
7 years ago
{
return GetScheduleOfType( SCHED_WAKE_ANGRY );
}
// zap player!
8 years ago
if( HasConditions( bits_COND_CAN_MELEE_ATTACK1 ) )
7 years ago
{
AttackSound();// this is a total hack. Should be parto f the schedule
8 years ago
return GetScheduleOfType( SCHED_MELEE_ATTACK1 );
7 years ago
}
8 years ago
if( HasConditions( bits_COND_HEAVY_DAMAGE ) )
7 years ago
{
return GetScheduleOfType( SCHED_SMALL_FLINCH );
}
// can attack
8 years ago
if( HasConditions( bits_COND_CAN_RANGE_ATTACK1 ) && OccupySlot ( bits_SLOTS_AGRUNT_HORNET ) )
7 years ago
{
8 years ago
return GetScheduleOfType( SCHED_RANGE_ATTACK1 );
7 years ago
}
/*if( OccupySlot ( bits_SLOT_AGRUNT_CHASE ) )
7 years ago
{
8 years ago
return GetScheduleOfType( SCHED_CHASE_ENEMY );
}*/
7 years ago
8 years ago
return GetScheduleOfType( SCHED_STANDOFF );
7 years ago
}
break;
default:
break;
}
8 years ago
return CSquadMonster::GetSchedule();
7 years ago
}
//=========================================================
//=========================================================
8 years ago
Schedule_t *CAGrunt::GetScheduleOfType( int Type )
7 years ago
{
switch( Type )
7 years ago
{
case SCHED_TAKE_COVER_FROM_ENEMY:
8 years ago
return &slAGruntTakeCoverFromEnemy[0];
7 years ago
break;
case SCHED_RANGE_ATTACK1:
8 years ago
if( HasConditions( bits_COND_SEE_ENEMY ) )
7 years ago
{
//normal attack
8 years ago
return &slAGruntRangeAttack1[0];
7 years ago
}
else
{
// attack an unseen enemy
8 years ago
// return &slAGruntHiddenRangeAttack[0];
return &slAGruntRangeAttack1[0];
7 years ago
}
break;
case SCHED_AGRUNT_THREAT_DISPLAY:
8 years ago
return &slAGruntThreatDisplay[0];
7 years ago
break;
case SCHED_AGRUNT_SUPPRESS:
8 years ago
return &slAGruntSuppress[0];
7 years ago
break;
case SCHED_STANDOFF:
8 years ago
return &slAGruntStandoff[0];
7 years ago
break;
case SCHED_VICTORY_DANCE:
8 years ago
return &slAGruntVictoryDance[0];
7 years ago
break;
case SCHED_FAIL:
// no fail schedule specified, so pick a good generic one.
{
if( m_hEnemy != 0 )
7 years ago
{
// I have an enemy
// !!!LATER - what if this enemy is really far away and i'm chasing him?
// this schedule will make me stop, face his last known position for 2
// seconds, and then try to move again
8 years ago
return &slAGruntCombatFail[0];
7 years ago
}
8 years ago
return &slAGruntFail[0];
7 years ago
}
break;
}
8 years ago
return CSquadMonster::GetScheduleOfType( Type );
7 years ago
}
void CAGrunt::Killed( entvars_t *pevAttacker, int iGib )
{
if ( pev->spawnflags & SF_MONSTER_NO_WPN_DROP )
{// drop the hornetgun!
Vector vecGunPos;
Vector vecGunAngles;
pev->body = AGRUNT_BODY_NOGUN;
GetAttachment( 0, vecGunPos, vecGunAngles );
DropItem( "weapon_hornetgun", vecGunPos, vecGunAngles );
}
CBaseMonster::Killed( pevAttacker, iGib );
}