2
0
mirror of https://github.com/FWGS/hlsdk-xash3d synced 2024-11-11 04:39:03 +01:00
hlsdk-xash3d/dlls/hassassin.cpp

993 lines
25 KiB
C++
Raw Normal View History

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