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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: This is a bastardization of the vehicle code for the choreography
// group who want to have smooth view lerping code out of a keyframed
// controlled player viewpoint.
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "vehicle_base.h"
#include "hl2_player.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CPropVehicleViewController : public CPropVehicleDriveable
{
DECLARE_CLASS( CPropVehicleViewController, CPropVehicleDriveable );
public:
DECLARE_DATADESC();
// CBaseEntity
void Spawn( void );
void Think(void);
// CPropVehicle
virtual void SetupMove( CBasePlayer *player, CUserCmd *ucmd, IMoveHelper *pHelper, CMoveData *move );
virtual void EnterVehicle( CBasePlayer *pPlayer );
virtual void ExitVehicle( int nRole );
// Inputs to force the player in/out of the vehicle
void InputForcePlayerIn( inputdata_t &inputdata );
void InputForcePlayerOut( inputdata_t &inputdata );
};
BEGIN_DATADESC( CPropVehicleViewController )
DEFINE_INPUTFUNC( FIELD_STRING, "ForcePlayerIn", InputForcePlayerIn ),
DEFINE_INPUTFUNC( FIELD_VOID, "ForcePlayerOut", InputForcePlayerOut ),
END_DATADESC()
LINK_ENTITY_TO_CLASS( vehicle_viewcontroller, CPropVehicleViewController );
//------------------------------------------------
// Spawn
//------------------------------------------------
void CPropVehicleViewController::Spawn( void )
{
BaseClass::Spawn();
AddSolidFlags( FSOLID_NOT_STANDABLE );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPropVehicleViewController::Think(void)
{
BaseClass::Think();
SetSimulationTime( gpGlobals->curtime );
SetNextThink( gpGlobals->curtime );
SetAnimatedEveryTick( true );
StudioFrameAdvance();
// If the exit anim has finished, move the player to the right spot and stop animating
if ( IsSequenceFinished() && (m_bExitAnimOn || m_bEnterAnimOn) )
{
// If we're exiting and have had the tau cannon removed, we don't want to reset the animation
GetServerVehicle()->HandleEntryExitFinish( m_bExitAnimOn, false );
m_bExitAnimOn = false;
m_bEnterAnimOn = false;
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPropVehicleViewController::SetupMove( CBasePlayer *player, CUserCmd *ucmd, IMoveHelper *pHelper, CMoveData *move )
{
// Does nothing, because this vehicle doesn't drive
}
//-----------------------------------------------------------------------------
// Purpose:
// NOTE: Doesn't call the base call enter vehicle on purpose!
//-----------------------------------------------------------------------------
void CPropVehicleViewController::EnterVehicle( CBasePlayer *pPlayer )
{
if ( !pPlayer )
return;
m_hPlayer = pPlayer;
pPlayer->SetViewOffset( vec3_origin );
pPlayer->ShowCrosshair( false );
m_playerOn.FireOutput( pPlayer, this, 0 );
// Start Thinking
SetNextThink( gpGlobals->curtime );
m_VehiclePhysics.GetVehicle()->OnVehicleEnter();
// Stop the player sprint and flashlight.
CHL2_Player *pHL2Player = dynamic_cast<CHL2_Player*>( pPlayer );
if ( pHL2Player )
{
if ( pHL2Player->IsSprinting() )
{
pHL2Player->StopSprinting();
}
if ( pHL2Player->FlashlightIsOn() )
{
pHL2Player->FlashlightTurnOff();
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPropVehicleViewController::ExitVehicle( int nRole )
{
BaseClass::ExitVehicle( nRole );
m_bEnterAnimOn = false;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPropVehicleViewController::InputForcePlayerIn( inputdata_t &inputdata )
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(1);
if ( !pPlayer )
return;
ResetUseKey( pPlayer );
// Get the entry animation from the input
int iEntryAnim = ACTIVITY_NOT_AVAILABLE;
if ( inputdata.value.StringID() != NULL_STRING )
{
iEntryAnim = LookupSequence( inputdata.value.String() );
if ( iEntryAnim == ACTIVITY_NOT_AVAILABLE )
{
Warning("vehicle_viewcontroller %s could not find specified entry animation %s\n", STRING(GetEntityName()), inputdata.value.String() );
return;
}
}
// Make sure we successfully got in the vehicle
if ( pPlayer->GetInVehicle( GetServerVehicle(), VEHICLE_ROLE_DRIVER ) == false )
{
// The player was unable to enter the vehicle and the output has failed
Assert( 0 );
return;
}
// Setup the "enter" vehicle sequence
SetCycle( 0 );
m_flAnimTime = gpGlobals->curtime;
ResetSequence( iEntryAnim );
ResetClientsideFrame();
m_bEnterAnimOn = true;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPropVehicleViewController::InputForcePlayerOut( inputdata_t &inputdata )
{
if ( !GetDriver() )
return;
GetServerVehicle()->HandlePassengerExit( m_hPlayer );
}
|