forked from richard-allen/q2pro
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathp_hud.c
More file actions
1561 lines (1344 loc) · 48.6 KB
/
Copy pathp_hud.c
File metadata and controls
1561 lines (1344 loc) · 48.6 KB
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
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//-----------------------------------------------------------------------------
// p_hud.c
//
// $Id: p_hud.c,v 1.8 2002/01/24 02:24:56 deathwatch Exp $
//
//-----------------------------------------------------------------------------
// $Log: p_hud.c,v $
// Revision 1.8 2002/01/24 02:24:56 deathwatch
// Major update to Stats code (thanks to Freud)
// new cvars:
// stats_afterround - will display the stats after a round ends or map ends
// stats_endmap - if on (1) will display the stats scoreboard when the map ends
//
// Revision 1.7 2002/01/02 01:18:24 deathwatch
// Showing health icon when bandaging (thanks to Dome for submitting this code)
//
// Revision 1.6 2001/09/28 13:48:35 ra
// I ran indent over the sources. All .c and .h files reindented.
//
// Revision 1.5 2001/08/20 00:41:15 slicerdw
// Added a new scoreboard for Teamplay with stats ( when map ends )
//
// Revision 1.4 2001/07/16 19:02:06 ra
// Fixed compilerwarnings (-g -Wall). Only one remains.
//
// Revision 1.3 2001/05/31 16:58:14 igor_rock
// conflicts resolved
//
// Revision 1.2.2.3 2001/05/25 18:59:52 igor_rock
// Added CTF Mode completly :)
// Support for .flg files is still missing, but with "real" CTF maps like
// tq2gtd1 the ctf works fine.
// (I hope that all other modes still work, just tested DM and teamplay)
//
// Revision 1.2.2.2 2001/05/20 18:54:19 igor_rock
// added original ctf code snippets from zoid. lib compilesand runs but
// doesn't function the right way.
// Jsut committing these to have a base to return to if something wents
// awfully wrong.
//
// Revision 1.2.2.1 2001/05/20 15:17:31 igor_rock
// removed the old ctf code completly
//
// Revision 1.2 2001/05/11 16:07:26 mort
// Various CTF bits and pieces...
//
// Revision 1.1.1.1 2001/05/06 17:25:15 igor_rock
// This is the PG Bund Edition V1.25 with all stuff laying around here...
//
//-----------------------------------------------------------------------------
#include "g_local.h"
// Red team colors
int red_team_red = 220;
int red_team_green = 60;
int red_team_blue = 60;
int alt_red_team_red = 110;
int alt_red_team_green = 45;
int alt_red_team_blue = 45;
// Blue team colors
int blue_team_red = 40;
int blue_team_green = 40;
int blue_team_blue = 220;
int alt_blue_team_red = 30;
int alt_blue_team_green = 60;
int alt_blue_team_blue = 110;
// Green team colors
int green_team_red = 40;
int green_team_green = 220;
int green_team_blue = 40;
int alt_green_team_red = 30;
int alt_green_team_green = 140;
int alt_green_team_blue = 30;
/*
======================================================================
INTERMISSION
======================================================================
*/
void MoveClientToIntermission(edict_t *ent)
{
PMenu_Close(ent);
ent->client->layout = LAYOUT_SCORES;
VectorCopy(level.intermission_origin, ent->s.origin);
ent->client->ps.pmove.origin[0] = level.intermission_origin[0] * 8;
ent->client->ps.pmove.origin[1] = level.intermission_origin[1] * 8;
ent->client->ps.pmove.origin[2] = level.intermission_origin[2] * 8;
VectorCopy(level.intermission_angle, ent->client->ps.viewangles);
VectorClear(ent->client->ps.kick_angles);
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;
ent->client->ps.stats[STAT_FLASHES] = 0;
// 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;
ent->watertype = 0;
ent->waterlevel = 0;
ent->viewheight = 0;
ent->s.modelindex = 0;
ent->s.modelindex2 = 0;
ent->s.modelindex3 = 0;
ent->s.modelindex4 = 0;
ent->s.effects = 0;
ent->s.renderfx = 0;
ent->s.sound = 0;
ent->s.event = 0;
ent->s.solid = 0;
ent->solid = SOLID_NOT;
ent->svflags = SVF_NOCLIENT;
ent->client->resp.sniper_mode = SNIPER_1X;
ent->client->desired_fov = 90;
ent->client->ps.fov = 90;
ent->client->ps.stats[STAT_SNIPER_ICON] = 0;
ent->client->pickup_msg_framenum = 0;
#ifndef NO_BOTS
if( ent->is_bot )
return;
#endif
// Defer the layout send to ClientEndServerFrames for staggered delivery
ent->client->needs_intermission_scoreboard = true;
}
void BeginIntermission(edict_t *targ)
{
int i;
edict_t *ent;
// Clear all timed messages
free(timedMessages);
if (level.intermission_framenum)
return; // already activated
level.intermission_framenum = level.realFramenum;
if (ctf->value) {
CTFCalcScores();
} else if (teamplay->value) {
TallyEndOfLevelTeamScores();
}
// Generates stats for non-CTF, Teamplay or Matchmode
if (!matchmode->value) {
LOG_MATCH(); // Generates end of game stats
LOG_END_MATCH_STATS(); // Generates end of match stats
}
CALL_DISCORD_WEBHOOK(DM_MATCH_END_MSG, MATCH_END_MSG, AWARD_NONE);
// respawn any dead clients
for (i = 0, ent = g_edicts + 1; i < game.maxclients; i++, ent++)
{
if (!ent->inuse)
continue;
if (ent->health <= 0)
respawn(ent);
}
level.changemap = targ->map;
level.intermission_exit = 0;
// find an intermission spot
ent = G_Find(NULL, FOFS(classname), "info_player_intermission");
if (!ent)
{ // the map creator forgot to put in an intermission point...
ent = G_Find(NULL, FOFS(classname), "info_player_start");
if (!ent)
ent = G_Find(NULL, FOFS(classname), "info_player_deathmatch");
}
else
{ // chose one of four spots
i = rand () & 3;
while (i--)
{
ent = G_Find(ent, FOFS(classname), "info_player_intermission");
if (!ent) // wrap around the list
ent = G_Find(ent, FOFS(classname), "info_player_intermission");
}
}
if (ent) {
VectorCopy( ent->s.origin, level.intermission_origin );
VectorCopy( ent->s.angles, level.intermission_angle );
}
// move all clients to the intermission point
for (i = 0, ent = g_edicts + 1; i < game.maxclients; i++, ent++)
{
if (!ent->inuse)
continue;
MoveClientToIntermission(ent);
}
InitTransparentList();
}
/*
======================================================================
Point of Interest
This isn't perfect, but it gets you in the 'area' of a point of interest
Could use some refactoring, but it works for now.
Works much like intermission, but it more or less 'teleports' spectators
and those who are not 'spawned in' to the point of interest.
Points of interest are generally on the ground, so this adds 25 units
to each axis to move the camera in the area without being directly
on top of the point of interest.
======================================================================
*/
void MoveClientToPOI(edict_t *ent, edict_t *poi)
{
PMenu_Close(ent);
VectorCopy(level.poi_origin, ent->s.origin);
ent->s.origin[0] -= 25;
ent->s.origin[1] -= 25;
ent->s.origin[2] += 25;
ent->client->ps.pmove.origin[0] = (level.poi_origin[0] - 25) * 8;
ent->client->ps.pmove.origin[1] = (level.poi_origin[1] - 25) * 8;
ent->client->ps.pmove.origin[2] = (level.poi_origin[2] + 25) * 8;
vec3_t ownerv, o, ownerv_forward, ownerv_right;
vec3_t angles;
VectorCopy(level.poi_origin, ownerv);
ownerv[2] += poi->viewheight;
VectorCopy(ent->client->ps.viewangles, angles);
AngleVectors(angles, ownerv_forward, ownerv_right, NULL);
VectorNormalize(ownerv_forward);
VectorMA(ownerv, -75, ownerv_forward, o);
VectorCopy(o, ent->s.origin);
VectorCopy(o, ent->client->ps.pmove.origin);
VectorSubtract(level.poi_origin, ent->s.origin, ent->client->ps.viewangles);
vectoangles(ent->client->ps.viewangles, ent->client->ps.viewangles);
VectorClear(ent->client->ps.kick_angles);
ent->client->ps.gunindex = 0;
ent->client->ps.blend[3] = 0;
ent->client->ps.rdflags &= ~RDF_UNDERWATER;
ent->client->ps.stats[STAT_FLASHES] = 0;
// 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;
ent->watertype = 0;
ent->waterlevel = 0;
ent->viewheight = 0;
ent->s.modelindex = 0;
ent->s.modelindex2 = 0;
ent->s.modelindex3 = 0;
ent->s.modelindex4 = 0;
ent->s.effects = 0;
ent->s.renderfx = 0;
ent->s.sound = 0;
ent->s.event = 0;
ent->s.solid = 0;
ent->solid = SOLID_NOT;
ent->svflags = SVF_NOCLIENT;
ent->client->resp.sniper_mode = SNIPER_1X;
ent->client->desired_fov = 90;
ent->client->ps.fov = 90;
ent->client->ps.stats[STAT_SNIPER_ICON] = 0;
ent->client->pickup_msg_framenum = 0;
#ifndef NO_BOTS
if( ent->is_bot )
return;
#endif
}
/*
==================
DeathmatchScoreboardMessage
==================
*/
void DeathmatchScoreboardMessage (edict_t * ent, edict_t * killer)
{
char entry[128];
char string[1024];
int stringlength;
int i, j, totalClients;
gclient_t *sortedClients[MAX_CLIENTS];
int x, y;
gclient_t *cl;
edict_t *cl_ent;
char *tag;
#ifndef NO_BOTS
if (ent->is_bot)
return;
#endif
if (teamplay->value && !use_tourney->value)
{
// DW: If the map ends
if (level.intermission_framenum) {
if (stats_endmap->value && (gameSettings & GS_ROUNDBASED)) // And we are to show the stats screen
A_ScoreboardEndLevel(ent, killer); // do it
else // otherwise
A_ScoreboardMessage(ent, killer); // show the original
}
else
A_ScoreboardMessage(ent, killer);
return;
}
totalClients = G_SortedClients(sortedClients);
// print level name and exit rules
string[0] = 0;
stringlength = 0;
// add the clients in sorted order
if (totalClients > 12)
totalClients = 12;
for (i = 0; i < totalClients; i++)
{
cl = sortedClients[i];
cl_ent = g_edicts + 1 + (cl - game.clients);
x = (i >= 6) ? 160 : 0;
y = 32 + 32 * (i % 6);
// add a dogtag
if (cl_ent == ent)
tag = "tag1";
else if (cl_ent == killer)
tag = "tag2";
else
tag = NULL;
if (tag)
{
Q_snprintf (entry, sizeof (entry),
"xv %i yv %i picn %s ", x + 32, y, tag);
j = strlen (entry);
if (stringlength + j > 1023)
break;
strcpy (string + stringlength, entry);
stringlength += j;
}
// Convert ping to string so we can report pings as BOT if needed
char pingstr[8];
Q_snprintf(pingstr, sizeof(pingstr), "%d", min(cl->ping, 999));
#ifndef NO_BOTS
if (IS_BOT(cl_ent)) {
if (!bot_reportasclient->value || !bot_reportpings->value) {
Q_snprintf(pingstr, sizeof(pingstr), "BOT");
}
}
#endif
// send the layout
Q_snprintf (entry, sizeof (entry),
"client %i %i %i %i %s %i ",
x, y, (int)(cl - game.clients), cl->resp.score,
pingstr,
(level.framenum - cl->resp.enterframe) / 600 / FRAMEDIV);
j = strlen (entry);
if (stringlength + j > 1023)
break;
strcpy (string + stringlength, entry);
stringlength += j;
}
gi.WriteByte (svc_layout);
gi.WriteString (string);
}
/*
==================
DeathmatchScoreboard
Draw instead of help message.
Note that it isn't that hard to overflow the 1400 byte message limit!
==================
*/
void DeathmatchScoreboard(edict_t *ent)
{
#ifndef NO_BOTS
if( ent->is_bot )
return;
#endif
DeathmatchScoreboardMessage(ent, ent->enemy);
/* Reliable: this is a per-client on-demand request (TAB key), not part
* of the periodic broadcast burst the stagger changes are reducing. The
* 3-second periodic refresh is too slow to mask a dropped TAB response,
* and a single-client unicast doesn't contribute to the full-server
* burst problem. */
gi.unicast(ent, true);
}
/*
==================
Cmd_Score_f
Display the scoreboard
==================
*/
void Cmd_Score_f(edict_t *ent)
{
ent->client->showinventory = false;
if (ent->client->layout == LAYOUT_MENU)
PMenu_Close(ent);
if (ent->client->layout == LAYOUT_SCORES)
{
if (teamplay->value) { // toggle scoreboards...
ent->client->layout = LAYOUT_SCORES2;
DeathmatchScoreboard(ent);
return;
}
ent->client->layout = LAYOUT_NONE;
return;
}
if (ent->client->layout == LAYOUT_SCORES2) {
ent->client->layout = LAYOUT_NONE;
return;
}
ent->client->layout = LAYOUT_SCORES;
DeathmatchScoreboard(ent);
}
/*
==================
Cmd_Help_f
Display the current help message
==================
*/
void Cmd_Help_f (edict_t * ent)
{
// this is for backwards compatability
Cmd_Score_f (ent);
}
//=======================================================================
/*
===============
G_SetStats
Rearranged for chase cam support -FB
===============
*/
void G_SetStats (edict_t * ent)
{
gitem_t *item;
if (jump->value)
{
Jmp_SetStats(ent);
return;
}
if (!ent->client->chase_mode)
{
int icons[ 6 ], numbers[ 2 ], icon_count, i;
int cycle = hud_items_cycle->value * FRAMEDIV;
int weapon_ids[ 6 ] = { SNIPER_NUM, M4_NUM, MP5_NUM, M3_NUM, HC_NUM, DUAL_NUM };
int s_item_ids[ 6 ] = { KEV_NUM, HELM_NUM, BAND_NUM, SIL_NUM, SLIP_NUM, LASER_NUM };
//
// health
//
ent->client->ps.stats[STAT_HEALTH_ICON] = level.pic_health;
ent->client->ps.stats[STAT_HEALTH] = ent->health;
//
// ammo (now clips really)
//
// zucc modified this to do clips instead
if (!ent->client-> ammo_index
/* || !ent->client->inventory[ent->client->ammo_index] */ )
{
ent->client->ps.stats[STAT_CLIP_ICON] = 0;
ent->client->ps.stats[STAT_CLIP] = 0;
}
else
{
item = &itemlist[ent->client->ammo_index];
if (item->typeNum < AMMO_MAX)
ent->client->ps.stats[STAT_CLIP_ICON] = level.pic_items[item->typeNum];
else
ent->client->ps.stats[STAT_CLIP_ICON] = gi.imageindex(item->icon);
ent->client->ps.stats[STAT_CLIP] = ent->client->inventory[ent->client->ammo_index];
}
// zucc display special item and special weapon
// Raptor007: Modified to rotate through all carried special weapons and items.
icon_count = 0;
for( i = 0; i < 6; i ++ )
{
if( INV_AMMO( ent, weapon_ids[i] ) )
icons[ icon_count ++ ] = level.pic_items[ weapon_ids[i] ];
}
if( icon_count && ! cycle )
icon_count = 1;
if( icon_count )
ent->client->ps.stats[STAT_WEAPONS_ICON] = icons[ (level.framenum/cycle) % icon_count ];
else
ent->client->ps.stats[STAT_WEAPONS_ICON] = 0;
icon_count = 0;
for( i = 0; i < 6; i ++ )
{
if( INV_AMMO( ent, s_item_ids[i] ) )
icons[ icon_count ++ ] = level.pic_items[ s_item_ids[i]];
}
if( icon_count && ! cycle )
icon_count = 1;
if( icon_count )
ent->client->ps.stats[STAT_ITEMS_ICON] = icons[ ((level.framenum+cycle/2)/cycle) % icon_count ];
else
ent->client->ps.stats[STAT_ITEMS_ICON] = 0;
// grenades remaining
icon_count = 0;
numbers[ icon_count ] = INV_AMMO( ent, GRENADE_NUM );
if( numbers[ icon_count ] )
icons[ icon_count ++ ] = level.pic_weapon_ammo[GRENADE_NUM];
// MedKit
numbers[ icon_count ] = ent->client->medkit;
if( numbers[ icon_count ] )
icons[ icon_count ++ ] = level.pic_health;
// Cycle grenades and medkit if player has both.
if( icon_count && ! cycle )
icon_count = 1;
if( icon_count )
{
int index = ((level.framenum+cycle/4)/cycle) % icon_count;
ent->client->ps.stats[STAT_GRENADE_ICON] = icons[ index ];
ent->client->ps.stats[STAT_GRENADES] = numbers[ index ];
}
else
{
ent->client->ps.stats[STAT_GRENADE_ICON] = 0;
ent->client->ps.stats[STAT_GRENADES] = 0;
}
//
// ammo by weapon
//
//
if (ent->client->weapon && ent->client->curr_weap)
{
switch (ent->client->curr_weap) {
case MK23_NUM:
ent->client->ps.stats[STAT_AMMO_ICON] = level.pic_weapon_ammo[ent->client->curr_weap];
ent->client->ps.stats[STAT_AMMO] = ent->client->mk23_rds;
break;
case MP5_NUM:
ent->client->ps.stats[STAT_AMMO_ICON] = level.pic_weapon_ammo[ent->client->curr_weap];
ent->client->ps.stats[STAT_AMMO] = ent->client->mp5_rds;
break;
case M4_NUM:
ent->client->ps.stats[STAT_AMMO_ICON] = level.pic_weapon_ammo[ent->client->curr_weap];
ent->client->ps.stats[STAT_AMMO] = ent->client->m4_rds;
break;
case M3_NUM:
ent->client->ps.stats[STAT_AMMO_ICON] = level.pic_weapon_ammo[ent->client->curr_weap];
ent->client->ps.stats[STAT_AMMO] = ent->client->shot_rds;
break;
case HC_NUM:
ent->client->ps.stats[STAT_AMMO_ICON] = level.pic_weapon_ammo[ent->client->curr_weap];
ent->client->ps.stats[STAT_AMMO] = ent->client->cannon_rds;
break;
case SNIPER_NUM:
ent->client->ps.stats[STAT_AMMO_ICON] = level.pic_weapon_ammo[ent->client->curr_weap];
ent->client->ps.stats[STAT_AMMO] = ent->client->sniper_rds;
break;
case DUAL_NUM:
ent->client->ps.stats[STAT_AMMO_ICON] = level.pic_weapon_ammo[ent->client->curr_weap];
ent->client->ps.stats[STAT_AMMO] = ent->client->dual_rds;
break;
case KNIFE_NUM:
ent->client->ps.stats[STAT_AMMO_ICON] = level.pic_weapon_ammo[ent->client->curr_weap];
ent->client->ps.stats[STAT_AMMO] = INV_AMMO(ent, KNIFE_NUM);
break;
case GRENADE_NUM:
ent->client->ps.stats[STAT_AMMO_ICON] = level.pic_weapon_ammo[ent->client->curr_weap];
ent->client->ps.stats[STAT_AMMO] = INV_AMMO(ent, GRENADE_NUM);
break;
case GRAPPLE_NUM:
ent->client->ps.stats[STAT_AMMO_ICON] = 0;
ent->client->ps.stats[STAT_AMMO] = 0;
break;
default:
gi.dprintf ("Failed to find hud weapon/icon for num %d.\n", ent->client->curr_weap);
break;
}
} else {
ent->client->ps.stats[STAT_AMMO_ICON] = 0;
ent->client->ps.stats[STAT_AMMO] = 0;
}
//
// sniper mode icons
//
//if ( ent->client->sniper_mode )
// gi.cprintf (ent, PRINT_HIGH, "Sniper Zoom set at %d.\n", ent->client->sniper_mode);
if (ent->client->resp.sniper_mode == SNIPER_1X
|| ent->client->weaponstate == WEAPON_RELOADING
|| ent->client->weaponstate == WEAPON_BUSY
|| ent->client->no_sniper_display
|| ! IS_ALIVE(ent) )
ent->client->ps.stats[STAT_SNIPER_ICON] = 0;
else
ent->client->ps.stats[STAT_SNIPER_ICON] = level.pic_sniper_mode[ent->client->resp.sniper_mode];
//
// armor
//
//ent->client->ps.stats[STAT_ARMOR_ICON] = 0; // Replaced with STAT_TEAM_ICON.
ent->client->ps.stats[STAT_ARMOR] = 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) / HZ;
// }
// 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) / HZ;
// }
// 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) / HZ;
// }
// 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) / HZ;
// }
// else
// if (esp->value) {
// if (!IS_LEADER(ent) && ent->client->respawn_framenum > 0 && ent->client->respawn_framenum > level.framenum > 0){
// ent->client->ps.stats[STAT_TIMER_ICON] = level.pic_esp_respawn_icon;
// ent->client->ps.stats[STAT_TIMER] = (ent->client->respawn_framenum - level.framenum) / HZ;
// } else {
// ent->client->ps.stats[STAT_TIMER_ICON] = 0;
// ent->client->ps.stats[STAT_TIMER] = 0;
// }
// }
// else
// {
ent->client->ps.stats[STAT_TIMER_ICON] = 0;
ent->client->ps.stats[STAT_TIMER] = 0;
//}
//
// selected item
//
if (ent->client->selected_item < 1) {
ent->client->ps.stats[STAT_SELECTED_ICON] = 0;
} else {
item = &itemlist[ent->client->selected_item];
if (item->typeNum < AMMO_MAX)
ent->client->ps.stats[STAT_SELECTED_ICON] = level.pic_items[item->typeNum];
else
ent->client->ps.stats[STAT_SELECTED_ICON] = gi.imageindex(item->icon);
}
ent->client->ps.stats[STAT_SELECTED_ITEM] = ent->client->selected_item;
//
// bandaging icon / current weapon if not shown
//
// TNG: Show health icon when bandaging (thanks to Dome for this code)
if (ent->client->weaponstate == WEAPON_BANDAGING || ent->client->bandaging || ent->client->bandage_stopped)
ent->client->ps.stats[STAT_HELPICON] = level.pic_health;
else if ((ent->client->pers.hand == CENTER_HANDED || ent->client->ps.fov > 91) && ent->client->weapon)
ent->client->ps.stats[STAT_HELPICON] = level.pic_items[ent->client->weapon->typeNum];
else
ent->client->ps.stats[STAT_HELPICON] = 0;
// Hide health, ammo, weapon, and bandaging state when free spectating.
if( ! IS_ALIVE(ent) )
{
ent->client->ps.stats[STAT_HEALTH_ICON] = 0;
ent->client->ps.stats[STAT_AMMO_ICON] = 0;
ent->client->ps.stats[STAT_SELECTED_ICON] = 0;
ent->client->ps.stats[STAT_HELPICON] = 0;
}
// Team icon.
if( teamplay->value && hud_team_icon->value && (ent->client->resp.team != NOTEAM) && IS_ALIVE(ent) )
ent->client->ps.stats[STAT_TEAM_ICON] = level.pic_teamskin[ent->client->resp.team];
else
ent->client->ps.stats[STAT_TEAM_ICON] = 0;
}
//
// pickup message
//
if (level.realFramenum > ent->client->pickup_msg_framenum)
{
ent->client->ps.stats[STAT_PICKUP_ICON] = 0;
ent->client->ps.stats[STAT_PICKUP_STRING] = 0;
}
//
// frags
//
ent->client->ps.stats[STAT_FRAGS] = ent->client->resp.score;
//
// layouts
//
ent->client->ps.stats[STAT_LAYOUTS] = 0;
if (level.intermission_framenum || ent->client->layout)
ent->client->ps.stats[STAT_LAYOUTS] |= 1;
if (ent->client->showinventory && ent->health > 0)
ent->client->ps.stats[STAT_LAYOUTS] |= 2;
if (level.intermission_framenum) {
ent->client->ps.stats[STAT_SNIPER_ICON] = 0;
ent->client->ps.stats[STAT_HELPICON] = 0;
ent->client->ps.stats[STAT_ID_VIEW] = 0;
} else {
SetIDView(ent);
}
//FIREBLADE
if (ctf->value)
SetCTFStats (ent);
else if (dom->value)
SetDomStats (ent);
else if (esp->value)
SetEspStats (ent);
else if (teamplay->value)
A_Scoreboard (ent);
//FIREBLADE
}
#ifdef AQTION_EXTENSION
void HUD_SetType(edict_t *clent, int type)
{
if (clent->client->resp.hud_type == type)
return;
if (type == -1)
HUD_ClientSetup(clent);
else if (type == 1)
HUD_SpectatorSetup(clent);
else
{
Ghud_ClearForClient(clent);
clent->client->resp.hud_type = 0;
}
}
void HUD_ClientSetup(edict_t *clent)
{
Ghud_ClearForClient(clent);
clent->client->resp.hud_type = -1;
}
void HUD_ClientUpdate(edict_t *clent)
{
}
typedef enum {
tm = 0,
mm = 1,
ts = 2,
ss = 3
} hud_time_digits;
static int GetRemainingTimeDigits(hud_time_digits timeval)
{
int remaining = 0, rmins = 0, rsecs = 0, gametime = 0;
gametime = level.matchTime;
remaining = (timelimit->value * 60) - gametime;
rmins = remaining / 60;
rsecs = remaining % 60;
// Ensure rmins and rsecs are non-negative
if (rmins < 0) {
rmins = 0;
}
if (rsecs < 0) {
rsecs = 0;
}
switch (timeval) {
case tm: // Tens of minutes
return (rmins / 10) % 10;
case mm: // Minutes
return rmins % 10;
case ts: // Tens of seconds
return (rsecs / 10) % 10;
case ss: // Seconds
return rsecs % 10;
default:
return 0; // Invalid timeval
}
}
// Returns the number of decimal digits needed to display val (minimum 1).
// Mirrors the client renderer's auto-numsize: floor(log10(val))+1.
static int ScoreDigitCount(int val)
{
if (val < 10) return 1;
if (val < 100) return 2;
if (val < 1000) return 3;
return 4;
}
// Returns the pos_x for the team-2 score element (anchor 1,0) so that the
// ones digit always ends 4 px left of the icon at x=-28, regardless of how
// many digits are in the score. Each additional high-order digit shifts the
// number 16 px further left (one DIGIT_WIDTH step).
static int T2ScorePosX(int digits)
{
return -50 - 16 * (digits - 1);
}
static void HUD_UpdateTeamScores(edict_t *clent)
{
int *hud = clent->client->resp.hud_items;
int score2, n;
// Team 1 (left edge anchor, anchor 0,0) — left-aligned, grows right.
// size[0]=0 (auto-numsize) keeps the left edge of the number fixed at
// pos_x+2=32; the ones digit shifts one slot right for each new digit place.
Ghud_SetFlags(clent, hud[h_team_l], 0);
Ghud_SetFlags(clent, hud[h_team_l_num], 0);
Ghud_SetInt(clent, hud[h_team_l_num], ctf->value ? ctfgame.team1 : teams[TEAM1].score);
// Team 2 (right edge anchor, anchor 1,0) — ones digit fixed, grows left.
// Shift pos_x one DIGIT_WIDTH step left for each additional digit so the
// ones digit always ends at the same screen position next to the icon.
Ghud_SetFlags(clent, hud[h_team_r], 0);
Ghud_SetFlags(clent, hud[h_team_r_num], 0);
score2 = ctf->value ? ctfgame.team2 : teams[TEAM2].score;
n = ScoreDigitCount(score2);
Ghud_SetPosition(clent, hud[h_team_r_num], T2ScorePosX(n), 28);
Ghud_SetInt(clent, hud[h_team_r_num], score2);
}
static void HUD_UpdateSpectatorTimer(edict_t *clent)
{
int *hud = clent->client->resp.hud_items;
// Update the HUD elements with the individual digits
Ghud_SetInt(clent, hud[h_spectator_time_tm], GetRemainingTimeDigits(tm));
Ghud_SetInt(clent, hud[h_spectator_time_mm], GetRemainingTimeDigits(mm));
Ghud_SetInt(clent, hud[h_spectator_time_ts], GetRemainingTimeDigits(ts));
Ghud_SetInt(clent, hud[h_spectator_time_ss], GetRemainingTimeDigits(ss));
if (GetRemainingTimeDigits(tm) == 0 && GetRemainingTimeDigits(mm) < 1) {
// Change bar color to red
Ghud_SetColor(clent, hud[h_spectator_timer_border], 255, 0, 0, 120);
} else if (GetRemainingTimeDigits(tm) == 0 && GetRemainingTimeDigits(mm) < 3){
// Change bar color to orange
Ghud_SetColor(clent, hud[h_spectator_timer_border], 255, 165, 0, 120);
} else {
// Change bar color to gray
Ghud_SetColor(clent, hud[h_spectator_timer_border], 20, 20, 20, 120);
}
}
void HUD_SpectatorTimerSetup(edict_t *clent)
{
int *hud = clent->client->resp.hud_items;
if (timelimit->value) {
// GHUD top middle time display
clent->client->resp.hud_type = 1;
// Unhide the other HUD elements
Ghud_SetFlags(clent, hud[h_spectator_timer_border], 0);
Ghud_SetFlags(clent, hud[h_spectator_timer], 0);
Ghud_SetFlags(clent, hud[h_spectator_time_tm], 0);
Ghud_SetFlags(clent, hud[h_spectator_time_mm], 0);
Ghud_SetFlags(clent, hud[h_spectator_time_sep], 0);
Ghud_SetFlags(clent, hud[h_spectator_time_ts], 0);
Ghud_SetFlags(clent, hud[h_spectator_time_ss], 0);
// Timer box sized to fit digits only (scores moved to edge columns).
// Digits span center±48px wide, 24px tall at y=30..54. 6px padding all sides.
int x, y;
x = 0;
y = 30;
hud[h_spectator_timer_border] = Ghud_NewElement(clent, GHT_FILL);
Ghud_SetAnchor(clent, hud[h_spectator_timer_border], 0.5, 0);
Ghud_SetPosition(clent, hud[h_spectator_timer_border], x - 55, y - 7);
Ghud_SetSize(clent, hud[h_spectator_timer_border], 110, 38);
Ghud_SetColor(clent, hud[h_spectator_timer_border], 50, 150, 50, 120);
hud[h_spectator_timer] = Ghud_NewElement(clent, GHT_FILL);
Ghud_SetAnchor(clent, hud[h_spectator_timer], 0.5, 0);
Ghud_SetPosition(clent, hud[h_spectator_timer], x - 54, y - 6);
Ghud_SetSize(clent, hud[h_spectator_timer], 108, 36);
Ghud_SetColor(clent, hud[h_spectator_timer], 50, 50, 50, 120);
// Add number elements for minutes
hud[h_spectator_time_tm] = Ghud_AddNumber(clent, x - 50, y, 0);
hud[h_spectator_time_mm] = Ghud_AddNumber(clent, x - 30, y, 0);
// Draw timer seperator
hud[h_spectator_time_sep] = Ghud_AddText(clent, x - 5, y + 12, ":");
// Add number elements for seconds
hud[h_spectator_time_ts] = Ghud_AddNumber(clent, x + 10, y, 0);
hud[h_spectator_time_ss] = Ghud_AddNumber(clent, x + 30, y, 0);
// Anchor everything to the top middle
Ghud_SetAnchor(clent, hud[h_spectator_time_tm], 0.5, 0);
Ghud_SetAnchor(clent, hud[h_spectator_time_mm], 0.5, 0);
Ghud_SetAnchor(clent, hud[h_spectator_time_sep], 0.5, 0);
Ghud_SetAnchor(clent, hud[h_spectator_time_ts], 0.5, 0);
Ghud_SetAnchor(clent, hud[h_spectator_time_ss], 0.5, 0);
} else {
Ghud_SetFlags(clent, hud[h_spectator_time_tm], GHF_HIDE);
Ghud_SetFlags(clent, hud[h_spectator_time_mm], GHF_HIDE);
Ghud_SetFlags(clent, hud[h_spectator_time_sep], GHF_HIDE);
Ghud_SetFlags(clent, hud[h_spectator_time_ts], GHF_HIDE);
Ghud_SetFlags(clent, hud[h_spectator_time_ss], GHF_HIDE);
}
// GHUD team icons and scores — anchored above their respective health bar columns.
// Left column: anchor(0,0), x=0..144. Right column: anchor(1,0), x=-144..0.
// Score numbers sit at y=28 (24px tall digits), 4px above the first nameplate at y=56.
// Icon (24x24) sits at x=4 (left) / x=-28 (right), score at x=30 / x=-66.
// Team 1 — left edge anchor
if (ctf->value) // CTF
hud[h_team_l] = Ghud_AddIcon(clent, 4, 28, level.pic_ctf_flagbase[TEAM1], 24, 24);
else if (esp->value) // Espionage
hud[h_team_l] = Ghud_AddIcon(clent, 4, 28, level.pic_esp_teamicon[TEAM1], 24, 24);
else if (matchmode->value) { // Matchmode: thin color bar across the full column
hud[h_team_l] = Ghud_NewElement(clent, GHT_FILL);
Ghud_SetPosition(clent, hud[h_team_l], 0, 24);
Ghud_SetSize(clent, hud[h_team_l], 144, 4);
Ghud_SetColor(clent, hud[h_team_l], red_team_red, red_team_green, red_team_blue, 255);
} else // Teamplay/Domination
hud[h_team_l] = Ghud_AddIcon(clent, 4, 28, level.pic_teamskin[TEAM1], 24, 24);
Ghud_SetAnchor(clent, hud[h_team_l], 0, 0);
// size[0] left at 0 (auto-numsize) so the renderer left-aligns from x=30.
hud[h_team_l_num] = Ghud_AddNumber(clent, 30, 28, ctf->value ? ctfgame.team1 : teams[TEAM1].score);
Ghud_SetAnchor(clent, hud[h_team_l_num], 0, 0);