-
Notifications
You must be signed in to change notification settings - Fork 2
/
hud.qc
620 lines (541 loc) · 13.6 KB
/
hud.qc
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
/*
======================================================================
INTERMISSION
======================================================================
*/
// from hud.qc
void(entity ent, entity killer) DeathmatchScoreboardMessage;
void(entity ent) MoveClientToIntermission =
{
#ifdef SINGLE_PLAYER
if (deathmatch.intVal || coop.intVal)
#endif
ent.client.showscores = true;
ent.s.origin = level.intermission_origin;
ent.client.ps.pmove.origin = level.intermission_origin;
ent.client.ps.viewangles = level.intermission_angle;
ent.client.ps.pmove.pm_type = PM_FREEZE;
ent.client.ps.gunindex = 0;
ent.client.ps.blend[3] = 0;
ent.client.ps.rdflags &= ~RDF_UNDERWATER;
// clean up powerup info
ent.client.quad_framenum = 0;
ent.client.invincible_framenum = 0;
ent.client.breather_framenum = 0;
ent.client.enviro_framenum = 0;
ent.client.grenade_blew_up = false;
ent.client.grenade_framenum = 0;
#ifdef THE_RECKONING
ent.client.quadfire_framenum = 0;
ent.client.trap_blew_up = false;
ent.client.trap_framenum = 0;
#endif
#ifdef GROUND_ZERO
ent.client.ps.rdflags &= ~RDF_IRGOGGLES; // PGM
ent.client.ir_framenum = 0; // PGM
ent.client.nuke_framenum = 0; // PMM
ent.client.double_framenum = 0; // PMM
#endif
ent.viewheight = 0;
ent.s.modelindex = 0;
ent.s.modelindex2 = 0;
ent.s.modelindex3 = 0;
ent.s.modelindex = 0;
ent.s.effects = 0;
ent.s.sound = 0;
ent.solid = SOLID_NOT;
gi.linkentity(ent);
// add the layout
#ifdef SINGLE_PLAYER
if (deathmatch.intVal || coop.intVal)
{
#endif
DeathmatchScoreboardMessage(ent, world);
gi.unicast(ent, true);
#ifdef SINGLE_PLAYER
}
#endif
}
void(entity targ) BeginIntermission =
{
entity ent, cl;
if (level.intermission_framenum)
return; // already activated
#ifdef CTF
if (ctf.intVal)
CTFCalcScores();
#endif
#ifdef SINGLE_PLAYER
game.autosaved = false;
#endif
// respawn any dead clients
for (int i = 0 ; i < game.maxclients ; i++)
{
cl = itoe(1 + i);
if (!cl.inuse)
continue;
if (cl.health <= 0)
respawn(cl);
}
level.intermission_framenum = level.framenum;
level.changemap = targ.map;
#ifdef SINGLE_PLAYER
if (strstr(level.changemap, "*") != -1)
{
if (coop.intVal)
{
for (int i = 0 ; i < game.maxclients ; i++)
{
cl = itoe(1 + i);
if (!cl.inuse)
continue;
gitem_t *it = itemlist;
// strip players of all keys between units
for (int n = 0; n < itemlist.length; n++, it++)
if (it->flags & IT_KEY)
cl.client.pers.inventory[n] = 0;
}
}
}
else
{
if (!deathmatch.intVal)
{
level.exitintermission = 1; // go immediately to the next level
return;
}
}
#endif
level.exitintermission = 0;
// find an intermission spot
ent = G_Find(world, classname, "info_player_intermission");
if !(ent)
{
// the map creator forgot to put in an intermission point...
ent = G_Find(world, classname, "info_player_start");
if !(ent)
ent = G_Find(world, classname, "info_player_deathmatch");
}
else
{
// chose one of four spots
int i = Q_rand() & 3;
while (i--)
{
ent = G_Find(ent, classname, "info_player_intermission");
if !(ent) // wrap around the list
ent = G_Find(ent, classname, "info_player_intermission");
}
}
level.intermission_origin = ent.s.origin;
level.intermission_angle = ent.s.angles;
// move all clients to the intermission point
for (int i = 0; i < game.maxclients; i++)
{
cl = itoe(1 + i);
if (!cl.inuse)
continue;
MoveClientToIntermission(cl);
}
}
/*
==================
DeathmatchScoreboardMessage
==================
*/
void(entity ent, entity killer) DeathmatchScoreboardMessage =
{
#ifdef CTF
if (ctf.intVal)
{
CTFScoreboardMessage(ent, killer);
return;
}
#endif
string entry;
string str = "";
int stringlength;
int i, j, k;
int sorted[MAX_CLIENTS] = { 0 };
int sortedscores[MAX_CLIENTS] = { 0 };
int score, total;
int x, y;
entity cl_ent;
string tag;
// sort the clients by score
total = 0;
for (i = 0 ; i < game.maxclients ; i++) {
cl_ent = itoe(1 + i);
if (!cl_ent.inuse || cl_ent.client.resp.spectator)
continue;
score = cl_ent.client.resp.score;
for (j = 0 ; j < total ; j++) {
if (score > sortedscores[j])
break;
}
for (k = total ; k > j ; k--) {
sorted[k] = sorted[(k - 1)];
sortedscores[k] = sortedscores[(k - 1)];
}
sorted[j] = i;
sortedscores[j] = score;
total++;
}
// print level name and exit rules
stringlength = 0;
// add the clients in sorted order
if (total > 12)
total = 12;
for (i = 0 ; i < total ; i++) {
cl_ent = itoe(1 + sorted[i]);
if (i >= 6)
x = 160;
else
x = 0;
y = 32 + 32 * (i % 6);
// add a dogtag
if (cl_ent == ent)
tag = "tag1";
else if (cl_ent == killer)
tag = "tag2";
else
tag = 0;
if (tag) {
entry = va("xv %i yv %i picn %s ", x + 32, y, tag);
j = strlen(entry);
if (stringlength + j > 1024)
break;
str = strconcat(str, entry);
stringlength += j;
}
// send the layout
entry = va("client %i %i %i %i %i %i ", x, y, sorted[i], cl_ent.client.resp.score, cl_ent.client.ping, ((level.framenum - cl_ent.client.resp.enterframe) / 600));
j = strlen(entry);
if (stringlength + j > 1024)
break;
str = strconcat(str, entry);
stringlength += j;
}
gi.WriteByte(svc_layout);
gi.WriteString(str);
}
/*
==================
DeathmatchScoreboard
Draw instead of help message.
Note that it isn't that hard to overflow the MESSAGE_LIMIT!
==================
*/
static void(entity ent) DeathmatchScoreboard =
{
DeathmatchScoreboardMessage(ent, ent.enemy);
gi.unicast(ent, true);
}
/*
==================
Cmd_Score_f
Display the scoreboard
==================
*/
void(entity ent) Cmd_Score_f =
{
ent.client.showinventory = false;
#ifdef PMENU
if (ent.client.menu.open)
PMenu_Close(ent);
#endif
#ifdef SINGLE_PLAYER
ent.client.showhelp = false;
if (!deathmatch.intVal && !coop.intVal)
return;
#endif
if (ent.client.showscores)
{
ent.client.showscores = false;
return;
}
ent.client.showscores = true;
DeathmatchScoreboard(ent);
}
#ifdef SINGLE_PLAYER
/*
==================
HelpComputer
Draw help computer.
==================
*/
static void(entity ent) HelpComputer =
{
string str;
string sk;
if (skill.intVal == 0)
sk = "easy";
else if (skill.intVal == 1)
sk = "medium";
else if (skill.intVal == 2)
sk = "hard";
else
sk = "hard+";
// send the layout
str = va( "xv 32 yv 8 picn help " // background
"xv 202 yv 12 string2 \"%s\" " // skill
"xv 0 yv 24 cstring2 \"%s\" " // level name
"xv 0 yv 54 cstring2 \"%s\" " // help 1
"xv 0 yv 110 cstring2 \"%s\" ", // help 2
sk,
level.level_name,
game.helpmessage1,
game.helpmessage2);
str = va( "%sxv 50 yv 164 string2 \" kills goals secrets\" "
"xv 50 yv 172 string2 \"%3i/%3i %i/%i %i/%i\" ",
str,
level.killed_monsters, level.total_monsters,
level.found_goals, level.total_goals,
level.found_secrets, level.total_secrets);
gi.WriteByte(svc_layout);
gi.WriteString(str);
gi.unicast(ent, true);
}
#endif
/*
==================
Cmd_Help_f
Display the current help message
==================
*/
void(entity ent) Cmd_Help_f =
{
#ifdef SINGLE_PLAYER
// this is for backwards compatability
if (deathmatch.intVal)
{
Cmd_Score_f(ent);
return;
}
ent.client.showinventory = false;
ent.client.showscores = false;
if (ent.client.showhelp && (ent.client.pers.game_helpchanged == game.helpchanged)) {
ent.client.showhelp = false;
return;
}
ent.client.showhelp = true;
ent.client.pers.helpchanged = 0;
HelpComputer(ent);
#else
Cmd_Score_f(ent);
#endif
}
//=======================================================================
/*
===============
G_SetStats
===============
*/
void(entity ent) G_SetStats =
{
gitem_t *it;
//
// health
//
ent.client.ps.stats[STAT_HEALTH_ICON] = level.pic_health;
ent.client.ps.stats[STAT_HEALTH] = ent.health;
//
// ammo
//
if (!ent.client.ammo_index)
{
ent.client.ps.stats[STAT_AMMO_ICON] = 0;
ent.client.ps.stats[STAT_AMMO] = 0;
}
else
{
it = GetItemByIndex(ent.client.ammo_index);
ent.client.ps.stats[STAT_AMMO_ICON] = gi.imageindex(it->icon);
ent.client.ps.stats[STAT_AMMO] = ent.client.pers.inventory[it->id];
}
//
// armor
//
power_armor_type_t power_armor_type = PowerArmorType(ent);
int cells = 0;
if (power_armor_type)
{
cells = ent.client.pers.inventory[ITEM_CELLS];
if (cells == 0)
{
// ran out of cells for power armor
ent.flags &= ~FL_POWER_ARMOR;
gi.sound(ent, CHAN_ITEM, gi.soundindex("misc/power2.wav"), 1, ATTN_NORM, 0);
power_armor_type = 0;;
}
}
gitem_id_t index = ArmorIndex(ent);
if (power_armor_type && (!index || (level.framenum & 8)))
{
// flash between power armor and other armor icon
// Knightmare- use correct icon for power screen
if (power_armor_type == POWER_ARMOR_SHIELD)
ent.client.ps.stats[STAT_ARMOR_ICON] = gi.imageindex ("i_powershield");
else // POWER_ARMOR_SCREEN
ent.client.ps.stats[STAT_ARMOR_ICON] = gi.imageindex ("i_powerscreen");
ent.client.ps.stats[STAT_ARMOR] = cells;
}
else if (index)
{
it = GetItemByIndex(index);
ent.client.ps.stats[STAT_ARMOR_ICON] = gi.imageindex(it->icon);
ent.client.ps.stats[STAT_ARMOR] = ent.client.pers.inventory[index];
}
else
{
ent.client.ps.stats[STAT_ARMOR_ICON] = 0;
ent.client.ps.stats[STAT_ARMOR] = 0;
}
//
// pickup message
//
if (level.framenum > ent.client.pickup_msg_framenum)
{
ent.client.ps.stats[STAT_PICKUP_ICON] = 0;
ent.client.ps.stats[STAT_PICKUP_STRING] = 0;
}
//
// timers
//
if (ent.client.quad_framenum > level.framenum)
{
ent.client.ps.stats[STAT_TIMER_ICON] = gi.imageindex("p_quad");
ent.client.ps.stats[STAT_TIMER] = (ent.client.quad_framenum - level.framenum) / 10;
}
#ifdef THE_RECKONING
// RAFAEL
else if (ent.client.quadfire_framenum > level.framenum)
{
ent.client.ps.stats[STAT_TIMER_ICON] = gi.imageindex ("p_quadfire");
ent.client.ps.stats[STAT_TIMER] = (ent.client.quadfire_framenum - level.framenum)/10;
}
#endif
#ifdef GROUND_ZERO
else if (ent.client.double_framenum > level.framenum)
{
ent.client.ps.stats[STAT_TIMER_ICON] = gi.imageindex ("p_double");
ent.client.ps.stats[STAT_TIMER] = (ent.client.double_framenum - level.framenum)/10;
}
#endif
else if (ent.client.invincible_framenum > level.framenum)
{
ent.client.ps.stats[STAT_TIMER_ICON] = gi.imageindex("p_invulnerability");
ent.client.ps.stats[STAT_TIMER] = (ent.client.invincible_framenum - level.framenum) / 10;
}
else if (ent.client.enviro_framenum > level.framenum)
{
ent.client.ps.stats[STAT_TIMER_ICON] = gi.imageindex("p_envirosuit");
ent.client.ps.stats[STAT_TIMER] = (ent.client.enviro_framenum - level.framenum) / 10;
}
else if (ent.client.breather_framenum > level.framenum)
{
ent.client.ps.stats[STAT_TIMER_ICON] = gi.imageindex("p_rebreather");
ent.client.ps.stats[STAT_TIMER] = (ent.client.breather_framenum - level.framenum) / 10;
}
#ifdef GROUND_ZERO
else if (ent.client.ir_framenum > level.framenum)
{
ent.client.ps.stats[STAT_TIMER_ICON] = gi.imageindex ("p_ir");
ent.client.ps.stats[STAT_TIMER] = (ent.client.ir_framenum - level.framenum)/10;
}
#endif
else
{
ent.client.ps.stats[STAT_TIMER_ICON] = 0;
ent.client.ps.stats[STAT_TIMER] = 0;
}
//
// selected item
//
if (ent.client.pers.selected_item == -1)
ent.client.ps.stats[STAT_SELECTED_ICON] = 0;
else
ent.client.ps.stats[STAT_SELECTED_ICON] = gi.imageindex(GetItemByIndex(ent.client.pers.selected_item)->icon);
ent.client.ps.stats[STAT_SELECTED_ITEM] = ent.client.pers.selected_item;
//
// layouts
//
ent.client.ps.stats[STAT_LAYOUTS] = 0;
#ifdef SINGLE_PLAYER
if (deathmatch.intVal)
{
#endif
if (ent.client.pers.health <= 0 || level.intermission_framenum || ent.client.showscores)
ent.client.ps.stats[STAT_LAYOUTS] |= 1;
if (ent.client.showinventory && ent.client.pers.health > 0)
ent.client.ps.stats[STAT_LAYOUTS] |= 2;
#ifdef SINGLE_PLAYER
}
else
{
if (ent.client.showscores || ent.client.showhelp)
ent.client.ps.stats[STAT_LAYOUTS] |= 1;
if (ent.client.showinventory && ent.client.pers.health > 0)
ent.client.ps.stats[STAT_LAYOUTS] |= 2;
}
#endif
//
// frags
//
ent.client.ps.stats[STAT_FRAGS] = ent.client.resp.score;
//
// help icon / current weapon if not shown
//
#ifdef SINGLE_PLAYER
if (ent.client.pers.helpchanged && (level.framenum & 8))
ent.client.ps.stats[STAT_HELPICON] = gi.imageindex("i_help");
else
#endif
if ((ent.client.pers.hand == CENTER_HANDED || ent.client.ps.fov > 91) && ent.client.pers.weapon)
ent.client.ps.stats[STAT_HELPICON] = gi.imageindex(ent.client.pers.weapon->icon);
else
ent.client.ps.stats[STAT_HELPICON] = 0;
ent.client.ps.stats[STAT_SPECTATOR] = 0;
#ifdef CTF
SetCTFStats(ent);
#endif
}
void(entity) G_SetSpectatorStats;
/*
===============
G_CheckChaseStats
===============
*/
void(entity ent) G_CheckChaseStats =
{
for (int i = 1; i <= game.maxclients; i++)
{
entity cl = itoe(i);
if (!cl.inuse || cl.client.chase_target != ent)
continue;
// FIXME: sizeof
memcpy(&cl.client.ps.stats[0], &ent.client.ps.stats[0], sizeof(int) * MAX_STATS);
G_SetSpectatorStats(cl);
}
}
/*
===============
G_SetSpectatorStats
===============
*/
void(entity ent) G_SetSpectatorStats =
{
if (!ent.client.chase_target)
G_SetStats(ent);
ent.client.ps.stats[STAT_SPECTATOR] = 1;
// layouts are independant in spectator
ent.client.ps.stats[STAT_LAYOUTS] = 0;
if (ent.client.pers.health <= 0 || level.intermission_framenum || ent.client.showscores)
ent.client.ps.stats[STAT_LAYOUTS] |= 1;
if (ent.client.showinventory && ent.client.pers.health > 0)
ent.client.ps.stats[STAT_LAYOUTS] |= 2;
if (ent.client.chase_target && ent.client.chase_target.inuse)
ent.client.ps.stats[STAT_CHASE] = CS_PLAYERSKINS + (ent.client.chase_target.s.number - 1);
else
ent.client.ps.stats[STAT_CHASE] = 0;
}