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.

1047 lines
27 KiB

7 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 "scripted.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
7 years ago
};
//=========================================================
// monster-specific tasks
//=========================================================
enum
{
TASK_ASSASSIN_FALL_TO_GROUND = LAST_COMMON_TASK + 1 // falling and waiting to hit ground
7 years ago
};
//=========================================================
// Monster's Anim Events Go Here
//=========================================================
#define ASSASSIN_AE_SHOOT1 1
#define ASSASSIN_AE_TOSS1 2
#define ASSASSIN_AE_JUMP 3
8 years ago
#define bits_MEMORY_BADJUMP ( bits_MEMORY_CUSTOM1 )
7 years ago
class CHAssassin : public CBaseMonster
{
public:
void Spawn( void );
void Precache( void );
void SetYawSpeed ( void );
8 years ago
int Classify( void );
int ISoundMask( void);
7 years ago
void Shoot( void );
void HandleAnimEvent( MonsterEvent_t *pEvent );
8 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 );
7 years ago
void RunAI( void );
8 years ago
void RunTask( Task_t *pTask );
void DeathSound( void );
void IdleSound( void );
CUSTOM_SCHEDULES
7 years ago
8 years ago
int Save( CSave &save );
7 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;
8 years ago
BOOL m_fThrowGrenade;
7 years ago
8 years ago
int m_iTargetRanderamt;
7 years ago
8 years ago
int m_iFrustration;
7 years ago
8 years ago
int m_iShell;
7 years ago
};
LINK_ENTITY_TO_CLASS( monster_human_assassin, CHAssassin )
7 years ago
8 years ago
TYPEDESCRIPTION CHAssassin::m_SaveData[] =
7 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 )
7 years ago
//=========================================================
// DieSound
//=========================================================
8 years ago
void CHAssassin::DeathSound( void )
7 years ago
{
}
//=========================================================
// IdleSound
//=========================================================
8 years ago
void CHAssassin::IdleSound( void )
7 years ago
{
}
//=========================================================
// ISoundMask - returns a bit mask indicating which types
// of sounds this monster regards.
//=========================================================
8 years ago
int CHAssassin::ISoundMask( void )
7 years ago
{
8 years ago
return bits_SOUND_WORLD |
bits_SOUND_COMBAT |
bits_SOUND_DANGER |
bits_SOUND_PLAYER;
7 years ago
}
//=========================================================
// Classify - indicates this monster's place in the
// relationship table.
//=========================================================
8 years ago
int CHAssassin::Classify( void )
7 years ago
{
return m_iClass?m_iClass:CLASS_HUMAN_MILITARY;
}
//=========================================================
// SetYawSpeed - allows each sequence to have a different
// turn rate associated with it.
//=========================================================
8 years ago
void CHAssassin::SetYawSpeed( void )
7 years ago
{
int ys;
8 years ago
switch( m_Activity )
7 years ago
{
case ACT_TURN_LEFT:
case ACT_TURN_RIGHT:
ys = 360;
break;
8 years ago
default:
7 years ago
ys = 360;
break;
}
pev->yaw_speed = ys;
}
//=========================================================
// Shoot
//=========================================================
8 years ago
void CHAssassin::Shoot( void )
7 years ago
{
if (m_hEnemy == 0 && !m_pCine) //LRC
7 years ago
{
return;
}
Vector vecShootOrigin = GetGunPosition();
Vector vecShootDir = ShootAtEnemy( vecShootOrigin );
if( m_flLastShot + 2.0f < gpGlobals->time )
7 years ago
{
m_flDiviation = 0.10f;
7 years ago
}
else
{
m_flDiviation -= 0.01f;
if( m_flDiviation < 0.02f )
m_flDiviation = 0.02f;
7 years ago
}
m_flLastShot = gpGlobals->time;
8 years ago
UTIL_MakeVectors( pev->angles );
7 years ago
8 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
7 years ago
8 years ago
switch( RANDOM_LONG( 0, 1 ) )
7 years ago
{
case 0:
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "weapons/pl_gun1.wav", RANDOM_FLOAT( 0.6f, 0.8f ), ATTN_NORM );
7 years ago
break;
case 1:
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "weapons/pl_gun2.wav", RANDOM_FLOAT( 0.6f, 0.8f ), ATTN_NORM );
7 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.
//=========================================================
8 years ago
void CHAssassin::HandleAnimEvent( MonsterEvent_t *pEvent )
7 years ago
{
switch( pEvent->event )
{
case ASSASSIN_AE_SHOOT1:
8 years ago
Shoot();
7 years ago
break;
case ASSASSIN_AE_TOSS1:
{
Vector vecGunPosition = pev->origin + gpGlobals->v_forward * 34 + Vector (0, 0, 32);
UTIL_MakeVectors( pev->angles );
//LRC
if (m_pCine && m_pCine->IsAction())
{
Vector vecToss;
if (m_pCine->PreciseAttack() && m_hTargetEnt != 0)
7 years ago
{
vecToss = VecCheckToss( pev, vecGunPosition, m_hTargetEnt->pev->origin, 0.5 );
//if (vecToss != g_vecZero)
// ALERT(at_console,"Assassin %s throws precise grenade\n",STRING(pev->targetname));
}
else
{
//ALERT(at_console,"Assassin %s throws nonprecise grenade\n",STRING(pev->targetname));
// what speed would be best to use, here? Borrowing the hgrunt grenade speed seems silly...
vecToss = ((gpGlobals->v_forward*0.5)+(gpGlobals->v_up*0.5)).Normalize()*gSkillData.hgruntGrenadeSpeed;
}
CGrenade::ShootTimed( pev, vecGunPosition, vecToss, 2.0 );
}
else
CGrenade::ShootTimed( pev, vecGunPosition, m_vecTossVelocity, 2.0 );
m_flNextGrenadeCheck = gpGlobals->time + 6.0f;// wait six seconds before even looking again to see if a grenade can be thrown.
7 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;
if (m_pCine) //LRC...
{
pev->velocity = g_vecZero;
if (m_pCine->PreciseAttack() && m_hTargetEnt != 0)
7 years ago
{
Vector vecTemp = m_hTargetEnt->pev->origin;
vecTemp.y = vecTemp.y + 50; // put her feet on the target.
pev->velocity = VecCheckToss( pev, pev->origin, vecTemp, 0.5 );
//if (pev->velocity != g_vecZero)
// ALERT(at_console,"Precise jump for assassin %s\n",STRING(pev->targetname));
//else
// ALERT(at_console,"Precise jump failed. ");
}
if (pev->velocity == g_vecZero)
{ // just jump, it doesn't matter where to.
//ALERT(at_console,"Nonprecise jump for assassin %s\n",STRING(pev->targetname));
float flGravity = g_psv_gravity->value;
float time = sqrt( 160 / (0.5 * flGravity));
float speed = flGravity * time / 160;
UTIL_MakeVectors(pev->angles);
Vector vecDest = pev->origin + (gpGlobals->v_forward * 32);
vecDest.z += 160; // don't forget to jump into the air, now...
pev->velocity= (vecDest - pev->origin) * speed;
}
}
else
pev->velocity = m_vecJumpVelocity;
m_flNextJump = gpGlobals->time + 3.0f;
7 years ago
}
return;
default:
CBaseMonster::HandleAnimEvent( pEvent );
break;
}
}
//=========================================================
// Spawn
//=========================================================
8 years ago
void CHAssassin::Spawn()
7 years ago
{
8 years ago
Precache();
7 years ago
if (pev->model)
SET_MODEL(ENT(pev), STRING(pev->model)); //LRC
else
SET_MODEL( ENT( pev ), "models/hassassin.mdl" );
8 years ago
UTIL_SetSize( pev, VEC_HUMAN_HULL_MIN, VEC_HUMAN_HULL_MAX );
7 years ago
8 years ago
pev->solid = SOLID_SLIDEBOX;
7 years ago
pev->movetype = MOVETYPE_STEP;
m_bloodColor = BLOOD_COLOR_RED;
pev->effects = 0;
if (pev->health == 0)
pev->health = gSkillData.hassassinHealth;
7 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
//=========================================================
8 years ago
void CHAssassin::Precache()
7 years ago
{
if (pev->model)
PRECACHE_MODEL(STRING(pev->model)); //LRC
7 years ago
else
PRECACHE_MODEL( "models/hassassin.mdl" );
7 years ago
8 years ago
PRECACHE_SOUND( "weapons/pl_gun1.wav" );
PRECACHE_SOUND( "weapons/pl_gun2.wav" );
7 years ago
8 years ago
PRECACHE_SOUND( "debris/beamstart1.wav" );
7 years ago
8 years ago
m_iShell = PRECACHE_MODEL( "models/shell.mdl" );// brass shell
7 years ago
}
//=========================================================
// AI Schedules Specific to this monster
//=========================================================
//=========================================================
// Fail Schedule
//=========================================================
8 years ago
Task_t tlAssassinFail[] =
7 years ago
{
8 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 },
7 years ago
};
8 years ago
Schedule_t slAssassinFail[] =
7 years ago
{
{
tlAssassinFail,
8 years ago
ARRAYSIZE( tlAssassinFail ),
bits_COND_LIGHT_DAMAGE |
bits_COND_HEAVY_DAMAGE |
bits_COND_PROVOKED |
7 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
//=========================================================
8 years ago
Task_t tlAssassinExposed[] =
7 years ago
{
8 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 },
7 years ago
};
Schedule_t slAssassinExposed[] =
{
{
tlAssassinExposed,
8 years ago
ARRAYSIZE( tlAssassinExposed ),
7 years ago
bits_COND_CAN_MELEE_ATTACK1,
0,
"AssassinExposed",
},
};
//=========================================================
// Take cover from enemy! Tries lateral cover before node
// cover!
//=========================================================
Task_t tlAssassinTakeCoverFromEnemy[] =
{
8 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 },
7 years ago
};
8 years ago
Schedule_t slAssassinTakeCoverFromEnemy[] =
7 years ago
{
8 years ago
{
7 years ago
tlAssassinTakeCoverFromEnemy,
8 years ago
ARRAYSIZE( tlAssassinTakeCoverFromEnemy ),
7 years ago
bits_COND_NEW_ENEMY |
8 years ago
bits_COND_CAN_MELEE_ATTACK1 |
7 years ago
bits_COND_HEAR_SOUND,
bits_SOUND_DANGER,
"AssassinTakeCoverFromEnemy"
},
};
//=========================================================
// Take cover from enemy! Tries lateral cover before node
// cover!
//=========================================================
8 years ago
Task_t tlAssassinTakeCoverFromEnemy2[] =
7 years ago
{
8 years ago
{ 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 },
7 years ago
};
8 years ago
Schedule_t slAssassinTakeCoverFromEnemy2[] =
7 years ago
{
8 years ago
{
7 years ago
tlAssassinTakeCoverFromEnemy2,
8 years ago
ARRAYSIZE( tlAssassinTakeCoverFromEnemy2 ),
7 years ago
bits_COND_NEW_ENEMY |
8 years ago
bits_COND_CAN_MELEE_ATTACK2 |
7 years ago
bits_COND_HEAR_SOUND,
bits_SOUND_DANGER,
"AssassinTakeCoverFromEnemy2"
},
};
//=========================================================
// hide from the loudest sound source
//=========================================================
8 years ago
Task_t tlAssassinTakeCoverFromBestSound[] =
7 years ago
{
8 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 },
7 years ago
};
8 years ago
Schedule_t slAssassinTakeCoverFromBestSound[] =
7 years ago
{
8 years ago
{
7 years ago
tlAssassinTakeCoverFromBestSound,
8 years ago
ARRAYSIZE( tlAssassinTakeCoverFromBestSound ),
7 years ago
bits_COND_NEW_ENEMY,
0,
"AssassinTakeCoverFromBestSound"
},
};
//=========================================================
// AlertIdle Schedules
//=========================================================
8 years ago
Task_t tlAssassinHide[] =
7 years ago
{
8 years ago
{ TASK_STOP_MOVING, 0 },
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_WAIT, (float)2 },
{ TASK_SET_SCHEDULE, (float)SCHED_CHASE_ENEMY },
7 years ago
};
8 years ago
Schedule_t slAssassinHide[] =
7 years ago
{
8 years ago
{
7 years ago
tlAssassinHide,
8 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 |
7 years ago
bits_COND_HEAR_SOUND,
bits_SOUND_DANGER,
"AssassinHide"
},
};
//=========================================================
// HUNT Schedules
//=========================================================
8 years ago
Task_t tlAssassinHunt[] =
7 years ago
{
8 years ago
{ TASK_GET_PATH_TO_ENEMY, (float)0 },
{ TASK_RUN_PATH, (float)0 },
{ TASK_WAIT_FOR_MOVEMENT, (float)0 },
7 years ago
};
Schedule_t slAssassinHunt[] =
{
8 years ago
{
7 years ago
tlAssassinHunt,
8 years ago
ARRAYSIZE( tlAssassinHunt ),
bits_COND_NEW_ENEMY |
// bits_COND_SEE_ENEMY |
bits_COND_CAN_RANGE_ATTACK1 |
7 years ago
bits_COND_HEAR_SOUND,
bits_SOUND_DANGER,
"AssassinHunt"
},
};
//=========================================================
// Jumping Schedules
//=========================================================
8 years ago
Task_t tlAssassinJump[] =
7 years ago
{
8 years ago
{ TASK_STOP_MOVING, (float)0 },
{ TASK_PLAY_SEQUENCE, (float)ACT_HOP },
{ TASK_SET_SCHEDULE, (float)SCHED_ASSASSIN_JUMP_ATTACK },
7 years ago
};
8 years ago
Schedule_t slAssassinJump[] =
7 years ago
{
8 years ago
{
7 years ago
tlAssassinJump,
8 years ago
ARRAYSIZE( tlAssassinJump ),
7 years ago
0,
0,
"AssassinJump"
},
};
//=========================================================
// repel
//=========================================================
8 years ago
Task_t tlAssassinJumpAttack[] =
7 years ago
{
8 years ago
{ TASK_SET_FAIL_SCHEDULE, (float)SCHED_ASSASSIN_JUMP_LAND },
// { TASK_SET_ACTIVITY, (float)ACT_FLY },
{ TASK_ASSASSIN_FALL_TO_GROUND, (float)0 },
7 years ago
};
8 years ago
Schedule_t slAssassinJumpAttack[] =
7 years ago
{
8 years ago
{
7 years ago
tlAssassinJumpAttack,
8 years ago
ARRAYSIZE( tlAssassinJumpAttack ),
7 years ago
0,
0,
"AssassinJumpAttack"
},
};
//=========================================================
// repel
//=========================================================
Task_t tlAssassinJumpLand[] =
{
8 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 },
7 years ago
};
8 years ago
Schedule_t slAssassinJumpLand[] =
7 years ago
{
8 years ago
{
7 years ago
tlAssassinJumpLand,
8 years ago
ARRAYSIZE( tlAssassinJumpLand ),
0,
7 years ago
0,
"AssassinJumpLand"
},
};
DEFINE_CUSTOM_SCHEDULES( CHAssassin )
{
slAssassinFail,
slAssassinExposed,
slAssassinTakeCoverFromEnemy,
slAssassinTakeCoverFromEnemy2,
slAssassinTakeCoverFromBestSound,
slAssassinHide,
slAssassinHunt,
slAssassinJump,
slAssassinJumpAttack,
slAssassinJumpLand,
};
IMPLEMENT_CUSTOM_SCHEDULES( CHAssassin, CBaseMonster )
7 years ago
//=========================================================
// CheckMeleeAttack1 - jump like crazy if the enemy gets too close.
//=========================================================
8 years ago
BOOL CHAssassin::CheckMeleeAttack1( float flDot, float flDist )
7 years ago
{
if( m_flNextJump < gpGlobals->time && ( flDist <= 128.0f || HasMemory( bits_MEMORY_BADJUMP ) ) && m_hEnemy != 0 )
7 years ago
{
8 years ago
TraceResult tr;
7 years ago
Vector vecDest = pev->origin + Vector( RANDOM_FLOAT( -64, 64), RANDOM_FLOAT( -64, 64 ), 160 );
8 years ago
UTIL_TraceHull( pev->origin + Vector( 0, 0, 36 ), vecDest + Vector( 0, 0, 36 ), dont_ignore_monsters, human_hull, ENT( pev ), &tr );
7 years ago
if( tr.fStartSolid || tr.flFraction < 1.0f )
7 years ago
{
return FALSE;
}
float flGravity = g_psv_gravity->value;
float time = sqrt( 160.0f / ( 0.5f * flGravity ) );
float speed = flGravity * time / 160.0f;
8 years ago
m_vecJumpVelocity = ( vecDest - pev->origin ) * speed;
7 years ago
return TRUE;
}
return FALSE;
}
//=========================================================
// CheckRangeAttack1 - drop a cap in their ass
//
//=========================================================
8 years ago
BOOL CHAssassin::CheckRangeAttack1( float flDot, float flDist )
7 years ago
{
8 years ago
if( !HasConditions( bits_COND_ENEMY_OCCLUDED ) && flDist > 64 && flDist <= 2048 /* && flDot >= 0.5 */ /* && NoFriendlyFire() */ )
7 years ago
{
8 years ago
TraceResult tr;
7 years ago
Vector vecSrc = GetGunPosition();
// verify that a bullet fired from the gun will hit the enemy before the world.
8 years ago
UTIL_TraceLine( vecSrc, m_hEnemy->BodyTarget( vecSrc ), dont_ignore_monsters, ENT( pev ), &tr );
7 years ago
8 years ago
if( tr.flFraction == 1 || tr.pHit == m_hEnemy->edict() )
7 years ago
{
return TRUE;
}
}
return FALSE;
}
//=========================================================
// CheckRangeAttack2 - toss grenade is enemy gets in the way and is too close.
//=========================================================
8 years ago
BOOL CHAssassin::CheckRangeAttack2( float flDot, float flDist )
7 years ago
{
m_fThrowGrenade = FALSE;
8 years ago
if( !FBitSet( m_hEnemy->pev->flags, FL_ONGROUND ) )
7 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
8 years ago
if( m_iFrustration <= 2 )
7 years ago
return FALSE;
8 years ago
if( m_flNextGrenadeCheck < gpGlobals->time && !HasConditions( bits_COND_ENEMY_OCCLUDED ) && flDist <= 512 /* && flDot >= 0.5 */ /* && NoFriendlyFire() */ )
7 years ago
{
8 years ago
Vector vecToss = VecCheckThrow( pev, GetGunPosition(), m_hEnemy->Center(), flDist, 0.5 ); // use dist as speed to get there in 1 second
7 years ago
8 years ago
if( vecToss != g_vecZero )
7 years ago
{
m_vecTossVelocity = vecToss;
// throw a hand grenade
m_fThrowGrenade = TRUE;
return TRUE;
}
}
return FALSE;
}
//=========================================================
// RunAI
//=========================================================
8 years ago
void CHAssassin::RunAI( void )
7 years ago
{
8 years ago
CBaseMonster::RunAI();
7 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 ) )
7 years ago
m_iTargetRanderamt = 255;
else
m_iTargetRanderamt = 20;
8 years ago
if( pev->renderamt > m_iTargetRanderamt )
7 years ago
{
8 years ago
if( pev->renderamt == 255 )
7 years ago
{
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_BODY, "debris/beamstart1.wav", 0.2, ATTN_NORM );
7 years ago
}
pev->renderamt = Q_max( pev->renderamt - 50, m_iTargetRanderamt );
7 years ago
pev->rendermode = kRenderTransTexture;
}
8 years ago
else if( pev->renderamt < m_iTargetRanderamt )
7 years ago
{
pev->renderamt = Q_min( pev->renderamt + 50, m_iTargetRanderamt );
8 years ago
if( pev->renderamt == 255 )
7 years ago
pev->rendermode = kRenderNormal;
}
8 years ago
if( m_Activity == ACT_RUN || m_Activity == ACT_WALK )
7 years ago
{
static int iStep = 0;
8 years ago
iStep = !iStep;
if( iStep )
7 years ago
{
switch( RANDOM_LONG( 0, 3 ) )
{
8 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;
7 years ago
}
}
}
}
//=========================================================
// StartTask
//=========================================================
8 years ago
void CHAssassin::StartTask( Task_t *pTask )
7 years ago
{
8 years ago
switch( pTask->iTask )
7 years ago
{
case TASK_RANGE_ATTACK2:
8 years ago
if( !m_fThrowGrenade )
7 years ago
{
8 years ago
TaskComplete();
7 years ago
}
else
{
8 years ago
CBaseMonster::StartTask( pTask );
7 years ago
}
break;
case TASK_ASSASSIN_FALL_TO_GROUND:
break;
default:
8 years ago
CBaseMonster::StartTask( pTask );
7 years ago
break;
}
}
//=========================================================
// RunTask
//=========================================================
8 years ago
void CHAssassin::RunTask( Task_t *pTask )
7 years ago
{
8 years ago
switch( pTask->iTask )
7 years ago
{
case TASK_ASSASSIN_FALL_TO_GROUND:
MakeIdealYaw( m_vecEnemyLKP );
ChangeYaw( pev->yaw_speed );
8 years ago
if( m_fSequenceFinished )
7 years ago
{
8 years ago
if( pev->velocity.z > 0 )
7 years ago
{
pev->sequence = LookupSequence( "fly_up" );
}
8 years ago
else if( HasConditions( bits_COND_SEE_ENEMY ) )
7 years ago
{
pev->sequence = LookupSequence( "fly_attack" );
pev->frame = 0;
}
else
{
pev->sequence = LookupSequence( "fly_down" );
pev->frame = 0;
}
8 years ago
ResetSequenceInfo();
7 years ago
SetYawSpeed();
}
8 years ago
if( pev->flags & FL_ONGROUND )
7 years ago
{
8 years ago
// ALERT( at_console, "on ground\n" );
TaskComplete();
7 years ago
}
break;
default:
8 years ago
CBaseMonster::RunTask( pTask );
7 years ago
break;
}
}
//=========================================================
// GetSchedule - Decides which type of schedule best suits
// the monster's current state and conditions. Then calls
// monster's member function to get a pointer to a schedule
// of the proper type.
//=========================================================
8 years ago
Schedule_t *CHAssassin::GetSchedule( void )
7 years ago
{
8 years ago
switch( m_MonsterState )
7 years ago
{
case MONSTERSTATE_IDLE:
case MONSTERSTATE_ALERT:
{
8 years ago
if( HasConditions( bits_COND_HEAR_SOUND ) )
7 years ago
{
CSound *pSound;
pSound = PBestSound();
ASSERT( pSound != NULL );
8 years ago
if( pSound &&( pSound->m_iType & bits_SOUND_DANGER ) )
7 years ago
{
return GetScheduleOfType( SCHED_TAKE_COVER_FROM_BEST_SOUND );
}
8 years ago
if( pSound &&( pSound->m_iType & bits_SOUND_COMBAT ) )
7 years ago
{
return GetScheduleOfType( SCHED_INVESTIGATE_SOUND );
}
}
}
break;
case MONSTERSTATE_COMBAT:
{
// dead enemy
8 years ago
if( HasConditions( bits_COND_ENEMY_DEAD ) )
7 years ago
{
// call base class, all code to handle dead enemies is centralized there.
8 years ago
return CBaseMonster::GetSchedule();
7 years ago
}
// flying?
8 years ago
if( pev->movetype == MOVETYPE_TOSS )
7 years ago
{
8 years ago
if( pev->flags & FL_ONGROUND )
7 years ago
{
8 years ago
// ALERT( at_console, "landed\n" );
7 years ago
// just landed
pev->movetype = MOVETYPE_STEP;
return GetScheduleOfType ( SCHED_ASSASSIN_JUMP_LAND );
}
else
{
8 years ago
// ALERT( at_console, "jump\n" );
7 years ago
// jump or jump/shoot
8 years ago
if( m_MonsterState == MONSTERSTATE_COMBAT )
return GetScheduleOfType( SCHED_ASSASSIN_JUMP );
7 years ago
else
8 years ago
return GetScheduleOfType( SCHED_ASSASSIN_JUMP_ATTACK );
7 years ago
}
}
8 years ago
if( HasConditions( bits_COND_HEAR_SOUND ) )
7 years ago
{
CSound *pSound;
pSound = PBestSound();
ASSERT( pSound != NULL );
8 years ago
if( pSound && ( pSound->m_iType & bits_SOUND_DANGER ) )
7 years ago
{
return GetScheduleOfType( SCHED_TAKE_COVER_FROM_BEST_SOUND );
}
}
8 years ago
if( HasConditions( bits_COND_LIGHT_DAMAGE ) )
7 years ago
{
m_iFrustration++;
}
8 years ago
if( HasConditions( bits_COND_HEAVY_DAMAGE ) )
7 years ago
{
m_iFrustration++;
}
// jump player!
8 years ago
if( HasConditions( bits_COND_CAN_MELEE_ATTACK1 ) )
7 years ago
{
8 years ago
// ALERT( at_console, "melee attack 1\n" );
return GetScheduleOfType( SCHED_MELEE_ATTACK1 );
7 years ago
}
// throw grenade
8 years ago
if( HasConditions( bits_COND_CAN_RANGE_ATTACK2 ) )
7 years ago
{
// ALERT( at_console, "range attack 2\n");
8 years ago
return GetScheduleOfType( SCHED_RANGE_ATTACK2 );
7 years ago
}
// spotted
8 years ago
if( HasConditions( bits_COND_SEE_ENEMY ) && HasConditions( bits_COND_ENEMY_FACING_ME ) )
7 years ago
{
8 years ago
// ALERT( at_console, "exposed\n" );
7 years ago
m_iFrustration++;
8 years ago
return GetScheduleOfType( SCHED_ASSASSIN_EXPOSED );
7 years ago
}
// can attack
8 years ago
if( HasConditions( bits_COND_CAN_RANGE_ATTACK1 ) )
7 years ago
{
8 years ago
// ALERT( at_console, "range attack 1\n" );
7 years ago
m_iFrustration = 0;
8 years ago
return GetScheduleOfType( SCHED_RANGE_ATTACK1 );
7 years ago
}
8 years ago
if( HasConditions( bits_COND_SEE_ENEMY ) )
7 years ago
{
8 years ago
// ALERT( at_console, "face\n" );
return GetScheduleOfType( SCHED_COMBAT_FACE );
7 years ago
}
// new enemy
8 years ago
if( HasConditions( bits_COND_NEW_ENEMY ) )
7 years ago
{
8 years ago
// ALERT( at_console, "take cover\n" );
return GetScheduleOfType( SCHED_TAKE_COVER_FROM_ENEMY );
7 years ago
}
8 years ago
// ALERT( at_console, "stand\n" );
return GetScheduleOfType( SCHED_ALERT_STAND );
7 years ago
}
break;
default:
break;
}
8 years ago
return CBaseMonster::GetSchedule();
7 years ago
}
//=========================================================
//=========================================================
8 years ago
Schedule_t *CHAssassin::GetScheduleOfType( int Type )
7 years ago
{
// ALERT( at_console, "%d\n", m_iFrustration );
8 years ago
switch( Type )
7 years ago
{
case SCHED_TAKE_COVER_FROM_ENEMY:
8 years ago
if( pev->health > 30 )
7 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:
8 years ago
if( m_MonsterState == MONSTERSTATE_COMBAT )
7 years ago
return slAssassinFail;
break;
case SCHED_ALERT_STAND:
8 years ago
if( m_MonsterState == MONSTERSTATE_COMBAT )
7 years ago
return slAssassinHide;
break;
case SCHED_CHASE_ENEMY:
return slAssassinHunt;
case SCHED_MELEE_ATTACK1:
8 years ago
if( pev->flags & FL_ONGROUND )
7 years ago
{
8 years ago
if( m_flNextJump > gpGlobals->time )
7 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;
}
8 years ago
return CBaseMonster::GetScheduleOfType( Type );
7 years ago
}
#endif