-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathteamplay.c
3824 lines (3263 loc) · 105 KB
/
teamplay.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
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) 2000-2003 Anton Gavrilov, A Nourai
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.
$Id: teamplay.c,v 1.96 2007-10-23 08:51:02 himan Exp $
*/
#include <time.h>
#include <string.h>
#include <limits.h>
#include "quakedef.h"
#include "ignore.h"
#include "gl_model.h"
#include "gl_local.h"
#include "teamplay.h"
#include "rulesets.h"
#include "pmove.h"
#include "stats_grid.h"
#include "utils.h"
#include "qsound.h"
#include "tp_msgs.h"
void OnChangeSkinForcing(cvar_t *var, char *string, qbool *cancel);
void OnChangeColorForcing(cvar_t *var, char *string, qbool *cancel);
void OnChangeSkinAndColorForcing(cvar_t *var, char *string, qbool *cancel);
cvar_t cl_parseSay = {"cl_parseSay", "1"};
cvar_t cl_parseFunChars = {"cl_parseFunChars", "1"};
cvar_t cl_nofake = {"cl_nofake", "2"};
cvar_t tp_loadlocs = {"tp_loadlocs", "1"};
cvar_t tp_pointpriorities = {"tp_pointpriorities", "0"}; // FIXME: buggy
cvar_t tp_tooktimeout = {"tp_tooktimeout", "15"};
cvar_t tp_pointtimeout = {"tp_pointtimeout", "15"};
cvar_t cl_teamtopcolor = {"teamtopcolor", "-1", 0, OnChangeColorForcing};
cvar_t cl_teambottomcolor = {"teambottomcolor", "-1", 0, OnChangeColorForcing};
cvar_t cl_enemytopcolor = {"enemytopcolor", "-1", 0, OnChangeColorForcing};
cvar_t cl_enemybottomcolor = {"enemybottomcolor", "-1", 0, OnChangeColorForcing};
cvar_t cl_teamskin = {"teamskin", "", 0, OnChangeSkinForcing};
cvar_t cl_enemyskin = {"enemyskin", "", 0, OnChangeSkinForcing};
cvar_t cl_teamquadskin = {"teamquadskin", "", 0, OnChangeSkinForcing};
cvar_t cl_enemyquadskin = {"enemyquadskin", "", 0, OnChangeSkinForcing};
cvar_t cl_teampentskin = {"teampentskin", "", 0, OnChangeSkinForcing};
cvar_t cl_enemypentskin = {"enemypentskin", "", 0, OnChangeSkinForcing};
cvar_t cl_teambothskin = {"teambothskin", "", 0, OnChangeSkinForcing};
cvar_t cl_enemybothskin = {"enemybothskin", "", 0, OnChangeSkinForcing};
cvar_t cl_teamlock = {"teamlock", "0", 0, OnChangeSkinAndColorForcing};
cvar_t tp_name_axe = {"tp_name_axe", "axe"};
cvar_t tp_name_sg = {"tp_name_sg", "sg"};
cvar_t tp_name_ssg = {"tp_name_ssg", "ssg"};
cvar_t tp_name_ng = {"tp_name_ng", "ng"};
cvar_t tp_name_sng = {"tp_name_sng", "sng"};
cvar_t tp_name_gl = {"tp_name_gl", "gl"};
cvar_t tp_name_rl = {"tp_name_rl", "{&cf13rl&cfff}"};
cvar_t tp_name_lg = {"tp_name_lg", "{&c2aalg&cfff}"};
cvar_t tp_name_rlg = {"tp_name_rlg", "{&cf13rl&cfff}{&c2aag&cfff}"};
cvar_t tp_name_armortype_ra = {"tp_name_armortype_ra", "{&cf00r&cfff}"};
cvar_t tp_name_armortype_ya = {"tp_name_armortype_ya", "{&cff0y&cfff}"};
cvar_t tp_name_armortype_ga = {"tp_name_armortype_ga", "{&c0b0g&cfff}"};
cvar_t tp_name_ra = {"tp_name_ra", "{&cf00ra&cfff}"};
cvar_t tp_name_ya = {"tp_name_ya", "{&cff0ya&cfff}"};
cvar_t tp_name_ga = {"tp_name_ga", "{&c0b0ga&cfff}"};
cvar_t tp_name_quad = {"tp_name_quad", "{&c05fquad&cfff}"};
cvar_t tp_name_pent = {"tp_name_pent", "{&cf00pent&cfff}"};
cvar_t tp_name_ring = {"tp_name_ring", "{&cff0ring&cfff}"};
cvar_t tp_name_suit = {"tp_name_suit", "suit"};
cvar_t tp_name_shells = {"tp_name_shells", "shells"};
cvar_t tp_name_nails = {"tp_name_nails", "nails"};
cvar_t tp_name_rockets = {"tp_name_rockets", "rox"};
cvar_t tp_name_cells = {"tp_name_cells", "cells"};
cvar_t tp_name_mh = {"tp_name_mh", "{&c0a0mega&cfff}"};
cvar_t tp_name_health = {"tp_name_health", "health"};
cvar_t tp_name_armor = {"tp_name_armor", "armor"};
cvar_t tp_name_weapon = {"tp_name_weapon", "weapon"};
cvar_t tp_name_backpack = {"tp_name_backpack", "{&cf2apack&cfff}"};
cvar_t tp_name_flag = {"tp_name_flag", "flag"};
cvar_t tp_name_sentry = {"tp_name_sentry", "sentry gun"};
cvar_t tp_name_disp = {"tp_name_disp", "dispenser"};
cvar_t tp_name_filter = {"tp_name_filter", ""};
cvar_t tp_name_rune1 = {"tp_name_rune1", "{&c0f0resistance&cfff}"};
cvar_t tp_name_rune2 = {"tp_name_rune2", "{&cf00strength&cfff}"};
cvar_t tp_name_rune3 = {"tp_name_rune3", "{&cff0haste&cfff}"};
cvar_t tp_name_rune4 = {"tp_name_rune4", "{&c0ffregeneration&cfff}"};
cvar_t tp_name_teammate = {"tp_name_teammate", ""};
cvar_t tp_name_enemy = {"tp_name_enemy", "{&cf00enemy&cfff}"};
cvar_t tp_name_eyes = {"tp_name_eyes", "{&cff0eyes&cfff}"};
cvar_t tp_name_quaded = {"tp_name_quaded", "{&c05fquaded&cfff}"};
cvar_t tp_name_pented = {"tp_name_pented", "{&cf00pented&cfff}"};
cvar_t tp_name_nothing = {"tp_name_nothing", "nothing"};
cvar_t tp_name_someplace = {"tp_name_someplace", "someplace"};
cvar_t tp_name_at = {"tp_name_at", "at"};
cvar_t tp_name_none = {"tp_name_none", ""};
cvar_t tp_name_separator = {"tp_name_separator", "/"};
cvar_t tp_weapon_order = {"tp_weapon_order", "78654321"};
cvar_t tp_name_status_green = {"tp_name_status_green", "$G"};
cvar_t tp_name_status_yellow = {"tp_name_status_yellow", "$Y"};
cvar_t tp_name_status_red = {"tp_name_status_red", "$R"};
cvar_t tp_name_status_blue = {"tp_name_status_blue", "$B"};
cvar_t tp_name_status_white = {"tp_name_status_white", "$W"};
cvar_t tp_need_ra = {"tp_need_ra", "120"};
cvar_t tp_need_ya = {"tp_need_ya", "80"};
cvar_t tp_need_ga = {"tp_need_ga", "60"};
cvar_t tp_need_health = {"tp_need_health", "50"};
cvar_t tp_need_weapon = {"tp_need_weapon", "87"};
cvar_t tp_need_rl = {"tp_need_rl", "1"};
cvar_t tp_need_rockets = {"tp_need_rockets", "5"};
cvar_t tp_need_cells = {"tp_need_cells", "13"};
cvar_t tp_need_nails = {"tp_need_nails", "0"}; // not so important, so let's not have it spam msg need
cvar_t tp_need_shells = {"tp_need_shells", "0"}; // not so important, so let's not have it spam msg need
static qbool suppress;
char *skinforcing_team = "";
void TP_FindModelNumbers (void);
void TP_FindPoint (void);
static void CountNearbyPlayers(qbool dead);
char *Macro_LastTookOrPointed (void);
char *Macro_LastTookOrPointed2 (void);
void R_TranslatePlayerSkin (int playernum);
#define POINT_TYPE_ITEM 1
#define POINT_TYPE_POWERUP 2
#define POINT_TYPE_TEAMMATE 3
#define POINT_TYPE_ENEMY 4
#define TP_MACRO_ALIGNMENT_LEFT 0
#define TP_MACRO_ALIGNMENT_RIGHT 1
#define TP_MACRO_ALIGNMENT_CENTERED 2
tvars_t vars;
char lastip[64]; // FIXME: remove it
/*********************************** MACROS ***********************************/
#define MAX_MACRO_VALUE 256
static char macro_buf[MAX_MACRO_VALUE] = "";
char *Macro_Lastip_f (void)
{
snprintf (macro_buf, sizeof(macro_buf), "%s", lastip);
return macro_buf;
}
char *Macro_Quote_f (void)
{
return "\"";
}
char *Macro_Latency (void)
{
snprintf(macro_buf, sizeof(macro_buf), "%i", Q_rint(cls.latency * 1000));
return macro_buf;
}
char *Macro_Health (void)
{
snprintf(macro_buf, sizeof(macro_buf), "%i", cl.stats[STAT_HEALTH]);
return macro_buf;
}
char *Macro_Armor (void)
{
snprintf(macro_buf, sizeof(macro_buf), "%i", cl.stats[STAT_ARMOR]);
return macro_buf;
}
char *Macro_Shells (void)
{
snprintf(macro_buf, sizeof(macro_buf), "%i", cl.stats[STAT_SHELLS]);
return macro_buf;
}
char *Macro_Nails (void)
{
snprintf(macro_buf, sizeof(macro_buf), "%i", cl.stats[STAT_NAILS]);
return macro_buf;
}
char *Macro_Rockets (void)
{
snprintf(macro_buf, sizeof(macro_buf), "%i", cl.stats[STAT_ROCKETS]);
return macro_buf;
}
char *Macro_Cells (void)
{
snprintf(macro_buf, sizeof(macro_buf), "%i", cl.stats[STAT_CELLS]);
return macro_buf;
}
char *Macro_Ammo (void)
{
snprintf(macro_buf, sizeof(macro_buf), "%i", cl.stats[STAT_AMMO]);
return macro_buf;
}
char *Macro_Weapon (void)
{
return TP_ItemName(cl.stats[STAT_ACTIVEWEAPON]);
}
char *Macro_WeaponAndAmmo (void)
{
char buf[MAX_MACRO_VALUE];
snprintf (buf, sizeof(buf), "%s:%s", Macro_Weapon(), Macro_Ammo());
strlcpy (macro_buf, buf, sizeof(macro_buf));
return macro_buf;
}
char *Macro_WeaponNum (void)
{
extern cvar_t cl_weaponpreselect;
int IN_BestWeapon (void);
int best;
if (cl_weaponpreselect.integer && (best = IN_BestWeapon())) {
char buf[4];
snprintf(buf, sizeof(buf), "%d", best);
strlcpy(macro_buf, buf, sizeof(macro_buf));
return macro_buf;
}
else {
switch (cl.stats[STAT_ACTIVEWEAPON]) {
case IT_AXE: return "1";
case IT_SHOTGUN: return "2";
case IT_SUPER_SHOTGUN: return "3";
case IT_NAILGUN: return "4";
case IT_SUPER_NAILGUN: return "5";
case IT_GRENADE_LAUNCHER: return "6";
case IT_ROCKET_LAUNCHER: return "7";
case IT_LIGHTNING: return "8";
default:
return "0";
}
}
}
int BestWeapon (void)
{
return BestWeaponFromStatItems (cl.stats[STAT_ITEMS]);
}
int BestWeaponFromStatItems (int stat)
{
int i;
char *t[] = {tp_weapon_order.string, "78654321", NULL}, **s;
for (s = t; *s; s++) {
for (i = 0 ; i < strlen(*s) ; i++) {
switch ((*s)[i]) {
case '1': if (stat & IT_AXE) return IT_AXE; break;
case '2': if (stat & IT_SHOTGUN) return IT_SHOTGUN; break;
case '3': if (stat & IT_SUPER_SHOTGUN) return IT_SUPER_SHOTGUN; break;
case '4': if (stat & IT_NAILGUN) return IT_NAILGUN; break;
case '5': if (stat & IT_SUPER_NAILGUN) return IT_SUPER_NAILGUN; break;
case '6': if (stat & IT_GRENADE_LAUNCHER) return IT_GRENADE_LAUNCHER; break;
case '7': if (stat & IT_ROCKET_LAUNCHER) return IT_ROCKET_LAUNCHER; break;
case '8': if (stat & IT_LIGHTNING) return IT_LIGHTNING; break;
}
}
}
return 0;
}
char *Macro_BestWeapon (void)
{
return TP_ItemName(BestWeapon());
}
char *TP_ItemName(int item_flag)
{
switch (item_flag) {
case IT_SHOTGUN: return tp_name_sg.string;
case IT_SUPER_SHOTGUN: return tp_name_ssg.string;
case IT_NAILGUN: return tp_name_ng.string;
case IT_SUPER_NAILGUN: return tp_name_sng.string;
case IT_GRENADE_LAUNCHER: return tp_name_gl.string;
case IT_ROCKET_LAUNCHER: return tp_name_rl.string;
case IT_LIGHTNING: return tp_name_lg.string;
case IT_SUPER_LIGHTNING: return "slg";
case IT_SHELLS: return tp_name_shells.string;
case IT_NAILS: return tp_name_nails.string;
case IT_ROCKETS: return tp_name_rockets.string;
case IT_CELLS: return tp_name_cells.string;
case IT_AXE: return tp_name_axe.string;
case IT_ARMOR1: return tp_name_ga.string;
case IT_ARMOR2: return tp_name_ya.string;
case IT_ARMOR3: return tp_name_ra.string;
case IT_SUPERHEALTH: return tp_name_mh.string;
case IT_KEY1: return "key1";
case IT_KEY2: return "key2";
case IT_INVISIBILITY: return tp_name_ring.string;
case IT_INVULNERABILITY: return tp_name_pent.string;
case IT_SUIT: return tp_name_suit.string;
case IT_QUAD: return tp_name_quad.string;
case IT_SIGIL1: return tp_name_rune1.string;
case IT_SIGIL2: return tp_name_rune2.string;
case IT_SIGIL3: return tp_name_rune3.string;
case IT_SIGIL4: return tp_name_rune4.string;
default: return tp_name_none.string;
}
}
char *Macro_BestAmmo (void)
{
switch (BestWeapon()) {
case IT_SHOTGUN: case IT_SUPER_SHOTGUN:
snprintf(macro_buf, sizeof(macro_buf), "%i", cl.stats[STAT_SHELLS]);
return macro_buf;
case IT_NAILGUN: case IT_SUPER_NAILGUN:
snprintf(macro_buf, sizeof(macro_buf), "%i", cl.stats[STAT_NAILS]);
return macro_buf;
case IT_GRENADE_LAUNCHER: case IT_ROCKET_LAUNCHER:
snprintf(macro_buf, sizeof(macro_buf), "%i", cl.stats[STAT_ROCKETS]);
return macro_buf;
case IT_LIGHTNING:
snprintf(macro_buf, sizeof(macro_buf), "%i", cl.stats[STAT_CELLS]);
return macro_buf;
default: return "0";
}
}
// needed for %b parsing
char *Macro_BestWeaponAndAmmo (void)
{
char buf[MAX_MACRO_VALUE];
snprintf (buf, sizeof(buf), "%s:%s", Macro_BestWeapon(), Macro_BestAmmo());
strlcpy (macro_buf, buf, sizeof(buf));
return macro_buf;
}
char *Macro_Colored_Armor_f (void)
{
snprintf(macro_buf, sizeof(macro_buf), "%s", TP_MSG_Colored_Armor());
return macro_buf;
}
char *Macro_Colored_Powerups_f (void)
{
snprintf (macro_buf, sizeof(macro_buf), "%s", TP_MSG_Colored_Powerup());
return macro_buf;
}
char *Macro_Colored_Short_Powerups_f (void) // same as above, but displays "qrp" instead of "quad ring pent"
{
snprintf (macro_buf, sizeof(macro_buf), "%s", TP_MSG_Colored_Short_Powerups());
return macro_buf;
}
char *Macro_ArmorType (void)
{
if (cl.stats[STAT_ITEMS] & IT_ARMOR1)
return tp_name_armortype_ga.string;
else if (cl.stats[STAT_ITEMS] & IT_ARMOR2)
return tp_name_armortype_ya.string;
else if (cl.stats[STAT_ITEMS] & IT_ARMOR3)
return tp_name_armortype_ra.string;
else
return tp_name_none.string;
}
char *Macro_Powerups (void)
{
int effects;
macro_buf[0] = 0;
if (cl.stats[STAT_ITEMS] & IT_QUAD)
strlcpy(macro_buf, tp_name_quad.string, sizeof(macro_buf));
if (cl.stats[STAT_ITEMS] & IT_INVULNERABILITY) {
if (macro_buf[0])
strlcat(macro_buf, tp_name_separator.string, sizeof(macro_buf));
strlcat(macro_buf, tp_name_pent.string, sizeof(macro_buf));
}
if (cl.stats[STAT_ITEMS] & IT_INVISIBILITY) {
if (macro_buf[0])
strlcat(macro_buf, tp_name_separator.string, sizeof(macro_buf));
strlcat(macro_buf, tp_name_ring.string, sizeof(macro_buf));
}
effects = cl.frames[cl.parsecount & UPDATE_MASK].playerstate[cl.playernum].effects;
if ( (effects & (EF_FLAG1|EF_FLAG2)) /* CTF */ ||
(cl.teamfortress && cl.stats[STAT_ITEMS] & (IT_KEY1|IT_KEY2)) /* TF */ ) {
if (macro_buf[0])
strlcat(macro_buf, tp_name_separator.string, sizeof(macro_buf));
strlcat(macro_buf, tp_name_flag.string, sizeof(macro_buf));
}
if (!macro_buf[0])
strlcpy(macro_buf, tp_name_none.string, sizeof(macro_buf));
return macro_buf;
}
char *Macro_Location (void)
{
strlcpy(vars.lastreportedloc, TP_LocationName(cl.simorg), sizeof(vars.lastreportedloc));
return vars.lastreportedloc;
}
char *Macro_LastDeath (void)
{
return vars.deathtrigger_time ? vars.lastdeathloc : tp_name_someplace.string;
}
char *Macro_Last_Location (void)
{
if (vars.deathtrigger_time && cls.realtime - vars.deathtrigger_time <= 5)
strlcpy(vars.lastreportedloc, vars.lastdeathloc, sizeof(vars.lastreportedloc));
else
strlcpy(vars.lastreportedloc, TP_LocationName(cl.simorg), sizeof(vars.lastreportedloc));
return vars.lastreportedloc;
}
char *Macro_LastReportedLoc(void)
{
if (!vars.lastreportedloc[0])
return tp_name_someplace.string;
return vars.lastreportedloc;
}
char *Macro_Rune (void)
{
if (cl.stats[STAT_ITEMS] & IT_SIGIL1)
return tp_name_rune1.string;
else if (cl.stats[STAT_ITEMS] & IT_SIGIL2)
return tp_name_rune2.string;
else if (cl.stats[STAT_ITEMS] & IT_SIGIL3)
return tp_name_rune3.string;
else if (cl.stats[STAT_ITEMS] & IT_SIGIL4)
return tp_name_rune4.string;
else
return "";
}
char *Macro_Time (void)
{
time_t t;
struct tm *ptm;
time (&t);
if (!(ptm = localtime (&t)))
return "#bad date#";
strftime (macro_buf, sizeof(macro_buf) - 1, "%H:%M", ptm);
return macro_buf;
}
char *Macro_Date (void)
{
time_t t;
struct tm *ptm;
time (&t);
if (!(ptm = localtime (&t)))
return "#bad date#";
strftime (macro_buf, sizeof(macro_buf) - 1, "%d.%m.%y", ptm);
return macro_buf;
}
// returns the last item picked up
char *Macro_Took (void)
{
if (TOOK_EMPTY())
strlcpy (macro_buf, tp_name_nothing.string, sizeof(macro_buf));
else
strlcpy (macro_buf, vars.tookname, sizeof(macro_buf));
return macro_buf;
}
// returns location of the last item picked up
char *Macro_TookLoc (void)
{
if (TOOK_EMPTY())
strlcpy (macro_buf, tp_name_someplace.string, sizeof(macro_buf));
else
strlcpy (macro_buf, vars.tookloc, sizeof(macro_buf));
return macro_buf;
}
// %i macro - last item picked up in "name at location" style
char *Macro_TookAtLoc (void)
{
if (TOOK_EMPTY())
strlcpy (macro_buf, tp_name_nothing.string, sizeof(macro_buf));
else {
strlcpy (macro_buf, va("%s %s %s", vars.tookname, tp_name_at.string, vars.tookloc), sizeof(macro_buf));
}
return macro_buf;
}
// pointing calculations are CPU expensive, so the results are cached
// in vars.pointname & vars.pointloc
char *Macro_PointName (void)
{
if (flashed) // there should be more smart way to do it
return tp_name_nothing.string;
TP_FindPoint ();
return vars.pointname;
}
char *Macro_PointLocation (void)
{
if (flashed) // there should be more smart way to do it
return tp_name_nothing.string;
TP_FindPoint ();
return vars.pointloc[0] ? vars.pointloc : Macro_Location();
}
char *Macro_LastPointAtLoc (void)
{
if (!vars.pointtime || cls.realtime - vars.pointtime > tp_pointtimeout.value)
strlcpy (macro_buf, tp_name_nothing.string, sizeof(macro_buf));
else
snprintf (macro_buf, sizeof(macro_buf), "%s %s %s", vars.pointname, tp_name_at.string, vars.pointloc[0] ? vars.pointloc : Macro_Location());
return macro_buf;
}
char *Macro_PointNameAtLocation (void)
{
if (flashed) // there should be more smart way to do it
return tp_name_nothing.string;
TP_FindPoint();
return Macro_LastPointAtLoc();
}
char *Macro_Weapons (void)
{
macro_buf[0] = 0;
if (cl.stats[STAT_ITEMS] & IT_LIGHTNING)
strlcpy(macro_buf, tp_name_lg.string, sizeof(macro_buf));
if (cl.stats[STAT_ITEMS] & IT_ROCKET_LAUNCHER) {
if (macro_buf[0])
strlcat(macro_buf, tp_name_separator.string, sizeof(macro_buf));
strlcat(macro_buf, tp_name_rl.string, sizeof(macro_buf));
}
if (cl.stats[STAT_ITEMS] & IT_GRENADE_LAUNCHER) {
if (macro_buf[0])
strlcat(macro_buf, tp_name_separator.string, sizeof(macro_buf));
strlcat(macro_buf, tp_name_gl.string, sizeof(macro_buf));
}
if (cl.stats[STAT_ITEMS] & IT_SUPER_NAILGUN) {
if (macro_buf[0])
strlcat(macro_buf, tp_name_separator.string, sizeof(macro_buf));
strlcat(macro_buf, tp_name_sng.string, sizeof(macro_buf));
}
if (cl.stats[STAT_ITEMS] & IT_NAILGUN) {
if (macro_buf[0])
strlcat(macro_buf, tp_name_separator.string, sizeof(macro_buf));
strlcat(macro_buf, tp_name_ng.string, sizeof(macro_buf));
}
if (cl.stats[STAT_ITEMS] & IT_SUPER_SHOTGUN) {
if (macro_buf[0])
strlcat(macro_buf, tp_name_separator.string, sizeof(macro_buf));
strlcat(macro_buf, tp_name_ssg.string, sizeof(macro_buf));
}
if (cl.stats[STAT_ITEMS] & IT_SHOTGUN) {
if (macro_buf[0])
strlcat(macro_buf, tp_name_separator.string, sizeof(macro_buf));
strlcat(macro_buf, tp_name_sg.string, sizeof(macro_buf));
}
if (cl.stats[STAT_ITEMS] & IT_AXE) {
if (macro_buf[0])
strlcat(macro_buf, tp_name_separator.string, sizeof(macro_buf));
strlcat(macro_buf, tp_name_axe.string, sizeof(macro_buf));
}
if (!macro_buf[0])
strlcpy(macro_buf, tp_name_none.string, sizeof(macro_buf));
return macro_buf;
}
static char *Skin_To_TFSkin (char *myskin) // These four TF classes don't have their full names as the skin (i.e. they have tf_snipe instead of tf_sniper)
{
if (!cl.teamfortress || cl.spectator || strncasecmp(myskin, "tf_", 3)) {
strlcpy(macro_buf, myskin, sizeof(macro_buf));
} else {
if (!strcasecmp(myskin, "tf_demo"))
strlcpy(macro_buf, "demoman", sizeof(macro_buf));
else if (!strcasecmp(myskin, "tf_eng"))
strlcpy(macro_buf, "engineer", sizeof(macro_buf));
else if (!strcasecmp(myskin, "tf_snipe"))
strlcpy(macro_buf, "sniper", sizeof(macro_buf));
else if (!strcasecmp(myskin, "tf_sold"))
strlcpy(macro_buf, "soldier", sizeof(macro_buf));
else
strlcpy(macro_buf, myskin + 3, sizeof(macro_buf));
}
return macro_buf;
}
char *Macro_TF_Skin (void)
{
return Skin_To_TFSkin(Info_ValueForKey(cl.players[cl.playernum].userinfo, "skin"));
}
char *Macro_LastDrop (void)
{
if (vars.lastdrop_time)
return vars.lastdroploc;
else
return tp_name_someplace.string;
}
char *Macro_GameDir(void)
{
snprintf(macro_buf, sizeof (macro_buf), "%s", cls.gamedirfile);
return macro_buf;
}
char *Macro_LastTrigger_Match(void)
{
return vars.lasttrigger_match;
}
char *Macro_LastDropTime (void)
{
if (vars.lastdrop_time)
snprintf (macro_buf, sizeof (macro_buf), "%d", (int) (cls.realtime - vars.lastdrop_time));
else
snprintf (macro_buf, sizeof (macro_buf), "%d", -1);
return macro_buf;
}
// fixme: rewrite this function into two separate functions
// first will just set vars.needflags value (put into TP_GetNeed function below)
// second will read it's value and produce appropriate $need macro string
char *Macro_Need (void)
{
int i, weapon;
char *needammo = NULL;
macro_buf[0] = 0;
vars.needflags = 0;
// check armor
if (((cl.stats[STAT_ITEMS] & IT_ARMOR1) && cl.stats[STAT_ARMOR] < tp_need_ga.value)
|| ((cl.stats[STAT_ITEMS] & IT_ARMOR2) && cl.stats[STAT_ARMOR] < tp_need_ya.value)
|| ((cl.stats[STAT_ITEMS] & IT_ARMOR3) && cl.stats[STAT_ARMOR] < tp_need_ra.value)
|| (!(cl.stats[STAT_ITEMS] & (IT_ARMOR1|IT_ARMOR2|IT_ARMOR3))
&& (tp_need_ga.value || tp_need_ya.value || tp_need_ra.value))
)
{
strlcpy (macro_buf, tp_name_armor.string, sizeof(macro_buf));
vars.needflags |= it_armor;
}
// check health
if (tp_need_health.value && cl.stats[STAT_HEALTH] < tp_need_health.value) {
if (macro_buf[0])
strlcat (macro_buf, tp_name_separator.string, sizeof(macro_buf));
strlcat (macro_buf, tp_name_health.string, sizeof(macro_buf));
vars.needflags |= it_health;
}
if (cl.teamfortress) {
if (cl.stats[STAT_ROCKETS] < tp_need_rockets.value) {
if (macro_buf[0])
strlcat (macro_buf, tp_name_separator.string, sizeof(macro_buf));
strlcat (macro_buf, tp_name_rockets.string, sizeof(macro_buf));
vars.needflags |= it_rockets;
}
if (cl.stats[STAT_SHELLS] < tp_need_shells.value) {
if (macro_buf[0])
strlcat (macro_buf, tp_name_separator.string, sizeof(macro_buf));
strlcat (macro_buf, tp_name_shells.string, sizeof(macro_buf));
vars.needflags |= it_shells;
}
if (cl.stats[STAT_NAILS] < tp_need_nails.value) {
if (macro_buf[0])
strlcat (macro_buf, tp_name_separator.string, sizeof(macro_buf));
strlcat (macro_buf, tp_name_nails.string, sizeof(macro_buf));
vars.needflags |= it_shells;
}
if (cl.stats[STAT_CELLS] < tp_need_cells.value) {
if (macro_buf[0])
strlcat (macro_buf, tp_name_separator.string, sizeof(macro_buf));
strlcat (macro_buf, tp_name_cells.string, sizeof(macro_buf));
vars.needflags |= it_cells;
}
goto done;
}
// check weapon
weapon = 0;
for (i = strlen(tp_need_weapon.string) - 1 ; i >= 0 ; i--) {
switch (tp_need_weapon.string[i]) {
case '2': if (cl.stats[STAT_ITEMS] & IT_SHOTGUN) weapon = 2; break;
case '3': if (cl.stats[STAT_ITEMS] & IT_SUPER_SHOTGUN) weapon = 3; break;
case '4': if (cl.stats[STAT_ITEMS] & IT_NAILGUN) weapon = 4; break;
case '5': if (cl.stats[STAT_ITEMS] & IT_SUPER_NAILGUN) weapon = 5; break;
case '6': if (cl.stats[STAT_ITEMS] & IT_GRENADE_LAUNCHER) weapon = 6; break;
case '7': if (cl.stats[STAT_ITEMS] & IT_ROCKET_LAUNCHER) weapon = 7; break;
case '8': if (cl.stats[STAT_ITEMS] & IT_LIGHTNING) weapon = 8; break;
}
if (weapon)
break;
}
if (!weapon) {
if (macro_buf[0])
strlcat (macro_buf, tp_name_separator.string, sizeof(macro_buf));
strlcat (macro_buf, tp_name_weapon.string, sizeof(macro_buf));
vars.needflags |= it_weapons;
} else {
if (tp_need_rl.value && !(cl.stats[STAT_ITEMS] & IT_ROCKET_LAUNCHER)) {
if (macro_buf[0])
strlcat (macro_buf, tp_name_separator.string, sizeof(macro_buf));
strlcat (macro_buf, tp_name_rl.string, sizeof(macro_buf));
vars.needflags |= it_rl;
}
switch (weapon) {
case 2: case 3: if (cl.stats[STAT_SHELLS] < tp_need_shells.value) {
needammo = tp_name_shells.string;
vars.needflags |= it_shells;
}
break;
case 4: case 5: if (cl.stats[STAT_NAILS] < tp_need_nails.value) {
needammo = tp_name_nails.string;
vars.needflags |= it_nails;
}
break;
case 6: case 7: if (cl.stats[STAT_ROCKETS] < tp_need_rockets.value) {
needammo = tp_name_rockets .string;
vars.needflags |= it_rockets;
} break;
case 8: if (cl.stats[STAT_CELLS] < tp_need_cells.value) {
needammo = tp_name_cells.string;
vars.needflags |= it_cells;
} break;
}
if (needammo) {
if (macro_buf[0])
strlcat (macro_buf, tp_name_separator.string, sizeof(macro_buf));
strlcat (macro_buf, needammo, sizeof(macro_buf));
vars.needflags |= it_ammo;
}
}
done:
if (!macro_buf[0])
strlcpy (macro_buf, tp_name_nothing.string, sizeof(macro_buf));
return macro_buf;
}
void TP_GetNeed(void)
{
Macro_Need();
}
char *Macro_Point_LED(void)
{
TP_FindPoint();
if (vars.pointtype == POINT_TYPE_ENEMY)
return tp_name_status_red.string;
else if (vars.pointtype == POINT_TYPE_TEAMMATE)
return tp_name_status_green.string;
else if (vars.pointtype == POINT_TYPE_POWERUP)
return tp_name_status_yellow.string;
else // POINT_TYPE_ITEM
return tp_name_status_blue.string;
}
char *Macro_MyStatus_LED(void)
{
int count;
float save_need_rl;
char *s, *save_separator;
static char separator[] = {'/', '\0'};
save_need_rl = tp_need_rl.value;
save_separator = tp_name_separator.string;
tp_need_rl.value = 0;
tp_name_separator.string = separator;
s = Macro_Need();
tp_need_rl.value = save_need_rl;
tp_name_separator.string = save_separator;
if (!strcmp(s, tp_name_nothing.string)) {
count = 0;
} else {
for (count = 1; *s; s++)
if (*s == separator[0])
count++;
}
if (count == 0)
snprintf(macro_buf, sizeof(macro_buf), "%s", tp_name_status_green.string);
else if (count <= 1)
snprintf(macro_buf, sizeof(macro_buf), "%s", tp_name_status_yellow.string);
else
snprintf(macro_buf, sizeof(macro_buf), "%s", tp_name_status_red.string);
return macro_buf;
}
char *Macro_EnemyStatus_LED(void)
{
CountNearbyPlayers(false);
if (vars.numenemies == 0)
snprintf(macro_buf, sizeof(macro_buf), "\xffl%s\xff", tp_name_status_green.string);
else if (vars.numenemies <= vars.numfriendlies)
snprintf(macro_buf, sizeof(macro_buf), "\xffl%s\xff", tp_name_status_yellow.string);
else
snprintf(macro_buf, sizeof(macro_buf), "\xffl%s\xff", tp_name_status_red.string);
suppress = true;
return macro_buf;
}
#define TP_PENT 1
#define TP_QUAD 2
#define TP_RING 4
char *Macro_LastSeenPowerup(void)
{
if (!vars.enemy_powerups_time || cls.realtime - vars.enemy_powerups_time > 5) {
strlcpy(macro_buf, tp_name_quad.string, sizeof(macro_buf));
} else {
macro_buf[0] = 0;
if (vars.enemy_powerups & TP_QUAD)
strlcat(macro_buf, tp_name_quad.string, sizeof(macro_buf));
if (vars.enemy_powerups & TP_PENT) {
if (macro_buf[0])
strlcat(macro_buf, tp_name_separator.string, sizeof(macro_buf));
strlcat(macro_buf, tp_name_pent.string, sizeof(macro_buf));
}
if (vars.enemy_powerups & TP_RING) {
if (macro_buf[0])
strlcat(macro_buf, tp_name_separator.string, sizeof(macro_buf));
strlcat(macro_buf, tp_name_ring.string, sizeof(macro_buf));
}
}
return macro_buf;
}
qbool TP_SuppressMessage (wchar *buf)
{
size_t len;
wchar *s;
if ((len = qwcslen (buf)) < 4)
return false;
s = buf + len - 4;
if (s[0] == 0x7F && s[1] == '!' && s[3] == '\n') {
*s++ = '\n';
*s++ = 0;
return (!cls.demoplayback && !cl.spectator && *s - 'A' == cl.playernum);
}
return false;
}
// things like content '%e' macro get hidden in here causing you yourself cannot see
// how many enemies are around you, the number get replaced with a 'x' char
// and then printed on screen as a message
void TP_PrintHiddenMessage(char *buf, int nodisplay)
{
qbool team, hide = false;
char dest[4096], msg[4096], *s, *d, c, *name;
int length, offset, flags;
extern cvar_t con_sound_mm2_file, con_sound_mm2_volume, cl_fakename, cl_fakename_suffix;
if (!buf || !(length = strlen(buf)))
return;
team = !strcasecmp("say_team", Cmd_Argv(0));
if (length >= 2 && buf[0] == '\"' && buf[length - 1] == '\"') {
memmove(buf, buf + 1, length - 2);
buf[length - 2] = 0;
}
s = buf;
d = dest;
while ((c = *s++) && (c != '\x7f')) {
if (c == '\xff') {
if ((hide = !hide)) {
*d++ = (*s == 'z') ? 'x' : 139;
s++;
memmove(s - 2, s, strlen(s) + 1);
s -= 2;
} else {
memmove(s - 1, s, strlen(s) + 1);
s -= 1;
}
} else if (!hide) {
*d++ = c;
}
}
*d = 0;
if (cls.demoplayback)
return;
name = Info_ValueForKey (cl.players[cl.playernum].userinfo, "name");
if (strlen(name) >= 32)
name[31] = 0;
if (team)
{
if (cl_fakename.string[0])
{
char c_fn[1024], c_fna[1024];
strlcpy (c_fn, cl_fakename.string, sizeof(c_fn));
strlcpy (c_fna, cl_fakename_suffix.string, sizeof(c_fna));
snprintf(msg, sizeof(msg), "%s\n", TP_ParseFunChars(strcat(strcat(c_fn, c_fna), dest) , true));
}
else
{
snprintf(msg, sizeof(msg), "(%s): %s\n", name, TP_ParseFunChars(dest, true));
}
}
else
{
snprintf(msg, sizeof(msg), "%s: %s\n", name, TP_ParseFunChars(dest, true));
}
flags = TP_CategorizeMessage (msg, &offset);
if (flags == msgtype_team && !TP_FilterMessage(str2wcs(msg) + offset))
return;
if (con_sound_mm2_volume.value > 0 && nodisplay == 0) {
S_LocalSoundWithVol(con_sound_mm2_file.string, con_sound_mm2_volume.value);
}
if (cl_nofake.value == 1 || (cl_nofake.value == 2 && flags != msgtype_team)) {
for (s = msg; *s; s++)
if (*s == 0x0D || (*s == 0x0A && s[1]))
*s = ' ';
}
if (nodisplay == 0) {
Com_Printf(wcs2str(TP_ParseWhiteText (str2wcs(msg), team, offset)));
}
}
#define ISDEAD(i) ( (i) >= 41 && (i) <= 102 )
static void CountNearbyPlayers(qbool dead)
{
int i;
player_state_t *state;
player_info_t *info;
static int lastframecount = -1;
if (cls.framecount == lastframecount)
return;
lastframecount = cls.framecount;
vars.numenemies = vars.numfriendlies = 0;