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.

1208 lines
32 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 "agrunt.h"
9 years ago
//=========================================================
// 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
#define AGRUNT_WORD_LENGTH 6
LINK_ENTITY_TO_CLASS( monster_alien_grunt, CAGrunt )
9 years ago
8 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
8 years ago
const char *CAGrunt::pAttackHitSounds[] =
9 years ago
{
"zombie/claw_strike1.wav",
"zombie/claw_strike2.wav",
"zombie/claw_strike3.wav",
};
8 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.
//=========================================================
8 years ago
int CAGrunt::IRelationship( CBaseEntity *pTarget )
9 years ago
{
8 years ago
return CSquadMonster::IRelationship( pTarget );
9 years ago
}
//=========================================================
// ISoundMask
//=========================================================
8 years ago
int CAGrunt::ISoundMask( void )
9 years ago
{
8 years ago
return ( bits_SOUND_WORLD | bits_SOUND_COMBAT | bits_SOUND_PLAYER | bits_SOUND_DANGER );
9 years ago
}
//=========================================================
// TraceAttack
//=========================================================
8 years ago
void CAGrunt::TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType )
9 years ago
{
if( ptr->iHitgroup == 10 && ( bitsDamageType & ( DMG_BULLET | DMG_SLASH | DMG_CLUB ) ) )
{
// hit armor
if( pev->dmgtime != gpGlobals->time || ( RANDOM_LONG( 0, 10 ) < 1 ) )
{
UTIL_Ricochet( ptr->vecEndPos, RANDOM_FLOAT( 1.0f, 2.0f ) );
pev->dmgtime = gpGlobals->time;
}
if( RANDOM_LONG( 0, 1 ) == 0 )
{
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 );
vecTracerDir = vecTracerDir * -512.0f;
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
}
else
{
SpawnBlood( ptr->vecEndPos, BloodColor(), flDamage );// a little surface blood.
TraceBleed( flDamage, vecDir, ptr, bitsDamageType );
}
9 years ago
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 + RANDOM_LONG( 0, 10 );
9 years ago
}
//=========================================================
// ShouldSpeak - Should this agrunt be talking?
//=========================================================
BOOL CAGrunt::ShouldSpeak( void )
{
/* if( m_flNextSpeakTime > gpGlobals->time )
9 years ago
{
// my time to talk is still in the future.
return FALSE;
}
8 years ago
if( pev->spawnflags & SF_MONSTER_GAG )
9 years ago
{
8 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 FALSE;
9 years ago
}
//=========================================================
// PrescheduleThink
//=========================================================
8 years ago
void CAGrunt::PrescheduleThink( void )
9 years ago
{
8 years ago
if( ShouldSpeak() )
9 years ago
{
8 years ago
if( m_flNextWordTime < gpGlobals->time )
9 years ago
{
const char *pszSound;
9 years ago
int num = -1;
do
{
8 years ago
num = RANDOM_LONG( 0, ARRAYSIZE( pIdleSounds ) - 1 );
9 years ago
} while( num == m_iLastWord );
m_iLastWord = num;
// play a new sound
if( pev->message )
pszSound = STRING( szCustomIdleSounds[num] );
else
pszSound = pIdleSounds[num];
EMIT_SOUND( ENT( pev ), CHAN_VOICE, pszSound, 1.0, ATTN_NORM );
9 years ago
// is this word our last?
8 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
//=========================================================
8 years ago
void CAGrunt::DeathSound( void )
9 years ago
{
StopTalking();
const char *pszSound;
int iRand = RANDOM_LONG( 0, ARRAYSIZE( pDieSounds ) - 1 );
if( pev->message )
pszSound = STRING( szCustomDieSounds[iRand] );
else
pszSound = pDieSounds[iRand];
EMIT_SOUND( ENT( pev ), CHAN_VOICE, pszSound, 1.0, ATTN_NORM );
9 years ago
}
//=========================================================
// AlertSound
//=========================================================
8 years ago
void CAGrunt::AlertSound( void )
9 years ago
{
StopTalking();
const char *pszSound;
int iRand = RANDOM_LONG( 0, ARRAYSIZE( pAlertSounds ) - 1 );
if( pev->message )
pszSound = STRING( szCustomAlertSounds[iRand] );
else
pszSound = pAlertSounds[iRand];
EMIT_SOUND( ENT( pev ), CHAN_VOICE, pszSound, 1.0, ATTN_NORM );
9 years ago
}
//=========================================================
// AttackSound
//=========================================================
8 years ago
void CAGrunt::AttackSound( void )
9 years ago
{
StopTalking();
const char *pszSound;
int iRand = RANDOM_LONG( 0, ARRAYSIZE( pAttackSounds ) - 1 );
if( pev->message )
pszSound = STRING( szCustomAttackSounds[iRand] );
else
pszSound = pAttackSounds[iRand];
EMIT_SOUND( ENT( pev ), CHAN_VOICE, pszSound, 1.0, ATTN_NORM );
9 years ago
}
//=========================================================
// PainSound
//=========================================================
8 years ago
void CAGrunt::PainSound( void )
9 years ago
{
8 years ago
if( m_flNextPainTime > gpGlobals->time )
9 years ago
{
return;
}
m_flNextPainTime = gpGlobals->time + 0.6f;
9 years ago
StopTalking();
const char *pszSound;
int iRand = RANDOM_LONG( 0, ARRAYSIZE( pPainSounds ) - 1 );
if( pev->message )
pszSound = STRING( szCustomPainSounds[iRand] );
else
pszSound = pPainSounds[iRand];
EMIT_SOUND( ENT( pev ), CHAN_VOICE, pszSound, 1.0, ATTN_NORM );
9 years ago
}
//=========================================================
8 years ago
// Classify - indicates this monster's place in the
9 years ago
// relationship table.
//=========================================================
8 years ago
int CAGrunt::Classify( void )
9 years ago
{
8 years ago
return CLASS_ALIEN_MILITARY;
9 years ago
}
//=========================================================
// SetYawSpeed - allows each sequence to have a different
// turn rate associated with it.
//=========================================================
8 years ago
void CAGrunt::SetYawSpeed( void )
9 years ago
{
int ys;
8 years ago
switch( m_Activity )
9 years ago
{
case ACT_TURN_LEFT:
case ACT_TURN_RIGHT:
ys = 110;
break;
8 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.
//=========================================================
8 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;
8 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;
8 years ago
switch( RANDOM_LONG( 0, 2 ) )
9 years ago
{
8 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();
8 years ago
if( pHornetMonster )
9 years ago
{
pHornetMonster->m_hEnemy = m_hEnemy;
}
}
break;
case AGRUNT_AE_LEFT_FOOT:
8 years ago
switch( RANDOM_LONG( 0, 1 ) )
9 years ago
{
// left foot
8 years ago
case 0:
EMIT_SOUND_DYN( ENT( pev ), CHAN_BODY, "zork/leftfoot2.wav", 1, ATTN_NORM, 0, 70 );
8 years ago
break;
case 1:
EMIT_SOUND_DYN( ENT( pev ), CHAN_BODY, "zork/leftfoot4.wav", 1, ATTN_NORM, 0, 70 );
8 years ago
break;
9 years ago
}
break;
case AGRUNT_AE_RIGHT_FOOT:
// right foot
8 years ago
switch( RANDOM_LONG( 0, 1 ) )
9 years ago
{
8 years ago
case 0:
EMIT_SOUND_DYN( ENT( pev ), CHAN_BODY, "zork/rightfoot1.wav", 1, ATTN_NORM, 0, 70 );
8 years ago
break;
case 1:
EMIT_SOUND_DYN( ENT( pev ), CHAN_BODY, "zork/rightfoot3.wav", 1, ATTN_NORM, 0, 70 );
8 years ago
break;
9 years ago
}
break;
case AGRUNT_AE_LEFT_PUNCH:
{
CBaseEntity *pHurt = CheckTraceHullAttack( AGRUNT_MELEE_DIST, gSkillData.agruntDmgPunch, DMG_CLUB );
8 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.
8 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 );
8 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 );
8 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.
8 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 );
8 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
//=========================================================
8 years ago
void CAGrunt::Spawn()
9 years ago
{
8 years ago
Precache();
9 years ago
8 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
8 years ago
pev->solid = SOLID_SLIDEBOX;
pev->movetype = MOVETYPE_STEP;
m_bloodColor = BLOOD_COLOR_RED;
8 years ago
pev->effects = 0;
if( !pev->health )
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
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;
9 years ago
m_HackedGunPos = Vector( 24.0f, 64.0f, 48.0f );
9 years ago
//m_flNextSpeakTime = m_flNextWordTime = gpGlobals->time + 10 + RANDOM_LONG( 0, 10 );
9 years ago
MonsterInit();
}
//=========================================================
// Precache - precaches all resources this monster needs
//=========================================================
8 years ago
void CAGrunt::Precache()
9 years ago
{
size_t i;
9 years ago
8 years ago
PRECACHE_MODEL( "models/agrunt.mdl" );
9 years ago
8 years ago
for( i = 0; i < ARRAYSIZE( pAttackHitSounds ); i++ )
PRECACHE_SOUND( pAttackHitSounds[i] );
9 years ago
8 years ago
for( i = 0; i < ARRAYSIZE( pAttackMissSounds ); i++ )
PRECACHE_SOUND( pAttackMissSounds[i] );
9 years ago
if( pev->message )
{
char szSound[32];
strcpy( szSound, STRING( pev->message ) );
for( i = 0; i < ARRAYSIZE( pAttackSounds ); i++ )
{
strcat( szSound, pAttackSounds[i] + AGRUNT_WORD_LENGTH );
szCustomAttackSounds[i] = ALLOC_STRING( szSound );
PRECACHE_SOUND( STRING( szCustomAttackSounds[i] ) );
szSound[strlen( STRING( pev->message ) )] = 0;
}
for( i = 0; i < ARRAYSIZE( pIdleSounds ); i++ )
{
strcat( szSound, pIdleSounds[i] + AGRUNT_WORD_LENGTH );
szCustomIdleSounds[i] = ALLOC_STRING( szSound );
PRECACHE_SOUND( STRING( szCustomIdleSounds[i] ) );
szSound[strlen( STRING( pev->message ) )] = 0;
}
for( i = 0; i < ARRAYSIZE( pAlertSounds ); i++ )
{
strcat( szSound, pAlertSounds[i] + AGRUNT_WORD_LENGTH );
szCustomAlertSounds[i] = ALLOC_STRING( szSound );
PRECACHE_SOUND( STRING( szCustomAlertSounds[i] ) );
szSound[strlen( STRING( pev->message ) )] = 0;
}
for( i = 0; i < ARRAYSIZE( pPainSounds ); i++ )
{
strcat( szSound, pPainSounds[i] + AGRUNT_WORD_LENGTH );
szCustomPainSounds[i] = ALLOC_STRING( szSound );
PRECACHE_SOUND( STRING( szCustomPainSounds[i] ) );
szSound[strlen( STRING( pev->message ) )] = 0;
}
for( i = 0; i < ARRAYSIZE( pDieSounds ); i++ )
{
strcat( szSound, pDieSounds[i] + AGRUNT_WORD_LENGTH );
szCustomDieSounds[i] = ALLOC_STRING( szSound );
PRECACHE_SOUND( STRING( szCustomDieSounds[i] ) );
szSound[strlen( STRING( pev->message ) )] = 0;
}
}
else
{
for( i = 0; i < ARRAYSIZE( pAttackSounds ); i++ )
PRECACHE_SOUND( pAttackSounds[i] );
9 years ago
for( i = 0; i < ARRAYSIZE( pIdleSounds ); i++ )
PRECACHE_SOUND( pIdleSounds[i] );
9 years ago
for( i = 0; i < ARRAYSIZE( pAlertSounds ); i++ )
PRECACHE_SOUND( pAlertSounds[i] );
9 years ago
for( i = 0; i < ARRAYSIZE( pPainSounds ); i++ )
PRECACHE_SOUND( pPainSounds[i] );
9 years ago
for( i = 0; i < ARRAYSIZE( pDieSounds ); i++ )
PRECACHE_SOUND( pDieSounds[i] );
}
9 years ago
PRECACHE_SOUND( "hassault/hw_shoot1.wav" );
iAgruntMuzzleFlash = PRECACHE_MODEL( "sprites/muz4.spr" );
PRECACHE_SOUND( "zork/leftfoot2.wav" );
PRECACHE_SOUND( "zork/leftfoot4.wav" );
PRECACHE_SOUND( "zork/rightfoot1.wav" );
PRECACHE_SOUND( "zork/rightfoot3.wav" );
UTIL_PrecacheOther( "hornet" );
8 years ago
}
9 years ago
//=========================================================
// AI Schedules Specific to this monster
//=========================================================
//=========================================================
// Fail Schedule
//=========================================================
8 years ago
Task_t tlAGruntFail[] =
9 years ago
{
8 years ago
{ TASK_STOP_MOVING, 0 },
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_WAIT, 2.0f },
{ TASK_WAIT_PVS, 0.0f },
9 years ago
};
8 years ago
Schedule_t slAGruntFail[] =
9 years ago
{
{
tlAGruntFail,
8 years ago
ARRAYSIZE( tlAGruntFail ),
bits_COND_CAN_RANGE_ATTACK1 |
9 years ago
bits_COND_CAN_MELEE_ATTACK1,
0,
"AGrunt Fail"
},
};
//=========================================================
// Combat Fail Schedule
//=========================================================
8 years ago
Task_t tlAGruntCombatFail[] =
9 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 },
9 years ago
};
8 years ago
Schedule_t slAGruntCombatFail[] =
9 years ago
{
{
tlAGruntCombatFail,
8 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?
//=========================================================
8 years ago
Task_t tlAGruntStandoff[] =
9 years ago
{
{ TASK_STOP_MOVING, 0.0f },
8 years ago
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_WAIT_FACE_ENEMY, 2.0f },
9 years ago
};
8 years ago
Schedule_t slAGruntStandoff[] =
9 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 |
9 years ago
bits_COND_HEAR_SOUND,
bits_SOUND_DANGER,
"Agrunt Standoff"
}
};
//=========================================================
// Suppress
//=========================================================
8 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,
8 years ago
ARRAYSIZE( tlAGruntSuppressHornet ),
9 years ago
0,
0,
"AGrunt Suppress Hornet",
},
};
//=========================================================
// primary range attacks
//=========================================================
8 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
};
8 years ago
Schedule_t slAGruntRangeAttack1[] =
9 years ago
{
8 years ago
{
9 years ago
tlAGruntRangeAttack1,
8 years ago
ARRAYSIZE( tlAGruntRangeAttack1 ),
bits_COND_NEW_ENEMY |
bits_COND_ENEMY_DEAD |
9 years ago
bits_COND_HEAVY_DAMAGE,
0,
"AGrunt Range Attack1"
},
};
8 years ago
Task_t tlAGruntHiddenRangeAttack1[] =
9 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 },
9 years ago
};
8 years ago
Schedule_t slAGruntHiddenRangeAttack[] =
9 years ago
{
8 years ago
{
9 years ago
tlAGruntHiddenRangeAttack1,
8 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"
},
};
//=========================================================
8 years ago
// Take cover from enemy! Tries lateral cover before node
// cover!
9 years ago
//=========================================================
8 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 },
8 years ago
{ TASK_REMEMBER, (float)bits_MEMORY_INCOVER },
{ TASK_FACE_ENEMY, 0.0f },
9 years ago
};
8 years ago
Schedule_t slAGruntTakeCoverFromEnemy[] =
9 years ago
{
8 years ago
{
9 years ago
tlAGruntTakeCoverFromEnemy,
8 years ago
ARRAYSIZE( tlAGruntTakeCoverFromEnemy ),
9 years ago
bits_COND_NEW_ENEMY,
0,
"AGruntTakeCoverFromEnemy"
},
};
//=========================================================
// Victory dance!
//=========================================================
8 years ago
Task_t tlAGruntVictoryDance[] =
9 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 },
9 years ago
};
8 years ago
Schedule_t slAGruntVictoryDance[] =
9 years ago
{
8 years ago
{
9 years ago
tlAGruntVictoryDance,
8 years ago
ARRAYSIZE( tlAGruntVictoryDance ),
bits_COND_NEW_ENEMY |
bits_COND_LIGHT_DAMAGE |
9 years ago
bits_COND_HEAVY_DAMAGE,
0,
"AGruntVictoryDance"
},
};
//=========================================================
//=========================================================
8 years ago
Task_t tlAGruntThreatDisplay[] =
9 years ago
{
{ TASK_STOP_MOVING, 0.0f },
{ TASK_FACE_ENEMY, 0.0f },
8 years ago
{ TASK_PLAY_SEQUENCE, (float)ACT_THREAT_DISPLAY },
9 years ago
};
8 years ago
Schedule_t slAGruntThreatDisplay[] =
9 years ago
{
8 years ago
{
9 years ago
tlAGruntThreatDisplay,
8 years ago
ARRAYSIZE( tlAGruntThreatDisplay ),
bits_COND_NEW_ENEMY |
bits_COND_LIGHT_DAMAGE |
9 years ago
bits_COND_HEAVY_DAMAGE,
8 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.
//=========================================================
8 years ago
BOOL CAGrunt::FCanCheckAttacks( void )
9 years ago
{
8 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.
//=========================================================
8 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.
//=========================================================
8 years ago
BOOL CAGrunt::CheckRangeAttack1( float flDot, float flDist )
9 years ago
{
if( gpGlobals->time < m_flNextHornetAttackCheck )
{
return m_fCanHornetAttack;
}
if( !FBitSet( pev->spawnflags, SF_SQUADMONSTER_NOZAP ) && HasConditions( bits_COND_SEE_ENEMY ) && flDist >= AGRUNT_MELEE_DIST && flDist <= 1024.0f && flDot >= 0.5f && NoFriendlyFire() )
{
TraceResult tr;
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 );
UTIL_TraceLine( vecArmPos, m_hEnemy->BodyTarget( vecArmPos ), dont_ignore_monsters, ENT( pev ), &tr );
if( tr.flFraction == 1.0f || tr.pHit == m_hEnemy->edict() )
{
m_flNextHornetAttackCheck = gpGlobals->time + RANDOM_FLOAT( 2.0f, 5.0f );
m_fCanHornetAttack = TRUE;
return m_fCanHornetAttack;
}
}
m_flNextHornetAttackCheck = gpGlobals->time + 0.2f;// don't check for half second if this check wasn't successful
m_fCanHornetAttack = FALSE;
return m_fCanHornetAttack;
9 years ago
}
//=========================================================
// StartTask
//=========================================================
8 years ago
void CAGrunt::StartTask( Task_t *pTask )
9 years ago
{
8 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
{
8 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();
8 years ago
if( pEnemyMonsterPtr )
9 years ago
{
8 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();
}
8 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();
}
}
8 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();
}
}
8 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();
}
}
8 years ago
if( !fSkip )
9 years ago
{
TaskFail();
}
}
else
{
8 years ago
ALERT( at_aiconsole, "AGRunt - no enemy monster ptr!!!\n" );
9 years ago
TaskFail();
}
break;
default:
8 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.
//=========================================================
8 years ago
Schedule_t *CAGrunt::GetSchedule( void )
9 years ago
{
8 years ago
if( HasConditions( bits_COND_HEAR_SOUND ) )
9 years ago
{
CSound *pSound;
pSound = PBestSound();
ASSERT( pSound != NULL );
8 years ago
if( pSound && ( pSound->m_iType & bits_SOUND_DANGER ) )
9 years ago
{
// dangerous sound nearby!
return GetScheduleOfType( SCHED_TAKE_COVER_FROM_BEST_SOUND );
}
}
8 years ago
switch( m_MonsterState )
9 years ago
{
case MONSTERSTATE_COMBAT:
{
// dead enemy
8 years ago
if( HasConditions( bits_COND_ENEMY_DEAD ) )
9 years ago
{
// call base class, all code to handle dead enemies is centralized there.
8 years ago
return CBaseMonster::GetSchedule();
9 years ago
}
8 years ago
if( HasConditions( bits_COND_NEW_ENEMY ) )
9 years ago
{
return GetScheduleOfType( SCHED_WAKE_ANGRY );
}
// zap player!
8 years ago
if( HasConditions( bits_COND_CAN_MELEE_ATTACK1 ) )
9 years ago
{
AttackSound();// this is a total hack. Should be parto f the schedule
8 years ago
return GetScheduleOfType( SCHED_MELEE_ATTACK1 );
9 years ago
}
8 years ago
if( HasConditions( bits_COND_HEAVY_DAMAGE ) )
9 years ago
{
return GetScheduleOfType( SCHED_SMALL_FLINCH );
}
// can attack
8 years ago
if( HasConditions( bits_COND_CAN_RANGE_ATTACK1 ) && OccupySlot ( bits_SLOTS_AGRUNT_HORNET ) )
9 years ago
{
8 years ago
return GetScheduleOfType( SCHED_RANGE_ATTACK1 );
9 years ago
}
8 years ago
if( OccupySlot ( bits_SLOT_AGRUNT_CHASE ) )
9 years ago
{
8 years ago
return GetScheduleOfType( SCHED_CHASE_ENEMY );
9 years ago
}
8 years ago
return GetScheduleOfType( SCHED_STANDOFF );
9 years ago
}
break;
default:
break;
9 years ago
}
8 years ago
return CSquadMonster::GetSchedule();
9 years ago
}
//=========================================================
//=========================================================
8 years ago
Schedule_t *CAGrunt::GetScheduleOfType( int Type )
9 years ago
{
switch( Type )
9 years ago
{
case SCHED_TAKE_COVER_FROM_ENEMY:
8 years ago
return &slAGruntTakeCoverFromEnemy[0];
9 years ago
break;
case SCHED_RANGE_ATTACK1:
8 years ago
if( HasConditions( bits_COND_SEE_ENEMY ) )
9 years ago
{
//normal attack
8 years ago
return &slAGruntRangeAttack1[0];
9 years ago
}
else
{
// attack an unseen enemy
8 years ago
// return &slAGruntHiddenRangeAttack[0];
return &slAGruntRangeAttack1[0];
9 years ago
}
break;
case SCHED_AGRUNT_THREAT_DISPLAY:
8 years ago
return &slAGruntThreatDisplay[0];
9 years ago
break;
case SCHED_AGRUNT_SUPPRESS:
8 years ago
return &slAGruntSuppress[0];
9 years ago
break;
case SCHED_STANDOFF:
8 years ago
return &slAGruntStandoff[0];
9 years ago
break;
case SCHED_VICTORY_DANCE:
8 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
8 years ago
return &slAGruntCombatFail[0];
9 years ago
}
8 years ago
return &slAGruntFail[0];
9 years ago
}
break;
}
8 years ago
return CSquadMonster::GetScheduleOfType( Type );
9 years ago
}