summaryrefslogtreecommitdiff
path: root/game/server/tf2/tf_basefourwheelvehicle.cpp
blob: f2b08084c20980a47cdcdcc9367cf2293d539342 (plain) (blame)
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: A moving vehicle that is used as a battering ram
//
// $NoKeywords: $
//=============================================================================//

#include "cbase.h"
#include "tf_basefourwheelvehicle.h"
#include "engine/IEngineSound.h"
#include "soundenvelope.h"
#include "vcollide_parse.h"
#include "in_buttons.h"
#include "tf_movedata.h"

#define BASEFOURWHEELEDVEHICLE_THINK_CONTEXT		"BaseFourWheeledThink"
#define BASEFOURWHEELEDVEHICLE_DEPLOYTHINK_CONTEXT	"BaseFourWheeledDeployThink"
// HACK HAC
#define BASEFOURWHEELEDVEHICLE_STOPTHERODEO_CONTEXT	"BaseFourWheeledVehicleStopTheRodeoMadnessThink"

ConVar road_feel( "road_feel", "0.1", FCVAR_NOTIFY | FCVAR_REPLICATED );
extern ConVar tf_fastbuild;

BEGIN_DATADESC( CBaseTFFourWheelVehicle )

	DEFINE_EMBEDDED( m_VehiclePhysics ),

	DEFINE_INPUTFUNC( FIELD_FLOAT, "Throttle", InputThrottle ),
	DEFINE_INPUTFUNC( FIELD_FLOAT, "Steer", InputSteering ),
	DEFINE_INPUTFUNC( FIELD_FLOAT, "Action", InputAction ),
	DEFINE_INPUTFUNC( FIELD_VOID, "TurnOn",	InputTurnOn ),
	DEFINE_INPUTFUNC( FIELD_VOID, "TurnOff", InputTurnOff ),

END_DATADESC()


// Used for debugging to make vehicle deploying go really fast.
ConVar tf_fastdeploy( "tf_fastdeploy", "0", FCVAR_CHEAT );


IMPLEMENT_SERVERCLASS_ST(CBaseTFFourWheelVehicle, DT_BaseTFFourWheelVehicle)
	SendPropFloat( SENDINFO( m_flDeployFinishTime ), 0, SPROP_NOSCALE ),
	SendPropInt( SENDINFO( m_eDeployMode ), NUM_VEHICLE_DEPLOYMODE_BITS, SPROP_UNSIGNED ),
	SendPropInt( SENDINFO( m_bBoostUpgrade ), 1, SPROP_UNSIGNED ),
	SendPropInt( SENDINFO( m_nBoostTimeLeft ), 8, SPROP_UNSIGNED ),
END_SEND_TABLE()

ConVar	fourwheelvehicle_hit_damage( "fourwheelvehicle_hit_damage","40", FCVAR_NONE, "Four-wheel vehicle hit damage" );
ConVar  fourwheelvehicle_hit_damage_boostmod( "fourwheelvehicle_hit_damage_boostmod", "1.5", FCVAR_NONE, "Four-wheel vehicle boosted hit damage modifier" );
ConVar	fourwheelvehicle_hit_mindamagevel( "fourwheelvehicle_hit_mindamagevel","100", FCVAR_NONE, "Four-wheel vehciel hit velocity for min damage" );
ConVar	fourwheelvehicle_hit_maxdamagevel( "fourwheelvehicle_hit_maxdamagevel","230", FCVAR_NONE, "Four-wheel vehicle hit velocity for max damage" );
ConVar  fourwheelvehicle_impact_time( "fourwheelvehicle_impact_time", "1.0", FCVAR_NONE, "Four-wheel vehicle impact wait time." );
ConVar	fourwheelvehicle_hit_damage_player( "fourwheelvehicle_hit_damage_player", "30.0f", FCVAR_NONE, "Four-wheel vehicle hit player damage." );

//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
#pragma warning( disable: 4355 )
CBaseTFFourWheelVehicle::CBaseTFFourWheelVehicle() : m_VehiclePhysics(this)
{
	m_flDeployFinishTime = -1;
}
#pragma warning( default: 4355 )

