1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: A base vehicle class
//
//=============================================================================//
#ifndef BASETFVEHICLE_H
#define BASETFVEHICLE_H
#ifdef _WIN32
#pragma once
#endif
#include "basetfplayer_shared.h"
#include "baseobject_shared.h"
#include "tf_obj_basedrivergun_shared.h"
#if defined( CLIENT_DLL )
#include "iclientvehicle.h"
#else
#include "IServerVehicle.h"
#endif
class CMoveData;
class CUserCmd;
class CBasePlayer;
#if defined( CLIENT_DLL )
#define CBaseTFVehicle C_BaseTFVehicle
#endif
class CBaseTFVehicle;
class CBaseObjectDriverGun;
struct VehicleBaseMoveData_t
{
CBaseTFVehicle *m_pVehicle;
};
// ------------------------------------------------------------------------ //
// The base class that all vehicles in tf2 will derive from
// ------------------------------------------------------------------------ //
#if defined( CLIENT_DLL )
class CBaseTFVehicle : public CBaseObject, public IClientVehicle
#else
class CBaseTFVehicle : public CBaseObject, public IServerVehicle
#endif
{
DECLARE_CLASS( CBaseTFVehicle, CBaseObject );
public:
DECLARE_NETWORKCLASS();
DECLARE_PREDICTABLE();
CBaseTFVehicle();
#if !defined (CLIENT_DLL)
// CBaseEntity overrides
virtual void FinishedBuilding( void );
virtual void DestroyObject( );
virtual void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
virtual bool UseAttachedItem( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
virtual void GetVectors(Vector* pForward, Vector* pRight, Vector* pUp) const;
virtual bool ClientCommand( CBaseTFPlayer *pPlayer, const CCommand &args );
// IVehicle overrides
virtual IServerVehicle* GetServerVehicle() { return this; }
virtual CBaseEntity* GetVehicleEnt();
// Get and set the current driver.
virtual void SetPassenger( int nRole, CBasePlayer *pEnt );
// Where do we get out of the vehicle?
virtual bool GetPassengerExitPoint( int nRole, Vector *pExitPoint, QAngle *pAngles );
virtual Class_T ClassifyPassenger( CBasePlayer *pPassenger, Class_T defaultClassification ) { return defaultClassification; }
virtual float DamageModifier ( CTakeDamageInfo &info ) { return 1.0; }
virtual const vehicleparams_t *GetVehicleParams( void ) { return NULL; }
virtual bool IsVehicleUpright( void ) { return true; }
virtual bool IsPassengerEntering( void ) { Assert( 0 ); return true; }
virtual bool IsPassengerExiting( void ) { Assert( 0 ); return true; }
// NPC Driving
virtual bool NPC_CanDrive( void ) { return true; }
virtual void NPC_SetDriver( CNPC_VehicleDriver *pDriver ) { return; }
virtual void NPC_DriveVehicle( void ) { return; }
virtual void NPC_ThrottleCenter( void ) { return; }
virtual void NPC_ThrottleReverse( void ) { return; }
virtual void NPC_ThrottleForward( void ) { return; }
virtual void NPC_Brake( void ) { return; }
virtual void NPC_TurnLeft( float flDegrees ) { return; }
virtual void NPC_TurnRight( float flDegrees ) { return; }
virtual void NPC_TurnCenter( void ) { return; }
virtual void NPC_PrimaryFire( void ) { return; }
virtual void NPC_SecondaryFire( void ) { return; }
virtual bool NPC_HasPrimaryWeapon( void ) { return false; }
virtual bool NPC_HasSecondaryWeapon( void ) { return false; }
virtual void NPC_AimPrimaryWeapon( Vector vecTarget ) { return; }
virtual void NPC_AimSecondaryWeapon( Vector vecTarget ) { return; }
// Weapon handling
virtual void Weapon_PrimaryRanges( float *flMinRange, float *flMaxRange ) { *flMinRange = 0; *flMaxRange = 0; }
virtual void Weapon_SecondaryRanges( float *flMinRange, float *flMaxRange ) { *flMinRange = 0; *flMaxRange = 0; }
virtual float Weapon_PrimaryCanFireAt( void ) { return gpGlobals->curtime; } // Return the time at which this vehicle's primary weapon can fire again
virtual float Weapon_SecondaryCanFireAt( void ) { return gpGlobals->curtime; } // Return the time at which this vehicle's secondary weapon can fire again
// Vehicles dont want to attach to anything they're built upon
virtual bool ShouldAttachToParent( void ) { return false; }
virtual bool MustNotBeBuiltInConstructionYard( void ) const { return false; }
// Purpose: Try to board the vehicle
void AttemptToBoardVehicle( CBaseTFPlayer *pPlayer );
// Figure out which role of a parent vehicle this vehicle is sitting in..
int GetParentVehicleRole();
// Purpose:
void GetPassengerExitPoint( CBasePlayer *pPlayer, int nRole, Vector *pAbsPosition, QAngle *pAbsAngles );
int GetEntryAnimForPoint( const Vector &vecPoint );
int GetExitAnimToUse( Vector &vecEyeExitEndpoint, bool &bAllPointsBlocked );
void HandleEntryExitFinish( bool bExitAnimOn, bool bResetAnim );
void HandlePassengerEntry( CBasePlayer *pPlayer, bool bAllowEntryOutsideZone = false );
bool HandlePassengerExit( CBasePlayer *pPlayer );
// Deterioration
void VehicleDeteriorationThink( void );
void VehiclePassengerThink( void );
#endif
bool IsReadyToDrive( void );
virtual bool IsAVehicle( void ) { return true; }
// Get a position in *local space* inside the vehicle for the player to start at
virtual void GetPassengerStartPoint( int nRole, Vector *pPoint, QAngle *pAngles );
#if defined( CLIENT_DLL )
// C_BaseEntity overrides
virtual IClientVehicle* GetClientVehicle() { return this; }
virtual C_BaseEntity *GetVehicleEnt();
virtual void ClientThink();
// Fills in the unperterbed view position for a particular role.
// Prediction
virtual bool ShouldPredict( void );
virtual bool IsPredicted( void ) const { return true; }
// IClientVehicle
// Called at time player enters vehicle
virtual void GetVehicleFOV( float &flFOV ) { return; }
virtual void DrawHudElements( void );
// Get the angles that a player in the specified role should be using for visuals
virtual QAngle GetPassengerAngles( QAngle angCurrent, int nRole );
// Allows the vehicle to restrict view angles
virtual void UpdateViewAngles( C_BasePlayer *pLocalPlayer, CUserCmd *pCmd ) {}
virtual void GetVehicleClipPlanes( float &flZNear, float &flZFar ) const {}
bool IsBoostable( void ) { return m_bBoostUpgrade; }
// Hud
virtual void DrawHudBoostData( void );
virtual void SetupCrosshair( void );
#endif
int LocateEntryPoint( CBaseTFPlayer *pPlayer, float* fBest2dDistanceSqr= NULL );
// This lets the object decide whether or not it wants to use the ThirdPersonCameraOrigin attachment for its view.
// The manned guns use first-person when they're on the ground and third-person when they're in a vehicle.
virtual bool ShouldUseThirdPersonVehicleView();
virtual void GetVehicleViewPosition( int nRole, Vector *pOrigin, QAngle *pAngles, float *pFOV = NULL );
virtual bool GetRoleViewPosition( int nRole, Vector *pVehicleEyeOrigin, QAngle *pVehicleEyeAngles );
virtual bool GetRoleAbsViewPosition( int nRole, Vector *pAbsVehicleEyeOrigin, QAngle *pAbsVehicleEyeAngles );
// Can a given passenger take damage?
virtual bool IsPassengerDamagable( int nRole ) { return (nRole != VEHICLE_DRIVER); }
virtual void Spawn();
virtual void SetupMove( CBasePlayer *player, CUserCmd *ucmd, IMoveHelper *pHelper, CMoveData *move );
virtual void ProcessMovement( CBasePlayer *pPlayer, CMoveData *pMove ) {}
virtual void FinishMove( CBasePlayer *player, CUserCmd *ucmd, CMoveData *move );
virtual void ItemPostFrame( CBasePlayer *pPassenger );
virtual CBasePlayer* GetPassenger( int nRole = VEHICLE_DRIVER );
virtual int GetPassengerRole( CBasePlayer *pEnt );
// Does the player use his normal weapons while in this mode?
virtual bool IsPassengerUsingStandardWeapons( int nRole = VEHICLE_DRIVER ) { return false; }
virtual Vector GetSoundEmissionOrigin() const;
// Returns the driver as a tfplayer pointer
CBaseTFPlayer *GetDriverPlayer();
int GetMaxPassengerCount() const;
int GetPassengerCount() const;
// Is a particular player in the vehicle?
bool IsPlayerInVehicle( CBaseTFPlayer *pPlayer );
void ResetDeteriorationTime( void );
// Driver controlled guns
void SetDriverGun( CBaseObjectDriverGun *pGun );
void VehicleDriverGunThink( void );
protected:
enum
{
MAX_PASSENGERS = 4,
MAX_PASSENGER_BITS = 3
};
// Can we get into the vehicle?
virtual bool CanGetInVehicle( CBaseTFPlayer *pPlayer );
// Here's where we deal with weapons
virtual void OnItemPostFrame( CBaseTFPlayer *pDriver );
// Specify the number of roles we can have
void SetMaxPassengerCount( int nMaxPassengers );
bool IsValidExitPoint( int nRole, Vector *pExitPoint, QAngle *pAngles );
int GetEmptyRole( void );
private:
#if !defined (CLIENT_DLL)
// Get the parent vehicle of this vehicle..
CBaseTFVehicle *GetParentVehicle();
// Get a position in *world space* inside the vehicle for the player to exit at
void GetInitialPassengerExitPoint( int nRole, Vector *pAbsPoint, QAngle *pAbsAngles );
// Figure out which role of a vehicle a child vehicle is sitting in..
int GetChildVehicleRole( CBaseTFVehicle *pChild );
#endif
private:
typedef CHandle<CBaseTFPlayer> CPlayerHandle;
CNetworkArray( CPlayerHandle, m_hPassengers, MAX_PASSENGERS );
CNetworkVar( int, m_nMaxPassengers );
// Driver controlled gun
CNetworkHandle( CBaseObjectDriverGun, m_hDriverGun );
#if defined( CLIENT_DLL )
CHudTexture *m_pIconDefaultCrosshair;
bool m_bBoostUpgrade;
int m_nBoostTimeLeft;
private:
CBaseTFVehicle( const CBaseTFVehicle & ); // not defined, not accessible
#endif
};
#endif // BASETFVEHICLE_H
|