-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathp_hud.cpp
1661 lines (1364 loc) · 50.3 KB
/
p_hud.cpp
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
// Copyright (c) ZeniMax Media Inc.
// Licensed under the GNU General Public License 2.0.
#include "g_local.h"
#include "g_statusbar.h"
/*
======================================================================
INTERMISSION
======================================================================
*/
void MultiplayerScoreboard(gentity_t *ent);
void MoveClientToIntermission(gentity_t *ent) {
// [Paril-KEX]
if (ent->client->ps.pmove.pm_type != PM_FREEZE)
ent->s.event = EV_OTHER_TELEPORT;
if (deathmatch->integer) {
ent->client->showscores = true;
ent->client->ps.stats[STAT_SHOW_STATUSBAR] = 0;
}
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.gunskin = 0;
ent->client->ps.damage_blend[3] = ent->client->ps.screen_blend[3] = 0;
ent->client->ps.rdflags = RDF_NONE;
// clean up powerup info
ent->client->pu_time_quad = 0_ms;
ent->client->pu_time_protection = 0_ms;
ent->client->pu_time_rebreather = 0_ms;
ent->client->pu_time_enviro = 0_ms;
ent->client->pu_time_invisibility = 0_ms;
ent->client->pu_time_regeneration = 0_ms;
ent->client->pu_time_duelfire = 0_ms;
ent->client->pu_time_double = 0_ms;
ent->client->grenade_blew_up = false;
ent->client->grenade_time = 0_ms;
ent->client->showhelp = false;
ent->client->showscores = false;
globals.server_flags &= ~SERVER_FLAG_SLOW_TIME;
ent->client->ir_time = 0_ms;
ent->client->nuke_time = 0_ms;
ent->client->tracker_pain_time = 0_ms;
ent->viewheight = 0;
ent->s.modelindex = 0;
ent->s.modelindex2 = 0;
ent->s.modelindex3 = 0;
ent->s.modelindex = 0;
ent->s.effects = EF_NONE;
ent->s.sound = 0;
ent->solid = SOLID_NOT;
ent->movetype = MOVETYPE_FREECAM;
gi.linkentity(ent);
// add the layout
if (deathmatch->integer) {
MultiplayerScoreboard(ent);
ent->client->showscores = true;
ent->client->ps.stats[STAT_SHOW_STATUSBAR] = 0;
}
}
// [Paril-KEX] update the level entry for end-of-unit screen
void G_UpdateLevelEntry() {
if (!level.entry)
return;
level.entry->found_secrets = level.found_secrets;
level.entry->total_secrets = level.total_secrets;
level.entry->killed_monsters = level.killed_monsters;
level.entry->total_monsters = level.total_monsters;
}
static inline void G_EndOfUnitEntry(std::stringstream &layout, const int &y, const level_entry_t &entry) {
layout << G_Fmt("yv {} ", y);
// we didn't visit this level, so print it as an unknown entry
if (!*entry.pretty_name) {
layout << "table_row 1 ??? ";
return;
}
layout << G_Fmt("table_row 4 \"{}\" ", entry.pretty_name) <<
G_Fmt("{}/{} ", entry.killed_monsters, entry.total_monsters) <<
G_Fmt("{}/{} ", entry.found_secrets, entry.total_secrets);
int32_t minutes = entry.time.milliseconds() / 60000;
int32_t seconds = (entry.time.milliseconds() / 1000) % 60;
int32_t milliseconds = entry.time.milliseconds() % 1000;
layout << G_Fmt("{:02}:{:02}:{:03} ", minutes, seconds, milliseconds);
}
void G_EndOfUnitMessage() {
// [Paril-KEX] update game level entry
G_UpdateLevelEntry();
std::stringstream layout;
// sort entries
std::sort(game.level_entries.begin(), game.level_entries.end(), [](const level_entry_t &a, const level_entry_t &b) {
int32_t a_order = a.visit_order ? a.visit_order : (*a.pretty_name ? (MAX_LEVELS_PER_UNIT + 1) : (MAX_LEVELS_PER_UNIT + 2));
int32_t b_order = b.visit_order ? b.visit_order : (*b.pretty_name ? (MAX_LEVELS_PER_UNIT + 1) : (MAX_LEVELS_PER_UNIT + 2));
return a_order < b_order;
});
layout << "start_table 4 $m_eou_level $m_eou_kills $m_eou_secrets $m_eou_time ";
int y = 16;
level_entry_t totals{};
int32_t num_rows = 0;
for (auto &entry : game.level_entries) {
if (!*entry.map_name)
break;
G_EndOfUnitEntry(layout, y, entry);
y += 8;
totals.found_secrets += entry.found_secrets;
totals.killed_monsters += entry.killed_monsters;
totals.time += entry.time;
totals.total_monsters += entry.total_monsters;
totals.total_secrets += entry.total_secrets;
if (entry.visit_order)
num_rows++;
}
y += 8;
// make this a space so it prints totals
if (num_rows > 1) {
layout << "table_row 0 "; // empty row to separate totals
totals.pretty_name[0] = ' ';
G_EndOfUnitEntry(layout, y, totals);
}
layout << "xv 160 yt 0 draw_table ";
layout << "ifgef " << (level.intermission_server_frame + (5_sec).frames()) << " yb -48 xv 0 loc_cstring2 0 \"$m_eou_press_button\" endif ";
gi.WriteByte(svc_layout);
gi.WriteString(layout.str().c_str());
gi.multicast(vec3_origin, MULTICAST_ALL, true);
for (auto player : active_clients())
player->client->showeou = true;
}
// data is binary now.
// u8 num_teams
// u8 num_players
// [ repeat num_teams:
// string team_name
// ]
// [ repeat num_players:
// u8 client_index
// s32 score
// u8 ranking
// (if num_teams > 0)
// u8 team
// ]
void G_ReportMatchDetails(bool is_end) {
static std::array<uint32_t, MAX_CLIENTS> player_ranks;
player_ranks = {};
bool teams = Teams();
// teamplay is simple
if (teams) {
Teams_CalcRankings(player_ranks);
gi.WriteByte(2);
gi.WriteString("HUMANS");
gi.WriteString("PREDATOR");
} else {
// sort players by score, then match everybody to
// the current highest score downwards until we run out of players.
static std::array<gentity_t *, MAX_CLIENTS> sorted_players;
size_t num_active_players = 0;
for (auto player : active_clients())
sorted_players[num_active_players++] = player;
std::sort(sorted_players.begin(), sorted_players.begin() + num_active_players, [](const gentity_t *a, const gentity_t *b) { return b->client->resp.score < a->client->resp.score; });
int32_t current_score = INT_MIN;
int32_t current_rank = 0;
for (size_t i = 0; i < num_active_players; i++) {
if (!current_rank || sorted_players[i]->client->resp.score != current_score) {
current_rank++;
current_score = sorted_players[i]->client->resp.score;
}
player_ranks[sorted_players[i]->s.number - 1] = current_rank;
}
gi.WriteByte(0);
}
uint8_t num_players = 0;
for (auto player : active_clients()) {
// leave spectators out of this data, they don't need to be seen.
if (player->client->pers.spawned && ClientIsPlaying(player->client)) {
// just in case...
if (teams && !ClientIsPlaying(player->client))
continue;
num_players++;
}
}
gi.WriteByte(num_players);
for (auto player : active_clients()) {
// leave spectators out of this data, they don't need to be seen.
if (player->client->pers.spawned && ClientIsPlaying(player->client)) {
// just in case...
if (teams && !ClientIsPlaying(player->client))
continue;
gi.WriteByte(player->s.number - 1);
gi.WriteLong(player->client->resp.score);
gi.WriteByte(player_ranks[player->s.number - 1]);
if (teams)
gi.WriteByte(player->client->sess.team == TEAM_SOLDIERS ? 0 : 1);
}
}
gi.ReportMatchDetails_Multicast(is_end);
}
/*
==================
TeamsScoreboardMessage
==================
*/
void TeamsScoreboardMessage(gentity_t *ent, gentity_t *killer) {
uint32_t i, j, k, n;
uint8_t sorted[2][MAX_CLIENTS];
int8_t sortedscores[2][MAX_CLIENTS];
int score;
uint8_t total[2];
uint8_t total_living[2];
int totalscore[2];
uint8_t last[2];
gclient_t *cl;
gentity_t *cl_ent;
int team;
int teamsize = floor(maxplayers->integer / 2);
// sort the clients by team and score
total[0] = total[1] = 0;
total_living[0] = total_living[1] = 0;
last[0] = last[1] = 0;
totalscore[0] = totalscore[1] = 0;
for (i = 0; i < game.maxclients; i++) {
cl_ent = g_entities + 1 + i;
if (!cl_ent->inuse)
continue;
if (game.clients[i].sess.team == TEAM_SOLDIERS)
team = 0;
else if (game.clients[i].sess.team == TEAM_PREDATOR)
team = 1;
else
continue; // unknown team?
score = game.clients[i].resp.score;
for (j = 0; j < total[team]; j++)
if (score > sortedscores[team][j])
break;
for (k = total[team]; k > j; k--) {
sorted[team][k] = sorted[team][k - 1];
sortedscores[team][k] = sortedscores[team][k - 1];
}
sorted[team][j] = i;
sortedscores[team][j] = score;
totalscore[team] += score;
total[team]++;
if (!game.clients[i].eliminated)
total_living[team]++;
}
// print level name and exit rules
// add the clients in sorted order
static std::string string;
string.clear();
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv -40 cstring2 \"{}\" "), level.level_name);
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv -30 cstring2 \"Score Limit: {}\" "), GT_ScoreLimit());
if (level.intermission_time) {
if (level.match_start_time) {
int t = (level.intermission_time - level.match_start_time - 1_sec).milliseconds();
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv -50 cstring2 \"Total Match Time: {}\" "), G_TimeStringMs(t, false));
}
if (level.intermission_victor_msg[0])
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv -10 cstring2 \"{}\" "), level.intermission_victor_msg);
fmt::format_to(std::back_inserter(string), FMT_STRING("ifgef {} yb -48 xv 0 loc_cstring2 0 \"$m_eou_press_button\" endif "), (level.intermission_server_frame + (5_sec).frames()));
} else if (level.match_state == MATCH_IN_PROGRESS) {
if (ent->client && ClientIsPlaying(ent->client) && ent->client->resp.score && level.num_playing_clients > 1) {
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv -10 cstring2 \"{} place with a score of {}\" "),
G_PlaceString(ent->client->resp.rank + 1), ent->client->resp.score);
}
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yb -48 cstring2 \"{}\" "), "Use inventory bind to toggle menu.");
}
fmt::format_to(std::back_inserter(string),
FMT_STRING("if 25 xv -32 yv 8 pic 25 endif "
"xv 0 yv 28 string \"{}/{}/{}\" "
"xv 58 yv 12 num 2 19 "
"xv -40 yv 42 string \"SC\" "
"xv -12 yv 42 picn ping "
"if 26 xv 208 yv 8 pic 26 endif "
"xv 240 yv 28 string \"{}/{}/{}\" "
"xv 296 yv 12 num 2 21 "
"xv 200 yv 42 string \"SC\" "
"xv 228 yv 42 picn ping "),
total_living[0], total[0], teamsize,
total_living[1], total[1], teamsize);
for (i = 0; i < 16; i++) {
if (i >= total[0] && i >= total[1])
break; // we're done
// red team on left
if (i < total[0]) {
cl = &game.clients[sorted[0][i]];
cl_ent = g_entities + 1 + sorted[0][i];
int ty = 52 + i * 8;
std::string_view entry = G_Fmt("ctf -40 {} {} {} {} \"\" ",
ty,
sorted[0][i],
cl->resp.score,
cl->ping > 999 ? 999 : cl->ping);
if (level.match_state == MATCH_WARMUP_READYUP && (cl->resp.ready || cl->sess.is_a_bot))
fmt::format_to(std::back_inserter(string),
FMT_STRING("xv -56 yv {} picn {} "), ty - 2, "wheel/p_compass_selected");
else if (level.match_state == MATCH_IN_PROGRESS && !cl->eliminated)
fmt::format_to(std::back_inserter(string),
FMT_STRING("xv -50 yv {} picn {} "), ty, "sbfctf1");
if (string.size() + entry.size() < MAX_STRING_CHARS) {
string += entry;
last[0] = i;
}
}
// blue team on right
if (i < total[1]) {
cl = &game.clients[sorted[1][i]];
cl_ent = g_entities + 1 + sorted[1][i];
int ty = 52 + i * 8;
std::string_view entry = G_Fmt("ctf 200 {} {} {} {} \"\" ",
ty,
sorted[1][i],
cl->resp.score,
cl->ping > 999 ? 999 : cl->ping);
if (level.match_state == MATCH_WARMUP_READYUP && (cl->resp.ready || cl->sess.is_a_bot))
fmt::format_to(std::back_inserter(string),
FMT_STRING("xv 182 yv {} picn {} "), ty - 2, "wheel/p_compass_selected");
else if (level.match_state == MATCH_IN_PROGRESS && !cl->eliminated)
fmt::format_to(std::back_inserter(string),
FMT_STRING("xv 190 yv {} picn {} "), ty, "sbfctf2");
if (string.size() + entry.size() < MAX_STRING_CHARS) {
string += entry;
last[1] = i;
}
}
}
// put in spectators if we have enough room
if (last[0] > last[1])
j = last[0];
else
j = last[1];
j = (j + 3) * 8 + 42;
k = n = 0;
if (string.size() < MAX_STRING_CHARS - 50) {
for (i = 0; i < game.maxclients; i++) {
cl_ent = g_entities + 1 + i;
cl = &game.clients[i];
if (!cl_ent->inuse ||
cl_ent->solid != SOLID_NOT ||
ClientIsPlaying(cl_ent->client))
continue;
if (!k) {
k = 1;
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv {} loc_string2 0 \"$g_pc_spectators\" "), j);
j += 8;
}
std::string_view entry = G_Fmt("ctf {} {} {} {} {} \"\" ",
(n & 1) ? 200 : -40, // x
j, // y
i, // playernum
cl->resp.score,
cl->ping > 999 ? 999 : cl->ping);
if (string.size() + entry.size() < MAX_STRING_CHARS)
string += entry;
if (n & 1)
j += 8;
n++;
}
}
if (total[0] - last[0] > 1) // couldn't fit everyone
fmt::format_to(std::back_inserter(string), FMT_STRING("xv -32 yv {} loc_string 1 $g_ctf_and_more {} "),
42 + (last[0] + 1) * 8, total[0] - last[0] - 1);
if (total[1] - last[1] > 1) // couldn't fit everyone
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 208 yv {} loc_string 1 $g_ctf_and_more {} "),
42 + (last[1] + 1) * 8, total[1] - last[1] - 1);
gi.WriteByte(svc_layout);
gi.WriteString(string.c_str());
}
/*
==================
DuelScoreboardMessage
==================
*/
static void DuelScoreboardMessage(gentity_t *ent, gentity_t *killer) {
uint8_t i, i2 = 0;
uint32_t j, k, n;
static std::string entry, string;
int x, y;
string.clear();
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv -40 cstring2 \"{}\" "), level.level_name);
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv -30 cstring2 \"Score Limit: {}\" "), GT_ScoreLimit());
if (level.intermission_time) {
if (level.match_start_time) {
int t = (level.intermission_time - level.match_start_time - 1_sec).milliseconds();
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv -50 cstring2 \"Total Match Time: {}\" "), G_TimeStringMs(t, false));
}
if (level.intermission_victor_msg[0])
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv -10 cstring2 \"{}\" "), level.intermission_victor_msg);
fmt::format_to(std::back_inserter(string), FMT_STRING("ifgef {} yb -48 xv 0 loc_cstring2 0 \"$m_eou_press_button\" endif "), (level.intermission_server_frame + (5_sec).frames()));
} else if (level.match_state == MATCH_IN_PROGRESS) {
if (ent->client && ClientIsPlaying(ent->client) && ent->client->resp.score && level.num_playing_clients > 1) {
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv -10 cstring2 \"{} place with a score of {}\" "),
G_PlaceString(ent->client->resp.rank + 1), ent->client->resp.score);
}
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yb -48 cstring2 \"{}\" "), "Use inventory bind to toggle menu.");
}
if (!level.num_playing_clients)
return;
gclient_t *cl;
gentity_t *cl_ent;
for (i = 0, i2 = 0; i < level.num_playing_clients, i2 < 2; i++) {
cl = &game.clients[level.sorted_clients[i]];
cl_ent = &g_entities[cl - game.clients];
if (!cl_ent)
continue;
if (!cl_ent->inuse)
continue;
if (!cl)
continue;
if (!ClientIsPlaying(cl))
continue;
x = i ? 130 : -72;
y = 0;
fmt::format_to(std::back_inserter(entry), FMT_STRING("xv {} yv {} picn {} "), x, y, "/tags/default");
const char *s = G_Fmt("/players/{}_i", cl->pers.skin).data();
int32_t img_index = cl->pers.skin_icon_index;
if (img_index)
fmt::format_to(std::back_inserter(entry), FMT_STRING("xv {} yv {} picn {} "), x, y, s);
// player ready marker
if (level.match_state == matchst_t::MATCH_WARMUP_READYUP && (cl->sess.is_a_bot || cl->resp.ready))
fmt::format_to(std::back_inserter(entry), FMT_STRING("xv {} yv {} picn {} "), x + 16, y + 16, "wheel/p_compass_selected");
if (string.length() + entry.length() > MAX_STRING_CHARS)
break;
string += entry;
entry.clear();
fmt::format_to(std::back_inserter(entry),
FMT_STRING("client {} {} {} {} {} {} "),
x, y, level.sorted_clients[i], cl->resp.score, cl->ping, (level.time - cl->resp.team_join_time).minutes<int>());
if (string.length() + entry.length() > MAX_STRING_CHARS)
break;
string += entry;
i2++;
entry.clear();
}
j = 58;
k = n = 0;
if (string.size() < MAX_STRING_CHARS - 50) {
for (i = 0; i < game.maxclients; i++) {
cl = &game.clients[level.sorted_clients[i]];
cl_ent = &g_entities[cl - game.clients + 1];
if (!cl_ent)
continue;
if (!cl_ent->inuse)
continue;
if (!cl)
continue;
if (ClientIsPlaying(cl))
continue;
if (!k) {
k = 1;
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv {} loc_string2 0 \"Queued Contenders:\" "), j);
j += 8;
fmt::format_to(std::back_inserter(string), FMT_STRING("xv -40 yv {} loc_string2 0 \"w l name\" "), j);
j += 8;
}
std::string_view entry = G_Fmt("ctf {} {} {} 0 0 \"\" ",
-40, // x
j, // y
level.sorted_clients[i] // playernum
);
if (string.size() + entry.size() < MAX_STRING_CHARS)
string += entry;
j += 8;
}
}
j += 8;
k = n = 0;
if (string.size() < MAX_STRING_CHARS - 50) {
for (i = 0; i < game.maxclients; i++) {
cl = &game.clients[level.sorted_clients[i]];
cl_ent = &g_entities[cl - game.clients + 1];
if (!cl_ent)
continue;
if (!cl_ent->inuse)
continue;
if (!cl)
continue;
if (ClientIsPlaying(cl))
continue;
if (!k) {
k = 1;
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv {} loc_string2 0 \"Spectators:\" "), j);
j += 8;
}
std::string_view entry = G_Fmt("ctf {} {} {} 0 0 \"\" ",
-40, // x
j, // y
level.sorted_clients[i] // playernum
);
if (string.size() + entry.size() < MAX_STRING_CHARS)
string += entry;
j += 8;
}
}
if (level.intermission_time)
fmt::format_to(std::back_inserter(string), FMT_STRING("ifgef {} yb -48 xv 0 loc_cstring2 0 \"$m_eou_press_button\" endif "), (level.intermission_server_frame + (5_sec).frames()));
else
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yb -48 cstring2 \"{}\" "), "Show inventory to toggle menu.");
gi.WriteByte(svc_layout);
gi.WriteString(string.c_str());
}
static inline void ScoreboardNotice(gentity_t *ent, std::string string) {
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv -40 cstring2 \"{}\" "), level.level_name);
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv -30 cstring2 \"Score Limit: {}\" "), GT_ScoreLimit());
if (level.intermission_time) {
if (level.match_start_time) {
int t = (level.intermission_time - level.match_start_time - 1_sec).milliseconds();
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv -50 cstring2 \"Total Match Time: {}\" "), G_TimeStringMs(t, false));
}
if (level.intermission_victor_msg[0])
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv -10 cstring2 \"{}\" "), level.intermission_victor_msg);
fmt::format_to(std::back_inserter(string), FMT_STRING("ifgef {} yb -48 xv 0 loc_cstring2 0 \"$m_eou_press_button\" endif "), (level.intermission_server_frame + (5_sec).frames()));
} else if (level.match_state == MATCH_IN_PROGRESS) {
if (ent->client && ClientIsPlaying(ent->client) && ent->client->resp.score && level.num_playing_clients > 1) {
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv -10 cstring2 \"{} place with a score of {}\" "),
G_PlaceString(ent->client->resp.rank + 1), ent->client->resp.score);
}
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yb -48 cstring2 \"{}\" "), "Use inventory bind to toggle menu.");
}
}
/*
==================
DeathmatchScoreboardMessage
==================
*/
void DeathmatchScoreboardMessage(gentity_t *ent, gentity_t *killer) {
if (Teams()) {
TeamsScoreboardMessage(ent, ent->enemy);
return;
}
uint8_t total = level.num_playing_clients;
if (total > 16)
total = 16;
static std::string entry, string;
int x, y;
gclient_t *cl;
gentity_t *cl_ent;
entry.clear();
string.clear();
for (size_t i = 0; i < total; i++) {
cl = &game.clients[level.sorted_clients[i]];
cl_ent = g_entities + 1 + level.sorted_clients[i];
if (!ClientIsPlaying(cl))
continue;
x = (i >= 8) ? 130 : -72;
y = 0 + 32 * (i % 8);
// selected player/killer tag
if (cl_ent == ent) {
const char *s = cl->sess.team == TEAM_SOLDIERS ? "/tags/ctf_red" : cl->sess.team == TEAM_PREDATOR ? "/tags/ctf_blue" : "/tags/default";
fmt::format_to(std::back_inserter(entry), FMT_STRING("xv {} yv {} picn {} "), x, y, s);
} else if (cl_ent == killer)
fmt::format_to(std::back_inserter(entry), FMT_STRING("xv {} yv {} picn {} "), x, y, "/tags/bloody");
// player skin icon
const char *s = G_Fmt("/players/{}_i", cl->pers.skin).data();
int32_t img_index = cl->pers.skin_icon_index;
if (img_index)
fmt::format_to(std::back_inserter(entry), FMT_STRING("xv {} yv {} picn {} "), x, y, s);
// player ready marker
if (level.match_state == matchst_t::MATCH_WARMUP_READYUP && (cl->sess.is_a_bot || cl->resp.ready)) {
fmt::format_to(std::back_inserter(entry), FMT_STRING("xv {} yv {} picn {} "), x + 16, y + 16, "wheel/p_compass_selected");
}
if (string.length() + entry.length() > MAX_STRING_CHARS)
break;
string += entry;
entry.clear();
fmt::format_to(std::back_inserter(entry),
FMT_STRING("client {} {} {} {} {} {} "),
x, y, level.sorted_clients[i], cl->resp.score, cl->ping, (int32_t)(level.time - cl->resp.entertime).minutes());
if (string.length() + entry.length() > MAX_STRING_CHARS)
break;
string += entry;
entry.clear();
}
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv -40 cstring2 \"{}\" "), level.level_name);
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv -30 cstring2 \"Score Limit: {}\" "), GT_ScoreLimit());
if (level.intermission_time) {
if (level.match_start_time) {
int t = (level.intermission_time - level.match_start_time - 1_sec).milliseconds();
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv -50 cstring2 \"Total Match Time: {}\" "), G_TimeStringMs(t, false));
}
if (level.intermission_victor_msg[0])
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv -10 cstring2 \"{}\" "), level.intermission_victor_msg);
fmt::format_to(std::back_inserter(string), FMT_STRING("ifgef {} yb -48 xv 0 loc_cstring2 0 \"$m_eou_press_button\" endif "), (level.intermission_server_frame + (5_sec).frames()));
} else if (level.match_state == MATCH_IN_PROGRESS) {
if (ent->client && ClientIsPlaying(ent->client) && ent->client->resp.score && level.num_playing_clients > 1) {
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yv -10 cstring2 \"{} place with a score of {}\" "),
G_PlaceString(ent->client->resp.rank + 1), ent->client->resp.score);
}
fmt::format_to(std::back_inserter(string), FMT_STRING("xv 0 yb -48 cstring2 \"{}\" "), "Use inventory bind to toggle menu.");
}
gi.WriteByte(svc_layout);
gi.WriteString(string.c_str());
}
/*
==================
MultiplayerScoreboard
Draw instead of help message.
Note that it isn't that hard to overflow the 1400 byte message limit!
==================
*/
void MultiplayerScoreboard(gentity_t *ent) {
gentity_t *e = ent->client->follow_target ? ent->client->follow_target : ent;
DeathmatchScoreboardMessage(e, e->enemy);
gi.unicast(ent, true);
ent->client->menutime = level.time + 3_sec;
}
/*
==================
Cmd_Score_f
Display the scoreboard
==================
*/
void Cmd_Score_f(gentity_t *ent) {
if (level.intermission_time)
return;
if (Vote_Menu_Active(ent)) {
ent->client->showinventory = false;
ent->client->showhelp = false;
gentity_t *e = ent->client->follow_target ? ent->client->follow_target : ent;
ent->client->ps.stats[STAT_SHOW_STATUSBAR] = !ClientIsPlaying(e->client) ? 0 : 1;
return;
}
ent->client->showinventory = false;
ent->client->showhelp = false;
globals.server_flags &= ~SERVER_FLAG_SLOW_TIME;
if (ent->client->menu)
P_Menu_Close(ent);
if (!deathmatch->integer && !coop->integer)
return;
if (ent->client->showscores) {
ent->client->showscores = false;
ent->client->follow_update = true;
gentity_t *e = ent->client->follow_target ? ent->client->follow_target : ent;
ent->client->ps.stats[STAT_SHOW_STATUSBAR] = !ClientIsPlaying(e->client) ? 0 : 1;
return;
}
ent->client->ps.stats[STAT_SHOW_STATUSBAR] = 0;
//globals.server_flags |= SERVER_FLAG_SLOW_TIME;
ent->client->showscores = true;
MultiplayerScoreboard(ent);
}
/*
==================
DrawHelpComputer
Draw help computer.
==================
*/
static void DrawHelpComputer(gentity_t *ent) {
const char *sk;
switch (skill->integer) {
case 0:
sk = "$m_easy";
break;
case 1:
sk = "$m_medium";
break;
case 2:
sk = "$m_hard";
break;
case 3:
sk = "$m_nightmare";
break;
default:
sk = "nightmare+";
break;
}
// send the layout
std::string helpString = "";
helpString += G_Fmt(
"xv 32 yv 8 picn help " // background
"xv 0 yv 25 cstring2 \"{}\" ", // level name
level.level_name);
if (level.is_n64) {
helpString += G_Fmt("xv 0 yv 54 loc_cstring 1 \"{{}}\" \"{}\" ", // help 1
game.helpmessage1);
} else {
int y = 54;
if (strlen(game.helpmessage1)) {
helpString += G_Fmt("xv 0 yv {} loc_cstring2 0 \"$g_pc_primary_objective\" " // title
"xv 0 yv {} loc_cstring 0 \"{}\" ",
y,
y + 11,
game.helpmessage1);
y += 58;
}
if (strlen(game.helpmessage2)) {
helpString += G_Fmt("xv 0 yv {} loc_cstring2 0 \"$g_pc_secondary_objective\" " // title
"xv 0 yv {} loc_cstring 0 \"{}\" ",
y,
y + 11,
game.helpmessage2);
}
}
helpString += G_Fmt("xv 55 yv 164 loc_string2 0 \"{}\" "
"xv 265 yv 164 loc_rstring2 1 \"{{}}: {}/{}\" \"$g_pc_goals\" "
"xv 55 yv 172 loc_string2 1 \"{{}}: {}/{}\" \"$g_pc_kills\" "
"xv 265 yv 172 loc_rstring2 1 \"{{}}: {}/{}\" \"$g_pc_secrets\" ",
sk,
level.found_goals, level.total_goals,
level.killed_monsters, level.total_monsters,
level.found_secrets, level.total_secrets);
gi.WriteByte(svc_layout);
gi.WriteString(helpString.c_str());
gi.unicast(ent, true);
}
/*
==================
Cmd_Help_f
Display the current help message
==================
*/
void Cmd_Help_f(gentity_t *ent) {
// this is for backwards compatability
if (deathmatch->integer) {
Cmd_Score_f(ent);
return;
}
if (level.intermission_time)
return;
ent->client->showinventory = false;
ent->client->showscores = false;
if (ent->client->showhelp &&
(ent->client->pers.game_help1changed == game.help1changed ||
ent->client->pers.game_help2changed == game.help2changed)) {
ent->client->showhelp = false;
globals.server_flags &= ~SERVER_FLAG_SLOW_TIME;
return;
}
ent->client->showhelp = true;
ent->client->pers.helpchanged = 0;
globals.server_flags |= SERVER_FLAG_SLOW_TIME;
DrawHelpComputer(ent);
}
//=======================================================================
// [Paril-KEX] for stats we want to always be set in coop
// even if we're spectating
void G_SetCoopStats(gentity_t *ent) {
if (InCoopStyle() && g_coop_enable_lives->integer)
ent->client->ps.stats[STAT_LIVES] = ent->client->pers.lives + 1;
else
ent->client->ps.stats[STAT_LIVES] = 0;
if (level.match_state == MATCH_IN_PROGRESS) {
ent->client->ps.stats[STAT_MONSTER_COUNT] = 0;
ent->client->ps.stats[STAT_ROUND_NUMBER] = level.round_number;
}
// stat for text on what we're doing for respawn
if (ent->client->coop_respawn_state)
ent->client->ps.stats[STAT_COOP_RESPAWN] = CONFIG_COOP_RESPAWN_STRING + (ent->client->coop_respawn_state - COOP_RESPAWN_IN_COMBAT);
else
ent->client->ps.stats[STAT_COOP_RESPAWN] = 0;
}
struct powerup_info_t {
item_id_t item;
gtime_t gclient_t:: *time_ptr = nullptr;
int32_t gclient_t:: *count_ptr = nullptr;
} powerup_table[] = {
{ IT_POWERUP_QUAD, &gclient_t::pu_time_quad },
{ IT_POWERUP_DUELFIRE, &gclient_t::pu_time_duelfire },
{ IT_POWERUP_DOUBLE, &gclient_t::pu_time_double },
{ IT_POWERUP_PROTECTION, &gclient_t::pu_time_protection },
{ IT_POWERUP_INVISIBILITY, &gclient_t::pu_time_invisibility },
{ IT_POWERUP_REGEN, &gclient_t::pu_time_regeneration },
{ IT_POWERUP_ENVIROSUIT, &gclient_t::pu_time_enviro },
{ IT_POWERUP_REBREATHER, &gclient_t::pu_time_rebreather },
{ IT_IR_GOGGLES, &gclient_t::ir_time },
{ IT_POWERUP_SILENCER, nullptr, &gclient_t::silencer_shots }
};
static void SetCrosshairIDView(gentity_t *ent) {
vec3_t forward, dir;
trace_t tr;
gentity_t *who, *best;
float bd = 0, d;
// only check every few frames
if (level.time - ent->client->resp.lastidtime < 250_ms)
return;
ent->client->resp.lastidtime = level.time;
ent->client->ps.stats[STAT_CROSSHAIR_ID_VIEW] = 0;
ent->client->ps.stats[STAT_CROSSHAIR_ID_VIEW_COLOR] = 0;
if (!g_dm_crosshair_id->integer)
return;
AngleVectors(ent->client->v_angle, forward, nullptr, nullptr);
forward *= 1024;
forward = ent->s.origin + forward;
tr = gi.traceline(ent->s.origin, forward, ent, CONTENTS_MIST | MASK_WATER | MASK_SOLID);
//gi.Draw_Line(ent->s.origin, tr.endpos, rgba_red, 5, false);
if (tr.fraction < 1 && tr.ent && tr.ent->client && tr.ent->health > 0) {
// don't show if traced client is spectating
if (!ClientIsPlaying(tr.ent->client))
return;
if (tr.ent->client->eliminated)
return;
// don't show if traced client is currently invisibile
if (ClientIsPredator(tr.ent->client) || tr.ent->client->pu_time_invisibility > level.time)
return;
ent->client->ps.stats[STAT_CROSSHAIR_ID_VIEW] = (tr.ent - g_entities);
if (tr.ent->client->sess.team == TEAM_SOLDIERS)
ent->client->ps.stats[STAT_CROSSHAIR_ID_VIEW_COLOR] = ii_teams_red_tiny;
else if (tr.ent->client->sess.team == TEAM_PREDATOR)
ent->client->ps.stats[STAT_CROSSHAIR_ID_VIEW_COLOR] = ii_teams_blue_tiny;
return;
}