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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "player_command.h"
#include "player.h"
#include "igamemovement.h"
#include "hl_movedata.h"
#include "ipredictionsystem.h"
#include "iservervehicle.h"
#include "hl2_player.h"
#include "vehicle_base.h"
#include "gamestats.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
class CHLPlayerMove : public CPlayerMove
{
DECLARE_CLASS( CHLPlayerMove, CPlayerMove );
public:
CHLPlayerMove() :
m_bWasInVehicle( false ),
m_bVehicleFlipped( false ),
m_bInGodMode( false ),
m_bInNoClip( false )
{
m_vecSaveOrigin.Init();
}
void SetupMove( CBasePlayer *player, CUserCmd *ucmd, IMoveHelper *pHelper, CMoveData *move );
void FinishMove( CBasePlayer *player, CUserCmd *ucmd, CMoveData *move );
private:
Vector m_vecSaveOrigin;
bool m_bWasInVehicle;
bool m_bVehicleFlipped;
bool m_bInGodMode;
bool m_bInNoClip;
};
//
//
// PlayerMove Interface
static CHLPlayerMove g_PlayerMove;
//-----------------------------------------------------------------------------
// Singleton accessor
//-----------------------------------------------------------------------------
CPlayerMove *PlayerMove()
{
return &g_PlayerMove;
}
//
static CHLMoveData g_HLMoveData;
CMoveData *g_pMoveData = &g_HLMoveData;
IPredictionSystem *IPredictionSystem::g_pPredictionSystems = NULL;
void CHLPlayerMove::SetupMove( CBasePlayer *player, CUserCmd *ucmd, IMoveHelper *pHelper, CMoveData *move )
{
// Call the default SetupMove code.
BaseClass::SetupMove( player, ucmd, pHelper, move );
// Convert to HL2 data.
CHL2_Player *pHLPlayer = static_cast<CHL2_Player*>( player );
Assert( pHLPlayer );
CHLMoveData *pHLMove = static_cast<CHLMoveData*>( move );
Assert( pHLMove );
player->m_flForwardMove = ucmd->forwardmove;
player->m_flSideMove = ucmd->sidemove;
pHLMove->m_bIsSprinting = pHLPlayer->IsSprinting();
if ( gpGlobals->frametime != 0 )
{
IServerVehicle *pVehicle = player->GetVehicle();
if ( pVehicle )
{
pVehicle->SetupMove( player, ucmd, pHelper, move );
if ( !m_bWasInVehicle )
{
m_bWasInVehicle = true;
m_vecSaveOrigin.Init();
}
}
else
{
m_vecSaveOrigin = player->GetAbsOrigin();
if ( m_bWasInVehicle )
{
m_bWasInVehicle = false;
}
}
}
}
void CHLPlayerMove::FinishMove( CBasePlayer *player, CUserCmd *ucmd, CMoveData *move )
{
// Call the default FinishMove code.
BaseClass::FinishMove( player, ucmd, move );
if ( gpGlobals->frametime != 0 )
{
float distance = 0.0f;
IServerVehicle *pVehicle = player->GetVehicle();
if ( pVehicle )
{
pVehicle->FinishMove( player, ucmd, move );
IPhysicsObject *obj = player->GetVehicleEntity()->VPhysicsGetObject();
if ( obj )
{
Vector newPos;
obj->GetPosition( &newPos, NULL );
distance = VectorLength( newPos - m_vecSaveOrigin );
if ( m_vecSaveOrigin == vec3_origin || distance > 100.0f )
distance = 0.0f;
m_vecSaveOrigin = newPos;
}
CPropVehicleDriveable *driveable = dynamic_cast< CPropVehicleDriveable * >( player->GetVehicleEntity() );
if ( driveable )
{
// Overturned and at rest (if still moving it can fix itself)
bool bFlipped = driveable->IsOverturned() && ( distance < 0.5f );
if ( m_bVehicleFlipped != bFlipped )
{
if ( bFlipped )
{
gamestats->Event_FlippedVehicle( player, driveable );
}
m_bVehicleFlipped = bFlipped;
}
}
else
{
m_bVehicleFlipped = false;
}
}
else
{
m_bVehicleFlipped = false;
distance = VectorLength( player->GetAbsOrigin() - m_vecSaveOrigin );
}
if ( distance > 0 )
{
gamestats->Event_PlayerTraveled( player, distance, pVehicle ? true : false, !pVehicle && static_cast< CHL2_Player * >( player )->IsSprinting() );
}
}
bool bGodMode = ( player->GetFlags() & FL_GODMODE ) ? true : false;
if ( m_bInGodMode != bGodMode )
{
m_bInGodMode = bGodMode;
if ( bGodMode )
{
gamestats->Event_PlayerEnteredGodMode( player );
}
}
bool bNoClip = ( player->GetMoveType() == MOVETYPE_NOCLIP );
if ( m_bInNoClip != bNoClip )
{
m_bInNoClip = bNoClip;
if ( bNoClip )
{
gamestats->Event_PlayerEnteredNoClip( player );
}
}
}
|