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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
//
// Purpose:
//
//=============================================================================
#ifndef VEHICLE_CRANE_H
#define VEHICLE_CRANE_H
#ifdef _WIN32
#pragma once
#endif
#include "physobj.h"
#include "rope.h"
#include "rope_shared.h"
#include "physics_bone_follower.h"
#define CRANE_EXTENSION_RATE_MAX 0.01
#define CRANE_TURN_RATE_MAX 1.2
#define MAXIMUM_CRANE_PICKUP_MASS 10000
#define MINIMUM_CRANE_PICKUP_MASS 500
#define MAX_CRANE_FLAT_REACH 1400.0
#define MIN_CRANE_FLAT_REACH 700.0
#define CRANE_EXTENSION_ACCEL 0.006
#define CRANE_EXTENSION_DECEL 0.02
#define CRANE_TURN_ACCEL 0.2
#define CRANE_DECEL 0.5
#define CRANE_SLOWRAISE_TIME 5.0
// Turning stats
enum
{
TURNING_NOT,
TURNING_LEFT,
TURNING_RIGHT,
};
class CPropCrane;
//-----------------------------------------------------------------------------
// Purpose: This is the entity we attach to the tip of the crane and dangle the cable from
//-----------------------------------------------------------------------------
class CCraneTip : public CBaseAnimating
{
DECLARE_CLASS( CCraneTip, CBaseAnimating );
public:
DECLARE_DATADESC();
~CCraneTip( void )
{
if ( m_pSpring )
{
physenv->DestroySpring( m_pSpring );
}
}
void Spawn( void );
void Precache( void );
bool CreateConstraint( CBaseAnimating *pMagnet, IPhysicsConstraintGroup *pGroup );
static CCraneTip *Create( CBaseAnimating *pCraneMagnet, IPhysicsConstraintGroup *pGroup, const Vector &vecOrigin, const QAngle &vecAngles );
public:
IPhysicsSpring *m_pSpring;
};
//-----------------------------------------------------------------------------
// Purpose: Crane vehicle server
//-----------------------------------------------------------------------------
class CCraneServerVehicle : public CBaseServerVehicle
{
typedef CBaseServerVehicle BaseClass;
// IServerVehicle
public:
void GetVehicleViewPosition( int nRole, Vector *pAbsOrigin, QAngle *pAbsAngles, float *pFOV = NULL );
// NPC Driving
void NPC_SetDriver( CNPC_VehicleDriver *pDriver );
void NPC_DriveVehicle( void );
virtual bool IsPassengerEntering( void ) { return false; } // NOTE: This mimics the scenario HL2 would have seen
virtual bool IsPassengerExiting( void ) { return false; }
protected:
CPropCrane *GetCrane( void );
};
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CPropCrane : public CBaseProp, public IDrivableVehicle
{
DECLARE_CLASS( CPropCrane, CBaseProp );
public:
DECLARE_DATADESC();
DECLARE_SERVERCLASS();
CPropCrane( void )
{
m_ServerVehicle.SetVehicle( this );
}
~CPropCrane( void )
{
physenv->DestroyConstraintGroup( m_pConstraintGroup );
}
// CBaseEntity
virtual void Precache( void );
void Spawn( void );
void Activate( void );
void UpdateOnRemove( void );
bool CreateVPhysics( void );
void InitCraneSpeeds( void );
void Think(void);
virtual int ObjectCaps( void ) { return BaseClass::ObjectCaps() | FCAP_IMPULSE_USE; };
virtual void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
virtual void DrawDebugGeometryOverlays( void );
virtual bool PassengerShouldReceiveDamage( CTakeDamageInfo &info )
{
if ( info.GetDamageType() & DMG_VEHICLE )
return true;
return (info.GetDamageType() & (DMG_RADIATION|DMG_BLAST) ) == 0;
}
virtual Vector BodyTarget( const Vector &posSrc, bool bNoisy = true );
virtual void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator );
virtual int OnTakeDamage( const CTakeDamageInfo &info );
void PlayerControlInit( CBasePlayer *pPlayer );
void PlayerControlShutdown( void );
void ResetUseKey( CBasePlayer *pPlayer );
void DriveCrane( int iDriverButtons, int iButtonsPressed, float flNPCSteering = 0.0 );
void RunCraneMovement( float flTime );
void TurnMagnetOn( void );
void TurnMagnetOff( void );
const Vector &GetCraneTipPosition( void );
float GetExtensionRate( void ) { return m_flExtensionRate; }
float GetTurnRate( void ) { return m_flTurn; }
float GetMaxTurnRate( void ) { return m_flMaxTurnSpeed; }
CPhysMagnet *GetMagnet( void ) { return m_hCraneMagnet; }
float GetTotalMassOnCrane( void ) { return m_hCraneMagnet->GetTotalMassAttachedObjects(); }
bool IsDropping( void ) { return m_bDropping; }
// Inputs
void InputLock( inputdata_t &inputdata );
void InputUnlock( inputdata_t &inputdata );
void InputForcePlayerIn( inputdata_t &inputdata );
// Crane handling
void GetCraneTipPosition( Vector *vecOrigin, QAngle *vecAngles );
void RecalculateCraneTip( void );
void GetVectors(Vector* pForward, Vector* pRight, Vector* pUp) const;
void SetNPCDriver( CNPC_VehicleDriver *pDriver );
// IDrivableVehicle
public:
virtual CBaseEntity *GetDriver( void );
virtual void ItemPostFrame( CBasePlayer *pPlayer );
virtual void SetupMove( CBasePlayer *player, CUserCmd *ucmd, IMoveHelper *pHelper, CMoveData *move );
virtual void ProcessMovement( CBasePlayer *pPlayer, CMoveData *pMoveData ) { return; }
virtual void FinishMove( CBasePlayer *player, CUserCmd *ucmd, CMoveData *move ) { return; }
virtual bool CanEnterVehicle( CBaseEntity *pEntity );
virtual bool CanExitVehicle( CBaseEntity *pEntity );
virtual void SetVehicleEntryAnim( bool bOn ) { m_bEnterAnimOn = bOn; }
virtual void SetVehicleExitAnim( bool bOn, Vector vecEyeExitEndpoint ) { m_bExitAnimOn = bOn; if ( bOn ) m_vecEyeExitEndpoint = vecEyeExitEndpoint; }
virtual void EnterVehicle( CBaseCombatCharacter *pPassenger );
virtual bool AllowBlockedExit( CBaseCombatCharacter *pPassenger, int nRole ) { return true; }
virtual bool AllowMidairExit( CBaseCombatCharacter *pPassenger, int nRole ) { return false; }
virtual void PreExitVehicle( CBaseCombatCharacter *pPassenger, int nRole );
virtual void ExitVehicle( int nRole );
virtual string_t GetVehicleScriptName() { return m_vehicleScript; }
// If this is a vehicle, returns the vehicle interface
virtual IServerVehicle *GetServerVehicle() { return &m_ServerVehicle; }
protected:
// Contained IServerVehicle
CCraneServerVehicle m_ServerVehicle;
// Contained Bone Follower manager
CBoneFollowerManager m_BoneFollowerManager;
private:
CNetworkHandle( CBasePlayer, m_hPlayer );
CNetworkVar( bool, m_bMagnetOn );
// NPC Driving
CHandle<CNPC_VehicleDriver> m_hNPCDriver;
int m_nNPCButtons;
// Entering / Exiting
bool m_bLocked;
CNetworkVar( bool, m_bEnterAnimOn );
CNetworkVar( bool, m_bExitAnimOn );
CNetworkVector( m_vecEyeExitEndpoint );
COutputEvent m_playerOn;
COutputEvent m_playerOff;
// Turning
int m_iTurning;
bool m_bStartSoundAtCrossover;
float m_flTurn;
// Crane arm extension / retraction
bool m_bExtending;
float m_flExtension;
float m_flExtensionRate;
// Magnet movement
bool m_bDropping;
float m_flNextDangerSoundTime;
float m_flNextCreakSound;
float m_flNextDropAllowedTime;
float m_flSlowRaiseTime;
// Speeds
float m_flMaxExtensionSpeed;
float m_flMaxTurnSpeed;
float m_flExtensionAccel;
float m_flExtensionDecel;
float m_flTurnAccel;
float m_flTurnDecel;
// Cable Tip & Magnet
string_t m_iszMagnetName;
CHandle<CPhysMagnet> m_hCraneMagnet;
CHandle<CCraneTip> m_hCraneTip;
CHandle<CRopeKeyframe> m_hRope;
IPhysicsConstraintGroup *m_pConstraintGroup;
// Vehicle script filename
string_t m_vehicleScript;
};
#endif // VEHICLE_CRANE_H
|