//-----------------------------------------------------------------------------
// Destructor
//-----------------------------------------------------------------------------
CBaseTFFourWheelVehicle::~CBaseTFFourWheelVehicle ()
{
}

//-----------------------------------------------------------------------------
// Purpose: Put a vehicle in a deploy state. Turn off the engine and run a
//          deploy animation.
//-----------------------------------------------------------------------------
bool CBaseTFFourWheelVehicle::Deploy( void )
{
	// Make sure we're allowed to deploy here
	if ( !IsReadyToDrive() )
		return false;

	// Check to see if we are already in a deploy mode.
	if ( m_eDeployMode != VEHICLE_MODE_NORMAL )
		return false;

	// Disable the vehicle's motion.
	DisableMotion();

	// Save pre-deploy activity.
	m_PreDeployActivity = GetActivity();

	// Set the deploying activity - ACT_DEPLOY
	SetActivity( ACT_DEPLOY );

	// Get the deployment time.
	float flDeployTime = SequenceDuration();
	if ( tf_fastdeploy.GetBool() )
		flDeployTime = 1;

	m_flDeployFinishTime = gpGlobals->curtime + flDeployTime;

	SetContextThink( BaseFourWheeledVehicleDeployThink, gpGlobals->curtime + flDeployTime, 
		             BASEFOURWHEELEDVEHICLE_DEPLOYTHINK_CONTEXT );

	// Set the deploy mode.
	m_eDeployMode = VEHICLE_MODE_DEPLOYING;

	return true;
}

