2
0
mirror of https://github.com/FWGS/hlsdk-xash3d synced 2024-11-10 20:29:35 +01:00
hlsdk-xash3d/dlls/islave.cpp

837 lines
22 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.
*
****/
//=========================================================
// Alien slave monster
//=========================================================
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "squadmonster.h"
#include "schedule.h"
#include "effects.h"
#include "weapons.h"
#include "soundent.h"
extern DLL_GLOBAL int g_iSkillLevel;
//=========================================================
// Monster's Anim Events Go Here
//=========================================================
2016-07-31 15:48:50 +02:00
#define ISLAVE_AE_CLAW ( 1 )
#define ISLAVE_AE_CLAWRAKE ( 2 )
#define ISLAVE_AE_ZAP_POWERUP ( 3 )
2016-06-04 15:24:23 +02:00
#define ISLAVE_AE_ZAP_SHOOT ( 4 )
#define ISLAVE_AE_ZAP_DONE ( 5 )
2016-07-31 15:48:50 +02:00
#define ISLAVE_MAX_BEAMS 8
2016-06-04 15:24:23 +02:00
class CISlave : public CSquadMonster
{
public:
void Spawn( void );
void Precache( void );
void UpdateOnRemove();
2016-06-04 15:24:23 +02:00
void SetYawSpeed( void );
2016-07-31 15:48:50 +02:00
int ISoundMask( void );
int Classify( void );
int IRelationship( CBaseEntity *pTarget );
2016-06-04 15:24:23 +02:00
void HandleAnimEvent( MonsterEvent_t *pEvent );
2016-07-31 15:48:50 +02:00
BOOL CheckRangeAttack1( float flDot, float flDist );
BOOL CheckRangeAttack2( float flDot, float flDist );
2017-06-29 15:56:03 +02:00
void CallForHelp( const char *szClassname, float flDist, EHANDLE hEnemy, Vector &vecLocation );
2016-07-31 15:48:50 +02:00
void TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType );
int TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType );
2016-06-04 15:24:23 +02:00
void DeathSound( void );
void PainSound( void );
void AlertSound( void );
void IdleSound( void );
void Killed( entvars_t *pevAttacker, int iGib );
2016-07-31 15:48:50 +02:00
void StartTask( Task_t *pTask );
2016-06-04 15:24:23 +02:00
Schedule_t *GetSchedule( void );
2016-07-31 15:48:50 +02:00
Schedule_t *GetScheduleOfType( int Type );
CUSTOM_SCHEDULES
2016-06-04 15:24:23 +02:00
int Save( CSave &save );
2016-06-04 15:24:23 +02:00
int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
2016-07-31 15:48:50 +02:00
void ClearBeams();
2016-06-04 15:24:23 +02:00
void ArmBeam( int side );
void WackBeam( int side, CBaseEntity *pEntity );
void ZapBeam( int side );
void BeamGlow( void );
int m_iBravery;
CBeam *m_pBeam[ISLAVE_MAX_BEAMS];
int m_iBeams;
float m_flNextAttack;
2016-07-31 15:48:50 +02:00
int m_voicePitch;
2016-06-04 15:24:23 +02:00
EHANDLE m_hDead;
static const char *pAttackHitSounds[];
static const char *pAttackMissSounds[];
static const char *pPainSounds[];
static const char *pDeathSounds[];
};
LINK_ENTITY_TO_CLASS( monster_alien_slave, CISlave )
LINK_ENTITY_TO_CLASS( monster_vortigaunt, CISlave )
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
TYPEDESCRIPTION CISlave::m_SaveData[] =
2016-06-04 15:24:23 +02:00
{
DEFINE_FIELD( CISlave, m_iBravery, FIELD_INTEGER ),
DEFINE_ARRAY( CISlave, m_pBeam, FIELD_CLASSPTR, ISLAVE_MAX_BEAMS ),
DEFINE_FIELD( CISlave, m_iBeams, FIELD_INTEGER ),
DEFINE_FIELD( CISlave, m_flNextAttack, FIELD_TIME ),
DEFINE_FIELD( CISlave, m_voicePitch, FIELD_INTEGER ),
DEFINE_FIELD( CISlave, m_hDead, FIELD_EHANDLE ),
};
IMPLEMENT_SAVERESTORE( CISlave, CSquadMonster )
2016-06-04 15:24:23 +02:00
const char *CISlave::pAttackHitSounds[] =
2016-06-04 15:24:23 +02:00
{
"zombie/claw_strike1.wav",
"zombie/claw_strike2.wav",
"zombie/claw_strike3.wav",
};
const char *CISlave::pAttackMissSounds[] =
2016-06-04 15:24:23 +02:00
{
"zombie/claw_miss1.wav",
"zombie/claw_miss2.wav",
};
const char *CISlave::pPainSounds[] =
2016-06-04 15:24:23 +02:00
{
"aslave/slv_pain1.wav",
"aslave/slv_pain2.wav",
};
const char *CISlave::pDeathSounds[] =
2016-06-04 15:24:23 +02:00
{
"aslave/slv_die1.wav",
"aslave/slv_die2.wav",
};
//=========================================================
// Classify - indicates this monster's place in the
// relationship table.
//=========================================================
2016-07-31 15:48:50 +02:00
int CISlave::Classify( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
return CLASS_ALIEN_MILITARY;
2016-06-04 15:24:23 +02:00
}
int CISlave::IRelationship( CBaseEntity *pTarget )
{
2016-07-31 15:48:50 +02:00
if( ( pTarget->IsPlayer() ) )
if( ( pev->spawnflags & SF_MONSTER_WAIT_UNTIL_PROVOKED ) && ! ( m_afMemory & bits_MEMORY_PROVOKED ) )
2016-06-04 15:24:23 +02:00
return R_NO;
return CBaseMonster::IRelationship( pTarget );
}
2017-06-29 15:56:03 +02:00
void CISlave::CallForHelp( const char *szClassname, float flDist, EHANDLE hEnemy, Vector &vecLocation )
2016-06-04 15:24:23 +02:00
{
// ALERT( at_aiconsole, "help " );
// skip ones not on my netname
2016-07-31 15:48:50 +02:00
if( FStringNull( pev->netname ) )
2016-06-04 15:24:23 +02:00
return;
CBaseEntity *pEntity = NULL;
2016-07-31 15:48:50 +02:00
while( ( pEntity = UTIL_FindEntityByString( pEntity, "netname", STRING( pev->netname ) ) ) != NULL)
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
float d = ( pev->origin - pEntity->pev->origin ).Length();
if( d < flDist )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
CBaseMonster *pMonster = pEntity->MyMonsterPointer();
if( pMonster )
2016-06-04 15:24:23 +02:00
{
pMonster->m_afMemory |= bits_MEMORY_PROVOKED;
pMonster->PushEnemy( hEnemy, vecLocation );
}
}
}
}
//=========================================================
// ALertSound - scream
//=========================================================
2016-07-31 15:48:50 +02:00
void CISlave::AlertSound( void )
2016-06-04 15:24:23 +02:00
{
2017-06-29 15:56:03 +02:00
if( m_hEnemy != 0 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
SENTENCEG_PlayRndSz( ENT( pev ), "SLV_ALERT", 0.85, ATTN_NORM, 0, m_voicePitch );
2016-06-04 15:24:23 +02:00
CallForHelp( "monster_alien_slave", 512, m_hEnemy, m_vecEnemyLKP );
}
}
//=========================================================
// IdleSound
//=========================================================
2016-07-31 15:48:50 +02:00
void CISlave::IdleSound( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( RANDOM_LONG( 0, 2 ) == 0 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
SENTENCEG_PlayRndSz( ENT( pev ), "SLV_IDLE", 0.85, ATTN_NORM, 0, m_voicePitch );
2016-06-04 15:24:23 +02:00
}
#if 0
int side = RANDOM_LONG( 0, 1 ) * 2 - 1;
2016-07-31 15:48:50 +02:00
ClearBeams();
2016-06-04 15:24:23 +02:00
ArmBeam( side );
UTIL_MakeAimVectors( pev->angles );
Vector vecSrc = pev->origin + gpGlobals->v_right * 2 * side;
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSrc );
2016-07-31 15:48:50 +02:00
WRITE_BYTE( TE_DLIGHT );
WRITE_COORD( vecSrc.x ); // X
WRITE_COORD( vecSrc.y ); // Y
WRITE_COORD( vecSrc.z ); // Z
2016-06-04 15:24:23 +02:00
WRITE_BYTE( 8 ); // radius * 0.1
WRITE_BYTE( 255 ); // r
WRITE_BYTE( 180 ); // g
WRITE_BYTE( 96 ); // b
WRITE_BYTE( 10 ); // time * 10
WRITE_BYTE( 0 ); // decay * 0.1
2016-07-31 15:48:50 +02:00
MESSAGE_END();
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, "debris/zap1.wav", 1, ATTN_NORM, 0, 100 );
2016-06-04 15:24:23 +02:00
#endif
}
//=========================================================
// PainSound
//=========================================================
2016-07-31 15:48:50 +02:00
void CISlave::PainSound( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( RANDOM_LONG( 0, 2 ) == 0 )
2016-06-04 15:24:23 +02:00
{
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, RANDOM_SOUND_ARRAY( pPainSounds ), 1.0, ATTN_NORM, 0, m_voicePitch );
2016-06-04 15:24:23 +02:00
}
}
//=========================================================
// DieSound
//=========================================================
2016-07-31 15:48:50 +02:00
void CISlave::DeathSound( void )
2016-06-04 15:24:23 +02:00
{
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, RANDOM_SOUND_ARRAY( pDeathSounds ), 1.0, ATTN_NORM, 0, m_voicePitch );
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 CISlave::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
}
void CISlave::Killed( entvars_t *pevAttacker, int iGib )
{
2016-07-31 15:48:50 +02:00
ClearBeams();
2016-06-04 15:24:23 +02:00
CSquadMonster::Killed( pevAttacker, iGib );
}
//=========================================================
// SetYawSpeed - allows each sequence to have a different
// turn rate associated with it.
//=========================================================
2016-07-31 15:48:50 +02:00
void CISlave::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_WALK:
ys = 50;
break;
case ACT_RUN:
ys = 70;
break;
case ACT_IDLE:
ys = 50;
break;
default:
ys = 90;
break;
}
pev->yaw_speed = ys;
}
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//
// Returns number of events handled, 0 if none.
//=========================================================
2016-07-31 15:48:50 +02:00
void CISlave::HandleAnimEvent( MonsterEvent_t *pEvent )
2016-06-04 15:24:23 +02:00
{
// ALERT( at_console, "event %d : %f\n", pEvent->event, pev->frame );
switch( pEvent->event )
{
case ISLAVE_AE_CLAW:
{
// SOUND HERE!
CBaseEntity *pHurt = CheckTraceHullAttack( 70, gSkillData.slaveDmgClaw, DMG_SLASH );
2016-07-31 15:48:50 +02:00
if( pHurt )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pHurt->pev->flags & ( FL_MONSTER | FL_CLIENT ) )
2016-06-04 15:24:23 +02:00
{
pHurt->pev->punchangle.z = -18;
pHurt->pev->punchangle.x = 5;
}
// Play a random attack hit sound
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, RANDOM_SOUND_ARRAY( pAttackHitSounds ), 1.0, ATTN_NORM, 0, m_voicePitch );
2016-06-04 15:24:23 +02:00
}
else
{
// Play a random attack miss sound
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, RANDOM_SOUND_ARRAY( pAttackMissSounds ), 1.0, ATTN_NORM, 0, m_voicePitch );
2016-06-04 15:24:23 +02:00
}
}
break;
2016-06-04 15:24:23 +02:00
case ISLAVE_AE_CLAWRAKE:
{
CBaseEntity *pHurt = CheckTraceHullAttack( 70, gSkillData.slaveDmgClawrake, DMG_SLASH );
2016-07-31 15:48:50 +02:00
if( pHurt )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pHurt->pev->flags & ( FL_MONSTER | FL_CLIENT ) )
2016-06-04 15:24:23 +02:00
{
pHurt->pev->punchangle.z = -18;
pHurt->pev->punchangle.x = 5;
}
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, RANDOM_SOUND_ARRAY( pAttackHitSounds ), 1.0, ATTN_NORM, 0, m_voicePitch );
2016-06-04 15:24:23 +02:00
}
else
{
EMIT_SOUND_DYN( ENT(pev), CHAN_WEAPON, RANDOM_SOUND_ARRAY( pAttackMissSounds ), 1.0, ATTN_NORM, 0, m_voicePitch );
2016-06-04 15:24:23 +02:00
}
}
break;
2016-06-04 15:24:23 +02:00
case ISLAVE_AE_ZAP_POWERUP:
{
// speed up attack when on hard
2016-07-31 15:48:50 +02:00
if( g_iSkillLevel == SKILL_HARD )
2016-06-04 15:24:23 +02:00
pev->framerate = 1.5;
UTIL_MakeAimVectors( pev->angles );
2016-07-31 15:48:50 +02:00
if( m_iBeams == 0 )
2016-06-04 15:24:23 +02:00
{
Vector vecSrc = pev->origin + gpGlobals->v_forward * 2;
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSrc );
2016-07-31 15:48:50 +02:00
WRITE_BYTE( TE_DLIGHT );
WRITE_COORD( vecSrc.x ); // X
WRITE_COORD( vecSrc.y ); // Y
WRITE_COORD( vecSrc.z ); // Z
2016-06-04 15:24:23 +02:00
WRITE_BYTE( 12 ); // radius * 0.1
WRITE_BYTE( 255 ); // r
WRITE_BYTE( 180 ); // g
WRITE_BYTE( 96 ); // b
WRITE_BYTE( 20 / pev->framerate ); // time * 10
WRITE_BYTE( 0 ); // decay * 0.1
2016-07-31 15:48:50 +02:00
MESSAGE_END();
2016-06-04 15:24:23 +02:00
}
2017-06-29 15:56:03 +02:00
if( m_hDead != 0 )
2016-06-04 15:24:23 +02:00
{
WackBeam( -1, m_hDead );
WackBeam( 1, m_hDead );
}
else
{
ArmBeam( -1 );
ArmBeam( 1 );
2016-07-31 15:48:50 +02:00
BeamGlow();
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, "debris/zap4.wav", 1, ATTN_NORM, 0, 100 + m_iBeams * 10 );
2016-06-04 15:24:23 +02:00
pev->skin = m_iBeams / 2;
}
break;
2016-06-04 15:24:23 +02:00
case ISLAVE_AE_ZAP_SHOOT:
{
2016-07-31 15:48:50 +02:00
ClearBeams();
2016-06-04 15:24:23 +02:00
2017-06-29 15:56:03 +02:00
if( m_hDead != 0 )
2016-06-04 15:24:23 +02:00
{
Vector vecDest = m_hDead->pev->origin + Vector( 0, 0, 38 );
TraceResult trace;
UTIL_TraceHull( vecDest, vecDest, dont_ignore_monsters, human_hull, m_hDead->edict(), &trace );
2016-07-31 15:48:50 +02:00
if( !trace.fStartSolid )
2016-06-04 15:24:23 +02:00
{
CBaseEntity *pNew = Create( "monster_alien_slave", m_hDead->pev->origin, m_hDead->pev->angles );
2017-06-29 15:56:03 +02:00
//CBaseMonster *pNewMonster = pNew->MyMonsterPointer();
2016-06-04 15:24:23 +02:00
pNew->pev->spawnflags |= 1;
WackBeam( -1, pNew );
WackBeam( 1, pNew );
UTIL_Remove( m_hDead );
2016-07-31 15:48:50 +02:00
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, "hassault/hw_shoot1.wav", 1, ATTN_NORM, 0, RANDOM_LONG( 130, 160 ) );
2016-06-04 15:24:23 +02:00
/*
CBaseEntity *pEffect = Create( "test_effect", pNew->Center(), pev->angles );
pEffect->Use( this, this, USE_ON, 1 );
*/
break;
}
}
ClearMultiDamage();
UTIL_MakeAimVectors( pev->angles );
ZapBeam( -1 );
ZapBeam( 1 );
2016-07-31 15:48:50 +02:00
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, "hassault/hw_shoot1.wav", 1, ATTN_NORM, 0, RANDOM_LONG( 130, 160 ) );
// STOP_SOUND( ENT( pev ), CHAN_WEAPON, "debris/zap4.wav" );
ApplyMultiDamage( pev, pev );
2016-06-04 15:24:23 +02:00
m_flNextAttack = gpGlobals->time + RANDOM_FLOAT( 0.5, 4.0 );
}
break;
2016-06-04 15:24:23 +02:00
case ISLAVE_AE_ZAP_DONE:
{
2016-07-31 15:48:50 +02:00
ClearBeams();
2016-06-04 15:24:23 +02:00
}
break;
2016-06-04 15:24:23 +02:00
default:
CSquadMonster::HandleAnimEvent( pEvent );
break;
}
}
//=========================================================
// CheckRangeAttack1 - normal beam attack
//=========================================================
2016-07-31 15:48:50 +02:00
BOOL CISlave::CheckRangeAttack1( float flDot, float flDist )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_flNextAttack > gpGlobals->time )
2016-06-04 15:24:23 +02:00
{
return FALSE;
}
return CSquadMonster::CheckRangeAttack1( flDot, flDist );
}
//=========================================================
// CheckRangeAttack2 - check bravery and try to resurect dead comrades
//=========================================================
2016-07-31 15:48:50 +02:00
BOOL CISlave::CheckRangeAttack2( float flDot, float flDist )
2016-06-04 15:24:23 +02:00
{
return FALSE;
2016-07-31 15:48:50 +02:00
if( m_flNextAttack > gpGlobals->time )
2016-06-04 15:24:23 +02:00
{
return FALSE;
}
m_hDead = NULL;
m_iBravery = 0;
CBaseEntity *pEntity = NULL;
2016-07-31 15:48:50 +02:00
while( ( pEntity = UTIL_FindEntityByClassname( pEntity, "monster_alien_slave" ) ) != NULL )
2016-06-04 15:24:23 +02:00
{
TraceResult tr;
2016-07-31 15:48:50 +02:00
UTIL_TraceLine( EyePosition(), pEntity->EyePosition(), ignore_monsters, ENT( pev ), &tr );
2019-10-13 13:49:25 +02:00
if( tr.flFraction == 1.0f || tr.pHit == pEntity->edict() )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pEntity->pev->deadflag == DEAD_DEAD )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
float d = ( pev->origin - pEntity->pev->origin ).Length();
if( d < flDist )
2016-06-04 15:24:23 +02:00
{
m_hDead = pEntity;
flDist = d;
}
m_iBravery--;
}
else
{
m_iBravery++;
}
}
}
2017-06-29 15:56:03 +02:00
if( m_hDead != 0 )
2016-06-04 15:24:23 +02:00
return TRUE;
else
return FALSE;
}
//=========================================================
// StartTask
//=========================================================
2016-07-31 15:48:50 +02:00
void CISlave::StartTask( Task_t *pTask )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
ClearBeams();
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
CSquadMonster::StartTask( pTask );
2016-06-04 15:24:23 +02:00
}
//=========================================================
// Spawn
//=========================================================
2016-07-31 15:48:50 +02:00
void CISlave::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/islave.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_GREEN;
pev->effects = 0;
2016-07-31 15:48:50 +02:00
pev->health = gSkillData.slaveHealth;
pev->view_ofs = Vector( 0, 0, 64 );// position of the eyes relative to monster's origin.
2016-06-04 15:24:23 +02:00
m_flFieldOfView = VIEW_FIELD_WIDE; // NOTE: we need a wide field of view so npc will notice player and say hello
m_MonsterState = MONSTERSTATE_NONE;
m_afCapability = bits_CAP_HEAR | bits_CAP_TURN_HEAD | bits_CAP_RANGE_ATTACK2 | bits_CAP_DOORS_GROUP;
m_voicePitch = RANDOM_LONG( 85, 110 );
MonsterInit();
}
//=========================================================
// Precache - precaches all resources this monster needs
//=========================================================
2016-07-31 15:48:50 +02:00
void CISlave::Precache()
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
PRECACHE_MODEL( "models/islave.mdl" );
PRECACHE_MODEL( "sprites/lgtning.spr" );
PRECACHE_SOUND( "debris/zap1.wav" );
PRECACHE_SOUND( "debris/zap4.wav" );
PRECACHE_SOUND( "weapons/electro4.wav" );
PRECACHE_SOUND( "hassault/hw_shoot1.wav" );
PRECACHE_SOUND( "zombie/zo_pain2.wav" );
PRECACHE_SOUND( "headcrab/hc_headbite.wav" );
PRECACHE_SOUND( "weapons/cbar_miss1.wav" );
2016-06-04 15:24:23 +02:00
PRECACHE_SOUND_ARRAY( pAttackHitSounds );
PRECACHE_SOUND_ARRAY( pAttackMissSounds );
PRECACHE_SOUND_ARRAY( pPainSounds );
PRECACHE_SOUND_ARRAY( pDeathSounds );
2016-06-04 15:24:23 +02:00
UTIL_PrecacheOther( "test_effect" );
2016-07-31 15:48:50 +02:00
}
2016-06-04 15:24:23 +02:00
void CISlave::UpdateOnRemove()
{
CBaseEntity::UpdateOnRemove();
ClearBeams();
}
2016-06-04 15:24:23 +02:00
//=========================================================
// TakeDamage - get provoked when injured
//=========================================================
2016-07-31 15:48:50 +02:00
int CISlave::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
2016-06-04 15:24:23 +02:00
{
// don't slash one of your own
2016-07-31 15:48:50 +02:00
if( ( bitsDamageType & DMG_SLASH ) && pevAttacker && IRelationship( Instance( pevAttacker ) ) < R_DL )
2016-06-04 15:24:23 +02:00
return 0;
m_afMemory |= bits_MEMORY_PROVOKED;
2016-07-31 15:48:50 +02:00
return CSquadMonster::TakeDamage( pevInflictor, pevAttacker, flDamage, bitsDamageType );
2016-06-04 15:24:23 +02:00
}
void CISlave::TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType)
{
2016-07-31 15:48:50 +02:00
if( bitsDamageType & DMG_SHOCK )
2016-06-04 15:24:23 +02:00
return;
CSquadMonster::TraceAttack( pevAttacker, flDamage, vecDir, ptr, bitsDamageType );
}
//=========================================================
// AI Schedules Specific to this monster
//=========================================================
// primary range attack
Task_t tlSlaveAttack1[] =
{
{ TASK_STOP_MOVING, 0 },
{ TASK_FACE_IDEAL, (float)0 },
{ TASK_RANGE_ATTACK1, (float)0 },
};
Schedule_t slSlaveAttack1[] =
{
{
tlSlaveAttack1,
ARRAYSIZE ( tlSlaveAttack1 ),
bits_COND_CAN_MELEE_ATTACK1 |
bits_COND_HEAR_SOUND |
bits_COND_HEAVY_DAMAGE,
bits_SOUND_DANGER,
"Slave Range Attack1"
},
};
DEFINE_CUSTOM_SCHEDULES( CISlave )
{
slSlaveAttack1,
};
IMPLEMENT_CUSTOM_SCHEDULES( CISlave, CSquadMonster )
2016-06-04 15:24:23 +02:00
//=========================================================
//=========================================================
2016-07-31 15:48:50 +02:00
Schedule_t *CISlave::GetSchedule( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
ClearBeams();
2016-06-04 15:24:23 +02:00
/*
2016-07-31 15:48:50 +02:00
if( pev->spawnflags )
2016-06-04 15:24:23 +02:00
{
pev->spawnflags = 0;
return GetScheduleOfType( SCHED_RELOAD );
}
*/
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 );
if( pSound )
{
if( pSound->m_iType & bits_SOUND_DANGER )
return GetScheduleOfType( SCHED_TAKE_COVER_FROM_BEST_SOUND );
if( pSound->m_iType & bits_SOUND_COMBAT )
m_afMemory |= bits_MEMORY_PROVOKED;
}
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_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
}
2016-07-31 15:48:50 +02:00
if( pev->health < 20 || m_iBravery < 0 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !HasConditions( bits_COND_CAN_MELEE_ATTACK1 ) )
2016-06-04 15:24:23 +02:00
{
m_failSchedule = SCHED_CHASE_ENEMY;
2016-07-31 15:48:50 +02:00
if( HasConditions( bits_COND_LIGHT_DAMAGE | bits_COND_HEAVY_DAMAGE ) )
2016-06-04 15:24:23 +02:00
{
return GetScheduleOfType( SCHED_TAKE_COVER_FROM_ENEMY );
}
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
{
// ALERT( at_console, "exposed\n");
return GetScheduleOfType( SCHED_TAKE_COVER_FROM_ENEMY );
}
}
}
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 CSquadMonster::GetSchedule();
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
Schedule_t *CISlave::GetScheduleOfType( int Type )
2016-06-04 15:24:23 +02:00
{
switch( Type )
2016-06-04 15:24:23 +02:00
{
case SCHED_FAIL:
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
return CSquadMonster::GetScheduleOfType( SCHED_MELEE_ATTACK1 );
2016-06-04 15:24:23 +02:00
}
break;
case SCHED_RANGE_ATTACK1:
return slSlaveAttack1;
case SCHED_RANGE_ATTACK2:
return slSlaveAttack1;
}
2016-07-31 15:48:50 +02:00
return CSquadMonster::GetScheduleOfType( Type );
2016-06-04 15:24:23 +02:00
}
//=========================================================
// ArmBeam - small beam from arm to nearby geometry
//=========================================================
2016-07-31 15:48:50 +02:00
void CISlave::ArmBeam( int side )
2016-06-04 15:24:23 +02:00
{
TraceResult tr;
float flDist = 1.0;
2016-07-31 15:48:50 +02:00
if( m_iBeams >= ISLAVE_MAX_BEAMS )
2016-06-04 15:24:23 +02:00
return;
UTIL_MakeAimVectors( pev->angles );
Vector vecSrc = pev->origin + gpGlobals->v_up * 36 + gpGlobals->v_right * side * 16 + gpGlobals->v_forward * 32;
2016-07-31 15:48:50 +02:00
for( int i = 0; i < 3; i++ )
2016-06-04 15:24:23 +02:00
{
Vector vecAim = gpGlobals->v_right * side * RANDOM_FLOAT( 0, 1 ) + gpGlobals->v_up * RANDOM_FLOAT( -1, 1 );
TraceResult tr1;
2016-07-31 15:48:50 +02:00
UTIL_TraceLine( vecSrc, vecSrc + vecAim * 512, dont_ignore_monsters, ENT( pev ), &tr1 );
if( flDist > tr1.flFraction )
2016-06-04 15:24:23 +02:00
{
tr = tr1;
flDist = tr.flFraction;
}
}
// Couldn't find anything close enough
2019-10-13 13:49:25 +02:00
if( flDist == 1.0f )
2016-06-04 15:24:23 +02:00
return;
DecalGunshot( &tr, BULLET_PLAYER_CROWBAR );
m_pBeam[m_iBeams] = CBeam::BeamCreate( "sprites/lgtning.spr", 30 );
2016-07-31 15:48:50 +02:00
if( !m_pBeam[m_iBeams] )
2016-06-04 15:24:23 +02:00
return;
2016-07-31 15:48:50 +02:00
m_pBeam[m_iBeams]->PointEntInit( tr.vecEndPos, entindex() );
2016-06-04 15:24:23 +02:00
m_pBeam[m_iBeams]->SetEndAttachment( side < 0 ? 2 : 1 );
// m_pBeam[m_iBeams]->SetColor( 180, 255, 96 );
m_pBeam[m_iBeams]->SetColor( 96, 128, 16 );
m_pBeam[m_iBeams]->SetBrightness( 64 );
m_pBeam[m_iBeams]->SetNoise( 80 );
m_iBeams++;
}
//=========================================================
// BeamGlow - brighten all beams
//=========================================================
2016-07-31 15:48:50 +02:00
void CISlave::BeamGlow()
2016-06-04 15:24:23 +02:00
{
int b = m_iBeams * 32;
2016-07-31 15:48:50 +02:00
if( b > 255 )
2016-06-04 15:24:23 +02:00
b = 255;
2016-07-31 15:48:50 +02:00
for( int i = 0; i < m_iBeams; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_pBeam[i]->GetBrightness() != 255 )
2016-06-04 15:24:23 +02:00
{
m_pBeam[i]->SetBrightness( b );
}
}
}
//=========================================================
// WackBeam - regenerate dead colleagues
//=========================================================
2016-07-31 15:48:50 +02:00
void CISlave::WackBeam( int side, CBaseEntity *pEntity )
2016-06-04 15:24:23 +02:00
{
2017-06-29 15:56:03 +02:00
//Vector vecDest;
//float flDist = 1.0;
2016-07-31 15:48:50 +02:00
if( m_iBeams >= ISLAVE_MAX_BEAMS )
2016-06-04 15:24:23 +02:00
return;
2016-07-31 15:48:50 +02:00
if( pEntity == NULL )
2016-06-04 15:24:23 +02:00
return;
m_pBeam[m_iBeams] = CBeam::BeamCreate( "sprites/lgtning.spr", 30 );
2016-07-31 15:48:50 +02:00
if( !m_pBeam[m_iBeams] )
2016-06-04 15:24:23 +02:00
return;
2016-07-31 15:48:50 +02:00
m_pBeam[m_iBeams]->PointEntInit( pEntity->Center(), entindex() );
2016-06-04 15:24:23 +02:00
m_pBeam[m_iBeams]->SetEndAttachment( side < 0 ? 2 : 1 );
m_pBeam[m_iBeams]->SetColor( 180, 255, 96 );
m_pBeam[m_iBeams]->SetBrightness( 255 );
m_pBeam[m_iBeams]->SetNoise( 80 );
m_iBeams++;
}
//=========================================================
// ZapBeam - heavy damage directly forward
//=========================================================
2016-07-31 15:48:50 +02:00
void CISlave::ZapBeam( int side )
2016-06-04 15:24:23 +02:00
{
Vector vecSrc, vecAim;
TraceResult tr;
CBaseEntity *pEntity;
2016-07-31 15:48:50 +02:00
if( m_iBeams >= ISLAVE_MAX_BEAMS )
2016-06-04 15:24:23 +02:00
return;
vecSrc = pev->origin + gpGlobals->v_up * 36;
vecAim = ShootAtEnemy( vecSrc );
float deflection = 0.01;
vecAim = vecAim + side * gpGlobals->v_right * RANDOM_FLOAT( 0, deflection ) + gpGlobals->v_up * RANDOM_FLOAT( -deflection, deflection );
2016-07-31 15:48:50 +02:00
UTIL_TraceLine( vecSrc, vecSrc + vecAim * 1024, dont_ignore_monsters, ENT( pev ), &tr );
2016-06-04 15:24:23 +02:00
m_pBeam[m_iBeams] = CBeam::BeamCreate( "sprites/lgtning.spr", 50 );
2016-07-31 15:48:50 +02:00
if( !m_pBeam[m_iBeams] )
2016-06-04 15:24:23 +02:00
return;
2016-07-31 15:48:50 +02:00
m_pBeam[m_iBeams]->PointEntInit( tr.vecEndPos, entindex() );
2016-06-04 15:24:23 +02:00
m_pBeam[m_iBeams]->SetEndAttachment( side < 0 ? 2 : 1 );
m_pBeam[m_iBeams]->SetColor( 180, 255, 96 );
m_pBeam[m_iBeams]->SetBrightness( 255 );
m_pBeam[m_iBeams]->SetNoise( 20 );
m_iBeams++;
2016-07-31 15:48:50 +02:00
pEntity = CBaseEntity::Instance( tr.pHit );
if( pEntity != NULL && pEntity->pev->takedamage )
2016-06-04 15:24:23 +02:00
{
pEntity->TraceAttack( pev, gSkillData.slaveDmgZap, vecAim, &tr, DMG_SHOCK );
}
2016-07-31 15:48:50 +02:00
UTIL_EmitAmbientSound( ENT( pev ), tr.vecEndPos, "weapons/electro4.wav", 0.5, ATTN_NORM, 0, RANDOM_LONG( 140, 160 ) );
2016-06-04 15:24:23 +02:00
}
//=========================================================
// ClearBeams - remove all beams
//=========================================================
2016-07-31 15:48:50 +02:00
void CISlave::ClearBeams()
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
for( int i = 0; i < ISLAVE_MAX_BEAMS; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_pBeam[i] )
2016-06-04 15:24:23 +02:00
{
UTIL_Remove( m_pBeam[i] );
m_pBeam[i] = NULL;
}
}
m_iBeams = 0;
pev->skin = 0;
2016-07-31 15:48:50 +02:00
STOP_SOUND( ENT( pev ), CHAN_WEAPON, "debris/zap4.wav" );
2016-06-04 15:24:23 +02:00
}