2
0
mirror of https://github.com/FWGS/hlsdk-xash3d synced 2024-11-12 05:10:52 +01:00
hlsdk-xash3d/dlls/apache.cpp

1030 lines
27 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.
*
****/
2021-06-07 02:05:58 +02:00
#if !OEM_BUILD
2016-06-04 15:24:23 +02:00
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "nodes.h"
#include "effects.h"
extern DLL_GLOBAL int g_iSkillLevel;
#define SF_WAITFORTRIGGER (0x04 | 0x40) // UNDONE: Fix!
#define SF_NOWRECKAGE 0x08
class CApache : public CBaseMonster
{
2016-07-31 15:48:50 +02:00
int Save( CSave &save );
int Restore( CRestore &restore );
2016-06-04 15:24:23 +02:00
static TYPEDESCRIPTION m_SaveData[];
void Spawn( void );
void Precache( void );
2016-07-31 15:48:50 +02:00
int Classify( void ) { return CLASS_HUMAN_MILITARY; };
int BloodColor( void ) { return DONT_BLEED; }
2016-06-04 15:24:23 +02:00
void Killed( entvars_t *pevAttacker, int iGib );
void GibMonster( void );
void SetObjectCollisionBox( void )
{
2019-10-13 13:49:25 +02:00
pev->absmin = pev->origin + Vector( -300.0f, -300.0f, -172.0f );
pev->absmax = pev->origin + Vector( 300.0f, 300.0f, 8.0f );
2016-06-04 15:24:23 +02:00
}
void EXPORT HuntThink( void );
void EXPORT FlyTouch( CBaseEntity *pOther );
void EXPORT CrashTouch( CBaseEntity *pOther );
void EXPORT DyingThink( void );
void EXPORT StartupUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
void EXPORT NullThink( void );
void ShowDamage( void );
void Flight( void );
void FireRocket( void );
BOOL FireGun( void );
2016-07-31 15:48:50 +02:00
2016-06-04 15:24:23 +02:00
int TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType );
2016-07-31 15:48:50 +02:00
void TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType );
2016-06-04 15:24:23 +02:00
int m_iRockets;
float m_flForce;
float m_flNextRocket;
Vector m_vecTarget;
Vector m_posTarget;
Vector m_vecDesired;
Vector m_posDesired;
Vector m_vecGoal;
Vector m_angGun;
float m_flLastSeen;
float m_flPrevSeen;
int m_iSoundState; // don't save this
int m_iSpriteTexture;
int m_iExplode;
int m_iBodyGibs;
float m_flGoalSpeed;
int m_iDoSmokePuff;
CBeam *m_pBeam;
};
LINK_ENTITY_TO_CLASS( monster_apache, CApache )
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
TYPEDESCRIPTION CApache::m_SaveData[] =
2016-06-04 15:24:23 +02:00
{
DEFINE_FIELD( CApache, m_iRockets, FIELD_INTEGER ),
DEFINE_FIELD( CApache, m_flForce, FIELD_FLOAT ),
DEFINE_FIELD( CApache, m_flNextRocket, FIELD_TIME ),
DEFINE_FIELD( CApache, m_vecTarget, FIELD_VECTOR ),
DEFINE_FIELD( CApache, m_posTarget, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( CApache, m_vecDesired, FIELD_VECTOR ),
DEFINE_FIELD( CApache, m_posDesired, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( CApache, m_vecGoal, FIELD_VECTOR ),
DEFINE_FIELD( CApache, m_angGun, FIELD_VECTOR ),
DEFINE_FIELD( CApache, m_flLastSeen, FIELD_TIME ),
DEFINE_FIELD( CApache, m_flPrevSeen, FIELD_TIME ),
2016-07-31 15:48:50 +02:00
//DEFINE_FIELD( CApache, m_iSoundState, FIELD_INTEGER ), // Don't save, precached
//DEFINE_FIELD( CApache, m_iSpriteTexture, FIELD_INTEGER ),
//DEFINE_FIELD( CApache, m_iExplode, FIELD_INTEGER ),
//DEFINE_FIELD( CApache, m_iBodyGibs, FIELD_INTEGER ),
2016-06-04 15:24:23 +02:00
DEFINE_FIELD( CApache, m_pBeam, FIELD_CLASSPTR ),
DEFINE_FIELD( CApache, m_flGoalSpeed, FIELD_FLOAT ),
DEFINE_FIELD( CApache, m_iDoSmokePuff, FIELD_INTEGER ),
};
IMPLEMENT_SAVERESTORE( CApache, CBaseMonster )
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
void CApache::Spawn( void )
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
// motor
pev->movetype = MOVETYPE_FLY;
pev->solid = SOLID_BBOX;
2016-07-31 15:48:50 +02:00
SET_MODEL( ENT( pev ), "models/apache.mdl" );
2019-10-13 13:49:25 +02:00
UTIL_SetSize( pev, Vector( -32.0f, -32.0f, -64.0f ), Vector( 32.0f, 32.0f, 0.0f ) );
2016-06-04 15:24:23 +02:00
UTIL_SetOrigin( pev, pev->origin );
pev->flags |= FL_MONSTER;
2016-07-31 15:48:50 +02:00
pev->takedamage = DAMAGE_AIM;
pev->health = gSkillData.apacheHealth;
2016-06-04 15:24:23 +02:00
2019-10-13 13:49:25 +02:00
m_flFieldOfView = -0.707f; // 270 degrees
2016-06-04 15:24:23 +02:00
pev->sequence = 0;
2016-07-31 15:48:50 +02:00
ResetSequenceInfo();
pev->frame = RANDOM_LONG( 0, 0xFF );
2016-06-04 15:24:23 +02:00
InitBoneControllers();
2016-07-31 15:48:50 +02:00
if( pev->spawnflags & SF_WAITFORTRIGGER )
2016-06-04 15:24:23 +02:00
{
SetUse( &CApache::StartupUse );
}
else
{
SetThink( &CApache::HuntThink );
SetTouch( &CApache::FlyTouch );
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 1.0f;
2016-06-04 15:24:23 +02:00
}
m_iRockets = 10;
}
void CApache::Precache( void )
{
2016-07-31 15:48:50 +02:00
PRECACHE_MODEL( "models/apache.mdl" );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
PRECACHE_SOUND( "apache/ap_rotor1.wav" );
PRECACHE_SOUND( "apache/ap_rotor2.wav" );
PRECACHE_SOUND( "apache/ap_rotor3.wav" );
PRECACHE_SOUND( "apache/ap_whine1.wav" );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
PRECACHE_SOUND( "weapons/mortarhit.wav" );
2016-06-04 15:24:23 +02:00
m_iSpriteTexture = PRECACHE_MODEL( "sprites/white.spr" );
2016-07-31 15:48:50 +02:00
PRECACHE_SOUND( "turret/tu_fire1.wav" );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
PRECACHE_MODEL( "sprites/lgtning.spr" );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
m_iExplode = PRECACHE_MODEL( "sprites/fexplo.spr" );
2016-06-04 15:24:23 +02:00
m_iBodyGibs = PRECACHE_MODEL( "models/metalplategibs_green.mdl" );
UTIL_PrecacheOther( "hvr_rocket" );
}
void CApache::NullThink( void )
{
2016-07-31 15:48:50 +02:00
StudioFrameAdvance();
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.5f;
2016-06-04 15:24:23 +02:00
}
void CApache::StartupUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
SetThink( &CApache::HuntThink );
SetTouch( &CApache::FlyTouch );
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.1f;
2016-06-04 15:24:23 +02:00
SetUse( NULL );
}
2016-07-31 15:48:50 +02:00
void CApache::Killed( entvars_t *pevAttacker, int iGib )
2016-06-04 15:24:23 +02:00
{
pev->movetype = MOVETYPE_TOSS;
2019-10-13 13:49:25 +02:00
pev->gravity = 0.3f;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
STOP_SOUND( ENT( pev ), CHAN_STATIC, "apache/ap_rotor2.wav" );
2016-06-04 15:24:23 +02:00
2019-10-13 13:49:25 +02:00
UTIL_SetSize( pev, Vector( -32.0f, -32.0f, -64.0f ), Vector( 32.0f, 32.0f, 0.0f ) );
2016-06-04 15:24:23 +02:00
SetThink( &CApache::DyingThink );
SetTouch( &CApache::CrashTouch );
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.1f;
2016-06-04 15:24:23 +02:00
pev->health = 0;
pev->takedamage = DAMAGE_NO;
2016-07-31 15:48:50 +02:00
if( pev->spawnflags & SF_NOWRECKAGE )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
m_flNextRocket = gpGlobals->time + 4.0f;
2016-06-04 15:24:23 +02:00
}
else
{
2019-10-13 13:49:25 +02:00
m_flNextRocket = gpGlobals->time + 15.0f;
2016-06-04 15:24:23 +02:00
}
}
2016-07-31 15:48:50 +02:00
void CApache::DyingThink( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
StudioFrameAdvance();
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.1f;
2016-06-04 15:24:23 +02:00
2019-10-13 13:49:25 +02:00
pev->avelocity = pev->avelocity * 1.02f;
2016-06-04 15:24:23 +02:00
// still falling?
2016-07-31 15:48:50 +02:00
if( m_flNextRocket > gpGlobals->time )
2016-06-04 15:24:23 +02:00
{
// random explosions
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, pev->origin );
2016-07-31 15:48:50 +02:00
WRITE_BYTE( TE_EXPLOSION ); // This just makes a dynamic light now
2019-10-13 13:49:25 +02:00
WRITE_COORD( pev->origin.x + RANDOM_FLOAT( -150.0f, 150.0f ) );
WRITE_COORD( pev->origin.y + RANDOM_FLOAT( -150.0f, 150.0f ) );
WRITE_COORD( pev->origin.z + RANDOM_FLOAT( -150.0f, -50.0f ) );
2016-06-04 15:24:23 +02:00
WRITE_SHORT( g_sModelIndexFireball );
2016-07-31 15:48:50 +02:00
WRITE_BYTE( RANDOM_LONG( 0, 29 ) + 30 ); // scale * 10
WRITE_BYTE( 12 ); // framerate
2016-06-04 15:24:23 +02:00
WRITE_BYTE( TE_EXPLFLAG_NONE );
MESSAGE_END();
// lots of smoke
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, pev->origin );
WRITE_BYTE( TE_SMOKE );
2019-10-13 13:49:25 +02:00
WRITE_COORD( pev->origin.x + RANDOM_FLOAT( -150.0f, 150.0f ) );
WRITE_COORD( pev->origin.y + RANDOM_FLOAT( -150.0f, 150.0f ) );
WRITE_COORD( pev->origin.z + RANDOM_FLOAT( -150.0f, -50.0f ) );
2016-06-04 15:24:23 +02:00
WRITE_SHORT( g_sModelIndexSmoke );
WRITE_BYTE( 100 ); // scale * 10
2016-07-31 15:48:50 +02:00
WRITE_BYTE( 10 ); // framerate
2016-06-04 15:24:23 +02:00
MESSAGE_END();
2019-10-13 13:49:25 +02:00
Vector vecSpot = pev->origin + ( pev->mins + pev->maxs ) * 0.5f;
2016-06-04 15:24:23 +02:00
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot );
2016-07-31 15:48:50 +02:00
WRITE_BYTE( TE_BREAKMODEL );
2016-06-04 15:24:23 +02:00
// position
WRITE_COORD( vecSpot.x );
WRITE_COORD( vecSpot.y );
WRITE_COORD( vecSpot.z );
// size
WRITE_COORD( 400 );
WRITE_COORD( 400 );
WRITE_COORD( 132 );
// velocity
WRITE_COORD( pev->velocity.x );
WRITE_COORD( pev->velocity.y );
WRITE_COORD( pev->velocity.z );
// randomization
WRITE_BYTE( 50 );
// Model
WRITE_SHORT( m_iBodyGibs ); //model id#
// # of shards
WRITE_BYTE( 4 ); // let client decide
// duration
WRITE_BYTE( 30 );// 3.0 seconds
// flags
WRITE_BYTE( BREAK_METAL );
MESSAGE_END();
// don't stop it we touch a entity
pev->flags &= ~FL_ONGROUND;
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.2f;
2016-06-04 15:24:23 +02:00
return;
}
else
{
2019-10-13 13:49:25 +02:00
Vector vecSpot = pev->origin + ( pev->mins + pev->maxs ) * 0.5f;
2016-06-04 15:24:23 +02:00
/*
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_EXPLOSION); // This just makes a dynamic light now
WRITE_COORD( vecSpot.x );
WRITE_COORD( vecSpot.y );
2019-10-13 13:49:25 +02:00
WRITE_COORD( vecSpot.z + 300.0f );
2016-06-04 15:24:23 +02:00
WRITE_SHORT( g_sModelIndexFireball );
WRITE_BYTE( 250 ); // scale * 10
2016-07-31 15:48:50 +02:00
WRITE_BYTE( 8 ); // framerate
2016-06-04 15:24:23 +02:00
MESSAGE_END();
*/
// fireball
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot );
WRITE_BYTE( TE_SPRITE );
WRITE_COORD( vecSpot.x );
WRITE_COORD( vecSpot.y );
2019-10-13 13:49:25 +02:00
WRITE_COORD( vecSpot.z + 256.0f );
2016-06-04 15:24:23 +02:00
WRITE_SHORT( m_iExplode );
WRITE_BYTE( 120 ); // scale * 10
WRITE_BYTE( 255 ); // brightness
MESSAGE_END();
2016-07-31 15:48:50 +02:00
2016-06-04 15:24:23 +02:00
// big smoke
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot );
WRITE_BYTE( TE_SMOKE );
WRITE_COORD( vecSpot.x );
WRITE_COORD( vecSpot.y );
2019-10-13 13:49:25 +02:00
WRITE_COORD( vecSpot.z + 512.0f );
2016-06-04 15:24:23 +02:00
WRITE_SHORT( g_sModelIndexSmoke );
WRITE_BYTE( 250 ); // scale * 10
2016-07-31 15:48:50 +02:00
WRITE_BYTE( 5 ); // framerate
2016-06-04 15:24:23 +02:00
MESSAGE_END();
// blast circle
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, pev->origin );
WRITE_BYTE( TE_BEAMCYLINDER );
2016-07-31 15:48:50 +02:00
WRITE_COORD( pev->origin.x );
WRITE_COORD( pev->origin.y );
WRITE_COORD( pev->origin.z );
WRITE_COORD( pev->origin.x );
WRITE_COORD( pev->origin.y );
2016-06-04 15:24:23 +02:00
WRITE_COORD( pev->origin.z + 2000 ); // reach damage radius over .2 seconds
WRITE_SHORT( m_iSpriteTexture );
WRITE_BYTE( 0 ); // startframe
WRITE_BYTE( 0 ); // framerate
WRITE_BYTE( 4 ); // life
WRITE_BYTE( 32 ); // width
WRITE_BYTE( 0 ); // noise
WRITE_BYTE( 255 ); // r, g, b
WRITE_BYTE( 255 ); // r, g, b
WRITE_BYTE( 192 ); // r, g, b
WRITE_BYTE( 128 ); // brightness
WRITE_BYTE( 0 ); // speed
MESSAGE_END();
2019-10-13 13:49:25 +02:00
EMIT_SOUND( ENT( pev ), CHAN_STATIC, "weapons/mortarhit.wav", 1.0f, 0.3f );
2016-06-04 15:24:23 +02:00
RadiusDamage( pev->origin, pev, pev, 300, CLASS_NONE, DMG_BLAST );
2016-07-31 15:48:50 +02:00
if(/*!( pev->spawnflags & SF_NOWRECKAGE ) && */( pev->flags & FL_ONGROUND ) )
2016-06-04 15:24:23 +02:00
{
CBaseEntity *pWreckage = Create( "cycler_wreckage", pev->origin, pev->angles );
2016-07-31 15:48:50 +02:00
// SET_MODEL( ENT( pWreckage->pev ), STRING( pev->model ) );
2019-10-13 13:49:25 +02:00
UTIL_SetSize( pWreckage->pev, Vector( -200.0f, -200.0f, -128.0f ), Vector( 200.0f, 200.0f, -32.0f ) );
2016-06-04 15:24:23 +02:00
pWreckage->pev->frame = pev->frame;
pWreckage->pev->sequence = pev->sequence;
pWreckage->pev->framerate = 0;
2019-10-13 13:49:25 +02:00
pWreckage->pev->dmgtime = gpGlobals->time + 5.0f;
2016-06-04 15:24:23 +02:00
}
// gibs
2019-10-13 13:49:25 +02:00
vecSpot = pev->origin + ( pev->mins + pev->maxs ) * 0.5f;
2016-06-04 15:24:23 +02:00
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot );
WRITE_BYTE( TE_BREAKMODEL);
// position
WRITE_COORD( vecSpot.x );
WRITE_COORD( vecSpot.y );
2019-10-13 13:49:25 +02:00
WRITE_COORD( vecSpot.z + 64.0f );
2016-06-04 15:24:23 +02:00
// size
WRITE_COORD( 400 );
WRITE_COORD( 400 );
WRITE_COORD( 128 );
// velocity
2016-07-31 15:48:50 +02:00
WRITE_COORD( 0 );
2016-06-04 15:24:23 +02:00
WRITE_COORD( 0 );
WRITE_COORD( 200 );
// randomization
2016-07-31 15:48:50 +02:00
WRITE_BYTE( 30 );
2016-06-04 15:24:23 +02:00
// Model
WRITE_SHORT( m_iBodyGibs ); //model id#
// # of shards
WRITE_BYTE( 200 );
// duration
WRITE_BYTE( 200 );// 10.0 seconds
// flags
WRITE_BYTE( BREAK_METAL );
MESSAGE_END();
SetThink( &CBaseEntity::SUB_Remove );
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.1f;
2016-06-04 15:24:23 +02:00
}
}
void CApache::FlyTouch( CBaseEntity *pOther )
{
// bounce if we hit something solid
2016-07-31 15:48:50 +02:00
if( pOther->pev->solid == SOLID_BSP )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
TraceResult tr = UTIL_GetGlobalTrace();
2016-06-04 15:24:23 +02:00
// UNDONE, do a real bounce
2019-10-13 13:49:25 +02:00
pev->velocity = pev->velocity + tr.vecPlaneNormal * ( pev->velocity.Length() + 200.0f );
2016-06-04 15:24:23 +02:00
}
}
void CApache::CrashTouch( CBaseEntity *pOther )
{
// only crash if we hit something solid
2016-07-31 15:48:50 +02:00
if( pOther->pev->solid == SOLID_BSP )
2016-06-04 15:24:23 +02:00
{
SetTouch( NULL );
m_flNextRocket = gpGlobals->time;
pev->nextthink = gpGlobals->time;
}
}
2016-07-31 15:48:50 +02:00
void CApache::GibMonster( void )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
// EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "common/bodysplat.wav", 0.75f, ATTN_NORM, 0, 200 );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
void CApache::HuntThink( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
StudioFrameAdvance();
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.1f;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
ShowDamage();
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( m_pGoalEnt == NULL && !FStringNull( pev->target ) )// this monster has a target
2016-06-04 15:24:23 +02:00
{
m_pGoalEnt = UTIL_FindEntityByTargetname( NULL, STRING( pev->target ) );
2016-07-31 15:48:50 +02:00
if( m_pGoalEnt )
2016-06-04 15:24:23 +02:00
{
m_posDesired = m_pGoalEnt->pev->origin;
UTIL_MakeAimVectors( m_pGoalEnt->pev->angles );
m_vecGoal = gpGlobals->v_forward;
}
}
2016-07-31 15:48:50 +02:00
// if( m_hEnemy == NULL )
2016-06-04 15:24:23 +02:00
{
Look( 4092 );
2016-07-31 15:48:50 +02:00
m_hEnemy = BestVisibleEnemy();
2016-06-04 15:24:23 +02:00
}
// generic speed up
2019-10-13 13:49:25 +02:00
if( m_flGoalSpeed < 800.0f )
m_flGoalSpeed += 5.0f;
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
{
// ALERT( at_console, "%s\n", STRING( m_hEnemy->pev->classname ) );
2016-07-31 15:48:50 +02:00
if( FVisible( m_hEnemy ) )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
if( m_flLastSeen < gpGlobals->time - 5.0f )
2016-06-04 15:24:23 +02:00
m_flPrevSeen = gpGlobals->time;
m_flLastSeen = gpGlobals->time;
2016-07-31 15:48:50 +02:00
m_posTarget = m_hEnemy->Center();
2016-06-04 15:24:23 +02:00
}
else
{
m_hEnemy = NULL;
}
}
2016-07-31 15:48:50 +02:00
m_vecTarget = ( m_posTarget - pev->origin ).Normalize();
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
float flLength = ( pev->origin - m_posDesired ).Length();
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( m_pGoalEnt )
2016-06-04 15:24:23 +02:00
{
// ALERT( at_console, "%.0f\n", flLength );
2019-10-13 13:49:25 +02:00
if( flLength < 128.0f )
2016-06-04 15:24:23 +02:00
{
m_pGoalEnt = UTIL_FindEntityByTargetname( NULL, STRING( m_pGoalEnt->pev->target ) );
2016-07-31 15:48:50 +02:00
if( m_pGoalEnt )
2016-06-04 15:24:23 +02:00
{
m_posDesired = m_pGoalEnt->pev->origin;
UTIL_MakeAimVectors( m_pGoalEnt->pev->angles );
m_vecGoal = gpGlobals->v_forward;
2016-07-31 15:48:50 +02:00
flLength = ( pev->origin - m_posDesired ).Length();
2016-06-04 15:24:23 +02:00
}
}
}
else
{
m_posDesired = pev->origin;
}
2019-10-13 13:49:25 +02:00
if( flLength > 250.0f ) // 500
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
// float flLength2 = ( m_posTarget - pev->origin ).Length() * ( 1.5f - DotProduct( ( m_posTarget - pev->origin ).Normalize(), pev->velocity.Normalize() ) );
2016-07-31 15:48:50 +02:00
// if( flLength2 < flLength )
2019-10-13 13:49:25 +02:00
if( m_flLastSeen + 90.0f > gpGlobals->time && DotProduct( ( m_posTarget - pev->origin ).Normalize(), ( m_posDesired - pev->origin ).Normalize() ) > 0.25f )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
m_vecDesired = ( m_posTarget - pev->origin ).Normalize();
2016-06-04 15:24:23 +02:00
}
else
{
2016-07-31 15:48:50 +02:00
m_vecDesired = ( m_posDesired - pev->origin ).Normalize();
2016-06-04 15:24:23 +02:00
}
}
else
{
m_vecDesired = m_vecGoal;
}
2016-07-31 15:48:50 +02:00
Flight();
2016-06-04 15:24:23 +02:00
// ALERT( at_console, "%.0f %.0f %.0f\n", gpGlobals->time, m_flLastSeen, m_flPrevSeen );
2019-10-13 13:49:25 +02:00
if( ( m_flLastSeen + 1.0f > gpGlobals->time ) && ( m_flPrevSeen + 2.0f < gpGlobals->time ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( FireGun() )
2016-06-04 15:24:23 +02:00
{
// slow down if we're fireing
2019-10-13 13:49:25 +02:00
if( m_flGoalSpeed > 400.0f )
m_flGoalSpeed = 400.0f;
2016-06-04 15:24:23 +02:00
}
// don't fire rockets and gun on easy mode
2016-07-31 15:48:50 +02:00
if( g_iSkillLevel == SKILL_EASY )
2019-10-13 13:49:25 +02:00
m_flNextRocket = gpGlobals->time + 10.0f;
2016-06-04 15:24:23 +02:00
}
UTIL_MakeAimVectors( pev->angles );
2019-10-13 13:49:25 +02:00
Vector vecEst = ( gpGlobals->v_forward * 800.0f + pev->velocity ).Normalize();
// ALERT( at_console, "%d %d %d %4.2f\n", pev->angles.x < 0.0f, DotProduct( pev->velocity, gpGlobals->v_forward ) > -100.0f, m_flNextRocket < gpGlobals->time, DotProduct( m_vecTarget, vecEst ) );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( ( m_iRockets % 2 ) == 1 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
FireRocket();
2019-10-13 13:49:25 +02:00
m_flNextRocket = gpGlobals->time + 0.5f;
2016-07-31 15:48:50 +02:00
if( m_iRockets <= 0 )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
m_flNextRocket = gpGlobals->time + 10.0f;
2016-06-04 15:24:23 +02:00
m_iRockets = 10;
}
}
2019-10-13 13:49:25 +02:00
else if( pev->angles.x < 0.0f && DotProduct( pev->velocity, gpGlobals->v_forward ) > -100.0f && m_flNextRocket < gpGlobals->time )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
if( m_flLastSeen + 60.0f > gpGlobals->time )
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
{
// make sure it's a good shot
2019-10-13 13:49:25 +02:00
if( DotProduct( m_vecTarget, vecEst ) > .965f )
2016-06-04 15:24:23 +02:00
{
TraceResult tr;
2016-07-31 15:48:50 +02:00
2019-10-13 13:49:25 +02:00
UTIL_TraceLine( pev->origin, pev->origin + vecEst * 4096.0f, ignore_monsters, edict(), &tr );
if( (tr.vecEndPos - m_posTarget ).Length() < 512.0f )
2016-07-31 15:48:50 +02:00
FireRocket();
2016-06-04 15:24:23 +02:00
}
}
else
{
TraceResult tr;
2016-07-31 15:48:50 +02:00
2019-10-13 13:49:25 +02:00
UTIL_TraceLine( pev->origin, pev->origin + vecEst * 4096.0f, dont_ignore_monsters, edict(), &tr );
2016-06-04 15:24:23 +02:00
// just fire when close
2019-10-13 13:49:25 +02:00
if( ( tr.vecEndPos - m_posTarget ).Length() < 512.0f )
2016-07-31 15:48:50 +02:00
FireRocket();
2016-06-04 15:24:23 +02:00
}
}
}
}
2016-07-31 15:48:50 +02:00
void CApache::Flight( void )
2016-06-04 15:24:23 +02:00
{
// tilt model 5 degrees
2019-10-13 13:49:25 +02:00
Vector vecAdj = Vector( 5.0f, 0.0f, 0.0f );
2016-06-04 15:24:23 +02:00
// estimate where I'll be facing in one seconds
2019-10-13 13:49:25 +02:00
UTIL_MakeAimVectors( pev->angles + pev->avelocity * 2.0f + vecAdj );
// Vector vecEst1 = pev->origin + pev->velocity + gpGlobals->v_up * m_flForce - Vector( 0.0f, 0.0f, 384.0f );
2016-06-04 15:24:23 +02:00
// float flSide = DotProduct( m_posDesired - vecEst1, gpGlobals->v_right );
float flSide = DotProduct( m_vecDesired, gpGlobals->v_right );
2019-10-13 13:49:25 +02:00
if( flSide < 0.0f )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
if( pev->avelocity.y < 60.0f )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
pev->avelocity.y += 8.0f; // 9 * ( 3.0 / 2.0 );
2016-06-04 15:24:23 +02:00
}
}
else
{
2019-10-13 13:49:25 +02:00
if( pev->avelocity.y > -60.0f )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
pev->avelocity.y -= 8.0f; // 9 * ( 3.0 / 2.0 );
2016-06-04 15:24:23 +02:00
}
}
2019-10-13 13:49:25 +02:00
pev->avelocity.y *= 0.98f;
2016-06-04 15:24:23 +02:00
// estimate where I'll be in two seconds
2019-10-13 13:49:25 +02:00
UTIL_MakeAimVectors( pev->angles + pev->avelocity * 1.0f + vecAdj );
Vector vecEst = pev->origin + pev->velocity * 2.0f + gpGlobals->v_up * m_flForce * 20.0f - Vector( 0.0f, 0.0f, 384.0f * 2.0f );
2016-06-04 15:24:23 +02:00
// add immediate force
2016-07-31 15:48:50 +02:00
UTIL_MakeAimVectors( pev->angles + vecAdj );
2016-06-04 15:24:23 +02:00
pev->velocity.x += gpGlobals->v_up.x * m_flForce;
pev->velocity.y += gpGlobals->v_up.y * m_flForce;
pev->velocity.z += gpGlobals->v_up.z * m_flForce;
// add gravity
2019-10-13 13:49:25 +02:00
pev->velocity.z -= 38.4f; // 32ft/sec
2016-06-04 15:24:23 +02:00
float flSpeed = pev->velocity.Length();
2019-10-13 13:49:25 +02:00
float flDir = DotProduct( Vector( gpGlobals->v_forward.x, gpGlobals->v_forward.y, 0.0f ), Vector( pev->velocity.x, pev->velocity.y, 0.0f ) );
2016-07-31 15:48:50 +02:00
if( flDir < 0 )
2016-06-04 15:24:23 +02:00
flSpeed = -flSpeed;
float flDist = DotProduct( m_posDesired - vecEst, gpGlobals->v_forward );
// float flSlip = DotProduct( pev->velocity, gpGlobals->v_right );
float flSlip = -DotProduct( m_posDesired - vecEst, gpGlobals->v_right );
// fly sideways
2019-10-13 13:49:25 +02:00
if( flSlip > 0.0f )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
if( pev->angles.z > -30.0f && pev->avelocity.z > -15.0f )
pev->avelocity.z -= 4.0f;
2016-06-04 15:24:23 +02:00
else
2019-10-13 13:49:25 +02:00
pev->avelocity.z += 2.0f;
2016-06-04 15:24:23 +02:00
}
else
{
2019-10-13 13:49:25 +02:00
if( pev->angles.z < 30 && pev->avelocity.z < 15.0f )
pev->avelocity.z += 4.0f;
2016-06-04 15:24:23 +02:00
else
2019-10-13 13:49:25 +02:00
pev->avelocity.z -= 2.0f;
2016-06-04 15:24:23 +02:00
}
// sideways drag
2019-10-13 13:49:25 +02:00
pev->velocity.x = pev->velocity.x * ( 1.0f - fabs( gpGlobals->v_right.x ) * 0.05f );
pev->velocity.y = pev->velocity.y * ( 1.0f - fabs( gpGlobals->v_right.y ) * 0.05f );
pev->velocity.z = pev->velocity.z * ( 1.0f - fabs( gpGlobals->v_right.z ) * 0.05f );
2016-06-04 15:24:23 +02:00
// general drag
2019-10-13 13:49:25 +02:00
pev->velocity = pev->velocity * 0.995f;
2016-07-31 15:48:50 +02:00
2016-06-04 15:24:23 +02:00
// apply power to stay correct height
2019-10-13 13:49:25 +02:00
if( m_flForce < 80.0f && vecEst.z < m_posDesired.z )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
m_flForce += 12.0f;
2016-06-04 15:24:23 +02:00
}
2019-10-13 13:49:25 +02:00
else if( m_flForce > 30.0f )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( vecEst.z > m_posDesired.z )
2019-10-13 13:49:25 +02:00
m_flForce -= 8.0f;
2016-06-04 15:24:23 +02:00
}
// pitch forward or back to get to target
2019-10-13 13:49:25 +02:00
if( flDist > 0.0f && flSpeed < m_flGoalSpeed /* && flSpeed < flDist */ && pev->angles.x + pev->avelocity.x > -40.0f )
2016-06-04 15:24:23 +02:00
{
// ALERT( at_console, "F " );
// lean forward
2019-10-13 14:12:41 +02:00
pev->avelocity.x -= 12.0f;
2016-06-04 15:24:23 +02:00
}
2019-10-13 13:49:25 +02:00
else if( flDist < 0.0f && flSpeed > -50.0f && pev->angles.x + pev->avelocity.x < 20.0f )
2016-06-04 15:24:23 +02:00
{
// ALERT( at_console, "B " );
// lean backward
2019-10-13 13:49:25 +02:00
pev->avelocity.x += 12.0f;
2016-06-04 15:24:23 +02:00
}
2019-10-13 13:49:25 +02:00
else if( pev->angles.x + pev->avelocity.x > 0.0f )
2016-06-04 15:24:23 +02:00
{
// ALERT( at_console, "f " );
2019-10-13 13:49:25 +02:00
pev->avelocity.x -= 4.0f;
2016-06-04 15:24:23 +02:00
}
2019-10-13 13:49:25 +02:00
else if( pev->angles.x + pev->avelocity.x < 0.0f )
2016-06-04 15:24:23 +02:00
{
// ALERT( at_console, "b " );
2019-10-13 13:49:25 +02:00
pev->avelocity.x += 4.0f;
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
// ALERT( at_console, "%.0f %.0f : %.0f %.0f : %.0f %.0f : %.0f\n", pev->origin.x, pev->velocity.x, flDist, flSpeed, pev->angles.x, pev->avelocity.x, m_flForce );
// ALERT( at_console, "%.0f %.0f : %.0f %0.f : %.0f\n", pev->origin.z, pev->velocity.z, vecEst.z, m_posDesired.z, m_flForce );
2016-06-04 15:24:23 +02:00
// make rotor, engine sounds
2016-07-31 15:48:50 +02:00
if( m_iSoundState == 0 )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
EMIT_SOUND_DYN( ENT( pev ), CHAN_STATIC, "apache/ap_rotor2.wav", 1.0f, 0.3f, 0, 110 );
// EMIT_SOUND_DYN( ENT( pev ), CHAN_STATIC, "apache/ap_whine1.wav", 0.5f, 0.2f, 0, 110 );
2016-06-04 15:24:23 +02:00
m_iSoundState = SND_CHANGE_PITCH; // hack for going through level transitions
}
else
{
CBaseEntity *pPlayer = NULL;
pPlayer = UTIL_FindEntityByClassname( NULL, "player" );
// UNDONE: this needs to send different sounds to every player for multiplayer.
2016-07-31 15:48:50 +02:00
if( pPlayer )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
float pitch = DotProduct( pev->velocity - pPlayer->pev->velocity, ( pPlayer->pev->origin - pev->origin ).Normalize() );
2016-06-04 15:24:23 +02:00
2019-10-13 13:49:25 +02:00
pitch = (int)( 100.0f + pitch / 50.0f );
2016-06-04 15:24:23 +02:00
2019-10-13 13:49:25 +02:00
if( pitch > 250.0f )
pitch = 250.0f;
if( pitch < 50.0f )
pitch = 50.0f;
if( pitch == 100.0f )
pitch = 101.0f;
2016-06-04 15:24:23 +02:00
/*float flVol = ( m_flForce / 100.0f ) + 0.1f;
2019-10-13 13:49:25 +02:00
if( flVol > 1.0f )
flVol = 1.0f;*/
2016-06-04 15:24:23 +02:00
2019-10-13 13:49:25 +02:00
EMIT_SOUND_DYN( ENT( pev ), CHAN_STATIC, "apache/ap_rotor2.wav", 1.0f, 0.3f, SND_CHANGE_PITCH | SND_CHANGE_VOL, pitch );
2016-06-04 15:24:23 +02:00
}
2019-10-13 13:49:25 +02:00
// EMIT_SOUND_DYN( ENT( pev ), CHAN_STATIC, "apache/ap_whine1.wav", flVol, 0.2f, SND_CHANGE_PITCH | SND_CHANGE_VOL, pitch );
2016-06-04 15:24:23 +02:00
// ALERT( at_console, "%.0f %.2f\n", pitch, flVol );
}
}
2016-07-31 15:48:50 +02:00
void CApache::FireRocket( void )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
static float side = 1.0f;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( m_iRockets <= 0 )
2016-06-04 15:24:23 +02:00
return;
UTIL_MakeAimVectors( pev->angles );
2019-10-13 13:49:25 +02:00
Vector vecSrc = pev->origin + 1.5f * ( gpGlobals->v_forward * 21.0f + gpGlobals->v_right * 70.0f * side + gpGlobals->v_up * -79.0f );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
switch( m_iRockets % 5 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
case 0:
2019-10-13 13:49:25 +02:00
vecSrc = vecSrc + gpGlobals->v_right * 10.0f;
2016-07-31 15:48:50 +02:00
break;
case 1:
2019-10-13 13:49:25 +02:00
vecSrc = vecSrc - gpGlobals->v_right * 10.0f;
2016-07-31 15:48:50 +02:00
break;
case 2:
2019-10-13 13:49:25 +02:00
vecSrc = vecSrc + gpGlobals->v_up * 10.0f;
2016-07-31 15:48:50 +02:00
break;
case 3:
2019-10-13 13:49:25 +02:00
vecSrc = vecSrc - gpGlobals->v_up * 10.0f;
2016-07-31 15:48:50 +02:00
break;
case 4:
break;
2016-06-04 15:24:23 +02:00
}
CBaseEntity *pRocket = CBaseEntity::Create( "hvr_rocket", vecSrc, pev->angles, edict() );
2016-07-31 15:48:50 +02:00
if( pRocket )
{
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSrc );
WRITE_BYTE( TE_SMOKE );
WRITE_COORD( vecSrc.x );
WRITE_COORD( vecSrc.y );
WRITE_COORD( vecSrc.z );
WRITE_SHORT( g_sModelIndexSmoke );
WRITE_BYTE( 20 ); // scale * 10
WRITE_BYTE( 12 ); // framerate
MESSAGE_END();
2019-10-13 13:49:25 +02:00
pRocket->pev->velocity = pev->velocity + gpGlobals->v_forward * 100.0f;
2016-06-04 15:24:23 +02:00
m_iRockets--;
2016-06-04 15:24:23 +02:00
side = - side;
}
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
BOOL CApache::FireGun()
2016-06-04 15:24:23 +02:00
{
UTIL_MakeAimVectors( pev->angles );
2016-07-31 15:48:50 +02:00
2016-06-04 15:24:23 +02:00
Vector posGun, angGun;
GetAttachment( 1, posGun, angGun );
2016-07-31 15:48:50 +02:00
Vector vecTarget = ( m_posTarget - posGun ).Normalize();
2016-06-04 15:24:23 +02:00
Vector vecOut;
vecOut.x = DotProduct( gpGlobals->v_forward, vecTarget );
vecOut.y = -DotProduct( gpGlobals->v_right, vecTarget );
vecOut.z = DotProduct( gpGlobals->v_up, vecTarget );
2016-07-31 15:48:50 +02:00
Vector angles = UTIL_VecToAngles( vecOut );
2016-06-04 15:24:23 +02:00
angles.x = -angles.x;
2019-10-13 13:49:25 +02:00
if( angles.y > 180.0f )
angles.y = angles.y - 360.0f;
if( angles.y < -180.0f )
angles.y = angles.y + 360.0f;
if( angles.x > 180.0f )
angles.x = angles.x - 360.0f;
if( angles.x < -180.0f )
angles.x = angles.x + 360.0f;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( angles.x > m_angGun.x )
2019-10-13 13:49:25 +02:00
m_angGun.x = Q_min( angles.x, m_angGun.x + 12.0f );
2016-07-31 15:48:50 +02:00
if( angles.x < m_angGun.x )
2019-10-13 13:49:25 +02:00
m_angGun.x = Q_max( angles.x, m_angGun.x - 12.0f );
2016-07-31 15:48:50 +02:00
if( angles.y > m_angGun.y )
2019-10-13 13:49:25 +02:00
m_angGun.y = Q_min( angles.y, m_angGun.y + 12.0f );
2016-07-31 15:48:50 +02:00
if( angles.y < m_angGun.y )
2019-10-13 13:49:25 +02:00
m_angGun.y = Q_max( angles.y, m_angGun.y - 12.0f );
2016-06-04 15:24:23 +02:00
m_angGun.y = SetBoneController( 0, m_angGun.y );
m_angGun.x = SetBoneController( 1, m_angGun.x );
Vector posBarrel, angBarrel;
GetAttachment( 0, posBarrel, angBarrel );
2016-07-31 15:48:50 +02:00
Vector vecGun = ( posBarrel - posGun ).Normalize();
2016-06-04 15:24:23 +02:00
2019-10-13 13:49:25 +02:00
if( DotProduct( vecGun, vecTarget ) > 0.98f )
2016-06-04 15:24:23 +02:00
{
#if 1
FireBullets( 1, posGun, vecGun, VECTOR_CONE_4DEGREES, 8192, BULLET_MONSTER_12MM, 1 );
2019-10-13 13:49:25 +02:00
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "turret/tu_fire1.wav", 1, 0.3f );
2016-06-04 15:24:23 +02:00
#else
static float flNext;
TraceResult tr;
UTIL_TraceLine( posGun, posGun + vecGun * 8192, dont_ignore_monsters, ENT( pev ), &tr );
2016-07-31 15:48:50 +02:00
if( !m_pBeam )
2016-06-04 15:24:23 +02:00
{
m_pBeam = CBeam::BeamCreate( "sprites/lgtning.spr", 80 );
2016-07-31 15:48:50 +02:00
m_pBeam->PointEntInit( pev->origin, entindex() );
2016-06-04 15:24:23 +02:00
m_pBeam->SetEndAttachment( 1 );
m_pBeam->SetColor( 255, 180, 96 );
m_pBeam->SetBrightness( 192 );
}
2016-07-31 15:48:50 +02:00
if( flNext < gpGlobals->time )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
flNext = gpGlobals->time + 0.5f;
2016-06-04 15:24:23 +02:00
m_pBeam->SetStartPos( tr.vecEndPos );
}
#endif
return TRUE;
}
else
{
2016-07-31 15:48:50 +02:00
if( m_pBeam )
2016-06-04 15:24:23 +02:00
{
UTIL_Remove( m_pBeam );
m_pBeam = NULL;
}
}
return FALSE;
}
2016-07-31 15:48:50 +02:00
void CApache::ShowDamage( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_iDoSmokePuff > 0 || RANDOM_LONG( 0, 99 ) > pev->health )
2016-06-04 15:24:23 +02:00
{
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, pev->origin );
WRITE_BYTE( TE_SMOKE );
WRITE_COORD( pev->origin.x );
WRITE_COORD( pev->origin.y );
WRITE_COORD( pev->origin.z - 32 );
WRITE_SHORT( g_sModelIndexSmoke );
2016-07-31 15:48:50 +02:00
WRITE_BYTE( RANDOM_LONG( 0, 9 ) + 20 ); // scale * 10
2016-06-04 15:24:23 +02:00
WRITE_BYTE( 12 ); // framerate
MESSAGE_END();
}
2016-07-31 15:48:50 +02:00
if( m_iDoSmokePuff > 0 )
2016-06-04 15:24:23 +02:00
m_iDoSmokePuff--;
}
2016-07-31 15:48:50 +02:00
int CApache::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pevInflictor->owner == edict() )
2016-06-04 15:24:23 +02:00
return 0;
2016-07-31 15:48:50 +02:00
if( bitsDamageType & DMG_BLAST )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
flDamage *= 2.0f;
2016-06-04 15:24:23 +02:00
}
/*
2019-10-13 13:49:25 +02:00
if( ( bitsDamageType & DMG_BULLET ) && flDamage > 50.0f )
2016-06-04 15:24:23 +02:00
{
// clip bullet damage at 50
2019-10-13 13:49:25 +02:00
flDamage = 50.0f;
2016-06-04 15:24:23 +02:00
}
*/
// ALERT( at_console, "%.0f\n", flDamage );
2016-07-31 15:48:50 +02:00
return CBaseEntity::TakeDamage( pevInflictor, pevAttacker, flDamage, bitsDamageType );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
void CApache::TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType )
2016-06-04 15:24:23 +02:00
{
// ALERT( at_console, "%d %.0f\n", ptr->iHitgroup, flDamage );
// ignore blades
2016-07-31 15:48:50 +02:00
if( ptr->iHitgroup == 6 && ( bitsDamageType & ( DMG_ENERGYBEAM | DMG_BULLET | DMG_CLUB ) ) )
2016-06-04 15:24:23 +02:00
return;
// hit hard, hits cockpit, hits engines
2016-07-31 15:48:50 +02:00
if( flDamage > 50 || ptr->iHitgroup == 1 || ptr->iHitgroup == 2 )
2016-06-04 15:24:23 +02:00
{
// ALERT( at_console, "%.0f\n", flDamage );
AddMultiDamage( pevAttacker, this, flDamage, bitsDamageType );
2019-10-13 13:49:25 +02:00
m_iDoSmokePuff = 3.0f + ( flDamage / 5.0f );
2016-06-04 15:24:23 +02:00
}
else
{
// do half damage in the body
2019-10-13 13:49:25 +02:00
// AddMultiDamage( pevAttacker, this, flDamage / 2.0f, bitsDamageType );
UTIL_Ricochet( ptr->vecEndPos, 2.0f );
2016-06-04 15:24:23 +02:00
}
}
class CApacheHVR : public CGrenade
{
void Spawn( void );
void Precache( void );
void EXPORT IgniteThink( void );
void EXPORT AccelerateThink( void );
2016-07-31 15:48:50 +02:00
int Save( CSave &save );
int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
2016-06-04 15:24:23 +02:00
int m_iTrail;
Vector m_vecForward;
};
LINK_ENTITY_TO_CLASS( hvr_rocket, CApacheHVR )
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
TYPEDESCRIPTION CApacheHVR::m_SaveData[] =
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
//DEFINE_FIELD( CApacheHVR, m_iTrail, FIELD_INTEGER ), // Dont' save, precache
2016-06-04 15:24:23 +02:00
DEFINE_FIELD( CApacheHVR, m_vecForward, FIELD_VECTOR ),
};
IMPLEMENT_SAVERESTORE( CApacheHVR, CGrenade )
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
void CApacheHVR::Spawn( void )
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
// motor
pev->movetype = MOVETYPE_FLY;
pev->solid = SOLID_BBOX;
2016-07-31 15:48:50 +02:00
SET_MODEL( ENT( pev ), "models/HVR.mdl" );
UTIL_SetSize( pev, Vector( 0, 0, 0), Vector(0, 0, 0) );
2016-06-04 15:24:23 +02:00
UTIL_SetOrigin( pev, pev->origin );
SetThink( &CApacheHVR::IgniteThink );
SetTouch( &CGrenade::ExplodeTouch );
UTIL_MakeAimVectors( pev->angles );
m_vecForward = gpGlobals->v_forward;
2019-10-13 13:49:25 +02:00
pev->gravity = 0.5f;
2016-06-04 15:24:23 +02:00
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.1f;
2016-06-04 15:24:23 +02:00
pev->dmg = 150;
}
2016-07-31 15:48:50 +02:00
void CApacheHVR::Precache( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
PRECACHE_MODEL( "models/HVR.mdl" );
m_iTrail = PRECACHE_MODEL( "sprites/smoke.spr" );
2019-10-13 13:49:25 +02:00
PRECACHE_SOUND( "weapons/rocket1.wav" );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
void CApacheHVR::IgniteThink( void )
2016-06-04 15:24:23 +02:00
{
// pev->movetype = MOVETYPE_TOSS;
// pev->movetype = MOVETYPE_FLY;
pev->effects |= EF_LIGHT;
// make rocket sound
2019-10-13 13:49:25 +02:00
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "weapons/rocket1.wav", 1, 0.5f );
2016-06-04 15:24:23 +02:00
// rocket trail
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_BEAMFOLLOW );
2016-07-31 15:48:50 +02:00
WRITE_SHORT( entindex() ); // entity
WRITE_SHORT( m_iTrail ); // model
2016-06-04 15:24:23 +02:00
WRITE_BYTE( 15 ); // life
WRITE_BYTE( 5 ); // width
WRITE_BYTE( 224 ); // r, g, b
WRITE_BYTE( 224 ); // r, g, b
WRITE_BYTE( 255 ); // r, g, b
WRITE_BYTE( 255 ); // brightness
MESSAGE_END(); // move PHS/PVS data sending into here (SEND_ALL, SEND_PVS, SEND_PHS)
// set to accelerate
SetThink( &CApacheHVR::AccelerateThink );
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.1f;
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
void CApacheHVR::AccelerateThink( void )
2016-06-04 15:24:23 +02:00
{
// check world boundaries
2019-10-13 13:49:25 +02:00
if( pev->origin.x < -4096.0f || pev->origin.x > 4096.0f || pev->origin.y < -4096.0f || pev->origin.y > 4096.0f || pev->origin.z < -4096.0f || pev->origin.z > 4096.0f )
2016-06-04 15:24:23 +02:00
{
UTIL_Remove( this );
return;
}
// accelerate
float flSpeed = pev->velocity.Length();
2019-10-13 13:49:25 +02:00
if( flSpeed < 1800.0f )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
pev->velocity = pev->velocity + m_vecForward * 200.0f;
2016-06-04 15:24:23 +02:00
}
// re-aim
pev->angles = UTIL_VecToAngles( pev->velocity );
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.1f;
2016-06-04 15:24:23 +02:00
}
2016-04-17 22:30:05 +02:00
#endif