?? vehicle_chopper.cpp
字號(hào):
#include "cbase.h"
#if 0
// KEEPING this file around for reference for a while.
// The helicopter is now derived from CBaseHelicopter.
/***
*
* Copyright (c) 1999, 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.
*
****/
#include "AI_Network.h"
#include "AI_Default.h"
#include "AI_Schedule.h"
#include "AI_Hull.h"
#include "AI_Node.h"
#include "AI_Task.h"
#include "entitylist.h"
#include "basecombatweapon.h"
#include "soundenvelope.h"
#include "gib.h"
#include "gamerules.h"
#include "ammodef.h"
#include "grenade_homer.h"
#include "ndebugoverlay.h"
#include "globals.h"
// -------------------------------------
// Bone controllers
// -------------------------------------
#define CHOPPER_BC_GUN_YAW 0
#define CHOPPER_BC_GUN_PITCH 1
#define CHOPPER_BC_POD_PITCH 2
// -------------------------------------
// Attachment points
// -------------------------------------
#define CHOPPER_AP_GUN_TIP 1
#define CHOPPER_AP_GUN_BASE 2
#define CHOPPER_AP_RR_POD_TIP 3
#define CHOPPER_AP_RL_POD_TIP 4
#define CHOPPER_AP_LR_POD_TIP 5
#define CHOPPER_AP_LL_POD_TIP 6
#define CHOPPER_AP_RR_POD_BASE 7
#define CHOPPER_AP_RL_POD_BASE 8
#define CHOPPER_AP_LR_POD_BASE 9
#define CHOPPER_AP_LL_POD_BASE 10
#define CHOPPER_MAX_SPEED 400.0f
#define CHOPPER_MAX_FIRING_SPEED 250.0f
#define CHOPPER_MIN_ROCKET_DIST 1000.0f
#define CHOPPER_MAX_GUN_DIST 2000.0f
class CNPC_Helicopter : public CAI_BaseNPC
{
DECLARE_CLASS( CNPC_Helicopter, CAI_BaseNPC );
public:
DECLARE_DATADESC();
void Spawn( void );
void Precache( void );
void Event_Killed( const CTakeDamageInfo &info );
int BloodColor( void ) { return DONT_BLEED; }
void GibMonster( void );
void SetObjectCollisionBox( void )
{
SetAbsMins( GetAbsOrigin() + Vector( -300, -300, -172) );
SetAbsMaxs( GetAbsOrigin() + Vector(300, 300, 8) );
}
Class_T Classify ( void ) { return CLASS_COMBINE; }
void HuntThink( void );
void FlyTouch( CBaseEntity *pOther );
void CrashTouch( CBaseEntity *pOther );
void DyingThink( void );
void StartupUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
void NullThink( void );
void ShowDamage( void );
void Flight( void );
void AimRocketGun(void);
void FireRocket( Vector vLaunchPos, Vector vLaunchDir );
bool FireGun( void );
int OnTakeDamage_Alive( const CTakeDamageInfo &info );
void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr );
void GunOn( CBaseEntity *pActivator, CBaseEntity *pCaller, string_t targetEntity );
void GunOff( CBaseEntity *pActivator, CBaseEntity *pCaller, string_t targetEntity );
void MissileOn( CBaseEntity *pActivator, CBaseEntity *pCaller, string_t targetEntity );
void MissileOff( CBaseEntity *pActivator, CBaseEntity *pCaller, string_t targetEntity );
void DrawDebugGeometryOverlays(void);
~CNPC_Helicopter();
int m_iRockets;
float m_flForce;
float m_flNextRocket;
int m_fHelicopterFlags;
Vector m_vecTarget;
Vector m_posTarget;
Vector m_vecDesired;
Vector m_posDesired;
Vector m_vecGoal;
Vector m_angGun;
Vector m_angPod;
float m_flLastSeen;
float m_flPrevSeen;
CSoundPatch* m_pRotorSound;
int m_iSpriteTexture;
int m_iExplode;
int m_iBodyGibs;
int m_iAmmoType;
float m_flGoalSpeed; // Goal speed
float m_flInitialSpeed; // Instanteous initial speed
int m_iDoSmokePuff;
COutputEvent m_AtTarget; // Fired when pathcorner has been reached
COutputEvent m_LeaveTarget; // Fired when pathcorner is left
};
LINK_ENTITY_TO_CLASS( znpc_helicopter, CNPC_Helicopter );
BEGIN_DATADESC( CNPC_Helicopter )
DEFINE_FUNCTION( CNPC_Helicopter, HuntThink ),
DEFINE_FUNCTION( CNPC_Helicopter, FlyTouch ),
DEFINE_FIELD( CNPC_Helicopter, m_iRockets, FIELD_INTEGER ),
DEFINE_FIELD( CNPC_Helicopter, m_flForce, FIELD_FLOAT ),
DEFINE_FIELD( CNPC_Helicopter, m_flNextRocket, FIELD_TIME ),
DEFINE_FIELD( CNPC_Helicopter, m_fHelicopterFlags, FIELD_INTEGER),
DEFINE_FIELD( CNPC_Helicopter, m_vecTarget, FIELD_VECTOR ),
DEFINE_FIELD( CNPC_Helicopter, m_posTarget, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( CNPC_Helicopter, m_vecDesired, FIELD_VECTOR ),
DEFINE_FIELD( CNPC_Helicopter, m_posDesired, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( CNPC_Helicopter, m_vecGoal, FIELD_VECTOR ),
DEFINE_FIELD( CNPC_Helicopter, m_angGun, FIELD_VECTOR ),
DEFINE_FIELD( CNPC_Helicopter, m_angPod, FIELD_VECTOR ),
DEFINE_FIELD( CNPC_Helicopter, m_flLastSeen, FIELD_TIME ),
DEFINE_FIELD( CNPC_Helicopter, m_flPrevSeen, FIELD_TIME ),
DEFINE_SOUNDPATCH( CNPC_Helicopter, m_pRotorSound ),
// DEFINE_FIELD( CNPC_Helicopter, m_iSpriteTexture, FIELD_INTEGER ),
// DEFINE_FIELD( CNPC_Helicopter, m_iExplode, FIELD_INTEGER ),
// DEFINE_FIELD( CNPC_Helicopter, m_iBodyGibs, FIELD_INTEGER ),
DEFINE_FIELD( CNPC_Helicopter, m_flGoalSpeed, FIELD_FLOAT ),
DEFINE_FIELD( CNPC_Helicopter, m_iDoSmokePuff, FIELD_INTEGER ),
DEFINE_FIELD( CNPC_Helicopter, m_iAmmoType, FIELD_INTEGER ),
DEFINE_KEYFIELD( CNPC_Helicopter, m_flInitialSpeed, FIELD_FLOAT, "InitialSpeed" ),
// Inputs
DEFINE_INPUTFUNC( CNPC_Helicopter, FIELD_VOID, "GunOn", GunOn ),
DEFINE_INPUTFUNC( CNPC_Helicopter, FIELD_VOID, "GunOff", GunOff ),
DEFINE_INPUTFUNC( CNPC_Helicopter, FIELD_VOID, "MissileOn", MissileOn ),
DEFINE_INPUTFUNC( CNPC_Helicopter, FIELD_VOID, "MissileOff", MissileOff ),
// Outputs
DEFINE_OUTPUT(CNPC_Helicopter, m_AtTarget, "AtPathCorner" ),
DEFINE_OUTPUT(CNPC_Helicopter, m_LeaveTarget, "LeavePathCorner" ),//<<TEMP>> Undone
// Function pointers
DEFINE_FUNCTION( CNPC_Helicopter, StartupUse ),
END_DATADESC()
//------------------------------------------------------------------------------
// Purpose : Inputs
// Input :
// Output :
//------------------------------------------------------------------------------
void CNPC_Helicopter::GunOn( CBaseEntity *pActivator, CBaseEntity *pCaller, string_t targetEntity )
{
m_fHelicopterFlags |= BITS_HELICOPTER_GUN_ON;
}
void CNPC_Helicopter::GunOff( CBaseEntity *pActivator, CBaseEntity *pCaller, string_t targetEntity )
{
m_fHelicopterFlags &= ~BITS_HELICOPTER_GUN_ON;
}
void CNPC_Helicopter::MissileOn( CBaseEntity *pActivator, CBaseEntity *pCaller, string_t targetEntity )
{
m_fHelicopterFlags |= BITS_HELICOPTER_MISSILE_ON;
}
void CNPC_Helicopter::MissileOff( CBaseEntity *pActivator, CBaseEntity *pCaller, string_t targetEntity )
{
m_fHelicopterFlags &= ~BITS_HELICOPTER_MISSILE_ON;
}
//------------------------------------------------------------------------------
// Purpose :
// Input :
// Output :
//------------------------------------------------------------------------------
void CNPC_Helicopter::Spawn( void )
{
Precache( );
// motor
SetMoveType( MOVETYPE_FLY );
SetSolid( SOLID_BBOX );
m_iAmmoType = g_pGameRules->GetAmmoDef()->Index("MediumRound");
SetModel( "models/attack_helicopter.mdl" );
UTIL_SetSize( this, Vector( -32, -32, -64 ), Vector( 32, 32, 0 ) );
Relink();
m_iHealth = 100;
m_flFieldOfView = -0.707; // 270 degrees
m_nSequence = 0;
ResetSequenceInfo( );
m_flCycle = 0;
InitBoneControllers();
if (m_spawnflags & SF_WAITFORTRIGGER)
{
SetUse( StartupUse );
}
else
{
SetThink( HuntThink );
SetTouch( FlyTouch );
SetNextThink( gpGlobals->curtime + 1.0 );
}
m_iRockets = 10;
m_fHelicopterFlags = BITS_HELICOPTER_MISSILE_ON | BITS_HELICOPTER_GUN_ON;
// Get the rotor sound started up.
CSoundEnvelopeController &controller = CSoundEnvelopeController::GetController();
m_takedamage = DAMAGE_AIM;
m_pRotorSound = controller.SoundCreate( edict(), CHAN_STATIC, "vehicles/chopper_rotor2.wav", 0.2 );
}
void CNPC_Helicopter::Precache( void )
{
engine->PrecacheModel("models/attack_helicopter.mdl");
engine->PrecacheModel("models/combine_soldier.mdl");
engine->PrecacheSound("vehicles/chopper_rotor1.wav");
engine->PrecacheSound("vehicles/chopper_rotor2.wav");
engine->PrecacheSound("vehicles/chopper_rotor3.wav");
engine->PrecacheSound("vehicles/chopper_whine1.wav");
engine->PrecacheSound("weapons/mortarhit.wav");
m_iSpriteTexture = engine->PrecacheModel( "sprites/white.vmt" );
engine->PrecacheSound("weapons/ar2/ar2_fire2.wav");//<<TEMP>>temp sound
engine->PrecacheModel("sprites/lgtning.vmt");
// Missile
engine->PrecacheSound("weapons/stinger_fire1.wav");
engine->PrecacheModel("models/weapons/w_missile.mdl");
#if 0 // These don't port yet
m_iExplode = engine->PrecacheModel( "sprites/fexplo.vmt" );
m_iBodyGibs = engine->PrecacheModel( "models/metalplategibs_green.mdl" );
UTIL_PrecacheOther( "hvr_rocket" );
#endif
}
//-----------------------------------------------------------------------------
// Purpose: Override base class to add display of fly direction
// Input :
// Output :
//-----------------------------------------------------------------------------
void CNPC_Helicopter::DrawDebugGeometryOverlays(void)
{
if (m_pfnThink!= NULL)
{
// ------------------------------
// Draw route if requested
// ------------------------------
if (m_debugOverlays & OVERLAY_NPC_ROUTE_BIT)
{
NDebugOverlay::Line(GetAbsOrigin(), m_posDesired, 0,0,255, true, 0);
}
}
BaseClass::DrawDebugGeometryOverlays();
}
//------------------------------------------------------------------------------
// Purpose :
// Input :
// Output :
//------------------------------------------------------------------------------
void CNPC_Helicopter::NullThink( void )
{
StudioFrameAdvance( );
SetNextThink( gpGlobals->curtime + 0.5 );
}
void CNPC_Helicopter::StartupUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
m_flGoalSpeed = m_flInitialSpeed;
SetThink( HuntThink );
SetTouch( FlyTouch );
SetNextThink( gpGlobals->curtime + 0.1f );
SetUse( NULL );
}
void CNPC_Helicopter::Event_Killed( const CTakeDamageInfo &info )
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -