forked from skullernet/openffa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
g_chase.c
299 lines (247 loc) · 7.75 KB
/
g_chase.c
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
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program 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.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "g_local.h"
static void SetChaseStats(gclient_t *client)
{
edict_t *targ = client->chase_target;
int playernum = (targ - g_edicts) - 1;
memcpy(client->ps.stats, targ->client->ps.stats, sizeof(client->ps.stats));
// layouts are independant in chasecam mode
client->ps.stats[STAT_LAYOUTS] = 0;
if (client->layout)
client->ps.stats[STAT_LAYOUTS] |= 1;
client->ps.stats[STAT_CHASE] = CS_PLAYERNAMES + playernum;
client->ps.stats[STAT_SPECTATOR] = CS_SPECMODE;
// STAT_FRAGS is no longer used for HUD,
// but the server reports it in status responses
client->ps.stats[STAT_FRAGS] = 0;
// check view id settings
if (client->pers.noviewid || client->layout == LAYOUT_MOTD) {
client->ps.stats[STAT_VIEWID] = 0;
} else if (targ->client->pers.noviewid) {
client->ps.stats[STAT_VIEWID] = G_GetPlayerIdView(targ);
}
}
static void UpdateChaseCamHack(gclient_t *client)
{
vec3_t o, ownerv, goal;
edict_t *ent = client->edict;
edict_t *targ = client->chase_target;
vec3_t forward, right;
trace_t trace;
vec3_t angles;
VectorCopy(targ->s.origin, ownerv);
ownerv[2] += targ->viewheight;
VectorCopy(targ->client->v_angle, angles);
if (angles[PITCH] > 56)
angles[PITCH] = 56;
AngleVectors(angles, forward, right, NULL);
VectorNormalize(forward);
VectorMA(ownerv, -30, forward, o);
if (o[2] < targ->s.origin[2] + 20)
o[2] = targ->s.origin[2] + 20;
// jump animation lifts
if (!targ->groundentity)
o[2] += 16;
trace = gi.trace(ownerv, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
VectorCopy(trace.endpos, goal);
VectorMA(goal, 2, forward, goal);
// pad for floors and ceilings
VectorCopy(goal, o);
o[2] += 6;
trace = gi.trace(goal, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
if (trace.fraction < 1) {
VectorCopy(trace.endpos, goal);
goal[2] -= 6;
}
VectorCopy(goal, o);
o[2] -= 6;
trace = gi.trace(goal, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
if (trace.fraction < 1) {
VectorCopy(trace.endpos, goal);
goal[2] += 6;
}
if (targ->deadflag)
client->ps.pmove.pm_type = PM_DEAD;
else
client->ps.pmove.pm_type = PM_FREEZE;
client->ps.pmove.pm_flags |= PMF_NO_PREDICTION;
VectorCopy(goal, ent->s.origin);
VectorScale(goal, 8, client->ps.pmove.origin);
if (targ->deadflag) {
client->ps.viewangles[ROLL] = 40;
client->ps.viewangles[PITCH] = -15;
client->ps.viewangles[YAW] = targ->client->killer_yaw;
} else {
G_SetDeltaAngles(ent, targ->client->v_angle);
VectorCopy(targ->client->v_angle, ent->client->ps.viewangles);
VectorCopy(targ->client->v_angle, client->v_angle);
}
ent->viewheight = 0;
// gi.linkentity(ent);
}
static void UpdateChaseCam(gclient_t *client)
{
edict_t *ent = client->edict;
edict_t *targ = client->chase_target;
client->ps = targ->client->ps;
if (client->pers.uf & UF_LOCALFOV) {
client->ps.fov = client->pers.fov;
}
client->ps.pmove.pm_flags |= PMF_NO_PREDICTION;
/*if (targ->deadflag) {
client->ps.pmove.pm_type = PM_DEAD;
} else*/ {
client->ps.pmove.pm_type = PM_FREEZE;
}
VectorCopy(ent->client->ps.viewangles, ent->s.angles);
VectorCopy(ent->client->ps.viewangles, ent->client->v_angle);
VectorScale(ent->client->ps.pmove.origin, 0.125f, ent->s.origin);
ent->viewheight = targ->viewheight;
}
void SetChaseTarget(edict_t *ent, edict_t *targ)
{
int i;
ent->client->chase_target = targ;
// stop chasecam
if (!targ) {
ent->client->clientNum = (ent - g_edicts) - 1;
ent->client->ps.pmove.pm_flags = 0;
ent->client->ps.pmove.pm_type = PM_SPECTATOR;
ent->client->ps.viewangles[ROLL] = 0;
G_SetDeltaAngles(ent, ent->client->ps.viewangles);
VectorCopy(ent->client->ps.viewangles, ent->s.angles);
VectorCopy(ent->client->ps.viewangles, ent->client->v_angle);
VectorScale(ent->client->ps.pmove.origin, 0.125f, ent->s.origin);
ent->client->chase_mode = CHASE_NONE;
ClientEndServerFrame(ent);
} else {
ent->client->clientNum = (targ - g_edicts) - 1;
for (i = 0; i < PCS_TOTAL; i++) {
G_PrivateString(ent, i, targ->client->level.strings[i]);
}
ChaseEndServerFrame(ent);
}
}
void UpdateChaseTargets(chase_mode_t mode, edict_t *targ)
{
edict_t *other;
int i;
for (i = 1; i <= game.maxclients; i++) {
other = &g_edicts[i];
if (!other->inuse) {
continue;
}
if (other->client->pers.connected != CONN_SPECTATOR) {
continue;
}
if (other->client->chase_mode != mode) {
continue;
}
if (other->client->chase_target != targ) {
SetChaseTarget(other, targ);
}
}
}
bool ChaseNext(edict_t *ent)
{
int i;
edict_t *e, *targ = ent->client->chase_target;
if (!targ)
return false;
i = targ - g_edicts;
do {
i++;
if (i > game.maxclients)
i = 1;
e = g_edicts + i;
if (e == targ)
return false;
} while (!PlayerSpawned(e));
SetChaseTarget(ent, e);
return true;
}
bool ChasePrev(edict_t *ent)
{
int i;
edict_t *e, *targ = ent->client->chase_target;
if (!targ)
return false;
i = targ - g_edicts;
do {
i--;
if (i < 1)
i = game.maxclients;
e = g_edicts + i;
if (e == targ)
return false;
} while (!PlayerSpawned(e));
SetChaseTarget(ent, e);
return true;
}
bool GetChaseTarget(edict_t *ent, chase_mode_t mode)
{
gclient_t *ranks[MAX_CLIENTS];
edict_t *other, *found = NULL;
int i;
if (mode == CHASE_LEADER) {
if (G_CalcRanks(ranks)) {
found = ranks[0]->edict;
}
} else for (i = 1; i <= game.maxclients; i++) {
other = &g_edicts[i];
if (!other->inuse) {
continue;
}
if (!PlayerSpawned(other)) {
continue;
}
if (mode == CHASE_NONE
|| (mode == CHASE_QUAD && other->client->quad_framenum > level.framenum)
|| (mode == CHASE_INVU && other->client->invincible_framenum > level.framenum)) {
found = other;
break;
}
}
if (!found) {
gi.cprintf(ent, PRINT_HIGH, "No players to chase.\n");
return false;
}
SetChaseTarget(ent, found);
ent->client->chase_mode = mode;
return true;
}
void ChaseEndServerFrame(edict_t *ent)
{
gclient_t *c = ent->client;
if (!c->chase_target) {
return;
}
// is our chase target gone?
if (!PlayerSpawned(c->chase_target)) {
if (!ChaseNext(ent)) {
SetChaseTarget(ent, NULL);
return;
}
}
// camera
if (game.serverFeatures & GMF_CLIENTNUM) {
UpdateChaseCam(c);
} else {
UpdateChaseCamHack(c);
}
// stats
SetChaseStats(c);
}