summaryrefslogtreecommitdiff
path: root/game/client/tf2/c_vehicle_tank.cpp
blob: be290393e446fd0dbf17d0861d8e4f1bd059b980 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//

#include "cbase.h"
#include "c_basefourwheelvehicle.h"
#include "tf_movedata.h"
#include "ObjectControlPanel.h"
#include <vgui_controls/Label.h>
#include <vgui_controls/Button.h>
#include "vgui_rotation_slider.h"
#include <vgui/ISurface.h>
#include "vgui_basepanel.h"
#include "ground_line.h"
#include "hud_minimap.h"
#include "vgui_bitmapimage.h"
#include "view.h"
#include "c_basetempentity.h"
#include "particles_simple.h"
#include "in_buttons.h"


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
class C_VehicleTank : public C_BaseTFFourWheelVehicle
{
	DECLARE_CLASS( C_VehicleTank, C_BaseTFFourWheelVehicle );
public:
	DECLARE_CLIENTCLASS();

	C_VehicleTank();


	virtual void ClientThink();

	virtual void OnItemPostFrame( CBaseTFPlayer *pDriver );

// C_BaseEntity overrides.
public:
	virtual void GetBoneControllers(float controllers[MAXSTUDIOBONECTRLS]);

private:
	C_VehicleTank( const C_VehicleTank & );		// not defined, not accessible

	float m_flClientYaw;
	float m_flClientPitch;

	// Sent by the server. This is what we render with.
	float m_flTurretYaw;
	float m_flTurretPitch;
};


IMPLEMENT_CLIENTCLASS_DT( C_VehicleTank, DT_VehicleTank, CVehicleTank )
	RecvPropFloat( RECVINFO( m_flTurretYaw ) ),
	RecvPropFloat( RECVINFO( m_flTurretPitch ) )
END_RECV_TABLE()


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------

C_VehicleTank::C_VehicleTank()
{
	m_flClientYaw = 0;
	m_flClientPitch = 0;
	m_flTurretYaw = 0;
	m_flTurretPitch = 0;
}


void C_VehicleTank::ClientThink()
{
	if ( GetPassenger( VEHICLE_ROLE_DRIVER ) == C_BasePlayer::GetLocalPlayer() )
	{
		// Cast a ray out of the view to see where the player is looking.
		trace_t trace;
		UTIL_TraceLine( 
			MainViewOrigin(), 
			MainViewOrigin() + MainViewForward() * 100000,
			MASK_OPAQUE, NULL,
			COLLISION_GROUP_NONE,
			&trace );

		if ( trace.fraction < 1 )
		{
			// Figure out what angles our turret needs to be at in order to hit the target.

			Vector vFireOrigin;
			QAngle dummy;
			GetAttachment( LookupAttachment( "barrel" ), vFireOrigin, dummy );

			// Get a direction vector that points at the target.
			Vector vTo = trace.endpos - vFireOrigin;

			// Transform it into the tank's local space.
			matrix3x4_t tankToWorld;
			AngleMatrix( GetAbsAngles(), tankToWorld );
			
			Vector vLocalTo;
			VectorITransform( vTo, tankToWorld, vLocalTo );

			// Now figure out what the angles are in local space.
			QAngle localAngles;
			VectorAngles( vLocalTo, localAngles );

			// Make the angles adhere to the definition in CVehicleTank's header.
			m_flClientYaw = localAngles[YAW] - 90;
			m_flClientPitch = anglemod( -localAngles[PITCH] );


			char cmd[512];
			Q_snprintf( cmd, sizeof( cmd ), "TurretAngles %.2f %.2f", m_flClientYaw, m_flClientPitch );
			SendClientCommand( cmd );
		}
	}

	BaseClass::ClientThink();
}


void C_VehicleTank::GetBoneControllers( float controllers[MAXSTUDIOBONECTRLS])
{
	BaseClass::GetBoneControllers( controllers );

	controllers[0] = anglemod( m_flTurretYaw ) / 360.0;
	controllers[1] = anglemod( m_flTurretPitch ) / 360.0;
}

//-----------------------------------------------------------------------------
// Here's where we deal with weapons
//-----------------------------------------------------------------------------
void C_VehicleTank::OnItemPostFrame( CBaseTFPlayer *pDriver )
{
	if ( GetPassengerRole(pDriver) != VEHICLE_ROLE_DRIVER )
		return;

	if ( pDriver->m_nButtons & IN_ATTACK )
	{
	}
	else if ( pDriver->m_nButtons & (IN_ATTACK2 | IN_SPEED) )
	{
		BaseClass::OnItemPostFrame( pDriver );
	}
}