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
|
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
Copyright (C) 2000-2006 Tim Angus
This file is part of Tremulous.
Tremulous is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
Tremulous is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Tremulous; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
// cg_playerstate.c -- this file acts on changes in a new playerState_t
// With normal play, this will be done after local prediction, but when
// following another player or playing back a demo, it will be checked
// when the snapshot transitions like all the other entities
#include "cg_local.h"
/*
==============
CG_DamageFeedback
==============
*/
void CG_DamageFeedback( int yawByte, int pitchByte, int damage )
{
float left, front, up;
float kick;
int health;
float scale;
vec3_t dir;
vec3_t angles;
float dist;
float yaw, pitch;
// show the attacking player's head and name in corner
cg.attackerTime = cg.time;
// the lower on health you are, the greater the view kick will be
health = cg.snap->ps.stats[STAT_HEALTH];
if( health < 40 )
scale = 1;
else
scale = 40.0 / health;
kick = damage * scale;
if( kick < 5 )
kick = 5;
if( kick > 10 )
kick = 10;
// if yaw and pitch are both 255, make the damage always centered (falling, etc)
if( yawByte == 255 && pitchByte == 255 )
{
cg.damageX = 0;
cg.damageY = 0;
cg.v_dmg_roll = 0;
cg.v_dmg_pitch = -kick;
}
else
{
// positional
pitch = pitchByte / 255.0 * 360;
yaw = yawByte / 255.0 * 360;
angles[ PITCH ] = pitch;
angles[ YAW ] = yaw;
angles[ ROLL ] = 0;
AngleVectors( angles, dir, NULL, NULL );
VectorSubtract( vec3_origin, dir, dir );
front = DotProduct( dir, cg.refdef.viewaxis[ 0 ] );
left = DotProduct( dir, cg.refdef.viewaxis[ 1 ] );
up = DotProduct( dir, cg.refdef.viewaxis[ 2 ] );
dir[ 0 ] = front;
dir[ 1 ] = left;
dir[ 2 ] = 0;
dist = VectorLength( dir );
if( dist < 0.1f )
dist = 0.1f;
cg.v_dmg_roll = kick * left;
cg.v_dmg_pitch = -kick * front;
if( front <= 0.1 )
front = 0.1f;
cg.damageX = -left / front;
cg.damageY = up / dist;
}
// clamp the position
if( cg.damageX > 1.0 )
cg.damageX = 1.0;
if( cg.damageX < - 1.0 )
cg.damageX = -1.0;
if( cg.damageY > 1.0 )
cg.damageY = 1.0;
if( cg.damageY < - 1.0 )
cg.damageY = -1.0;
// don't let the screen flashes vary as much
if( kick > 10 )
kick = 10;
cg.damageValue = kick;
cg.v_dmg_time = cg.time + DAMAGE_TIME;
cg.damageTime = cg.snap->serverTime;
}
/*
================
CG_Respawn
A respawn happened this snapshot
================
*/
void CG_Respawn( void )
{
// no error decay on player movement
cg.thisFrameTeleport = qtrue;
// display weapons available
cg.weaponSelectTime = cg.time;
// select the weapon the server says we are using
cg.weaponSelect = cg.snap->ps.weapon;
CG_ResetPainBlend( );
}
/*
==============
CG_CheckPlayerstateEvents
==============
*/
void CG_CheckPlayerstateEvents( playerState_t *ps, playerState_t *ops )
{
int i;
int event;
centity_t *cent;
if( ps->externalEvent && ps->externalEvent != ops->externalEvent )
{
cent = &cg_entities[ ps->clientNum ];
cent->currentState.event = ps->externalEvent;
cent->currentState.eventParm = ps->externalEventParm;
CG_EntityEvent( cent, cent->lerpOrigin );
}
cent = &cg.predictedPlayerEntity; // cg_entities[ ps->clientNum ];
// go through the predictable events buffer
for( i = ps->eventSequence - MAX_PS_EVENTS; i < ps->eventSequence; i++ )
{
// if we have a new predictable event
if( i >= ops->eventSequence ||
// or the server told us to play another event instead of a predicted event we already issued
// or something the server told us changed our prediction causing a different event
( i > ops->eventSequence - MAX_PS_EVENTS && ps->events[ i & ( MAX_PS_EVENTS - 1 ) ] !=
ops->events[ i & ( MAX_PS_EVENTS - 1 ) ] ) )
{
event = ps->events[ i & ( MAX_PS_EVENTS - 1 ) ];
cent->currentState.event = event;
cent->currentState.eventParm = ps->eventParms[ i & ( MAX_PS_EVENTS - 1 ) ];
CG_EntityEvent( cent, cent->lerpOrigin );
cg.predictableEvents[ i & ( MAX_PREDICTED_EVENTS - 1 ) ] = event;
cg.eventSequence++;
}
}
}
/*
==================
CG_CheckChangedPredictableEvents
==================
*/
void CG_CheckChangedPredictableEvents( playerState_t *ps )
{
int i;
int event;
centity_t *cent;
cent = &cg.predictedPlayerEntity;
for( i = ps->eventSequence - MAX_PS_EVENTS; i < ps->eventSequence; i++ )
{
//
if( i >= cg.eventSequence )
continue;
// if this event is not further back in than the maximum predictable events we remember
if( i > cg.eventSequence - MAX_PREDICTED_EVENTS )
{
// if the new playerstate event is different from a previously predicted one
if( ps->events[ i & ( MAX_PS_EVENTS - 1 ) ] != cg.predictableEvents[ i & ( MAX_PREDICTED_EVENTS - 1 ) ] )
{
event = ps->events[ i & ( MAX_PS_EVENTS - 1 ) ];
cent->currentState.event = event;
cent->currentState.eventParm = ps->eventParms[ i & ( MAX_PS_EVENTS - 1 ) ];
CG_EntityEvent( cent, cent->lerpOrigin );
cg.predictableEvents[ i & ( MAX_PREDICTED_EVENTS - 1 ) ] = event;
if( cg_showmiss.integer )
CG_Printf( "WARNING: changed predicted event\n" );
}
}
}
}
/*
==================
CG_CheckLocalSounds
==================
*/
void CG_CheckLocalSounds( playerState_t *ps, playerState_t *ops )
{
// don't play the sounds if the player just changed teams
if( ps->persistant[ PERS_TEAM ] != ops->persistant[ PERS_TEAM ] )
return;
// health changes of more than -1 should make pain sounds
if( ps->stats[ STAT_HEALTH ] < ops->stats[ STAT_HEALTH ] - 1 )
{
if( ps->stats[ STAT_HEALTH ] > 0 )
CG_PainEvent( &cg.predictedPlayerEntity, ps->stats[ STAT_HEALTH ] );
}
// if we are going into the intermission, don't start any voices
if( cg.intermissionStarted )
return;
}
/*
===============
CG_TransitionPlayerState
===============
*/
void CG_TransitionPlayerState( playerState_t *ps, playerState_t *ops )
{
// check for changing follow mode
if( ps->clientNum != ops->clientNum )
{
cg.thisFrameTeleport = qtrue;
// make sure we don't get any unwanted transition effects
*ops = *ps;
CG_ResetPainBlend( );
}
// damage events (player is getting wounded)
if( ps->damageEvent != ops->damageEvent && ps->damageCount )
CG_DamageFeedback( ps->damageYaw, ps->damagePitch, ps->damageCount );
// respawning
if( ps->persistant[ PERS_SPAWN_COUNT ] != ops->persistant[ PERS_SPAWN_COUNT ] )
CG_Respawn( );
if( cg.mapRestart )
{
CG_Respawn( );
cg.mapRestart = qfalse;
}
if( cg.snap->ps.pm_type != PM_INTERMISSION &&
ps->persistant[ PERS_TEAM ] != TEAM_SPECTATOR )
CG_CheckLocalSounds( ps, ops );
// run events
CG_CheckPlayerstateEvents( ps, ops );
// smooth the ducking viewheight change
if( ps->viewheight != ops->viewheight )
{
cg.duckChange = ps->viewheight - ops->viewheight;
cg.duckTime = cg.time;
}
}
|