//-----------------------------------------------------------------------------
// Purpose: Release a vehicle from a deployed state.  Run a de-coupling 
//          animation and turn on the vehicle.
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::UnDeploy( void )
{
	// Make sure we are deployed.
	if ( !IsDeployed() )
		return;

	// Enable motion and turn on the vehicle.
	EnableMotion();

	// Set the undeploying activity - ACT_UNDEPLOY
	SetActivity( ACT_UNDEPLOY );

	// Get the undeployment time.
	float flUnDeployTime = SequenceDuration();
	if ( tf_fastdeploy.GetBool() )
		flUnDeployTime = 1;

	m_flDeployFinishTime = gpGlobals->curtime + flUnDeployTime;

	SetContextThink( BaseFourWheeledVehicleDeployThink, gpGlobals->curtime + flUnDeployTime, 
		             BASEFOURWHEELEDVEHICLE_DEPLOYTHINK_CONTEXT );

	// Set the deploy mode.
	m_eDeployMode = VEHICLE_MODE_UNDEPLOYING;
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::CancelDeploy( void )
{
	// Check for the deploying state.
	if ( !IsDeploying() )
		return;

	// Re-enable the motion.
	EnableMotion();

	// Reset the activity to the previous activity.
	SetActivity( m_PreDeployActivity );
	
	// Reset the deploy mode.
	m_eDeployMode = VEHICLE_MODE_NORMAL;

	m_flDeployFinishTime = -1;

	// Turn off the context think.
	SetContextThink( NULL, 0, BASEFOURWHEELEDVEHICLE_DEPLOYTHINK_CONTEXT );
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::BaseFourWheeledVehicleDeployThink( void )
{
	// Called from deploy.
	if ( IsDeploying() )
	{
		OnFinishedDeploy();
		m_flDeployFinishTime = -1;
	}
	// Called from undeploy.
	else if ( IsUndeploying() )
	{
		OnFinishedUnDeploy();
		m_flDeployFinishTime = -1;
	}

	// Turn off the context think.
	SetContextThink( NULL, 0, BASEFOURWHEELEDVEHICLE_DEPLOYTHINK_CONTEXT );
}

void CBaseTFFourWheelVehicle::BaseFourWheeledVehicleStopTheRodeoMadnessThink( void )
{
	// HACK HACK:  See note above at FinishBuilding call
	// This resets the handbrake, so the newly placed object doesn't roll down any hills.
	m_VehiclePhysics.ResetControls();

	// Turn off the context think.
	SetContextThink( NULL, 0, BASEFOURWHEELEDVEHICLE_STOPTHERODEO_CONTEXT );

	// Start our base think
	SetContextThink( BaseFourWheeledVehicleThink, gpGlobals->curtime + 0.1, BASEFOURWHEELEDVEHICLE_THINK_CONTEXT );
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::OnFinishedDeploy( void )
{
	SetActivity( ACT_DEPLOY_IDLE );
	m_eDeployMode = VEHICLE_MODE_DEPLOYED;
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::OnFinishedUnDeploy( void )
{
	m_eDeployMode = VEHICLE_MODE_NORMAL;
}

//-----------------------------------------------------------------------------
// Purpose: Allow the vehicle to move.
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::EnableMotion( void )
{
	// Enable vehicle chasis motion.
	IPhysicsObject *pVehicleObject = VPhysicsGetObject();
	if ( pVehicleObject )
	{
		pVehicleObject->EnableMotion( true );
	}

	// Enable motion on the tires.
	m_VehiclePhysics.EnableMotion();
}

//-----------------------------------------------------------------------------
// Purpose: Dis-allow the vehicle to move.
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::DisableMotion( void )
{
	// Disable vehicle chasis motion.
	IPhysicsObject *pVehicleObject = VPhysicsGetObject();
	if ( pVehicleObject )
	{
		pVehicleObject->EnableMotion( false );
	}

	// Disable motion on the tires.
	m_VehiclePhysics.DisableMotion();
}

//-----------------------------------------------------------------------------
// Precache
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::Precache()
{
	BaseClass::Precache();

	PrecacheScriptSound( "BaseTFFourWheelVehicle.EMP" );
	PrecacheScriptSound( "BaseTFFourWheelVehicle.RamSound" );
}

//-----------------------------------------------------------------------------
// Spawn
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::Spawn( )
{
	SetModel( STRING( GetModelName() ) );
//	CFourWheelServerVehicle *pServerVehicle = dynamic_cast<CFourWheelServerVehicle*>(GetServerVehicle());
//	m_VehiclePhysics.SetOuter( this, pServerVehicle );
	m_VehiclePhysics.Spawn();
	BaseClass::Spawn();
	// The base class spawn sets a default collision group, so this needs to
	// be called post.
	SetCollisionGroup( COLLISION_GROUP_VEHICLE );

	m_eDeployMode = VEHICLE_MODE_NORMAL;

	SetBoostUpgrade( false );

	m_flNextHitTime = 0.0f;
}	

//-----------------------------------------------------------------------------
// Teleport
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::Teleport( const Vector *newPosition, const QAngle *newAngles, const Vector *newVelocity )
{
	// We basically just have to make sure the wheels are in the right place
	// after teleportation occurs
	matrix3x4_t startMatrixInv;
	MatrixInvert( EntityToWorldTransform(), startMatrixInv );

	BaseClass::Teleport( newPosition, newAngles, newVelocity );

	// Teleport the vehicle physics from the starting position to the ending one
	matrix3x4_t relativeTransform;
	ConcatTransforms( EntityToWorldTransform(), startMatrixInv, relativeTransform );
	m_VehiclePhysics.Teleport( relativeTransform );
}


//-----------------------------------------------------------------------------
// Debugging methods
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::DrawDebugGeometryOverlays()
{
	if (m_debugOverlays & OVERLAY_BBOX_BIT) 
	{	
		m_VehiclePhysics.DrawDebugGeometryOverlays();
	}
	BaseClass::DrawDebugGeometryOverlays();
}

int CBaseTFFourWheelVehicle::DrawDebugTextOverlays()
{
	int nOffset = BaseClass::DrawDebugTextOverlays();
	if (m_debugOverlays & OVERLAY_TEXT_BIT) 
	{
		nOffset = m_VehiclePhysics.DrawDebugTextOverlays( nOffset );
	}
	return nOffset;
}


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CBaseTFFourWheelVehicle::StartBuilding( CBaseEntity *pPlayer )
{
	if (!BaseClass::StartBuilding(pPlayer))
		return false;

	// Until we're finished building, turn off vphysics-based motion
	SetSolid( SOLID_VPHYSICS );
	VPhysicsInitStatic();

	return true;
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::FinishedBuilding( void )
{
	BaseClass::FinishedBuilding();

	char pScriptName[128];
	Q_snprintf( pScriptName, sizeof( pScriptName ), "scripts/vehicles/%s.txt", GetClassname() );
	m_VehiclePhysics.Initialize( pScriptName, true );

	// HACK HACK:  This is a hack to avoid physics spazzing out on a newly created vehicle with the handbrake
	//  set.  We create and activate it, but then release the handbrake for a single Think function call and 
	//  then zero out the controls right then.  This seems to stabilize something in the physics simulator.
	m_VehiclePhysics.ReleaseHandbrake();
	SetContextThink( BaseFourWheeledVehicleStopTheRodeoMadnessThink, gpGlobals->curtime, BASEFOURWHEELEDVEHICLE_STOPTHERODEO_CONTEXT );
	
	ResetDeteriorationTime();
}

//-----------------------------------------------------------------------------
// Input methods
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::InputThrottle( inputdata_t &inputdata )
{
	m_VehiclePhysics.SetThrottle( inputdata.value.Float() );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::InputSteering( inputdata_t &inputdata )
{
	m_VehiclePhysics.SetSteering( inputdata.value.Float(), 2*gpGlobals->frametime );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::InputAction( inputdata_t &inputdata )
{
	m_VehiclePhysics.SetAction( inputdata.value.Float() );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::InputTurnOn( inputdata_t &inputdata )
{
	if (!m_VehiclePhysics.IsOn())
	{
		SetContextThink( BaseFourWheeledVehicleThink, gpGlobals->curtime + 0.1, BASEFOURWHEELEDVEHICLE_THINK_CONTEXT );
		m_VehiclePhysics.TurnOn( );
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::InputTurnOff( inputdata_t &inputdata )
{
	if ( m_VehiclePhysics.IsOn() )
	{
		m_VehiclePhysics.TurnOff( );
	}
}

//-----------------------------------------------------------------------------
// Input methods
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::BaseFourWheeledVehicleThink()
{
	if (m_VehiclePhysics.Think())
	{
		SetNextThink( gpGlobals->curtime, BASEFOURWHEELEDVEHICLE_THINK_CONTEXT );
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::VPhysicsUpdate( IPhysicsObject *pPhysics )
{
	// must be a wheel
	if (!m_VehiclePhysics.VPhysicsUpdate(pPhysics))
		return;

	BaseClass::VPhysicsUpdate( pPhysics );
}


//-----------------------------------------------------------------------------
// Methods related to getting in and out of the vehicle 
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::SetPassenger( int nRole, CBasePlayer *pEnt )
{
	if ( nRole == VEHICLE_ROLE_DRIVER )
	{
		if (pEnt)
		{
			PlayerControlInit( ToBasePlayer(pEnt) );
		}
		else
		{
			PlayerControlShutdown( );
		}
	}
	BaseClass::SetPassenger( nRole, pEnt );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::PlayerControlInit( CBasePlayer *pPlayer )
{
	// Blat out the view offset
	m_savedViewOffset = pPlayer->GetViewOffset();
	pPlayer->SetViewOffset( vec3_origin );

	m_playerOn.FireOutput( pPlayer, this, 0 );
	InputTurnOn( inputdata_t() );

	// Release the handbrake.
	if ( !IsDeployed() )
	{
		m_VehiclePhysics.ReleaseHandbrake();
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::ResetUseKey( CBasePlayer *pPlayer )
{
	pPlayer->m_afButtonPressed &= ~IN_USE;
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::PlayerControlShutdown()
{
	CBasePlayer *pPlayer = GetDriverPlayer();
	if ( !pPlayer )
		return;

	ResetUseKey( pPlayer );
	pPlayer->SetViewOffset( m_savedViewOffset );

	m_playerOff.FireOutput( pPlayer, this, 0 );
	// clear out the fire buttons
	m_attackaxis.Set( 0, pPlayer, this );
	m_attack2axis.Set( 0, pPlayer, this );

	InputTurnOff( inputdata_t() );
}

//-----------------------------------------------------------------------------
// Purpose: Powerup has just started
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::PowerupStart( int iPowerup, float flAmount, CBaseEntity *pAttacker, CDamageModifier *pDamageModifier )
{
	switch( iPowerup )
	{
	case POWERUP_EMP:
		m_VehiclePhysics.SetMaxThrottle( 0.1 );
		break;

	default:
		break;
	}

	BaseClass::PowerupStart( iPowerup, flAmount, pAttacker, pDamageModifier );
}

//-----------------------------------------------------------------------------
// Purpose: Powerup has just started
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::PowerupEnd( int iPowerup )
{
	switch ( iPowerup )
	{
	case POWERUP_EMP:
		m_VehiclePhysics.SetMaxThrottle( 1.0 );
		break;

	default:
		break;
	}

	BaseClass::PowerupEnd( iPowerup );
}

//-----------------------------------------------------------------------------
// Methods related to actually driving the vehicle
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::DriveVehicle( CBasePlayer *pPlayer, CUserCmd *ucmd )
{
	// Lose control when the player dies
	if ( pPlayer->IsAlive() == false )
		return;

	// Only the driver gets to drive.
	int nRole = GetPassengerRole( pPlayer );
	if ( nRole != VEHICLE_ROLE_DRIVER )
		return;

	// No driving in the mothership, kids
	if ( !tf_fastbuild.GetInt() && !IsReadyToDrive() )
	{
		m_VehiclePhysics.SetHandbrake( true );
		m_VehiclePhysics.SetThrottle( 0 );
		m_VehiclePhysics.SetSteering( 0, 0 );
		m_attackaxis.Set( 0, pPlayer, this );
		m_attack2axis.Set( 0, pPlayer, this );
		return;
	}

	// Update the boost time.
	m_nBoostTimeLeft = m_VehiclePhysics.BoostTimeLeft();

	// If the vehicle's emped, it can't drive
	if ( HasPowerup( POWERUP_EMP ) )
	{
		// Play sounds if they're trying to drive
		if ( ucmd->buttons & (IN_MOVELEFT | IN_MOVERIGHT | IN_FORWARD | IN_BACK) )
		{
			if ( m_flNextEmpSound < gpGlobals->curtime )
			{
				EmitSound( "BaseTFFourWheelVehicle.EMP" );
				m_flNextEmpSound = gpGlobals->curtime + 2.0;
			}
		}
	}

	ResetDeteriorationTime();

	m_VehiclePhysics.UpdateDriverControls( ucmd, TICK_INTERVAL );

	float attack = 0, attack2 = 0;

	if ( pPlayer->m_afButtonPressed & IN_ATTACK )
	{
		m_pressedAttack.FireOutput( pPlayer, this, 0 );
	}
	if ( pPlayer->m_afButtonPressed & IN_ATTACK2 )
	{
		m_pressedAttack2.FireOutput( pPlayer, this, 0 );
	}

	if ( ucmd->buttons & IN_ATTACK )
	{
		attack = 1;
	}
	if ( ucmd->buttons & IN_ATTACK2 )
	{
		attack2 = 1;
	}

	m_attackaxis.Set( attack, pPlayer, this );
	m_attack2axis.Set( attack2, pPlayer, this );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::SetupMove( CBasePlayer *pPlayer, CUserCmd *ucmd, IMoveHelper *pHelper, CMoveData *move )
{
	BaseClass::SetupMove( pPlayer, ucmd, pHelper, move );

	if ( IsDeployed() )
		return;

	DriveVehicle( pPlayer, ucmd );
	m_nMovementRole = GetPassengerRole( pPlayer );
	Assert( m_nMovementRole >= 0 );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::ProcessMovement( CBasePlayer *pPlayer, CMoveData *pMoveData )
{
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::SetBoostUpgrade( bool bBoostUpgrade ) 
{ 
	m_bBoostUpgrade = bBoostUpgrade;
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CBaseTFFourWheelVehicle::IsBoostable( void )
{
	return m_bBoostUpgrade;
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::StartBoost( void )
{
	if ( IsBoostable() )
	{
		m_VehiclePhysics.SetBoost( 1.0f );
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CBaseTFFourWheelVehicle::IsBoosting( void )
{
	return m_VehiclePhysics.IsBoosting();
}

//-----------------------------------------------------------------------------
// Purpose: Vehicle damage!
//-----------------------------------------------------------------------------
void CBaseTFFourWheelVehicle::VPhysicsCollision( int index, gamevcollisionevent_t *pEvent )
{
	BaseClass::VPhysicsCollision( index, pEvent );

	int otherIndex = !index;
	CBaseEntity *pEntity = pEvent->pEntities[otherIndex];

    // We only damage objects...
	// And only if we're travelling fast enough...
	Assert( pEntity );
	if ( !pEntity->IsSolid() )
		return;

	// Ignore shields..
	if ( pEntity->GetCollisionGroup() == TFCOLLISION_GROUP_SHIELD )
		return;

	// Ignore anything that's not an object
	if ( pEntity->Classify() != CLASS_MILITARY && !pEntity->IsPlayer() )
		return;

	// Ignore teammates
	if ( InSameTeam( pEntity ))
		return;

	// Ignore invulnerable stuff
	if ( pEntity->m_takedamage == DAMAGE_NO )
		return;

	// See if we can damage again? (Time-based)
	if ( m_flNextHitTime > gpGlobals->curtime )
		return;

	// Do damage based on velocity.
	Vector vecVelocity = pEvent->preVelocity[index];

	CTakeDamageInfo info;
	info.SetInflictor( this );
	info.SetAttacker( GetDriverPlayer() );
	info.SetDamageType( DMG_CLUB );

	float flMaxDamage = fourwheelvehicle_hit_damage.GetFloat();
	float flMaxDamageVel = fourwheelvehicle_hit_maxdamagevel.GetFloat();
	float flMinDamageVel = fourwheelvehicle_hit_mindamagevel.GetFloat();

	float flVel = vecVelocity.Length();
	if ( flVel < flMinDamageVel )
		return;

	EmitSound( "BaseTFFourWheelVehicle.RamSound" );

	float flDamageFactor = flMaxDamage;
	// Special damage for players.
	if ( pEntity->IsPlayer() )
	{
		flDamageFactor = fourwheelvehicle_hit_damage_player.GetFloat();

		if ( IsBoosting() )
		{
			flDamageFactor *= 4.0f;
		}

		// Knock the player up into the air
		float flForceScale = (flVel*0.5) * 75 * 4;
		Vector vecForce = vecVelocity;
		VectorNormalize( vecForce );
		vecForce.z += 0.7;
		vecForce *= flForceScale;
		info.SetDamageForce( vecForce );
	}
	// Damage to objects.
	else
	{
		if ( IsBoosting() )
		{
			flDamageFactor *= fourwheelvehicle_hit_damage_boostmod.GetFloat();
		}
		
		if ( ( flMaxDamageVel > flMinDamageVel ) && ( flVel < flMaxDamageVel ) )
		{
			// Use less damage when we're not moving fast enough
			float flVelocityFactor = ( flVel - flMinDamageVel ) / ( flMaxDamageVel - flMinDamageVel );
			flVelocityFactor *= flVelocityFactor;
			flDamageFactor *= flVelocityFactor;
		}
	}

	info.SetDamage( flDamageFactor );
	Vector damagePos;
	pEvent->pInternalData->GetContactPoint( damagePos );
	Vector damageForce = pEvent->postVelocity[index] * pEvent->pObjects[index]->GetMass();
	info.SetDamageForce( damageForce );
	info.SetDamagePosition( damagePos );
	PhysCallbackDamage( pEntity, info, *pEvent, index );

	// Set next time hit time
	m_flNextHitTime = gpGlobals->curtime + fourwheelvehicle_impact_time.GetFloat();
}