forked from id-Software/Quake-III-Arena
/
cg_newdraw.c
1835 lines (1581 loc) · 48.6 KB
/
cg_newdraw.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) 1999-2005 Id Software, Inc.
This file is part of Quake III Arena source code.
Quake III Arena source code 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.
Quake III Arena source code 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 Quake III Arena source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
#ifndef MISSIONPACK
#error This file not be used for classic Q3A.
#endif
#include "cg_local.h"
#include "../ui/ui_shared.h"
extern displayContextDef_t cgDC;
// set in CG_ParseTeamInfo
//static int sortedTeamPlayers[TEAM_MAXOVERLAY];
//static int numSortedTeamPlayers;
int drawTeamOverlayModificationCount = -1;
//static char systemChat[256];
//static char teamChat1[256];
//static char teamChat2[256];
void CG_InitTeamChat(void) {
memset(teamChat1, 0, sizeof(teamChat1));
memset(teamChat2, 0, sizeof(teamChat2));
memset(systemChat, 0, sizeof(systemChat));
}
void CG_SetPrintString(int type, const char *p) {
if (type == SYSTEM_PRINT) {
strcpy(systemChat, p);
} else {
strcpy(teamChat2, teamChat1);
strcpy(teamChat1, p);
}
}
void CG_CheckOrderPending(void) {
if (cgs.gametype < GT_CTF) {
return;
}
if (cgs.orderPending) {
//clientInfo_t *ci = cgs.clientinfo + sortedTeamPlayers[cg_currentSelectedPlayer.integer];
const char *p1, *p2, *b;
p1 = p2 = b = NULL;
switch (cgs.currentOrder) {
case TEAMTASK_OFFENSE:
p1 = VOICECHAT_ONOFFENSE;
p2 = VOICECHAT_OFFENSE;
b = "+button7; wait; -button7";
break;
case TEAMTASK_DEFENSE:
p1 = VOICECHAT_ONDEFENSE;
p2 = VOICECHAT_DEFEND;
b = "+button8; wait; -button8";
break;
case TEAMTASK_PATROL:
p1 = VOICECHAT_ONPATROL;
p2 = VOICECHAT_PATROL;
b = "+button9; wait; -button9";
break;
case TEAMTASK_FOLLOW:
p1 = VOICECHAT_ONFOLLOW;
p2 = VOICECHAT_FOLLOWME;
b = "+button10; wait; -button10";
break;
case TEAMTASK_CAMP:
p1 = VOICECHAT_ONCAMPING;
p2 = VOICECHAT_CAMP;
break;
case TEAMTASK_RETRIEVE:
p1 = VOICECHAT_ONGETFLAG;
p2 = VOICECHAT_RETURNFLAG;
break;
case TEAMTASK_ESCORT:
p1 = VOICECHAT_ONFOLLOWCARRIER;
p2 = VOICECHAT_FOLLOWFLAGCARRIER;
break;
}
if (cg_currentSelectedPlayer.integer == numSortedTeamPlayers) {
// to everyone
trap_SendConsoleCommand(va("cmd vsay_team %s\n", p2));
} else {
// for the player self
if (sortedTeamPlayers[cg_currentSelectedPlayer.integer] == cg.snap->ps.clientNum && p1) {
trap_SendConsoleCommand(va("teamtask %i\n", cgs.currentOrder));
//trap_SendConsoleCommand(va("cmd say_team %s\n", p2));
trap_SendConsoleCommand(va("cmd vsay_team %s\n", p1));
} else if (p2) {
//trap_SendConsoleCommand(va("cmd say_team %s, %s\n", ci->name,p));
trap_SendConsoleCommand(va("cmd vtell %d %s\n", sortedTeamPlayers[cg_currentSelectedPlayer.integer], p2));
}
}
if (b) {
trap_SendConsoleCommand(b);
}
cgs.orderPending = qfalse;
}
}
static void CG_SetSelectedPlayerName( void ) {
if (cg_currentSelectedPlayer.integer >= 0 && cg_currentSelectedPlayer.integer < numSortedTeamPlayers) {
clientInfo_t *ci = cgs.clientinfo + sortedTeamPlayers[cg_currentSelectedPlayer.integer];
if (ci) {
trap_Cvar_Set("cg_selectedPlayerName", ci->name);
trap_Cvar_Set("cg_selectedPlayer", va("%d", sortedTeamPlayers[cg_currentSelectedPlayer.integer]));
cgs.currentOrder = ci->teamTask;
}
} else {
trap_Cvar_Set("cg_selectedPlayerName", "Everyone");
}
}
int CG_GetSelectedPlayer( void ) {
if (cg_currentSelectedPlayer.integer < 0 || cg_currentSelectedPlayer.integer >= numSortedTeamPlayers) {
cg_currentSelectedPlayer.integer = 0;
}
return cg_currentSelectedPlayer.integer;
}
void CG_SelectNextPlayer( void ) {
CG_CheckOrderPending();
if (cg_currentSelectedPlayer.integer >= 0 && cg_currentSelectedPlayer.integer < numSortedTeamPlayers) {
cg_currentSelectedPlayer.integer++;
} else {
cg_currentSelectedPlayer.integer = 0;
}
CG_SetSelectedPlayerName();
}
void CG_SelectPrevPlayer( void ) {
CG_CheckOrderPending();
if (cg_currentSelectedPlayer.integer > 0 && cg_currentSelectedPlayer.integer <= numSortedTeamPlayers) {
cg_currentSelectedPlayer.integer--;
} else {
cg_currentSelectedPlayer.integer = numSortedTeamPlayers;
}
CG_SetSelectedPlayerName();
}
static void CG_DrawPlayerArmorIcon( rectDef_t *rect, qboolean draw2D ) {
vec3_t angles;
vec3_t origin;
if ( cg_drawStatus.integer == 0 ) {
return;
}
if ( draw2D || ( !cg_draw3dIcons.integer && cg_drawIcons.integer) ) {
CG_DrawPic( rect->x, rect->y + rect->h/2 + 1, rect->w, rect->h, cgs.media.armorIcon );
} else if (cg_draw3dIcons.integer) {
VectorClear( angles );
origin[0] = 90;
origin[1] = 0;
origin[2] = -10;
angles[YAW] = ( cg.time & 2047 ) * 360 / 2048.0f;
CG_Draw3DModel( rect->x, rect->y, rect->w, rect->h, cgs.media.armorModel, 0, origin, angles );
}
}
static void CG_DrawPlayerArmorValue(rectDef_t *rect, float scale, vec4_t color, qhandle_t shader, int textStyle) {
char num[16];
int value;
playerState_t *ps;
ps = &cg.snap->ps;
value = ps->stats[STAT_ARMOR];
if (shader) {
trap_R_SetColor( color );
CG_DrawPic(rect->x, rect->y, rect->w, rect->h, shader);
trap_R_SetColor( NULL );
} else {
Com_sprintf (num, sizeof(num), "%i", value);
value = CG_Text_Width(num, scale, 0);
CG_Text_Paint(rect->x + (rect->w - value) / 2, rect->y + rect->h, scale, color, num, 0, 0, textStyle);
}
}
static void CG_DrawPlayerAmmoIcon( rectDef_t *rect, qboolean draw2D ) {
centity_t *cent;
vec3_t angles;
vec3_t origin;
cent = &cg_entities[cg.snap->ps.clientNum];
if ( draw2D || (!cg_draw3dIcons.integer && cg_drawIcons.integer) ) {
qhandle_t icon;
icon = cg_weapons[ cg.predictedPlayerState.weapon ].ammoIcon;
if ( icon ) {
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, icon );
}
} else if (cg_draw3dIcons.integer) {
if ( cent->currentState.weapon && cg_weapons[ cent->currentState.weapon ].ammoModel ) {
VectorClear( angles );
origin[0] = 70;
origin[1] = 0;
origin[2] = 0;
angles[YAW] = 90 + 20 * sin( cg.time / 1000.0 );
CG_Draw3DModel( rect->x, rect->y, rect->w, rect->h, cg_weapons[ cent->currentState.weapon ].ammoModel, 0, origin, angles );
}
}
}
static void CG_DrawPlayerAmmoValue(rectDef_t *rect, float scale, vec4_t color, qhandle_t shader, int textStyle) {
char num[16];
int value;
centity_t *cent;
playerState_t *ps;
cent = &cg_entities[cg.snap->ps.clientNum];
ps = &cg.snap->ps;
if ( cent->currentState.weapon ) {
value = ps->ammo[cent->currentState.weapon];
if ( value > -1 ) {
if (shader) {
trap_R_SetColor( color );
CG_DrawPic(rect->x, rect->y, rect->w, rect->h, shader);
trap_R_SetColor( NULL );
} else {
Com_sprintf (num, sizeof(num), "%i", value);
value = CG_Text_Width(num, scale, 0);
CG_Text_Paint(rect->x + (rect->w - value) / 2, rect->y + rect->h, scale, color, num, 0, 0, textStyle);
}
}
}
}
static void CG_DrawPlayerHead(rectDef_t *rect, qboolean draw2D) {
vec3_t angles;
float size, stretch;
float frac;
float x = rect->x;
VectorClear( angles );
if ( cg.damageTime && cg.time - cg.damageTime < DAMAGE_TIME ) {
frac = (float)(cg.time - cg.damageTime ) / DAMAGE_TIME;
size = rect->w * 1.25 * ( 1.5 - frac * 0.5 );
stretch = size - rect->w * 1.25;
// kick in the direction of damage
x -= stretch * 0.5 + cg.damageX * stretch * 0.5;
cg.headStartYaw = 180 + cg.damageX * 45;
cg.headEndYaw = 180 + 20 * cos( crandom()*M_PI );
cg.headEndPitch = 5 * cos( crandom()*M_PI );
cg.headStartTime = cg.time;
cg.headEndTime = cg.time + 100 + random() * 2000;
} else {
if ( cg.time >= cg.headEndTime ) {
// select a new head angle
cg.headStartYaw = cg.headEndYaw;
cg.headStartPitch = cg.headEndPitch;
cg.headStartTime = cg.headEndTime;
cg.headEndTime = cg.time + 100 + random() * 2000;
cg.headEndYaw = 180 + 20 * cos( crandom()*M_PI );
cg.headEndPitch = 5 * cos( crandom()*M_PI );
}
}
// if the server was frozen for a while we may have a bad head start time
if ( cg.headStartTime > cg.time ) {
cg.headStartTime = cg.time;
}
frac = ( cg.time - cg.headStartTime ) / (float)( cg.headEndTime - cg.headStartTime );
frac = frac * frac * ( 3 - 2 * frac );
angles[YAW] = cg.headStartYaw + ( cg.headEndYaw - cg.headStartYaw ) * frac;
angles[PITCH] = cg.headStartPitch + ( cg.headEndPitch - cg.headStartPitch ) * frac;
CG_DrawHead( x, rect->y, rect->w, rect->h, cg.snap->ps.clientNum, angles );
}
static void CG_DrawSelectedPlayerHealth( rectDef_t *rect, float scale, vec4_t color, qhandle_t shader, int textStyle ) {
clientInfo_t *ci;
int value;
char num[16];
ci = cgs.clientinfo + sortedTeamPlayers[CG_GetSelectedPlayer()];
if (ci) {
if (shader) {
trap_R_SetColor( color );
CG_DrawPic(rect->x, rect->y, rect->w, rect->h, shader);
trap_R_SetColor( NULL );
} else {
Com_sprintf (num, sizeof(num), "%i", ci->health);
value = CG_Text_Width(num, scale, 0);
CG_Text_Paint(rect->x + (rect->w - value) / 2, rect->y + rect->h, scale, color, num, 0, 0, textStyle);
}
}
}
static void CG_DrawSelectedPlayerArmor( rectDef_t *rect, float scale, vec4_t color, qhandle_t shader, int textStyle ) {
clientInfo_t *ci;
int value;
char num[16];
ci = cgs.clientinfo + sortedTeamPlayers[CG_GetSelectedPlayer()];
if (ci) {
if (ci->armor > 0) {
if (shader) {
trap_R_SetColor( color );
CG_DrawPic(rect->x, rect->y, rect->w, rect->h, shader);
trap_R_SetColor( NULL );
} else {
Com_sprintf (num, sizeof(num), "%i", ci->armor);
value = CG_Text_Width(num, scale, 0);
CG_Text_Paint(rect->x + (rect->w - value) / 2, rect->y + rect->h, scale, color, num, 0, 0, textStyle);
}
}
}
}
qhandle_t CG_StatusHandle(int task) {
qhandle_t h;
switch (task) {
case TEAMTASK_OFFENSE :
h = cgs.media.assaultShader;
break;
case TEAMTASK_DEFENSE :
h = cgs.media.defendShader;
break;
case TEAMTASK_PATROL :
h = cgs.media.patrolShader;
break;
case TEAMTASK_FOLLOW :
h = cgs.media.followShader;
break;
case TEAMTASK_CAMP :
h = cgs.media.campShader;
break;
case TEAMTASK_RETRIEVE :
h = cgs.media.retrieveShader;
break;
case TEAMTASK_ESCORT :
h = cgs.media.escortShader;
break;
default :
h = cgs.media.assaultShader;
break;
}
return h;
}
static void CG_DrawSelectedPlayerStatus( rectDef_t *rect ) {
clientInfo_t *ci = cgs.clientinfo + sortedTeamPlayers[CG_GetSelectedPlayer()];
if (ci) {
qhandle_t h;
if (cgs.orderPending) {
// blink the icon
if ( cg.time > cgs.orderTime - 2500 && (cg.time >> 9 ) & 1 ) {
return;
}
h = CG_StatusHandle(cgs.currentOrder);
} else {
h = CG_StatusHandle(ci->teamTask);
}
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, h );
}
}
static void CG_DrawPlayerStatus( rectDef_t *rect ) {
clientInfo_t *ci = &cgs.clientinfo[cg.snap->ps.clientNum];
if (ci) {
qhandle_t h = CG_StatusHandle(ci->teamTask);
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, h);
}
}
static void CG_DrawSelectedPlayerName( rectDef_t *rect, float scale, vec4_t color, qboolean voice, int textStyle) {
clientInfo_t *ci;
ci = cgs.clientinfo + ((voice) ? cgs.currentVoiceClient : sortedTeamPlayers[CG_GetSelectedPlayer()]);
if (ci) {
CG_Text_Paint(rect->x, rect->y + rect->h, scale, color, ci->name, 0, 0, textStyle);
}
}
static void CG_DrawSelectedPlayerLocation( rectDef_t *rect, float scale, vec4_t color, int textStyle ) {
clientInfo_t *ci;
ci = cgs.clientinfo + sortedTeamPlayers[CG_GetSelectedPlayer()];
if (ci) {
const char *p = CG_ConfigString(CS_LOCATIONS + ci->location);
if (!p || !*p) {
p = "unknown";
}
CG_Text_Paint(rect->x, rect->y + rect->h, scale, color, p, 0, 0, textStyle);
}
}
static void CG_DrawPlayerLocation( rectDef_t *rect, float scale, vec4_t color, int textStyle ) {
clientInfo_t *ci = &cgs.clientinfo[cg.snap->ps.clientNum];
if (ci) {
const char *p = CG_ConfigString(CS_LOCATIONS + ci->location);
if (!p || !*p) {
p = "unknown";
}
CG_Text_Paint(rect->x, rect->y + rect->h, scale, color, p, 0, 0, textStyle);
}
}
static void CG_DrawSelectedPlayerWeapon( rectDef_t *rect ) {
clientInfo_t *ci;
ci = cgs.clientinfo + sortedTeamPlayers[CG_GetSelectedPlayer()];
if (ci) {
if ( cg_weapons[ci->curWeapon].weaponIcon ) {
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cg_weapons[ci->curWeapon].weaponIcon );
} else {
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cgs.media.deferShader);
}
}
}
static void CG_DrawPlayerScore( rectDef_t *rect, float scale, vec4_t color, qhandle_t shader, int textStyle ) {
char num[16];
int value = cg.snap->ps.persistant[PERS_SCORE];
if (shader) {
trap_R_SetColor( color );
CG_DrawPic(rect->x, rect->y, rect->w, rect->h, shader);
trap_R_SetColor( NULL );
} else {
Com_sprintf (num, sizeof(num), "%i", value);
value = CG_Text_Width(num, scale, 0);
CG_Text_Paint(rect->x + (rect->w - value) / 2, rect->y + rect->h, scale, color, num, 0, 0, textStyle);
}
}
static void CG_DrawPlayerItem( rectDef_t *rect, float scale, qboolean draw2D) {
int value;
vec3_t origin, angles;
value = cg.snap->ps.stats[STAT_HOLDABLE_ITEM];
if ( value ) {
CG_RegisterItemVisuals( value );
if (qtrue) {
CG_RegisterItemVisuals( value );
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cg_items[ value ].icon );
} else {
VectorClear( angles );
origin[0] = 90;
origin[1] = 0;
origin[2] = -10;
angles[YAW] = ( cg.time & 2047 ) * 360 / 2048.0;
CG_Draw3DModel(rect->x, rect->y, rect->w, rect->h, cg_items[ value ].models[0], 0, origin, angles );
}
}
}
static void CG_DrawSelectedPlayerPowerup( rectDef_t *rect, qboolean draw2D ) {
clientInfo_t *ci;
int j;
float x, y;
ci = cgs.clientinfo + sortedTeamPlayers[CG_GetSelectedPlayer()];
if (ci) {
x = rect->x;
y = rect->y;
for (j = 0; j < PW_NUM_POWERUPS; j++) {
if (ci->powerups & (1 << j)) {
gitem_t *item;
item = BG_FindItemForPowerup( j );
if (item) {
CG_DrawPic( x, y, rect->w, rect->h, trap_R_RegisterShader( item->icon ) );
return;
}
}
}
}
}
static void CG_DrawSelectedPlayerHead( rectDef_t *rect, qboolean draw2D, qboolean voice ) {
clipHandle_t cm;
clientInfo_t *ci;
float len;
vec3_t origin;
vec3_t mins, maxs, angles;
ci = cgs.clientinfo + ((voice) ? cgs.currentVoiceClient : sortedTeamPlayers[CG_GetSelectedPlayer()]);
if (ci) {
if ( cg_draw3dIcons.integer ) {
cm = ci->headModel;
if ( !cm ) {
return;
}
// offset the origin y and z to center the head
trap_R_ModelBounds( cm, mins, maxs );
origin[2] = -0.5 * ( mins[2] + maxs[2] );
origin[1] = 0.5 * ( mins[1] + maxs[1] );
// calculate distance so the head nearly fills the box
// assume heads are taller than wide
len = 0.7 * ( maxs[2] - mins[2] );
origin[0] = len / 0.268; // len / tan( fov/2 )
// allow per-model tweaking
VectorAdd( origin, ci->headOffset, origin );
angles[PITCH] = 0;
angles[YAW] = 180;
angles[ROLL] = 0;
CG_Draw3DModel( rect->x, rect->y, rect->w, rect->h, ci->headModel, ci->headSkin, origin, angles );
} else if ( cg_drawIcons.integer ) {
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, ci->modelIcon );
}
// if they are deferred, draw a cross out
if ( ci->deferred ) {
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cgs.media.deferShader );
}
}
}
static void CG_DrawPlayerHealth(rectDef_t *rect, float scale, vec4_t color, qhandle_t shader, int textStyle ) {
playerState_t *ps;
int value;
char num[16];
ps = &cg.snap->ps;
value = ps->stats[STAT_HEALTH];
if (shader) {
trap_R_SetColor( color );
CG_DrawPic(rect->x, rect->y, rect->w, rect->h, shader);
trap_R_SetColor( NULL );
} else {
Com_sprintf (num, sizeof(num), "%i", value);
value = CG_Text_Width(num, scale, 0);
CG_Text_Paint(rect->x + (rect->w - value) / 2, rect->y + rect->h, scale, color, num, 0, 0, textStyle);
}
}
static void CG_DrawRedScore(rectDef_t *rect, float scale, vec4_t color, qhandle_t shader, int textStyle ) {
int value;
char num[16];
if ( cgs.scores1 == SCORE_NOT_PRESENT ) {
Com_sprintf (num, sizeof(num), "-");
}
else {
Com_sprintf (num, sizeof(num), "%i", cgs.scores1);
}
value = CG_Text_Width(num, scale, 0);
CG_Text_Paint(rect->x + rect->w - value, rect->y + rect->h, scale, color, num, 0, 0, textStyle);
}
static void CG_DrawBlueScore(rectDef_t *rect, float scale, vec4_t color, qhandle_t shader, int textStyle ) {
int value;
char num[16];
if ( cgs.scores2 == SCORE_NOT_PRESENT ) {
Com_sprintf (num, sizeof(num), "-");
}
else {
Com_sprintf (num, sizeof(num), "%i", cgs.scores2);
}
value = CG_Text_Width(num, scale, 0);
CG_Text_Paint(rect->x + rect->w - value, rect->y + rect->h, scale, color, num, 0, 0, textStyle);
}
// FIXME: team name support
static void CG_DrawRedName(rectDef_t *rect, float scale, vec4_t color, int textStyle ) {
CG_Text_Paint(rect->x, rect->y + rect->h, scale, color, cg_redTeamName.string , 0, 0, textStyle);
}
static void CG_DrawBlueName(rectDef_t *rect, float scale, vec4_t color, int textStyle ) {
CG_Text_Paint(rect->x, rect->y + rect->h, scale, color, cg_blueTeamName.string, 0, 0, textStyle);
}
static void CG_DrawBlueFlagName(rectDef_t *rect, float scale, vec4_t color, int textStyle ) {
int i;
for ( i = 0 ; i < cgs.maxclients ; i++ ) {
if ( cgs.clientinfo[i].infoValid && cgs.clientinfo[i].team == TEAM_RED && cgs.clientinfo[i].powerups & ( 1<< PW_BLUEFLAG )) {
CG_Text_Paint(rect->x, rect->y + rect->h, scale, color, cgs.clientinfo[i].name, 0, 0, textStyle);
return;
}
}
}
static void CG_DrawBlueFlagStatus(rectDef_t *rect, qhandle_t shader) {
if (cgs.gametype != GT_CTF && cgs.gametype != GT_1FCTF) {
if (cgs.gametype == GT_HARVESTER) {
vec4_t color = {0, 0, 1, 1};
trap_R_SetColor(color);
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cgs.media.blueCubeIcon );
trap_R_SetColor(NULL);
}
return;
}
if (shader) {
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, shader );
} else {
gitem_t *item = BG_FindItemForPowerup( PW_BLUEFLAG );
if (item) {
vec4_t color = {0, 0, 1, 1};
trap_R_SetColor(color);
if( cgs.blueflag >= 0 && cgs.blueflag <= 2 ) {
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cgs.media.flagShaders[cgs.blueflag] );
} else {
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cgs.media.flagShaders[0] );
}
trap_R_SetColor(NULL);
}
}
}
static void CG_DrawBlueFlagHead(rectDef_t *rect) {
int i;
for ( i = 0 ; i < cgs.maxclients ; i++ ) {
if ( cgs.clientinfo[i].infoValid && cgs.clientinfo[i].team == TEAM_RED && cgs.clientinfo[i].powerups & ( 1<< PW_BLUEFLAG )) {
vec3_t angles;
VectorClear( angles );
angles[YAW] = 180 + 20 * sin( cg.time / 650.0 );;
CG_DrawHead( rect->x, rect->y, rect->w, rect->h, 0,angles );
return;
}
}
}
static void CG_DrawRedFlagName(rectDef_t *rect, float scale, vec4_t color, int textStyle ) {
int i;
for ( i = 0 ; i < cgs.maxclients ; i++ ) {
if ( cgs.clientinfo[i].infoValid && cgs.clientinfo[i].team == TEAM_BLUE && cgs.clientinfo[i].powerups & ( 1<< PW_REDFLAG )) {
CG_Text_Paint(rect->x, rect->y + rect->h, scale, color, cgs.clientinfo[i].name, 0, 0, textStyle);
return;
}
}
}
static void CG_DrawRedFlagStatus(rectDef_t *rect, qhandle_t shader) {
if (cgs.gametype != GT_CTF && cgs.gametype != GT_1FCTF) {
if (cgs.gametype == GT_HARVESTER) {
vec4_t color = {1, 0, 0, 1};
trap_R_SetColor(color);
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cgs.media.redCubeIcon );
trap_R_SetColor(NULL);
}
return;
}
if (shader) {
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, shader );
} else {
gitem_t *item = BG_FindItemForPowerup( PW_REDFLAG );
if (item) {
vec4_t color = {1, 0, 0, 1};
trap_R_SetColor(color);
if( cgs.redflag >= 0 && cgs.redflag <= 2) {
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cgs.media.flagShaders[cgs.redflag] );
} else {
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cgs.media.flagShaders[0] );
}
trap_R_SetColor(NULL);
}
}
}
static void CG_DrawRedFlagHead(rectDef_t *rect) {
int i;
for ( i = 0 ; i < cgs.maxclients ; i++ ) {
if ( cgs.clientinfo[i].infoValid && cgs.clientinfo[i].team == TEAM_BLUE && cgs.clientinfo[i].powerups & ( 1<< PW_REDFLAG )) {
vec3_t angles;
VectorClear( angles );
angles[YAW] = 180 + 20 * sin( cg.time / 650.0 );;
CG_DrawHead( rect->x, rect->y, rect->w, rect->h, 0,angles );
return;
}
}
}
static void CG_HarvesterSkulls(rectDef_t *rect, float scale, vec4_t color, qboolean force2D, int textStyle ) {
char num[16];
vec3_t origin, angles;
qhandle_t handle;
int value = cg.snap->ps.generic1;
if (cgs.gametype != GT_HARVESTER) {
return;
}
if( value > 99 ) {
value = 99;
}
Com_sprintf (num, sizeof(num), "%i", value);
value = CG_Text_Width(num, scale, 0);
CG_Text_Paint(rect->x + (rect->w - value), rect->y + rect->h, scale, color, num, 0, 0, textStyle);
if (cg_drawIcons.integer) {
if (!force2D && cg_draw3dIcons.integer) {
VectorClear(angles);
origin[0] = 90;
origin[1] = 0;
origin[2] = -10;
angles[YAW] = ( cg.time & 2047 ) * 360 / 2048.0;
if( cg.snap->ps.persistant[PERS_TEAM] == TEAM_BLUE ) {
handle = cgs.media.redCubeModel;
} else {
handle = cgs.media.blueCubeModel;
}
CG_Draw3DModel( rect->x, rect->y, 35, 35, handle, 0, origin, angles );
} else {
if( cg.snap->ps.persistant[PERS_TEAM] == TEAM_BLUE ) {
handle = cgs.media.redCubeIcon;
} else {
handle = cgs.media.blueCubeIcon;
}
CG_DrawPic( rect->x + 3, rect->y + 16, 20, 20, handle );
}
}
}
static void CG_OneFlagStatus(rectDef_t *rect) {
if (cgs.gametype != GT_1FCTF) {
return;
} else {
gitem_t *item = BG_FindItemForPowerup( PW_NEUTRALFLAG );
if (item) {
if( cgs.flagStatus >= 0 && cgs.flagStatus <= 4 ) {
vec4_t color = {1, 1, 1, 1};
int index = 0;
if (cgs.flagStatus == FLAG_TAKEN_RED) {
color[1] = color[2] = 0;
index = 1;
} else if (cgs.flagStatus == FLAG_TAKEN_BLUE) {
color[0] = color[1] = 0;
index = 1;
} else if (cgs.flagStatus == FLAG_DROPPED) {
index = 2;
}
trap_R_SetColor(color);
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cgs.media.flagShaders[index] );
}
}
}
}
static void CG_DrawCTFPowerUp(rectDef_t *rect) {
int value;
if (cgs.gametype < GT_CTF) {
return;
}
value = cg.snap->ps.stats[STAT_PERSISTANT_POWERUP];
if ( value ) {
CG_RegisterItemVisuals( value );
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cg_items[ value ].icon );
}
}
static void CG_DrawTeamColor(rectDef_t *rect, vec4_t color) {
CG_DrawTeamBackground(rect->x, rect->y, rect->w, rect->h, color[3], cg.snap->ps.persistant[PERS_TEAM]);
}
static void CG_DrawAreaPowerUp(rectDef_t *rect, int align, float special, float scale, vec4_t color) {
char num[16];
int sorted[MAX_POWERUPS];
int sortedTime[MAX_POWERUPS];
int i, j, k;
int active;
playerState_t *ps;
int t;
gitem_t *item;
float f;
rectDef_t r2;
float *inc;
r2.x = rect->x;
r2.y = rect->y;
r2.w = rect->w;
r2.h = rect->h;
inc = (align == HUD_VERTICAL) ? &r2.y : &r2.x;
ps = &cg.snap->ps;
if ( ps->stats[STAT_HEALTH] <= 0 ) {
return;
}
// sort the list by time remaining
active = 0;
for ( i = 0 ; i < MAX_POWERUPS ; i++ ) {
if ( !ps->powerups[ i ] ) {
continue;
}
// ZOID--don't draw if the power up has unlimited time
// This is true of the CTF flags
if ( ps->powerups[ i ] == INT_MAX ) {
continue;
}
t = ps->powerups[ i ] - cg.time;
if ( t <= 0 ) {
continue;
}
// insert into the list
for ( j = 0 ; j < active ; j++ ) {
if ( sortedTime[j] >= t ) {
for ( k = active - 1 ; k >= j ; k-- ) {
sorted[k+1] = sorted[k];
sortedTime[k+1] = sortedTime[k];
}
break;
}
}
sorted[j] = i;
sortedTime[j] = t;
active++;
}
// draw the icons and timers
for ( i = 0 ; i < active ; i++ ) {
item = BG_FindItemForPowerup( sorted[i] );
if (item) {
t = ps->powerups[ sorted[i] ];
if ( t - cg.time >= POWERUP_BLINKS * POWERUP_BLINK_TIME ) {
trap_R_SetColor( NULL );
} else {
vec4_t modulate;
f = (float)( t - cg.time ) / POWERUP_BLINK_TIME;
f -= (int)f;
modulate[0] = modulate[1] = modulate[2] = modulate[3] = f;
trap_R_SetColor( modulate );
}
CG_DrawPic( r2.x, r2.y, r2.w * .75, r2.h, trap_R_RegisterShader( item->icon ) );
Com_sprintf (num, sizeof(num), "%i", sortedTime[i] / 1000);
CG_Text_Paint(r2.x + (r2.w * .75) + 3 , r2.y + r2.h, scale, color, num, 0, 0, 0);
*inc += r2.w + special;
}
}
trap_R_SetColor( NULL );
}
float CG_GetValue(int ownerDraw) {
centity_t *cent;
clientInfo_t *ci;
playerState_t *ps;
cent = &cg_entities[cg.snap->ps.clientNum];
ps = &cg.snap->ps;
switch (ownerDraw) {
case CG_SELECTEDPLAYER_ARMOR:
ci = cgs.clientinfo + sortedTeamPlayers[CG_GetSelectedPlayer()];
return ci->armor;
break;
case CG_SELECTEDPLAYER_HEALTH:
ci = cgs.clientinfo + sortedTeamPlayers[CG_GetSelectedPlayer()];
return ci->health;
break;
case CG_PLAYER_ARMOR_VALUE:
return ps->stats[STAT_ARMOR];
break;
case CG_PLAYER_AMMO_VALUE:
if ( cent->currentState.weapon ) {
return ps->ammo[cent->currentState.weapon];
}
break;
case CG_PLAYER_SCORE:
return cg.snap->ps.persistant[PERS_SCORE];
break;
case CG_PLAYER_HEALTH:
return ps->stats[STAT_HEALTH];
break;
case CG_RED_SCORE:
return cgs.scores1;
break;
case CG_BLUE_SCORE:
return cgs.scores2;
break;
default:
break;
}
return -1;
}
qboolean CG_OtherTeamHasFlag(void) {
if (cgs.gametype == GT_CTF || cgs.gametype == GT_1FCTF) {
int team = cg.snap->ps.persistant[PERS_TEAM];
if (cgs.gametype == GT_1FCTF) {
if (team == TEAM_RED && cgs.flagStatus == FLAG_TAKEN_BLUE) {
return qtrue;
} else if (team == TEAM_BLUE && cgs.flagStatus == FLAG_TAKEN_RED) {
return qtrue;
} else {
return qfalse;
}
} else {
if (team == TEAM_RED && cgs.redflag == FLAG_TAKEN) {
return qtrue;
} else if (team == TEAM_BLUE && cgs.blueflag == FLAG_TAKEN) {
return qtrue;
} else {
return qfalse;
}
}
}
return qfalse;
}
qboolean CG_YourTeamHasFlag(void) {
if (cgs.gametype == GT_CTF || cgs.gametype == GT_1FCTF) {
int team = cg.snap->ps.persistant[PERS_TEAM];
if (cgs.gametype == GT_1FCTF) {
if (team == TEAM_RED && cgs.flagStatus == FLAG_TAKEN_RED) {
return qtrue;
} else if (team == TEAM_BLUE && cgs.flagStatus == FLAG_TAKEN_BLUE) {
return qtrue;
} else {
return qfalse;
}
} else {
if (team == TEAM_RED && cgs.blueflag == FLAG_TAKEN) {
return qtrue;
} else if (team == TEAM_BLUE && cgs.redflag == FLAG_TAKEN) {
return qtrue;
} else {
return qfalse;
}
}
}
return qfalse;
}
// THINKABOUTME: should these be exclusive or inclusive..
//
qboolean CG_OwnerDrawVisible(int flags) {
if (flags & CG_SHOW_TEAMINFO) {
return (cg_currentSelectedPlayer.integer == numSortedTeamPlayers);
}
if (flags & CG_SHOW_NOTEAMINFO) {
return !(cg_currentSelectedPlayer.integer == numSortedTeamPlayers);
}
if (flags & CG_SHOW_OTHERTEAMHASFLAG) {
return CG_OtherTeamHasFlag();
}
if (flags & CG_SHOW_YOURTEAMHASENEMYFLAG) {
return CG_YourTeamHasFlag();
}