Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1028 lines
27 KiB

9 years ago
/***
*
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* This source code contains proprietary and confidential information of
* Valve LLC and its suppliers. Access to this code is restricted to
* persons who have executed a written SDK license with Valve. Any access,
* use or distribution of this code by or to any unlicensed person is illegal.
*
****/
#ifndef OEM_BUILD
#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
{
8 years ago
int Save( CSave &save );
int Restore( CRestore &restore );
9 years ago
static TYPEDESCRIPTION m_SaveData[];
void Spawn( void );
void Precache( void );
8 years ago
int Classify( void ) { return CLASS_HUMAN_MILITARY; };
int BloodColor( void ) { return DONT_BLEED; }
9 years ago
void Killed( entvars_t *pevAttacker, int iGib );
void GibMonster( void );
void SetObjectCollisionBox( void )
{
8 years ago
pev->absmin = pev->origin + Vector( -300, -300, -172 );
pev->absmax = pev->origin + Vector( 300, 300, 8 );
9 years ago
}
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 );
8 years ago
9 years ago
int TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType );
8 years ago
void TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType );
9 years ago
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 )
9 years ago
8 years ago
TYPEDESCRIPTION CApache::m_SaveData[] =
9 years ago
{
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 ),
8 years ago
//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 ),
9 years ago
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 )
9 years ago
8 years ago
void CApache::Spawn( void )
9 years ago
{
8 years ago
Precache();
9 years ago
// motor
pev->movetype = MOVETYPE_FLY;
pev->solid = SOLID_BBOX;
8 years ago
SET_MODEL( ENT( pev ), "models/apache.mdl" );
9 years ago
UTIL_SetSize( pev, Vector( -32, -32, -64 ), Vector( 32, 32, 0 ) );
UTIL_SetOrigin( pev, pev->origin );
pev->flags |= FL_MONSTER;
8 years ago
pev->takedamage = DAMAGE_AIM;
pev->health = gSkillData.apacheHealth;
9 years ago
m_flFieldOfView = -0.707; // 270 degrees
pev->sequence = 0;
8 years ago
ResetSequenceInfo();
pev->frame = RANDOM_LONG( 0, 0xFF );
9 years ago
InitBoneControllers();
8 years ago
if( pev->spawnflags & SF_WAITFORTRIGGER )
9 years ago
{
SetUse( &CApache::StartupUse );
}
else
{
SetThink( &CApache::HuntThink );
SetTouch( &CApache::FlyTouch );
pev->nextthink = gpGlobals->time + 1.0;
}
m_iRockets = 10;
}
void CApache::Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/apache.mdl" );
9 years ago
8 years ago
PRECACHE_SOUND( "apache/ap_rotor1.wav" );
PRECACHE_SOUND( "apache/ap_rotor2.wav" );
PRECACHE_SOUND( "apache/ap_rotor3.wav" );
PRECACHE_SOUND( "apache/ap_whine1.wav" );
9 years ago
8 years ago
PRECACHE_SOUND( "weapons/mortarhit.wav" );
9 years ago
m_iSpriteTexture = PRECACHE_MODEL( "sprites/white.spr" );
8 years ago
PRECACHE_SOUND( "turret/tu_fire1.wav" );
9 years ago
8 years ago
PRECACHE_MODEL( "sprites/lgtning.spr" );
9 years ago
8 years ago
m_iExplode = PRECACHE_MODEL( "sprites/fexplo.spr" );
9 years ago
m_iBodyGibs = PRECACHE_MODEL( "models/metalplategibs_green.mdl" );
UTIL_PrecacheOther( "hvr_rocket" );
}
void CApache::NullThink( void )
{
8 years ago
StudioFrameAdvance();
9 years ago
pev->nextthink = gpGlobals->time + 0.5;
}
void CApache::StartupUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
SetThink( &CApache::HuntThink );
SetTouch( &CApache::FlyTouch );
pev->nextthink = gpGlobals->time + 0.1;
SetUse( NULL );
}
8 years ago
void CApache::Killed( entvars_t *pevAttacker, int iGib )
9 years ago
{
pev->movetype = MOVETYPE_TOSS;
pev->gravity = 0.3;
8 years ago
STOP_SOUND( ENT( pev ), CHAN_STATIC, "apache/ap_rotor2.wav" );
9 years ago
8 years ago
UTIL_SetSize( pev, Vector( -32, -32, -64 ), Vector( 32, 32, 0 ) );
9 years ago
SetThink( &CApache::DyingThink );
SetTouch( &CApache::CrashTouch );
pev->nextthink = gpGlobals->time + 0.1;
pev->health = 0;
pev->takedamage = DAMAGE_NO;
8 years ago
if( pev->spawnflags & SF_NOWRECKAGE )
9 years ago
{
m_flNextRocket = gpGlobals->time + 4.0;
}
else
{
m_flNextRocket = gpGlobals->time + 15.0;
}
}
8 years ago
void CApache::DyingThink( void )
9 years ago
{
8 years ago
StudioFrameAdvance();
9 years ago
pev->nextthink = gpGlobals->time + 0.1;
pev->avelocity = pev->avelocity * 1.02;
// still falling?
8 years ago
if( m_flNextRocket > gpGlobals->time )
9 years ago
{
// random explosions
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, pev->origin );
8 years ago
WRITE_BYTE( TE_EXPLOSION ); // This just makes a dynamic light now
WRITE_COORD( pev->origin.x + RANDOM_FLOAT( -150, 150 ) );
WRITE_COORD( pev->origin.y + RANDOM_FLOAT( -150, 150 ) );
WRITE_COORD( pev->origin.z + RANDOM_FLOAT( -150, -50 ) );
9 years ago
WRITE_SHORT( g_sModelIndexFireball );
8 years ago
WRITE_BYTE( RANDOM_LONG( 0, 29 ) + 30 ); // scale * 10
WRITE_BYTE( 12 ); // framerate
9 years ago
WRITE_BYTE( TE_EXPLFLAG_NONE );
MESSAGE_END();
// lots of smoke
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, pev->origin );
WRITE_BYTE( TE_SMOKE );
8 years ago
WRITE_COORD( pev->origin.x + RANDOM_FLOAT( -150, 150 ) );
WRITE_COORD( pev->origin.y + RANDOM_FLOAT( -150, 150 ) );
WRITE_COORD( pev->origin.z + RANDOM_FLOAT( -150, -50 ) );
9 years ago
WRITE_SHORT( g_sModelIndexSmoke );
WRITE_BYTE( 100 ); // scale * 10
8 years ago
WRITE_BYTE( 10 ); // framerate
9 years ago
MESSAGE_END();
8 years ago
Vector vecSpot = pev->origin + ( pev->mins + pev->maxs ) * 0.5;
9 years ago
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot );
8 years ago
WRITE_BYTE( TE_BREAKMODEL );
9 years ago
// 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;
pev->nextthink = gpGlobals->time + 0.2;
return;
}
else
{
8 years ago
Vector vecSpot = pev->origin + ( pev->mins + pev->maxs ) * 0.5;
9 years ago
/*
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 );
WRITE_COORD( vecSpot.z + 300 );
WRITE_SHORT( g_sModelIndexFireball );
WRITE_BYTE( 250 ); // scale * 10
8 years ago
WRITE_BYTE( 8 ); // framerate
9 years ago
MESSAGE_END();
*/
// fireball
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot );
WRITE_BYTE( TE_SPRITE );
WRITE_COORD( vecSpot.x );
WRITE_COORD( vecSpot.y );
WRITE_COORD( vecSpot.z + 256 );
WRITE_SHORT( m_iExplode );
WRITE_BYTE( 120 ); // scale * 10
WRITE_BYTE( 255 ); // brightness
MESSAGE_END();
8 years ago
9 years ago
// big smoke
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot );
WRITE_BYTE( TE_SMOKE );
WRITE_COORD( vecSpot.x );
WRITE_COORD( vecSpot.y );
WRITE_COORD( vecSpot.z + 512 );
WRITE_SHORT( g_sModelIndexSmoke );
WRITE_BYTE( 250 ); // scale * 10
8 years ago
WRITE_BYTE( 5 ); // framerate
9 years ago
MESSAGE_END();
// blast circle
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, pev->origin );
WRITE_BYTE( TE_BEAMCYLINDER );
8 years ago
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 );
9 years ago
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();
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_STATIC, "weapons/mortarhit.wav", 1.0, 0.3 );
9 years ago
RadiusDamage( pev->origin, pev, pev, 300, CLASS_NONE, DMG_BLAST );
8 years ago
if(/*!( pev->spawnflags & SF_NOWRECKAGE ) && */( pev->flags & FL_ONGROUND ) )
9 years ago
{
CBaseEntity *pWreckage = Create( "cycler_wreckage", pev->origin, pev->angles );
8 years ago
// SET_MODEL( ENT( pWreckage->pev ), STRING( pev->model ) );
9 years ago
UTIL_SetSize( pWreckage->pev, Vector( -200, -200, -128 ), Vector( 200, 200, -32 ) );
pWreckage->pev->frame = pev->frame;
pWreckage->pev->sequence = pev->sequence;
pWreckage->pev->framerate = 0;
pWreckage->pev->dmgtime = gpGlobals->time + 5;
}
// gibs
8 years ago
vecSpot = pev->origin + ( pev->mins + pev->maxs ) * 0.5;
9 years ago
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot );
WRITE_BYTE( TE_BREAKMODEL);
// position
WRITE_COORD( vecSpot.x );
WRITE_COORD( vecSpot.y );
8 years ago
WRITE_COORD( vecSpot.z + 64 );
9 years ago
// size
WRITE_COORD( 400 );
WRITE_COORD( 400 );
WRITE_COORD( 128 );
// velocity
8 years ago
WRITE_COORD( 0 );
9 years ago
WRITE_COORD( 0 );
WRITE_COORD( 200 );
// randomization
8 years ago
WRITE_BYTE( 30 );
9 years ago
// 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 );
pev->nextthink = gpGlobals->time + 0.1;
}
}
void CApache::FlyTouch( CBaseEntity *pOther )
{
// bounce if we hit something solid
8 years ago
if( pOther->pev->solid == SOLID_BSP )
9 years ago
{
8 years ago
TraceResult tr = UTIL_GetGlobalTrace();
9 years ago
// UNDONE, do a real bounce
8 years ago
pev->velocity = pev->velocity + tr.vecPlaneNormal * ( pev->velocity.Length() + 200 );
9 years ago
}
}
void CApache::CrashTouch( CBaseEntity *pOther )
{
// only crash if we hit something solid
8 years ago
if( pOther->pev->solid == SOLID_BSP )
9 years ago
{
SetTouch( NULL );
m_flNextRocket = gpGlobals->time;
pev->nextthink = gpGlobals->time;
}
}
8 years ago
void CApache::GibMonster( void )
9 years ago
{
8 years ago
// EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "common/bodysplat.wav", 0.75, ATTN_NORM, 0, 200 );
9 years ago
}
8 years ago
void CApache::HuntThink( void )
9 years ago
{
8 years ago
StudioFrameAdvance();
9 years ago
pev->nextthink = gpGlobals->time + 0.1;
8 years ago
ShowDamage();
9 years ago
8 years ago
if( m_pGoalEnt == NULL && !FStringNull( pev->target ) )// this monster has a target
9 years ago
{
m_pGoalEnt = UTIL_FindEntityByTargetname( NULL, STRING( pev->target ) );
8 years ago
if( m_pGoalEnt )
9 years ago
{
m_posDesired = m_pGoalEnt->pev->origin;
UTIL_MakeAimVectors( m_pGoalEnt->pev->angles );
m_vecGoal = gpGlobals->v_forward;
}
}
8 years ago
// if( m_hEnemy == NULL )
9 years ago
{
Look( 4092 );
8 years ago
m_hEnemy = BestVisibleEnemy();
9 years ago
}
// generic speed up
8 years ago
if( m_flGoalSpeed < 800 )
9 years ago
m_flGoalSpeed += 5;
if( m_hEnemy != 0 )
9 years ago
{
// ALERT( at_console, "%s\n", STRING( m_hEnemy->pev->classname ) );
8 years ago
if( FVisible( m_hEnemy ) )
9 years ago
{
8 years ago
if( m_flLastSeen < gpGlobals->time - 5 )
9 years ago
m_flPrevSeen = gpGlobals->time;
m_flLastSeen = gpGlobals->time;
8 years ago
m_posTarget = m_hEnemy->Center();
9 years ago
}
else
{
m_hEnemy = NULL;
}
}
8 years ago
m_vecTarget = ( m_posTarget - pev->origin ).Normalize();
9 years ago
8 years ago
float flLength = ( pev->origin - m_posDesired ).Length();
9 years ago
8 years ago
if( m_pGoalEnt )
9 years ago
{
// ALERT( at_console, "%.0f\n", flLength );
8 years ago
if( flLength < 128 )
9 years ago
{
m_pGoalEnt = UTIL_FindEntityByTargetname( NULL, STRING( m_pGoalEnt->pev->target ) );
8 years ago
if( m_pGoalEnt )
9 years ago
{
m_posDesired = m_pGoalEnt->pev->origin;
UTIL_MakeAimVectors( m_pGoalEnt->pev->angles );
m_vecGoal = gpGlobals->v_forward;
8 years ago
flLength = ( pev->origin - m_posDesired ).Length();
9 years ago
}
}
}
else
{
m_posDesired = pev->origin;
}
8 years ago
if( flLength > 250 ) // 500
9 years ago
{
8 years ago
// float flLength2 = ( m_posTarget - pev->origin ).Length() * ( 1.5 - DotProduct( ( m_posTarget - pev->origin ).Normalize(), pev->velocity.Normalize() ) );
// if( flLength2 < flLength )
if( m_flLastSeen + 90 > gpGlobals->time && DotProduct( ( m_posTarget - pev->origin ).Normalize(), ( m_posDesired - pev->origin ).Normalize() ) > 0.25 )
9 years ago
{
8 years ago
m_vecDesired = ( m_posTarget - pev->origin ).Normalize();
9 years ago
}
else
{
8 years ago
m_vecDesired = ( m_posDesired - pev->origin ).Normalize();
9 years ago
}
}
else
{
m_vecDesired = m_vecGoal;
}
8 years ago
Flight();
9 years ago
// ALERT( at_console, "%.0f %.0f %.0f\n", gpGlobals->time, m_flLastSeen, m_flPrevSeen );
8 years ago
if( ( m_flLastSeen + 1 > gpGlobals->time ) && ( m_flPrevSeen + 2 < gpGlobals->time ) )
9 years ago
{
8 years ago
if( FireGun() )
9 years ago
{
// slow down if we're fireing
8 years ago
if( m_flGoalSpeed > 400 )
9 years ago
m_flGoalSpeed = 400;
}
// don't fire rockets and gun on easy mode
8 years ago
if( g_iSkillLevel == SKILL_EASY )
9 years ago
m_flNextRocket = gpGlobals->time + 10.0;
}
UTIL_MakeAimVectors( pev->angles );
8 years ago
Vector vecEst = ( gpGlobals->v_forward * 800 + pev->velocity ).Normalize();
9 years ago
// ALERT( at_console, "%d %d %d %4.2f\n", pev->angles.x < 0, DotProduct( pev->velocity, gpGlobals->v_forward ) > -100, m_flNextRocket < gpGlobals->time, DotProduct( m_vecTarget, vecEst ) );
8 years ago
if( ( m_iRockets % 2 ) == 1 )
9 years ago
{
8 years ago
FireRocket();
9 years ago
m_flNextRocket = gpGlobals->time + 0.5;
8 years ago
if( m_iRockets <= 0 )
9 years ago
{
m_flNextRocket = gpGlobals->time + 10;
m_iRockets = 10;
}
}
8 years ago
else if( pev->angles.x < 0 && DotProduct( pev->velocity, gpGlobals->v_forward ) > -100 && m_flNextRocket < gpGlobals->time )
9 years ago
{
8 years ago
if( m_flLastSeen + 60 > gpGlobals->time )
9 years ago
{
if( m_hEnemy != 0 )
9 years ago
{
// make sure it's a good shot
8 years ago
if( DotProduct( m_vecTarget, vecEst ) > .965 )
9 years ago
{
TraceResult tr;
8 years ago
9 years ago
UTIL_TraceLine( pev->origin, pev->origin + vecEst * 4096, ignore_monsters, edict(), &tr );
8 years ago
if( (tr.vecEndPos - m_posTarget ).Length() < 512 )
FireRocket();
9 years ago
}
}
else
{
TraceResult tr;
8 years ago
9 years ago
UTIL_TraceLine( pev->origin, pev->origin + vecEst * 4096, dont_ignore_monsters, edict(), &tr );
// just fire when close
8 years ago
if( ( tr.vecEndPos - m_posTarget ).Length() < 512 )
FireRocket();
9 years ago
}
}
}
}
8 years ago
void CApache::Flight( void )
9 years ago
{
// tilt model 5 degrees
Vector vecAdj = Vector( 5.0, 0, 0 );
// estimate where I'll be facing in one seconds
8 years ago
UTIL_MakeAimVectors( pev->angles + pev->avelocity * 2 + vecAdj );
9 years ago
// Vector vecEst1 = pev->origin + pev->velocity + gpGlobals->v_up * m_flForce - Vector( 0, 0, 384 );
// float flSide = DotProduct( m_posDesired - vecEst1, gpGlobals->v_right );
float flSide = DotProduct( m_vecDesired, gpGlobals->v_right );
8 years ago
if( flSide < 0 )
9 years ago
{
8 years ago
if( pev->avelocity.y < 60 )
9 years ago
{
8 years ago
pev->avelocity.y += 8; // 9 * ( 3.0 / 2.0 );
9 years ago
}
}
else
{
8 years ago
if( pev->avelocity.y > -60 )
9 years ago
{
8 years ago
pev->avelocity.y -= 8; // 9 * ( 3.0 / 2.0 );
9 years ago
}
}
pev->avelocity.y *= 0.98;
// estimate where I'll be in two seconds
8 years ago
UTIL_MakeAimVectors( pev->angles + pev->avelocity * 1 + vecAdj );
9 years ago
Vector vecEst = pev->origin + pev->velocity * 2.0 + gpGlobals->v_up * m_flForce * 20 - Vector( 0, 0, 384 * 2 );
// add immediate force
8 years ago
UTIL_MakeAimVectors( pev->angles + vecAdj );
9 years ago
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
pev->velocity.z -= 38.4; // 32ft/sec
float flSpeed = pev->velocity.Length();
float flDir = DotProduct( Vector( gpGlobals->v_forward.x, gpGlobals->v_forward.y, 0 ), Vector( pev->velocity.x, pev->velocity.y, 0 ) );
8 years ago
if( flDir < 0 )
9 years ago
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
8 years ago
if( flSlip > 0 )
9 years ago
{
8 years ago
if( pev->angles.z > -30 && pev->avelocity.z > -15 )
9 years ago
pev->avelocity.z -= 4;
else
pev->avelocity.z += 2;
}
else
{
8 years ago
if( pev->angles.z < 30 && pev->avelocity.z < 15 )
9 years ago
pev->avelocity.z += 4;
else
pev->avelocity.z -= 2;
}
// sideways drag
8 years ago
pev->velocity.x = pev->velocity.x * ( 1.0 - fabs( gpGlobals->v_right.x ) * 0.05 );
pev->velocity.y = pev->velocity.y * ( 1.0 - fabs( gpGlobals->v_right.y ) * 0.05 );
pev->velocity.z = pev->velocity.z * ( 1.0 - fabs( gpGlobals->v_right.z ) * 0.05 );
9 years ago
// general drag
pev->velocity = pev->velocity * 0.995;
8 years ago
9 years ago
// apply power to stay correct height
8 years ago
if( m_flForce < 80 && vecEst.z < m_posDesired.z )
9 years ago
{
m_flForce += 12;
}
8 years ago
else if( m_flForce > 30 )
9 years ago
{
8 years ago
if( vecEst.z > m_posDesired.z )
9 years ago
m_flForce -= 8;
}
// pitch forward or back to get to target
8 years ago
if( flDist > 0 && flSpeed < m_flGoalSpeed /* && flSpeed < flDist */ && pev->angles.x + pev->avelocity.x > -40 )
9 years ago
{
// ALERT( at_console, "F " );
// lean forward
pev->avelocity.x -= 12.0;
}
8 years ago
else if( flDist < 0 && flSpeed > -50 && pev->angles.x + pev->avelocity.x < 20 )
9 years ago
{
// ALERT( at_console, "B " );
// lean backward
pev->avelocity.x += 12.0;
}
8 years ago
else if( pev->angles.x + pev->avelocity.x > 0 )
9 years ago
{
// ALERT( at_console, "f " );
pev->avelocity.x -= 4.0;
}
8 years ago
else if( pev->angles.x + pev->avelocity.x < 0 )
9 years ago
{
// ALERT( at_console, "b " );
pev->avelocity.x += 4.0;
}
8 years ago
// 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 );
9 years ago
// make rotor, engine sounds
8 years ago
if( m_iSoundState == 0 )
9 years ago
{
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_STATIC, "apache/ap_rotor2.wav", 1.0, 0.3, 0, 110 );
// EMIT_SOUND_DYN( ENT( pev ), CHAN_STATIC, "apache/ap_whine1.wav", 0.5, 0.2, 0, 110 );
9 years ago
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.
8 years ago
if( pPlayer )
9 years ago
{
8 years ago
float pitch = DotProduct( pev->velocity - pPlayer->pev->velocity, ( pPlayer->pev->origin - pev->origin ).Normalize() );
9 years ago
8 years ago
pitch = (int)( 100 + pitch / 50.0 );
9 years ago
8 years ago
if( pitch > 250 )
9 years ago
pitch = 250;
8 years ago
if( pitch < 50 )
9 years ago
pitch = 50;
8 years ago
if( pitch == 100 )
9 years ago
pitch = 101;
8 years ago
float flVol = ( m_flForce / 100.0 ) + .1;
if( flVol > 1.0 )
9 years ago
flVol = 1.0;
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_STATIC, "apache/ap_rotor2.wav", 1.0, 0.3, SND_CHANGE_PITCH | SND_CHANGE_VOL, pitch );
9 years ago
}
8 years ago
// EMIT_SOUND_DYN( ENT( pev ), CHAN_STATIC, "apache/ap_whine1.wav", flVol, 0.2, SND_CHANGE_PITCH | SND_CHANGE_VOL, pitch );
9 years ago
// ALERT( at_console, "%.0f %.2f\n", pitch, flVol );
}
}
8 years ago
void CApache::FireRocket( void )
9 years ago
{
static float side = 1.0;
8 years ago
if( m_iRockets <= 0 )
9 years ago
return;
UTIL_MakeAimVectors( pev->angles );
8 years ago
Vector vecSrc = pev->origin + 1.5 * ( gpGlobals->v_forward * 21 + gpGlobals->v_right * 70 * side + gpGlobals->v_up * -79 );
9 years ago
8 years ago
switch( m_iRockets % 5 )
9 years ago
{
8 years ago
case 0:
vecSrc = vecSrc + gpGlobals->v_right * 10;
break;
case 1:
vecSrc = vecSrc - gpGlobals->v_right * 10;
break;
case 2:
vecSrc = vecSrc + gpGlobals->v_up * 10;
break;
case 3:
vecSrc = vecSrc - gpGlobals->v_up * 10;
break;
case 4:
break;
9 years ago
}
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();
CBaseEntity *pRocket = CBaseEntity::Create( "hvr_rocket", vecSrc, pev->angles, edict() );
8 years ago
if( pRocket )
9 years ago
pRocket->pev->velocity = pev->velocity + gpGlobals->v_forward * 100;
m_iRockets--;
side = - side;
}
8 years ago
BOOL CApache::FireGun()
9 years ago
{
UTIL_MakeAimVectors( pev->angles );
8 years ago
9 years ago
Vector posGun, angGun;
GetAttachment( 1, posGun, angGun );
8 years ago
Vector vecTarget = ( m_posTarget - posGun ).Normalize();
9 years ago
Vector vecOut;
vecOut.x = DotProduct( gpGlobals->v_forward, vecTarget );
vecOut.y = -DotProduct( gpGlobals->v_right, vecTarget );
vecOut.z = DotProduct( gpGlobals->v_up, vecTarget );
8 years ago
Vector angles = UTIL_VecToAngles( vecOut );
9 years ago
angles.x = -angles.x;
8 years ago
if( angles.y > 180 )
9 years ago
angles.y = angles.y - 360;
8 years ago
if( angles.y < -180 )
9 years ago
angles.y = angles.y + 360;
8 years ago
if( angles.x > 180 )
9 years ago
angles.x = angles.x - 360;
8 years ago
if( angles.x < -180 )
9 years ago
angles.x = angles.x + 360;
8 years ago
if( angles.x > m_angGun.x )
m_angGun.x = Q_min( angles.x, m_angGun.x + 12 );
8 years ago
if( angles.x < m_angGun.x )
m_angGun.x = Q_max( angles.x, m_angGun.x - 12 );
8 years ago
if( angles.y > m_angGun.y )
m_angGun.y = Q_min( angles.y, m_angGun.y + 12 );
8 years ago
if( angles.y < m_angGun.y )
m_angGun.y = Q_max( angles.y, m_angGun.y - 12 );
9 years ago
m_angGun.y = SetBoneController( 0, m_angGun.y );
m_angGun.x = SetBoneController( 1, m_angGun.x );
Vector posBarrel, angBarrel;
GetAttachment( 0, posBarrel, angBarrel );
8 years ago
Vector vecGun = ( posBarrel - posGun ).Normalize();
9 years ago
8 years ago
if( DotProduct( vecGun, vecTarget ) > 0.98 )
9 years ago
{
#if 1
FireBullets( 1, posGun, vecGun, VECTOR_CONE_4DEGREES, 8192, BULLET_MONSTER_12MM, 1 );
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "turret/tu_fire1.wav", 1, 0.3 );
9 years ago
#else
static float flNext;
TraceResult tr;
UTIL_TraceLine( posGun, posGun + vecGun * 8192, dont_ignore_monsters, ENT( pev ), &tr );
8 years ago
if( !m_pBeam )
9 years ago
{
m_pBeam = CBeam::BeamCreate( "sprites/lgtning.spr", 80 );
8 years ago
m_pBeam->PointEntInit( pev->origin, entindex() );
9 years ago
m_pBeam->SetEndAttachment( 1 );
m_pBeam->SetColor( 255, 180, 96 );
m_pBeam->SetBrightness( 192 );
}
8 years ago
if( flNext < gpGlobals->time )
9 years ago
{
flNext = gpGlobals->time + 0.5;
m_pBeam->SetStartPos( tr.vecEndPos );
}
#endif
return TRUE;
}
else
{
8 years ago
if( m_pBeam )
9 years ago
{
UTIL_Remove( m_pBeam );
m_pBeam = NULL;
}
}
return FALSE;
}
8 years ago
void CApache::ShowDamage( void )
9 years ago
{
8 years ago
if( m_iDoSmokePuff > 0 || RANDOM_LONG( 0, 99 ) > pev->health )
9 years ago
{
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 );
8 years ago
WRITE_BYTE( RANDOM_LONG( 0, 9 ) + 20 ); // scale * 10
9 years ago
WRITE_BYTE( 12 ); // framerate
MESSAGE_END();
}
8 years ago
if( m_iDoSmokePuff > 0 )
9 years ago
m_iDoSmokePuff--;
}
8 years ago
int CApache::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
9 years ago
{
8 years ago
if( pevInflictor->owner == edict() )
9 years ago
return 0;
8 years ago
if( bitsDamageType & DMG_BLAST )
9 years ago
{
flDamage *= 2;
}
/*
8 years ago
if( ( bitsDamageType & DMG_BULLET ) && flDamage > 50 )
9 years ago
{
// clip bullet damage at 50
flDamage = 50;
}
*/
// ALERT( at_console, "%.0f\n", flDamage );
8 years ago
return CBaseEntity::TakeDamage( pevInflictor, pevAttacker, flDamage, bitsDamageType );
9 years ago
}
8 years ago
void CApache::TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType )
9 years ago
{
// ALERT( at_console, "%d %.0f\n", ptr->iHitgroup, flDamage );
// ignore blades
8 years ago
if( ptr->iHitgroup == 6 && ( bitsDamageType & ( DMG_ENERGYBEAM | DMG_BULLET | DMG_CLUB ) ) )
9 years ago
return;
// hit hard, hits cockpit, hits engines
8 years ago
if( flDamage > 50 || ptr->iHitgroup == 1 || ptr->iHitgroup == 2 )
9 years ago
{
// ALERT( at_console, "%.0f\n", flDamage );
AddMultiDamage( pevAttacker, this, flDamage, bitsDamageType );
8 years ago
m_iDoSmokePuff = 3 + ( flDamage / 5.0 );
9 years ago
}
else
{
// do half damage in the body
// AddMultiDamage( pevAttacker, this, flDamage / 2.0, bitsDamageType );
UTIL_Ricochet( ptr->vecEndPos, 2.0 );
}
}
class CApacheHVR : public CGrenade
{
void Spawn( void );
void Precache( void );
void EXPORT IgniteThink( void );
void EXPORT AccelerateThink( void );
8 years ago
int Save( CSave &save );
int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
9 years ago
int m_iTrail;
Vector m_vecForward;
};
LINK_ENTITY_TO_CLASS( hvr_rocket, CApacheHVR )
9 years ago
8 years ago
TYPEDESCRIPTION CApacheHVR::m_SaveData[] =
9 years ago
{
8 years ago
//DEFINE_FIELD( CApacheHVR, m_iTrail, FIELD_INTEGER ), // Dont' save, precache
9 years ago
DEFINE_FIELD( CApacheHVR, m_vecForward, FIELD_VECTOR ),
};
IMPLEMENT_SAVERESTORE( CApacheHVR, CGrenade )
9 years ago
8 years ago
void CApacheHVR::Spawn( void )
9 years ago
{
8 years ago
Precache();
9 years ago
// motor
pev->movetype = MOVETYPE_FLY;
pev->solid = SOLID_BBOX;
8 years ago
SET_MODEL( ENT( pev ), "models/HVR.mdl" );
UTIL_SetSize( pev, Vector( 0, 0, 0), Vector(0, 0, 0) );
9 years ago
UTIL_SetOrigin( pev, pev->origin );
SetThink( &CApacheHVR::IgniteThink );
SetTouch( &CGrenade::ExplodeTouch );
UTIL_MakeAimVectors( pev->angles );
m_vecForward = gpGlobals->v_forward;
pev->gravity = 0.5;
pev->nextthink = gpGlobals->time + 0.1;
pev->dmg = 150;
}
8 years ago
void CApacheHVR::Precache( void )
9 years ago
{
8 years ago
PRECACHE_MODEL( "models/HVR.mdl" );
m_iTrail = PRECACHE_MODEL( "sprites/smoke.spr" );
PRECACHE_SOUND("weapons/rocket1.wav");
9 years ago
}
8 years ago
void CApacheHVR::IgniteThink( void )
9 years ago
{
// pev->movetype = MOVETYPE_TOSS;
// pev->movetype = MOVETYPE_FLY;
pev->effects |= EF_LIGHT;
// make rocket sound
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "weapons/rocket1.wav", 1, 0.5 );
9 years ago
// rocket trail
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_BEAMFOLLOW );
8 years ago
WRITE_SHORT( entindex() ); // entity
WRITE_SHORT( m_iTrail ); // model
9 years ago
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 );
pev->nextthink = gpGlobals->time + 0.1;
}
8 years ago
void CApacheHVR::AccelerateThink( void )
9 years ago
{
// check world boundaries
8 years ago
if( pev->origin.x < -4096 || pev->origin.x > 4096 || pev->origin.y < -4096 || pev->origin.y > 4096 || pev->origin.z < -4096 || pev->origin.z > 4096 )
9 years ago
{
UTIL_Remove( this );
return;
}
// accelerate
float flSpeed = pev->velocity.Length();
8 years ago
if( flSpeed < 1800 )
9 years ago
{
pev->velocity = pev->velocity + m_vecForward * 200;
}
// re-aim
pev->angles = UTIL_VecToAngles( pev->velocity );
pev->nextthink = gpGlobals->time + 0.1;
}
#endif