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.

993 lines
25 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.
*
****/
#if !defined( OEM_BUILD ) && !defined( HLDEMO_BUILD )
//=========================================================
// hassassin - Human assassin, fast and stealthy
//=========================================================
#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 "game.h"
extern DLL_GLOBAL int g_iSkillLevel;
//=========================================================
// monster-specific schedule types
//=========================================================
enum
{
SCHED_ASSASSIN_EXPOSED = LAST_COMMON_SCHEDULE + 1,// cover was blown.
SCHED_ASSASSIN_JUMP, // fly through the air
SCHED_ASSASSIN_JUMP_ATTACK, // fly through the air and shoot
SCHED_ASSASSIN_JUMP_LAND // hit and run away
9 years ago
};
//=========================================================
// monster-specific tasks
//=========================================================
enum
{
TASK_ASSASSIN_FALL_TO_GROUND = LAST_COMMON_TASK + 1 // falling and waiting to hit ground
9 years ago
};
//=========================================================
// Monster's Anim Events Go Here
//=========================================================
#define ASSASSIN_AE_SHOOT1 1
#define ASSASSIN_AE_TOSS1 2
#define ASSASSIN_AE_JUMP 3
9 years ago
#define bits_MEMORY_BADJUMP ( bits_MEMORY_CUSTOM1 )
9 years ago
class CHAssassin : public CBaseMonster
{
public:
void Spawn( void );
void Precache( void );
void SetYawSpeed ( void );
9 years ago
int Classify( void );
int ISoundMask( void);
9 years ago
void Shoot( void );
void HandleAnimEvent( MonsterEvent_t *pEvent );
9 years ago
Schedule_t *GetSchedule( void );
Schedule_t *GetScheduleOfType( int Type );
BOOL CheckMeleeAttack1( float flDot, float flDist ); // jump
// BOOL CheckMeleeAttack2( float flDot, float flDist );
BOOL CheckRangeAttack1( float flDot, float flDist ); // shoot
BOOL CheckRangeAttack2( float flDot, float flDist ); // throw grenade
void StartTask( Task_t *pTask );
9 years ago
void RunAI( void );
9 years ago
void RunTask( Task_t *pTask );
void DeathSound( void );
void IdleSound( void );
CUSTOM_SCHEDULES
9 years ago
9 years ago
int Save( CSave &save );
9 years ago
int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
float m_flLastShot;
float m_flDiviation;
float m_flNextJump;
Vector m_vecJumpVelocity;
float m_flNextGrenadeCheck;
Vector m_vecTossVelocity;
9 years ago
BOOL m_fThrowGrenade;
9 years ago
9 years ago
int m_iTargetRanderamt;
9 years ago
9 years ago
int m_iFrustration;
9 years ago
9 years ago
int m_iShell;
9 years ago
};
LINK_ENTITY_TO_CLASS( monster_human_assassin, CHAssassin )
9 years ago
9 years ago
TYPEDESCRIPTION CHAssassin::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CHAssassin, m_flLastShot, FIELD_TIME ),
DEFINE_FIELD( CHAssassin, m_flDiviation, FIELD_FLOAT ),
DEFINE_FIELD( CHAssassin, m_flNextJump, FIELD_TIME ),
DEFINE_FIELD( CHAssassin, m_vecJumpVelocity, FIELD_VECTOR ),
DEFINE_FIELD( CHAssassin, m_flNextGrenadeCheck, FIELD_TIME ),
DEFINE_FIELD( CHAssassin, m_vecTossVelocity, FIELD_VECTOR ),
DEFINE_FIELD( CHAssassin, m_fThrowGrenade, FIELD_BOOLEAN ),
DEFINE_FIELD( CHAssassin, m_iTargetRanderamt, FIELD_INTEGER ),
DEFINE_FIELD( CHAssassin, m_iFrustration, FIELD_INTEGER ),
};
IMPLEMENT_SAVERESTORE( CHAssassin, CBaseMonster )
9 years ago
//=========================================================
// DieSound
//=========================================================
9 years ago
void CHAssassin::DeathSound( void )
9 years ago
{
}
//=========================================================
// IdleSound
//=========================================================
9 years ago
void CHAssassin::IdleSound( void )
9 years ago
{
}
//=========================================================
// ISoundMask - returns a bit mask indicating which types
// of sounds this monster regards.
//=========================================================
9 years ago
int CHAssassin::ISoundMask( void )
9 years ago
{
9 years ago
return bits_SOUND_WORLD |
bits_SOUND_COMBAT |
bits_SOUND_DANGER |
bits_SOUND_PLAYER;
9 years ago
}
//=========================================================
// Classify - indicates this monster's place in the
// relationship table.
//=========================================================
9 years ago
int CHAssassin::Classify( void )
9 years ago
{
9 years ago
return CLASS_HUMAN_MILITARY;
9 years ago
}
//=========================================================
// SetYawSpeed - allows each sequence to have a different
// turn rate associated with it.
//=========================================================
9 years ago
void CHAssassin::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 = 360;
break;
9 years ago
default:
9 years ago
ys = 360;
break;
}
pev->yaw_speed = ys;
}
//=========================================================
// Shoot
//=========================================================
9 years ago
void CHAssassin::Shoot( void )
9 years ago
{
if( m_hEnemy == 0 )
9 years ago
{
return;
}
Vector vecShootOrigin = GetGunPosition();
Vector vecShootDir = ShootAtEnemy( vecShootOrigin );
if( m_flLastShot + 2.0f < gpGlobals->time )
9 years ago
{
m_flDiviation = 0.10f;
9 years ago
}
else
{
m_flDiviation -= 0.01f;
if( m_flDiviation < 0.02f )
m_flDiviation = 0.02f;
9 years ago
}
m_flLastShot = gpGlobals->time;
9 years ago
UTIL_MakeVectors( pev->angles );
9 years ago
9 years ago
Vector vecShellVelocity = gpGlobals->v_right * RANDOM_FLOAT( 40, 90 ) + gpGlobals->v_up * RANDOM_FLOAT( 75, 200 ) + gpGlobals->v_forward * RANDOM_FLOAT( -40, 40 );
EjectBrass( pev->origin + gpGlobals->v_up * 32 + gpGlobals->v_forward * 12, vecShellVelocity, pev->angles.y, m_iShell, TE_BOUNCE_SHELL );
FireBullets( 1, vecShootOrigin, vecShootDir, Vector( m_flDiviation, m_flDiviation, m_flDiviation ), 2048, BULLET_MONSTER_9MM ); // shoot +-8 degrees
9 years ago
9 years ago
switch( RANDOM_LONG( 0, 1 ) )
9 years ago
{
case 0:
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "weapons/pl_gun1.wav", RANDOM_FLOAT( 0.6f, 0.8f ), ATTN_NORM );
9 years ago
break;
case 1:
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "weapons/pl_gun2.wav", RANDOM_FLOAT( 0.6f, 0.8f ), ATTN_NORM );
9 years ago
break;
}
pev->effects |= EF_MUZZLEFLASH;
Vector angDir = UTIL_VecToAngles( vecShootDir );
SetBlending( 0, angDir.x );
m_cAmmoLoaded--;
}
//=========================================================
// 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 CHAssassin::HandleAnimEvent( MonsterEvent_t *pEvent )
9 years ago
{
switch( pEvent->event )
{
case ASSASSIN_AE_SHOOT1:
9 years ago
Shoot();
9 years ago
break;
case ASSASSIN_AE_TOSS1:
{
UTIL_MakeVectors( pev->angles );
9 years ago
CGrenade::ShootTimed( pev, pev->origin + gpGlobals->v_forward * 34 + Vector( 0, 0, 32 ), m_vecTossVelocity, 2.0 );
9 years ago
m_flNextGrenadeCheck = gpGlobals->time + 6.0f;// wait six seconds before even looking again to see if a grenade can be thrown.
9 years ago
m_fThrowGrenade = FALSE;
// !!!LATER - when in a group, only try to throw grenade if ordered.
}
break;
case ASSASSIN_AE_JUMP:
{
// ALERT( at_console, "jumping");
UTIL_MakeAimVectors( pev->angles );
pev->movetype = MOVETYPE_TOSS;
pev->flags &= ~FL_ONGROUND;
pev->velocity = m_vecJumpVelocity;
m_flNextJump = gpGlobals->time + 3.0f;
9 years ago
}
return;
default:
CBaseMonster::HandleAnimEvent( pEvent );
break;
}
}
//=========================================================
// Spawn
//=========================================================
9 years ago
void CHAssassin::Spawn()
9 years ago
{
9 years ago
Precache();
9 years ago
9 years ago
SET_MODEL( ENT( pev ), "models/hassassin.mdl" );
UTIL_SetSize( pev, VEC_HUMAN_HULL_MIN, VEC_HUMAN_HULL_MAX );
9 years ago
9 years ago
pev->solid = SOLID_SLIDEBOX;
9 years ago
pev->movetype = MOVETYPE_STEP;
m_bloodColor = BLOOD_COLOR_RED;
pev->effects = 0;
9 years ago
pev->health = gSkillData.hassassinHealth;
9 years ago
m_flFieldOfView = VIEW_FIELD_WIDE; // indicates the width of this monster's forward view cone ( as a dotproduct result )
m_MonsterState = MONSTERSTATE_NONE;
m_afCapability = bits_CAP_MELEE_ATTACK1 | bits_CAP_DOORS_GROUP;
pev->friction = 1;
m_HackedGunPos = Vector( 0, 24, 48 );
m_iTargetRanderamt = 20;
pev->renderamt = 20;
pev->rendermode = kRenderTransTexture;
MonsterInit();
}
//=========================================================
// Precache - precaches all resources this monster needs
//=========================================================
9 years ago
void CHAssassin::Precache()
9 years ago
{
9 years ago
PRECACHE_MODEL( "models/hassassin.mdl" );
9 years ago
9 years ago
PRECACHE_SOUND( "weapons/pl_gun1.wav" );
PRECACHE_SOUND( "weapons/pl_gun2.wav" );
9 years ago
9 years ago
PRECACHE_SOUND( "debris/beamstart1.wav" );
9 years ago
9 years ago
m_iShell = PRECACHE_MODEL( "models/shell.mdl" );// brass shell
9 years ago
}
//=========================================================
// AI Schedules Specific to this monster
//=========================================================
//=========================================================
// Fail Schedule
//=========================================================
9 years ago
Task_t tlAssassinFail[] =
9 years ago
{
9 years ago
{ TASK_STOP_MOVING, 0 },
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_WAIT_FACE_ENEMY, (float)2 },
// { TASK_WAIT_PVS, (float)0 },
{ TASK_SET_SCHEDULE, (float)SCHED_CHASE_ENEMY },
9 years ago
};
9 years ago
Schedule_t slAssassinFail[] =
9 years ago
{
{
tlAssassinFail,
9 years ago
ARRAYSIZE( tlAssassinFail ),
bits_COND_LIGHT_DAMAGE |
bits_COND_HEAVY_DAMAGE |
bits_COND_PROVOKED |
9 years ago
bits_COND_CAN_RANGE_ATTACK1 |
bits_COND_CAN_RANGE_ATTACK2 |
bits_COND_CAN_MELEE_ATTACK1 |
bits_COND_HEAR_SOUND,
bits_SOUND_DANGER |
bits_SOUND_PLAYER,
"AssassinFail"
},
};
//=========================================================
// Enemy exposed Agrunt's cover
//=========================================================
9 years ago
Task_t tlAssassinExposed[] =
9 years ago
{
9 years ago
{ TASK_STOP_MOVING, (float)0 },
{ TASK_RANGE_ATTACK1, (float)0 },
{ TASK_SET_FAIL_SCHEDULE, (float)SCHED_ASSASSIN_JUMP },
{ TASK_SET_SCHEDULE, (float)SCHED_TAKE_COVER_FROM_ENEMY },
9 years ago
};
Schedule_t slAssassinExposed[] =
{
{
tlAssassinExposed,
9 years ago
ARRAYSIZE( tlAssassinExposed ),
9 years ago
bits_COND_CAN_MELEE_ATTACK1,
0,
"AssassinExposed",
},
};
//=========================================================
// Take cover from enemy! Tries lateral cover before node
// cover!
//=========================================================
Task_t tlAssassinTakeCoverFromEnemy[] =
{
9 years ago
{ TASK_STOP_MOVING, (float)0 },
{ TASK_WAIT, (float)0.2 },
{ TASK_SET_FAIL_SCHEDULE, (float)SCHED_RANGE_ATTACK1 },
{ TASK_FIND_COVER_FROM_ENEMY, (float)0 },
{ TASK_RUN_PATH, (float)0 },
{ TASK_WAIT_FOR_MOVEMENT, (float)0 },
{ TASK_REMEMBER, (float)bits_MEMORY_INCOVER },
{ TASK_FACE_ENEMY, (float)0 },
9 years ago
};
9 years ago
Schedule_t slAssassinTakeCoverFromEnemy[] =
9 years ago
{
9 years ago
{
9 years ago
tlAssassinTakeCoverFromEnemy,
9 years ago
ARRAYSIZE( tlAssassinTakeCoverFromEnemy ),
9 years ago
bits_COND_NEW_ENEMY |
9 years ago
bits_COND_CAN_MELEE_ATTACK1 |
9 years ago
bits_COND_HEAR_SOUND,
bits_SOUND_DANGER,
"AssassinTakeCoverFromEnemy"
},
};
//=========================================================
// Take cover from enemy! Tries lateral cover before node
// cover!
//=========================================================
9 years ago
Task_t tlAssassinTakeCoverFromEnemy2[] =
{
{ TASK_STOP_MOVING, (float)0 },
{ TASK_WAIT, (float)0.2 },
{ TASK_FACE_ENEMY, (float)0 },
{ TASK_RANGE_ATTACK1, (float)0 },
{ TASK_SET_FAIL_SCHEDULE, (float)SCHED_RANGE_ATTACK2 },
{ TASK_FIND_FAR_NODE_COVER_FROM_ENEMY, (float)384 },
{ TASK_RUN_PATH, (float)0 },
{ TASK_WAIT_FOR_MOVEMENT, (float)0 },
{ TASK_REMEMBER, (float)bits_MEMORY_INCOVER },
{ TASK_FACE_ENEMY, (float)0 },
9 years ago
};
9 years ago
Schedule_t slAssassinTakeCoverFromEnemy2[] =
9 years ago
{
9 years ago
{
9 years ago
tlAssassinTakeCoverFromEnemy2,
9 years ago
ARRAYSIZE( tlAssassinTakeCoverFromEnemy2 ),
9 years ago
bits_COND_NEW_ENEMY |
9 years ago
bits_COND_CAN_MELEE_ATTACK2 |
9 years ago
bits_COND_HEAR_SOUND,
bits_SOUND_DANGER,
"AssassinTakeCoverFromEnemy2"
},
};
//=========================================================
// hide from the loudest sound source
//=========================================================
9 years ago
Task_t tlAssassinTakeCoverFromBestSound[] =
9 years ago
{
9 years ago
{ TASK_SET_FAIL_SCHEDULE, (float)SCHED_MELEE_ATTACK1 },
{ TASK_STOP_MOVING, (float)0 },
{ TASK_FIND_COVER_FROM_BEST_SOUND, (float)0 },
{ TASK_RUN_PATH, (float)0 },
{ TASK_WAIT_FOR_MOVEMENT, (float)0 },
{ TASK_REMEMBER, (float)bits_MEMORY_INCOVER },
{ TASK_TURN_LEFT, (float)179 },
9 years ago
};
9 years ago
Schedule_t slAssassinTakeCoverFromBestSound[] =
9 years ago
{
9 years ago
{
9 years ago
tlAssassinTakeCoverFromBestSound,
9 years ago
ARRAYSIZE( tlAssassinTakeCoverFromBestSound ),
9 years ago
bits_COND_NEW_ENEMY,
0,
"AssassinTakeCoverFromBestSound"
},
};
//=========================================================
// AlertIdle Schedules
//=========================================================
9 years ago
Task_t tlAssassinHide[] =
9 years ago
{
9 years ago
{ TASK_STOP_MOVING, 0 },
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_WAIT, (float)2 },
{ TASK_SET_SCHEDULE, (float)SCHED_CHASE_ENEMY },
9 years ago
};
9 years ago
Schedule_t slAssassinHide[] =
9 years ago
{
9 years ago
{
9 years ago
tlAssassinHide,
9 years ago
ARRAYSIZE( tlAssassinHide ),
bits_COND_NEW_ENEMY |
bits_COND_SEE_ENEMY |
bits_COND_SEE_FEAR |
bits_COND_LIGHT_DAMAGE |
bits_COND_HEAVY_DAMAGE |
bits_COND_PROVOKED |
9 years ago
bits_COND_HEAR_SOUND,
bits_SOUND_DANGER,
"AssassinHide"
},
};
//=========================================================
// HUNT Schedules
//=========================================================
9 years ago
Task_t tlAssassinHunt[] =
9 years ago
{
9 years ago
{ TASK_GET_PATH_TO_ENEMY, (float)0 },
{ TASK_RUN_PATH, (float)0 },
{ TASK_WAIT_FOR_MOVEMENT, (float)0 },
9 years ago
};
Schedule_t slAssassinHunt[] =
{
9 years ago
{
9 years ago
tlAssassinHunt,
9 years ago
ARRAYSIZE( tlAssassinHunt ),
bits_COND_NEW_ENEMY |
// bits_COND_SEE_ENEMY |
bits_COND_CAN_RANGE_ATTACK1 |
9 years ago
bits_COND_HEAR_SOUND,
bits_SOUND_DANGER,
"AssassinHunt"
},
};
//=========================================================
// Jumping Schedules
//=========================================================
9 years ago
Task_t tlAssassinJump[] =
9 years ago
{
9 years ago
{ TASK_STOP_MOVING, (float)0 },
{ TASK_PLAY_SEQUENCE, (float)ACT_HOP },
{ TASK_SET_SCHEDULE, (float)SCHED_ASSASSIN_JUMP_ATTACK },
9 years ago
};
9 years ago
Schedule_t slAssassinJump[] =
9 years ago
{
9 years ago
{
9 years ago
tlAssassinJump,
9 years ago
ARRAYSIZE( tlAssassinJump ),
9 years ago
0,
0,
"AssassinJump"
},
};
//=========================================================
// repel
//=========================================================
9 years ago
Task_t tlAssassinJumpAttack[] =
9 years ago
{
9 years ago
{ TASK_SET_FAIL_SCHEDULE, (float)SCHED_ASSASSIN_JUMP_LAND },
// { TASK_SET_ACTIVITY, (float)ACT_FLY },
{ TASK_ASSASSIN_FALL_TO_GROUND, (float)0 },
9 years ago
};
9 years ago
Schedule_t slAssassinJumpAttack[] =
9 years ago
{
9 years ago
{
9 years ago
tlAssassinJumpAttack,
9 years ago
ARRAYSIZE( tlAssassinJumpAttack ),
9 years ago
0,
0,
"AssassinJumpAttack"
},
};
//=========================================================
// repel
//=========================================================
Task_t tlAssassinJumpLand[] =
{
9 years ago
{ TASK_SET_FAIL_SCHEDULE, (float)SCHED_ASSASSIN_EXPOSED },
// { TASK_SET_FAIL_SCHEDULE, (float)SCHED_MELEE_ATTACK1 },
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_REMEMBER, (float)bits_MEMORY_BADJUMP },
{ TASK_FIND_NODE_COVER_FROM_ENEMY, (float)0 },
{ TASK_RUN_PATH, (float)0 },
{ TASK_FORGET, (float)bits_MEMORY_BADJUMP },
{ TASK_WAIT_FOR_MOVEMENT, (float)0 },
{ TASK_REMEMBER, (float)bits_MEMORY_INCOVER },
{ TASK_FACE_ENEMY, (float)0 },
{ TASK_SET_FAIL_SCHEDULE, (float)SCHED_RANGE_ATTACK1 },
9 years ago
};
9 years ago
Schedule_t slAssassinJumpLand[] =
9 years ago
{
9 years ago
{
9 years ago
tlAssassinJumpLand,
9 years ago
ARRAYSIZE( tlAssassinJumpLand ),
0,
9 years ago
0,
"AssassinJumpLand"
},
};
DEFINE_CUSTOM_SCHEDULES( CHAssassin )
{
slAssassinFail,
slAssassinExposed,
slAssassinTakeCoverFromEnemy,
slAssassinTakeCoverFromEnemy2,
slAssassinTakeCoverFromBestSound,
slAssassinHide,
slAssassinHunt,
slAssassinJump,
slAssassinJumpAttack,
slAssassinJumpLand,
};
IMPLEMENT_CUSTOM_SCHEDULES( CHAssassin, CBaseMonster )
9 years ago
//=========================================================
// CheckMeleeAttack1 - jump like crazy if the enemy gets too close.
//=========================================================
9 years ago
BOOL CHAssassin::CheckMeleeAttack1( float flDot, float flDist )
9 years ago
{
if( m_flNextJump < gpGlobals->time && ( flDist <= 128.0f || HasMemory( bits_MEMORY_BADJUMP ) ) && m_hEnemy != 0 )
9 years ago
{
9 years ago
TraceResult tr;
9 years ago
Vector vecDest = pev->origin + Vector( RANDOM_FLOAT( -64, 64), RANDOM_FLOAT( -64, 64 ), 160 );
9 years ago
UTIL_TraceHull( pev->origin + Vector( 0, 0, 36 ), vecDest + Vector( 0, 0, 36 ), dont_ignore_monsters, human_hull, ENT( pev ), &tr );
9 years ago
if( tr.fStartSolid || tr.flFraction < 1.0f )
9 years ago
{
return FALSE;
}
float flGravity = g_psv_gravity->value;
float time = sqrt( 160.0f / ( 0.5f * flGravity ) );
float speed = flGravity * time / 160.0f;
9 years ago
m_vecJumpVelocity = ( vecDest - pev->origin ) * speed;
9 years ago
return TRUE;
}
return FALSE;
}
//=========================================================
// CheckRangeAttack1 - drop a cap in their ass
//
//=========================================================
9 years ago
BOOL CHAssassin::CheckRangeAttack1( float flDot, float flDist )
9 years ago
{
9 years ago
if( !HasConditions( bits_COND_ENEMY_OCCLUDED ) && flDist > 64 && flDist <= 2048 /* && flDot >= 0.5 */ /* && NoFriendlyFire() */ )
9 years ago
{
9 years ago
TraceResult tr;
9 years ago
Vector vecSrc = GetGunPosition();
// verify that a bullet fired from the gun will hit the enemy before the world.
9 years ago
UTIL_TraceLine( vecSrc, m_hEnemy->BodyTarget( vecSrc ), dont_ignore_monsters, ENT( pev ), &tr );
9 years ago
9 years ago
if( tr.flFraction == 1 || tr.pHit == m_hEnemy->edict() )
9 years ago
{
return TRUE;
}
}
return FALSE;
}
//=========================================================
// CheckRangeAttack2 - toss grenade is enemy gets in the way and is too close.
//=========================================================
9 years ago
BOOL CHAssassin::CheckRangeAttack2( float flDot, float flDist )
9 years ago
{
m_fThrowGrenade = FALSE;
9 years ago
if( !FBitSet( m_hEnemy->pev->flags, FL_ONGROUND ) )
9 years ago
{
// don't throw grenades at anything that isn't on the ground!
return FALSE;
}
// don't get grenade happy unless the player starts to piss you off
9 years ago
if( m_iFrustration <= 2 )
9 years ago
return FALSE;
9 years ago
if( m_flNextGrenadeCheck < gpGlobals->time && !HasConditions( bits_COND_ENEMY_OCCLUDED ) && flDist <= 512 /* && flDot >= 0.5 */ /* && NoFriendlyFire() */ )
9 years ago
{
9 years ago
Vector vecToss = VecCheckThrow( pev, GetGunPosition(), m_hEnemy->Center(), flDist, 0.5 ); // use dist as speed to get there in 1 second
9 years ago
9 years ago
if( vecToss != g_vecZero )
9 years ago
{
m_vecTossVelocity = vecToss;
// throw a hand grenade
m_fThrowGrenade = TRUE;
return TRUE;
}
}
return FALSE;
}
//=========================================================
// RunAI
//=========================================================
9 years ago
void CHAssassin::RunAI( void )
9 years ago
{
9 years ago
CBaseMonster::RunAI();
9 years ago
// always visible if moving
// always visible is not on hard
if( g_iSkillLevel != SKILL_HARD || m_hEnemy == 0 || pev->deadflag != DEAD_NO || m_Activity == ACT_RUN || m_Activity == ACT_WALK || !( pev->flags & FL_ONGROUND ) )
9 years ago
m_iTargetRanderamt = 255;
else
m_iTargetRanderamt = 20;
9 years ago
if( pev->renderamt > m_iTargetRanderamt )
9 years ago
{
9 years ago
if( pev->renderamt == 255 )
9 years ago
{
9 years ago
EMIT_SOUND( ENT( pev ), CHAN_BODY, "debris/beamstart1.wav", 0.2, ATTN_NORM );
9 years ago
}
pev->renderamt = Q_max( pev->renderamt - 50, m_iTargetRanderamt );
9 years ago
pev->rendermode = kRenderTransTexture;
}
9 years ago
else if( pev->renderamt < m_iTargetRanderamt )
9 years ago
{
pev->renderamt = Q_min( pev->renderamt + 50, m_iTargetRanderamt );
9 years ago
if( pev->renderamt == 255 )
9 years ago
pev->rendermode = kRenderNormal;
}
9 years ago
if( m_Activity == ACT_RUN || m_Activity == ACT_WALK )
9 years ago
{
static int iStep = 0;
9 years ago
iStep = !iStep;
if( iStep )
9 years ago
{
switch( RANDOM_LONG( 0, 3 ) )
{
9 years ago
case 0:
EMIT_SOUND( ENT( pev ), CHAN_BODY, "player/pl_step1.wav", 0.5, ATTN_NORM );
break;
case 1:
EMIT_SOUND( ENT( pev ), CHAN_BODY, "player/pl_step3.wav", 0.5, ATTN_NORM );
break;
case 2:
EMIT_SOUND( ENT( pev ), CHAN_BODY, "player/pl_step2.wav", 0.5, ATTN_NORM );
break;
case 3:
EMIT_SOUND( ENT( pev ), CHAN_BODY, "player/pl_step4.wav", 0.5, ATTN_NORM );
break;
9 years ago
}
}
}
}
//=========================================================
// StartTask
//=========================================================
9 years ago
void CHAssassin::StartTask( Task_t *pTask )
9 years ago
{
9 years ago
switch( pTask->iTask )
9 years ago
{
case TASK_RANGE_ATTACK2:
9 years ago
if( !m_fThrowGrenade )
9 years ago
{
9 years ago
TaskComplete();
9 years ago
}
else
{
9 years ago
CBaseMonster::StartTask( pTask );
9 years ago
}
break;
case TASK_ASSASSIN_FALL_TO_GROUND:
break;
default:
9 years ago
CBaseMonster::StartTask( pTask );
9 years ago
break;
}
}
//=========================================================
// RunTask
//=========================================================
9 years ago
void CHAssassin::RunTask( Task_t *pTask )
9 years ago
{
9 years ago
switch( pTask->iTask )
9 years ago
{
case TASK_ASSASSIN_FALL_TO_GROUND:
MakeIdealYaw( m_vecEnemyLKP );
ChangeYaw( pev->yaw_speed );
9 years ago
if( m_fSequenceFinished )
9 years ago
{
9 years ago
if( pev->velocity.z > 0 )
9 years ago
{
pev->sequence = LookupSequence( "fly_up" );
}
9 years ago
else if( HasConditions( bits_COND_SEE_ENEMY ) )
9 years ago
{
pev->sequence = LookupSequence( "fly_attack" );
pev->frame = 0;
}
else
{
pev->sequence = LookupSequence( "fly_down" );
pev->frame = 0;
}
9 years ago
ResetSequenceInfo();
9 years ago
SetYawSpeed();
}
9 years ago
if( pev->flags & FL_ONGROUND )
9 years ago
{
9 years ago
// ALERT( at_console, "on ground\n" );
TaskComplete();
9 years ago
}
break;
default:
9 years ago
CBaseMonster::RunTask( 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 *CHAssassin::GetSchedule( void )
9 years ago
{
9 years ago
switch( m_MonsterState )
9 years ago
{
case MONSTERSTATE_IDLE:
case MONSTERSTATE_ALERT:
{
9 years ago
if( HasConditions( bits_COND_HEAR_SOUND ) )
9 years ago
{
CSound *pSound;
pSound = PBestSound();
ASSERT( pSound != NULL );
9 years ago
if( pSound &&( pSound->m_iType & bits_SOUND_DANGER ) )
9 years ago
{
return GetScheduleOfType( SCHED_TAKE_COVER_FROM_BEST_SOUND );
}
9 years ago
if( pSound &&( pSound->m_iType & bits_SOUND_COMBAT ) )
9 years ago
{
return GetScheduleOfType( SCHED_INVESTIGATE_SOUND );
}
}
}
break;
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
}
// flying?
9 years ago
if( pev->movetype == MOVETYPE_TOSS )
9 years ago
{
9 years ago
if( pev->flags & FL_ONGROUND )
9 years ago
{
9 years ago
// ALERT( at_console, "landed\n" );
9 years ago
// just landed
pev->movetype = MOVETYPE_STEP;
return GetScheduleOfType ( SCHED_ASSASSIN_JUMP_LAND );
}
else
{
9 years ago
// ALERT( at_console, "jump\n" );
9 years ago
// jump or jump/shoot
9 years ago
if( m_MonsterState == MONSTERSTATE_COMBAT )
return GetScheduleOfType( SCHED_ASSASSIN_JUMP );
9 years ago
else
9 years ago
return GetScheduleOfType( SCHED_ASSASSIN_JUMP_ATTACK );
9 years ago
}
}
9 years ago
if( HasConditions( bits_COND_HEAR_SOUND ) )
9 years ago
{
CSound *pSound;
pSound = PBestSound();
ASSERT( pSound != NULL );
9 years ago
if( pSound && ( pSound->m_iType & bits_SOUND_DANGER ) )
9 years ago
{
return GetScheduleOfType( SCHED_TAKE_COVER_FROM_BEST_SOUND );
}
}
9 years ago
if( HasConditions( bits_COND_LIGHT_DAMAGE ) )
9 years ago
{
m_iFrustration++;
}
9 years ago
if( HasConditions( bits_COND_HEAVY_DAMAGE ) )
9 years ago
{
m_iFrustration++;
}
// jump player!
9 years ago
if( HasConditions( bits_COND_CAN_MELEE_ATTACK1 ) )
9 years ago
{
9 years ago
// ALERT( at_console, "melee attack 1\n" );
return GetScheduleOfType( SCHED_MELEE_ATTACK1 );
9 years ago
}
// throw grenade
9 years ago
if( HasConditions( bits_COND_CAN_RANGE_ATTACK2 ) )
9 years ago
{
// ALERT( at_console, "range attack 2\n");
9 years ago
return GetScheduleOfType( SCHED_RANGE_ATTACK2 );
9 years ago
}
// spotted
9 years ago
if( HasConditions( bits_COND_SEE_ENEMY ) && HasConditions( bits_COND_ENEMY_FACING_ME ) )
9 years ago
{
9 years ago
// ALERT( at_console, "exposed\n" );
9 years ago
m_iFrustration++;
9 years ago
return GetScheduleOfType( SCHED_ASSASSIN_EXPOSED );
9 years ago
}
// can attack
9 years ago
if( HasConditions( bits_COND_CAN_RANGE_ATTACK1 ) )
9 years ago
{
9 years ago
// ALERT( at_console, "range attack 1\n" );
9 years ago
m_iFrustration = 0;
9 years ago
return GetScheduleOfType( SCHED_RANGE_ATTACK1 );
9 years ago
}
9 years ago
if( HasConditions( bits_COND_SEE_ENEMY ) )
9 years ago
{
9 years ago
// ALERT( at_console, "face\n" );
return GetScheduleOfType( SCHED_COMBAT_FACE );
9 years ago
}
// new enemy
9 years ago
if( HasConditions( bits_COND_NEW_ENEMY ) )
9 years ago
{
9 years ago
// ALERT( at_console, "take cover\n" );
return GetScheduleOfType( SCHED_TAKE_COVER_FROM_ENEMY );
9 years ago
}
9 years ago
// ALERT( at_console, "stand\n" );
return GetScheduleOfType( SCHED_ALERT_STAND );
9 years ago
}
break;
default:
break;
9 years ago
}
9 years ago
return CBaseMonster::GetSchedule();
9 years ago
}
//=========================================================
//=========================================================
9 years ago
Schedule_t *CHAssassin::GetScheduleOfType( int Type )
9 years ago
{
// ALERT( at_console, "%d\n", m_iFrustration );
9 years ago
switch( Type )
9 years ago
{
case SCHED_TAKE_COVER_FROM_ENEMY:
9 years ago
if( pev->health > 30 )
9 years ago
return slAssassinTakeCoverFromEnemy;
else
return slAssassinTakeCoverFromEnemy2;
case SCHED_TAKE_COVER_FROM_BEST_SOUND:
return slAssassinTakeCoverFromBestSound;
case SCHED_ASSASSIN_EXPOSED:
return slAssassinExposed;
case SCHED_FAIL:
9 years ago
if( m_MonsterState == MONSTERSTATE_COMBAT )
9 years ago
return slAssassinFail;
break;
case SCHED_ALERT_STAND:
9 years ago
if( m_MonsterState == MONSTERSTATE_COMBAT )
9 years ago
return slAssassinHide;
break;
case SCHED_CHASE_ENEMY:
return slAssassinHunt;
case SCHED_MELEE_ATTACK1:
9 years ago
if( pev->flags & FL_ONGROUND )
9 years ago
{
9 years ago
if( m_flNextJump > gpGlobals->time )
9 years ago
{
// can't jump yet, go ahead and fail
return slAssassinFail;
}
else
{
return slAssassinJump;
}
}
else
{
return slAssassinJumpAttack;
}
case SCHED_ASSASSIN_JUMP:
case SCHED_ASSASSIN_JUMP_ATTACK:
return slAssassinJumpAttack;
case SCHED_ASSASSIN_JUMP_LAND:
return slAssassinJumpLand;
}
9 years ago
return CBaseMonster::GetScheduleOfType( Type );
9 years ago
}
#endif