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.

1179 lines
31 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.
*
****/
//=========================================================
// 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"
//=========================================================
// monster-specific schedule types
//=========================================================
enum
{
SCHED_AGRUNT_SUPPRESS = LAST_COMMON_SCHEDULE + 1,
SCHED_AGRUNT_THREAT_DISPLAY
9 years ago
};
//=========================================================
// monster-specific tasks
//=========================================================
enum
{
TASK_AGRUNT_SETUP_HIDE_ATTACK = LAST_COMMON_TASK + 1,
TASK_AGRUNT_GET_PATH_TO_ENEMY_CORPSE
9 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
9 years ago
class CAGrunt : public CSquadMonster
{
public:
void Spawn( void );
void Precache( void );
9 years ago
void SetYawSpeed( void );
int Classify( void );
int ISoundMask( void );
9 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 );
9 years ago
}
9 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 );
9 years ago
void AlertSound( void );
9 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 );
9 years ago
int IRelationship( CBaseEntity *pTarget );
9 years ago
void StopTalking( void );
9 years ago
BOOL ShouldSpeak( void );
CUSTOM_SCHEDULES
9 years ago
9 years ago
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
9 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[];
9 years ago
BOOL m_fCanHornetAttack;
float m_flNextHornetAttackCheck;
9 years ago
float m_flNextPainTime;
// three hacky fields for speech stuff. These don't really need to be saved.
9 years ago
float m_flNextSpeakTime;
float m_flNextWordTime;
int m_iLastWord;
9 years ago
};
LINK_ENTITY_TO_CLASS( monster_alien_grunt, CAGrunt )
9 years ago
9 years ago
TYPEDESCRIPTION CAGrunt::m_SaveData[] =
9 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 )
9 years ago
9 years ago
const char *CAGrunt::pAttackHitSounds[] =
9 years ago
{
"zombie/claw_strike1.wav",
"zombie/claw_strike2.wav",
"zombie/claw_strike3.wav",
};
9 years ago
const char *CAGrunt::pAttackMissSounds[] =
9 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.
//=========================================================
9 years ago
int CAGrunt::IRelationship( CBaseEntity *pTarget )
9 years ago
{
9 years ago
if( FClassnameIs( pTarget->pev, "monster_human_grunt" ) )
9 years ago
{
return R_NM;
}
9 years ago
return CSquadMonster::IRelationship( pTarget );
9 years ago
}
//=========================================================
// ISoundMask
//=========================================================
9 years ago
int CAGrunt::ISoundMask( void )
9 years ago
{
9 years ago
return ( bits_SOUND_WORLD | bits_SOUND_COMBAT | bits_SOUND_PLAYER | bits_SOUND_DANGER );
9 years ago
}
//=========================================================
// TraceAttack
//=========================================================
9 years ago
void CAGrunt::TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType )
9 years ago
{
9 years ago
if( ptr->iHitgroup == 10 && ( bitsDamageType & ( DMG_BULLET | DMG_SLASH | DMG_CLUB ) ) )
9 years ago
{
// hit armor
9 years ago
if( pev->dmgtime != gpGlobals->time || ( RANDOM_LONG( 0, 10 ) < 1 ) )
9 years ago
{
UTIL_Ricochet( ptr->vecEndPos, RANDOM_FLOAT( 1.0f, 2.0f ) );
9 years ago
pev->dmgtime = gpGlobals->time;
}
9 years ago
if( RANDOM_LONG( 0, 1 ) == 0 )
9 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 );
9 years ago
vecTracerDir = vecTracerDir * -512.0f;
9 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
9 years ago
}
else
{
9 years ago
SpawnBlood( ptr->vecEndPos, BloodColor(), flDamage );// a little surface blood.
9 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 );
9 years ago
}
//=========================================================
// ShouldSpeak - Should this agrunt be talking?
//=========================================================
BOOL CAGrunt::ShouldSpeak( void )
{
9 years ago
if( m_flNextSpeakTime > gpGlobals->time )
9 years ago
{
// my time to talk is still in the future.
return FALSE;
}
9 years ago
if( pev->spawnflags & SF_MONSTER_GAG )
9 years ago
{
9 years ago
if( m_MonsterState != MONSTERSTATE_COMBAT )
9 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;
9 years ago
return FALSE;
}
}
return TRUE;
}
//=========================================================
// PrescheduleThink
//=========================================================
9 years ago
void CAGrunt::PrescheduleThink( void )
9 years ago
{
9 years ago
if( ShouldSpeak() )
9 years ago
{
9 years ago
if( m_flNextWordTime < gpGlobals->time )
9 years ago
{
int num = -1;
do
{
9 years ago
num = RANDOM_LONG( 0, ARRAYSIZE( pIdleSounds ) - 1 );
9 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 );
9 years ago
// is this word our last?
9 years ago
if( RANDOM_LONG( 1, 10 ) <= 1 )
9 years ago
{
// stop talking.
StopTalking();
}
else
{
m_flNextWordTime = gpGlobals->time + RANDOM_FLOAT( 0.5f, 1.0f );
9 years ago
}
}
}
}
//=========================================================
// DieSound
//=========================================================
9 years ago
void CAGrunt::DeathSound( void )
9 years ago
{
StopTalking();
EMIT_SOUND( ENT( pev ), CHAN_VOICE, pDieSounds[RANDOM_LONG( 0, ARRAYSIZE( pDieSounds ) - 1 )], 1.0f, ATTN_NORM );
9 years ago
}
//=========================================================
// AlertSound
//=========================================================
9 years ago
void CAGrunt::AlertSound( void )
9 years ago
{
StopTalking();
EMIT_SOUND( ENT( pev ), CHAN_VOICE, pAlertSounds[RANDOM_LONG( 0, ARRAYSIZE( pAlertSounds ) - 1 )], 1.0f, ATTN_NORM );
9 years ago
}
//=========================================================
// AttackSound
//=========================================================
9 years ago
void CAGrunt::AttackSound( void )
9 years ago
{
StopTalking();
EMIT_SOUND( ENT( pev ), CHAN_VOICE, pAttackSounds[RANDOM_LONG( 0, ARRAYSIZE( pAttackSounds ) - 1 )], 1.0f, ATTN_NORM );
9 years ago
}
//=========================================================
// PainSound
//=========================================================
9 years ago
void CAGrunt::PainSound( void )
9 years ago
{
9 years ago
if( m_flNextPainTime > gpGlobals->time )
9 years ago
{
return;
}
m_flNextPainTime = gpGlobals->time + 0.6f;
9 years ago
StopTalking();
EMIT_SOUND( ENT( pev ), CHAN_VOICE, pPainSounds[RANDOM_LONG( 0, ARRAYSIZE( pPainSounds ) - 1 )], 1.0f, ATTN_NORM );
9 years ago
}
//=========================================================
9 years ago
// Classify - indicates this monster's place in the
9 years ago
// relationship table.
//=========================================================
9 years ago
int CAGrunt::Classify( void )
9 years ago
{
9 years ago
return CLASS_ALIEN_MILITARY;
9 years ago
}
//=========================================================
// SetYawSpeed - allows each sequence to have a different
// turn rate associated with it.
//=========================================================
9 years ago
void CAGrunt::SetYawSpeed( void )
9 years ago
{
int ys;
9 years ago
switch( m_Activity )
9 years ago
{
case ACT_TURN_LEFT:
case ACT_TURN_RIGHT:
ys = 110;
break;
9 years ago
default:
ys = 100;
break;
9 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.
//=========================================================
9 years ago
void CAGrunt::HandleAnimEvent( MonsterEvent_t *pEvent )
9 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;
9 years ago
if( HasConditions( bits_COND_SEE_ENEMY ) )
9 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 )
9 years ago
{
angDir.x = angDir.x - 360.0f;
9 years ago
}
SetBlending( 0, angDir.x );
GetAttachment( 0, vecArmPos, vecArmDir );
vecArmPos = vecArmPos + vecDirToEnemy * 32.0f;
9 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;
9 years ago
switch( RANDOM_LONG( 0, 2 ) )
9 years ago
{
9 years ago
case 0:
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, "agrunt/ag_fire1.wav", 1.0, ATTN_NORM, 0, 100 );
break;
case 1:
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, "agrunt/ag_fire2.wav", 1.0, ATTN_NORM, 0, 100 );
break;
case 2:
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, "agrunt/ag_fire3.wav", 1.0, ATTN_NORM, 0, 100 );
break;
9 years ago
}
CBaseMonster *pHornetMonster = pHornet->MyMonsterPointer();
9 years ago
if( pHornetMonster )
9 years ago
{
pHornetMonster->m_hEnemy = m_hEnemy;
}
}
break;
case AGRUNT_AE_LEFT_FOOT:
9 years ago
switch( RANDOM_LONG( 0, 1 ) )
9 years ago
{
// left foot
9 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;
9 years ago
}
break;
case AGRUNT_AE_RIGHT_FOOT:
// right foot
9 years ago
switch( RANDOM_LONG( 0, 1 ) )
9 years ago
{
9 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 );
9 years ago
break;
9 years ago
}
break;
case AGRUNT_AE_LEFT_PUNCH:
{
CBaseEntity *pHurt = CheckTraceHullAttack( AGRUNT_MELEE_DIST, gSkillData.agruntDmgPunch, DMG_CLUB );
9 years ago
if( pHurt )
9 years ago
{
pHurt->pev->punchangle.y = -25.0f;
pHurt->pev->punchangle.x = 8.0f;
9 years ago
// OK to use gpGlobals without calling MakeVectors, cause CheckTraceHullAttack called it above.
9 years ago
if( pHurt->IsPlayer() )
9 years ago
{
// this is a player. Knock him around.
pHurt->pev->velocity = pHurt->pev->velocity + gpGlobals->v_right * 250.0f;
9 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 ) );
9 years ago
Vector vecArmPos, vecArmAng;
GetAttachment( 0, vecArmPos, vecArmAng );
9 years ago
SpawnBlood( vecArmPos, pHurt->BloodColor(), 25 );// a little surface blood.
9 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 ) );
9 years ago
}
}
break;
case AGRUNT_AE_RIGHT_PUNCH:
{
CBaseEntity *pHurt = CheckTraceHullAttack( AGRUNT_MELEE_DIST, gSkillData.agruntDmgPunch, DMG_CLUB );
9 years ago
if( pHurt )
9 years ago
{
pHurt->pev->punchangle.y = 25.0f;
pHurt->pev->punchangle.x = 8.0f;
9 years ago
// OK to use gpGlobals without calling MakeVectors, cause CheckTraceHullAttack called it above.
9 years ago
if( pHurt->IsPlayer() )
9 years ago
{
// this is a player. Knock him around.
pHurt->pev->velocity = pHurt->pev->velocity + gpGlobals->v_right * -250.0f;
9 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 ) );
9 years ago
Vector vecArmPos, vecArmAng;
GetAttachment( 0, vecArmPos, vecArmAng );
9 years ago
SpawnBlood( vecArmPos, pHurt->BloodColor(), 25 );// a little surface blood.
9 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 ) );
9 years ago
}
}
break;
default:
CSquadMonster::HandleAnimEvent( pEvent );
break;
}
}
//=========================================================
// Spawn
//=========================================================
9 years ago
void CAGrunt::Spawn()
9 years ago
{
9 years ago
Precache();
9 years ago
9 years ago
SET_MODEL( ENT( pev ), "models/agrunt.mdl" );
UTIL_SetSize( pev, Vector( -32.0f, -32.0f, 0.0f ), Vector( 32.0f, 32.0f, 64.0f ) );
9 years ago
9 years ago
pev->solid = SOLID_SLIDEBOX;
pev->movetype = MOVETYPE_STEP;
m_bloodColor = BLOOD_COLOR_GREEN;
pev->effects = 0;
pev->health = gSkillData.agruntHealth;
m_flFieldOfView = 0.2f;// indicates the width of this monster's forward view cone ( as a dotproduct result )
9 years ago
m_MonsterState = MONSTERSTATE_NONE;
m_afCapability = 0;
m_afCapability |= bits_CAP_SQUAD;
9 years ago
m_HackedGunPos = Vector( 24.0f, 64.0f, 48.0f );
9 years ago
m_flNextSpeakTime = m_flNextWordTime = gpGlobals->time + 10.0f + RANDOM_LONG( 0, 10 );
9 years ago
MonsterInit();
}
//=========================================================
// Precache - precaches all resources this monster needs
//=========================================================
9 years ago
void CAGrunt::Precache()
9 years ago
{
size_t i;
9 years ago
9 years ago
PRECACHE_MODEL( "models/agrunt.mdl" );
9 years ago
9 years ago
for( i = 0; i < ARRAYSIZE( pAttackHitSounds ); i++ )
PRECACHE_SOUND( pAttackHitSounds[i] );
9 years ago
9 years ago
for( i = 0; i < ARRAYSIZE( pAttackMissSounds ); i++ )
PRECACHE_SOUND( pAttackMissSounds[i] );
9 years ago
9 years ago
for( i = 0; i < ARRAYSIZE( pIdleSounds ); i++ )
PRECACHE_SOUND( pIdleSounds[i] );
9 years ago
9 years ago
for( i = 0; i < ARRAYSIZE( pDieSounds ); i++ )
PRECACHE_SOUND( pDieSounds[i] );
9 years ago
9 years ago
for( i = 0; i < ARRAYSIZE( pPainSounds ); i++ )
PRECACHE_SOUND( pPainSounds[i] );
9 years ago
9 years ago
for( i = 0; i < ARRAYSIZE( pAttackSounds ); i++ )
PRECACHE_SOUND( pAttackSounds[i] );
9 years ago
9 years ago
for( i = 0; i < ARRAYSIZE( pAlertSounds ); i++ )
PRECACHE_SOUND( pAlertSounds[i] );
9 years ago
PRECACHE_SOUND( "hassault/hw_shoot1.wav" );
iAgruntMuzzleFlash = PRECACHE_MODEL( "sprites/muz4.spr" );
UTIL_PrecacheOther( "hornet" );
9 years ago
}
9 years ago
//=========================================================
// AI Schedules Specific to this monster
//=========================================================
//=========================================================
// Fail Schedule
//=========================================================
9 years ago
Task_t tlAGruntFail[] =
9 years ago
{
9 years ago
{ TASK_STOP_MOVING, 0 },
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_WAIT, 2.0f },
{ TASK_WAIT_PVS, 0.0f },
9 years ago
};
9 years ago
Schedule_t slAGruntFail[] =
9 years ago
{
{
tlAGruntFail,
9 years ago
ARRAYSIZE( tlAGruntFail ),
bits_COND_CAN_RANGE_ATTACK1 |
9 years ago
bits_COND_CAN_MELEE_ATTACK1,
0,
"AGrunt Fail"
},
};
//=========================================================
// Combat Fail Schedule
//=========================================================
9 years ago
Task_t tlAGruntCombatFail[] =
9 years ago
{
9 years ago
{ TASK_STOP_MOVING, 0 },
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_WAIT_FACE_ENEMY, 2.0f },
{ TASK_WAIT_PVS, 0.0f },
9 years ago
};
9 years ago
Schedule_t slAGruntCombatFail[] =
9 years ago
{
{
tlAGruntCombatFail,
9 years ago
ARRAYSIZE( tlAGruntCombatFail ),
bits_COND_CAN_RANGE_ATTACK1 |
9 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?
//=========================================================
9 years ago
Task_t tlAGruntStandoff[] =
9 years ago
{
{ TASK_STOP_MOVING, 0.0f },
9 years ago
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_WAIT_FACE_ENEMY, 2.0f },
9 years ago
};
9 years ago
Schedule_t slAGruntStandoff[] =
9 years ago
{
{
tlAGruntStandoff,
9 years ago
ARRAYSIZE( tlAGruntStandoff ),
bits_COND_CAN_RANGE_ATTACK1 |
bits_COND_CAN_MELEE_ATTACK1 |
bits_COND_SEE_ENEMY |
bits_COND_NEW_ENEMY |
9 years ago
bits_COND_HEAR_SOUND,
bits_SOUND_DANGER,
"Agrunt Standoff"
}
};
//=========================================================
// Suppress
//=========================================================
9 years ago
Task_t tlAGruntSuppressHornet[] =
9 years ago
{
{ TASK_STOP_MOVING, 0.0f },
{ TASK_RANGE_ATTACK1, 0.0f },
9 years ago
};
Schedule_t slAGruntSuppress[] =
{
{
tlAGruntSuppressHornet,
9 years ago
ARRAYSIZE( tlAGruntSuppressHornet ),
9 years ago
0,
0,
"AGrunt Suppress Hornet",
},
};
//=========================================================
// primary range attacks
//=========================================================
9 years ago
Task_t tlAGruntRangeAttack1[] =
9 years ago
{
{ TASK_STOP_MOVING, 0.0f },
{ TASK_FACE_ENEMY, 0.0f },
{ TASK_RANGE_ATTACK1, 0.0f },
9 years ago
};
9 years ago
Schedule_t slAGruntRangeAttack1[] =
9 years ago
{
9 years ago
{
9 years ago
tlAGruntRangeAttack1,
9 years ago
ARRAYSIZE( tlAGruntRangeAttack1 ),
bits_COND_NEW_ENEMY |
bits_COND_ENEMY_DEAD |
9 years ago
bits_COND_HEAVY_DAMAGE,
0,
"AGrunt Range Attack1"
},
};
9 years ago
Task_t tlAGruntHiddenRangeAttack1[] =
9 years ago
{
9 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 },
9 years ago
};
9 years ago
Schedule_t slAGruntHiddenRangeAttack[] =
9 years ago
{
9 years ago
{
9 years ago
tlAGruntHiddenRangeAttack1,
9 years ago
ARRAYSIZE ( tlAGruntHiddenRangeAttack1 ),
bits_COND_NEW_ENEMY |
bits_COND_HEAVY_DAMAGE |
9 years ago
bits_COND_HEAR_SOUND,
bits_SOUND_DANGER,
"AGrunt Hidden Range Attack1"
},
};
//=========================================================
9 years ago
// Take cover from enemy! Tries lateral cover before node
// cover!
9 years ago
//=========================================================
9 years ago
Task_t tlAGruntTakeCoverFromEnemy[] =
9 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 },
9 years ago
{ TASK_REMEMBER, (float)bits_MEMORY_INCOVER },
{ TASK_FACE_ENEMY, 0.0f },
9 years ago
};
9 years ago
Schedule_t slAGruntTakeCoverFromEnemy[] =
9 years ago
{
9 years ago
{
9 years ago
tlAGruntTakeCoverFromEnemy,
9 years ago
ARRAYSIZE( tlAGruntTakeCoverFromEnemy ),
9 years ago
bits_COND_NEW_ENEMY,
0,
"AGruntTakeCoverFromEnemy"
},
};
//=========================================================
// Victory dance!
//=========================================================
9 years ago
Task_t tlAGruntVictoryDance[] =
9 years ago
{
{ TASK_STOP_MOVING, 0.0f },
9 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 },
9 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 },
9 years ago
};
9 years ago
Schedule_t slAGruntVictoryDance[] =
9 years ago
{
9 years ago
{
9 years ago
tlAGruntVictoryDance,
9 years ago
ARRAYSIZE( tlAGruntVictoryDance ),
bits_COND_NEW_ENEMY |
bits_COND_LIGHT_DAMAGE |
9 years ago
bits_COND_HEAVY_DAMAGE,
0,
"AGruntVictoryDance"
},
};
//=========================================================
//=========================================================
9 years ago
Task_t tlAGruntThreatDisplay[] =
9 years ago
{
{ TASK_STOP_MOVING, 0.0f },
{ TASK_FACE_ENEMY, 0.0f },
9 years ago
{ TASK_PLAY_SEQUENCE, (float)ACT_THREAT_DISPLAY },
9 years ago
};
9 years ago
Schedule_t slAGruntThreatDisplay[] =
9 years ago
{
9 years ago
{
9 years ago
tlAGruntThreatDisplay,
9 years ago
ARRAYSIZE( tlAGruntThreatDisplay ),
bits_COND_NEW_ENEMY |
bits_COND_LIGHT_DAMAGE |
9 years ago
bits_COND_HEAVY_DAMAGE,
9 years ago
bits_SOUND_PLAYER |
bits_SOUND_COMBAT |
9 years ago
bits_SOUND_WORLD,
"AGruntThreatDisplay"
},
};
DEFINE_CUSTOM_SCHEDULES( CAGrunt )
{
slAGruntFail,
slAGruntCombatFail,
slAGruntStandoff,
slAGruntSuppress,
slAGruntRangeAttack1,
slAGruntHiddenRangeAttack,
slAGruntTakeCoverFromEnemy,
slAGruntVictoryDance,
slAGruntThreatDisplay,
};
IMPLEMENT_CUSTOM_SCHEDULES( CAGrunt, CSquadMonster )
9 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.
//=========================================================
9 years ago
BOOL CAGrunt::FCanCheckAttacks( void )
9 years ago
{
9 years ago
if( !HasConditions( bits_COND_ENEMY_TOOFAR ) )
9 years ago
{
return TRUE;
}
else
{
return FALSE;
}
}
//=========================================================
// CheckMeleeAttack1 - alien grunts zap the crap out of
// any enemy that gets too close.
//=========================================================
9 years ago
BOOL CAGrunt::CheckMeleeAttack1( float flDot, float flDist )
9 years ago
{
if( HasConditions( bits_COND_SEE_ENEMY ) && flDist <= AGRUNT_MELEE_DIST && flDot >= 0.6f && m_hEnemy != 0 )
9 years ago
{
return TRUE;
}
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.
//=========================================================
9 years ago
BOOL CAGrunt::CheckRangeAttack1( float flDot, float flDist )
9 years ago
{
9 years ago
if( gpGlobals->time < m_flNextHornetAttackCheck )
9 years ago
{
return m_fCanHornetAttack;
}
if( HasConditions( bits_COND_SEE_ENEMY ) && flDist >= AGRUNT_MELEE_DIST && flDist <= 1024.0f && flDot >= 0.5f && NoFriendlyFire() )
9 years ago
{
9 years ago
TraceResult tr;
9 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 );
9 years ago
UTIL_TraceLine( vecArmPos, m_hEnemy->BodyTarget( vecArmPos ), dont_ignore_monsters, ENT( pev ), &tr );
9 years ago
if( tr.flFraction == 1.0f || tr.pHit == m_hEnemy->edict() )
9 years ago
{
m_flNextHornetAttackCheck = gpGlobals->time + RANDOM_FLOAT( 2.0f, 5.0f );
9 years ago
m_fCanHornetAttack = TRUE;
return m_fCanHornetAttack;
}
}
9 years ago
m_flNextHornetAttackCheck = gpGlobals->time + 0.2f;// don't check for half second if this check wasn't successful
9 years ago
m_fCanHornetAttack = FALSE;
return m_fCanHornetAttack;
}
//=========================================================
// StartTask
//=========================================================
9 years ago
void CAGrunt::StartTask( Task_t *pTask )
9 years ago
{
9 years ago
switch( pTask->iTask )
9 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 ) )
9 years ago
{
TaskComplete();
}
else
{
9 years ago
ALERT( at_aiconsole, "AGruntGetPathToEnemyCorpse failed!!\n" );
9 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();
9 years ago
if( pEnemyMonsterPtr )
9 years ago
{
9 years ago
Vector vecCenter;
TraceResult tr;
BOOL fSkip;
9 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 )
9 years ago
{
MakeIdealYaw( pev->origin + gpGlobals->v_right * 128.0f );
9 years ago
fSkip = TRUE;
TaskComplete();
}
9 years ago
if( !fSkip )
9 years ago
{
UTIL_TraceLine( Center() - gpGlobals->v_forward * 128.0f, m_vecEnemyLKP, ignore_monsters, ENT( pev ), &tr );
if( tr.flFraction == 1.0f )
9 years ago
{
MakeIdealYaw( pev->origin - gpGlobals->v_right * 128.0f );
9 years ago
fSkip = TRUE;
TaskComplete();
}
}
9 years ago
if( !fSkip )
9 years ago
{
UTIL_TraceLine( Center() + gpGlobals->v_forward * 256.0f, m_vecEnemyLKP, ignore_monsters, ENT( pev ), &tr );
if( tr.flFraction == 1.0f )
9 years ago
{
MakeIdealYaw( pev->origin + gpGlobals->v_right * 256.0f );
9 years ago
fSkip = TRUE;
TaskComplete();
}
}
9 years ago
if( !fSkip )
9 years ago
{
UTIL_TraceLine( Center() - gpGlobals->v_forward * 256.0f, m_vecEnemyLKP, ignore_monsters, ENT( pev ), &tr );
if( tr.flFraction == 1.0f )
9 years ago
{
MakeIdealYaw( pev->origin - gpGlobals->v_right * 256.0f );
9 years ago
fSkip = TRUE;
TaskComplete();
}
}
9 years ago
if( !fSkip )
9 years ago
{
TaskFail();
}
}
else
{
9 years ago
ALERT( at_aiconsole, "AGRunt - no enemy monster ptr!!!\n" );
9 years ago
TaskFail();
}
break;
default:
9 years ago
CSquadMonster::StartTask( pTask );
9 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.
//=========================================================
9 years ago
Schedule_t *CAGrunt::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
{
// dangerous sound nearby!
return GetScheduleOfType( SCHED_TAKE_COVER_FROM_BEST_SOUND );
}
}
9 years ago
switch( m_MonsterState )
9 years ago
{
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
}
9 years ago
if( HasConditions( bits_COND_NEW_ENEMY ) )
9 years ago
{
return GetScheduleOfType( SCHED_WAKE_ANGRY );
}
// zap player!
9 years ago
if( HasConditions( bits_COND_CAN_MELEE_ATTACK1 ) )
9 years ago
{
AttackSound();// this is a total hack. Should be parto f the schedule
9 years ago
return GetScheduleOfType( SCHED_MELEE_ATTACK1 );
9 years ago
}
9 years ago
if( HasConditions( bits_COND_HEAVY_DAMAGE ) )
9 years ago
{
return GetScheduleOfType( SCHED_SMALL_FLINCH );
}
// can attack
9 years ago
if( HasConditions( bits_COND_CAN_RANGE_ATTACK1 ) && OccupySlot ( bits_SLOTS_AGRUNT_HORNET ) )
9 years ago
{
9 years ago
return GetScheduleOfType( SCHED_RANGE_ATTACK1 );
9 years ago
}
9 years ago
if( OccupySlot ( bits_SLOT_AGRUNT_CHASE ) )
9 years ago
{
9 years ago
return GetScheduleOfType( SCHED_CHASE_ENEMY );
9 years ago
}
9 years ago
return GetScheduleOfType( SCHED_STANDOFF );
9 years ago
}
break;
default:
break;
9 years ago
}
9 years ago
return CSquadMonster::GetSchedule();
9 years ago
}
//=========================================================
//=========================================================
9 years ago
Schedule_t *CAGrunt::GetScheduleOfType( int Type )
9 years ago
{
switch( Type )
9 years ago
{
case SCHED_TAKE_COVER_FROM_ENEMY:
9 years ago
return &slAGruntTakeCoverFromEnemy[0];
9 years ago
break;
case SCHED_RANGE_ATTACK1:
9 years ago
if( HasConditions( bits_COND_SEE_ENEMY ) )
9 years ago
{
//normal attack
9 years ago
return &slAGruntRangeAttack1[0];
9 years ago
}
else
{
// attack an unseen enemy
9 years ago
// return &slAGruntHiddenRangeAttack[0];
return &slAGruntRangeAttack1[0];
9 years ago
}
break;
case SCHED_AGRUNT_THREAT_DISPLAY:
9 years ago
return &slAGruntThreatDisplay[0];
9 years ago
break;
case SCHED_AGRUNT_SUPPRESS:
9 years ago
return &slAGruntSuppress[0];
9 years ago
break;
case SCHED_STANDOFF:
9 years ago
return &slAGruntStandoff[0];
9 years ago
break;
case SCHED_VICTORY_DANCE:
9 years ago
return &slAGruntVictoryDance[0];
9 years ago
break;
case SCHED_FAIL:
// no fail schedule specified, so pick a good generic one.
{
if( m_hEnemy != 0 )
9 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
9 years ago
return &slAGruntCombatFail[0];
9 years ago
}
9 years ago
return &slAGruntFail[0];
9 years ago
}
break;
}
9 years ago
return CSquadMonster::GetScheduleOfType( Type );
9 years ago
}