/
st_stuff.c
1569 lines (1303 loc) · 44.6 KB
/
st_stuff.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
/**\file
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2009 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2006-2009 Daniel Swanson <danij@dengine.net>
*\author Copyright © 1993-1996 by id Software, Inc.
*
* 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., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/**
* st_stuff.c: Status bar code - jDoom specific.
*
* Does the face/direction indicator animation and the palette indicators as
* well (red pain/berserk, bright pickup)
*/
// HEADER FILES ------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "jdoom.h"
#include "d_net.h"
#include "st_lib.h"
#include "hu_stuff.h"
#include "p_tick.h" // for P_IsPaused
#include "p_player.h"
#include "am_map.h"
#include "p_user.h"
// MACROS ------------------------------------------------------------------
// Radiation suit, green shift.
#define RADIATIONPAL (13)
// N/256*100% probability
// that the normal face state will change
#define ST_FACEPROBABILITY (96)
// Location of status bar
#define ST_X (0)
#define ST_X2 (104)
#define ST_FX (144)
#define ST_FY (169)
// Number of status faces.
#define ST_NUMPAINFACES (5)
#define ST_NUMSTRAIGHTFACES (3)
#define ST_NUMTURNFACES (2)
#define ST_NUMSPECIALFACES (3)
#define ST_FACESTRIDE \
(ST_NUMSTRAIGHTFACES+ST_NUMTURNFACES+ST_NUMSPECIALFACES)
#define ST_NUMEXTRAFACES (2)
#define ST_NUMFACES \
(ST_FACESTRIDE*ST_NUMPAINFACES+ST_NUMEXTRAFACES)
#define ST_TURNOFFSET (ST_NUMSTRAIGHTFACES)
#define ST_OUCHOFFSET (ST_TURNOFFSET + ST_NUMTURNFACES)
#define ST_EVILGRINOFFSET (ST_OUCHOFFSET + 1)
#define ST_RAMPAGEOFFSET (ST_EVILGRINOFFSET + 1)
#define ST_GODFACE (ST_NUMPAINFACES*ST_FACESTRIDE)
#define ST_DEADFACE (ST_GODFACE+1)
#define ST_FACESX (143)
#define ST_FACESY (168)
#define ST_EVILGRINCOUNT (2*TICRATE)
#define ST_STRAIGHTFACECOUNT (TICRATE/2)
#define ST_TURNCOUNT (1*TICRATE)
#define ST_OUCHCOUNT (1*TICRATE)
#define ST_RAMPAGEDELAY (2*TICRATE)
#define ST_MUCHPAIN (20)
// AMMO number pos.
#define ST_CURRENTAMMOWIDTH (3)
#define ST_CURRENTAMMOX (44)
#define ST_CURRENTAMMOY (171)
// HEALTH number pos.
#define ST_HEALTHWIDTH (3)
#define ST_HEALTHX (90)
#define ST_HEALTHY (171)
// Weapon pos.
#define ST_ARMSX (111)
#define ST_ARMSY (172)
#define ST_ARMSBGX (104)
#define ST_ARMSBGY (168)
#define ST_ARMSXSPACE (12)
#define ST_ARMSYSPACE (10)
// Frags pos.
#define ST_FRAGSX (138)
#define ST_FRAGSY (171)
#define ST_FRAGSWIDTH (2)
// ARMOR number pos.
#define ST_ARMORWIDTH (3)
#define ST_ARMORX (221)
#define ST_ARMORY (171)
// Key icon positions.
#define ST_KEY0WIDTH (8)
#define ST_KEY0HEIGHT (5)
#define ST_KEY0X (239)
#define ST_KEY0Y (171)
#define ST_KEY1WIDTH (ST_KEY0WIDTH)
#define ST_KEY1X (239)
#define ST_KEY1Y (181)
#define ST_KEY2WIDTH (ST_KEY0WIDTH)
#define ST_KEY2X (239)
#define ST_KEY2Y (191)
// Ready Ammunition counter.
#define ST_READYAMMOWIDTH (3)
#define ST_READYAMMOX (44)
#define ST_READYAMMOY (171)
// Ammo counters.
#define ST_AMMOWIDTH (3)
#define ST_AMMOHEIGHT (6)
#define ST_AMMOX (288)
#define ST_AMMOY (173)
#define ST_MAXAMMOWIDTH (3)
#define ST_MAXAMMOHEIGHT (6)
#define ST_MAXAMMOX (314)
#define ST_MAXAMMOY (173)
// Pistol.
#define ST_WEAPON0X (110)
#define ST_WEAPON0Y (172)
// Shotgun.
#define ST_WEAPON1X (122)
#define ST_WEAPON1Y (172)
// Chain gun.
#define ST_WEAPON2X (134)
#define ST_WEAPON2Y (172)
// Missile launcher.
#define ST_WEAPON3X (110)
#define ST_WEAPON3Y (181)
// Plasma gun.
#define ST_WEAPON4X (122)
#define ST_WEAPON4Y (181)
// BFG.
#define ST_WEAPON5X (134)
#define ST_WEAPON5Y (181)
// WPNS title.
#define ST_WPNSX (109)
#define ST_WPNSY (191)
// DETH title.
#define ST_DETHX (109)
#define ST_DETHY (191)
// TYPES -------------------------------------------------------------------
typedef enum hotloc_e {
HOT_TLEFT,
HOT_TRIGHT,
HOT_BRIGHT,
HOT_BLEFT
} hotloc_t;
typedef struct {
boolean stopped;
int hideTics;
float hideAmount;
float alpha; // Fullscreen hud alpha value.
float showBar; // Slide statusbar amount 1.0 is fully open.
float statusbarCounterAlpha;
boolean firstTime; // ST_Start() has just been called.
boolean blended; // Whether to use alpha blending.
boolean statusbarActive; // Whether the main status bar is active.
int currentFragsCount; // Number of frags so far in deathmatch.
int keyBoxes[3]; // Holds key-type for each key box on bar.
// For status face:
int oldHealth; // Used to use appopriately pained face.
boolean oldWeaponsOwned[NUM_WEAPON_TYPES]; // Used for evil grin.
int faceCount; // Count until face changes.
int faceIndex; // Current face index, used by wFaces.
int lastAttackDown;
int priority;
// Widgets:
st_number_t wReadyWeapon; // Ready-weapon widget.
st_number_t wFrags; // In deathmatch only, summary of frags stats.
st_percent_t wHealth; // Health widget.
st_multiicon_t wArms[6]; // Weapon ownership widgets.
st_multiicon_t wFaces; // Face status widget.
st_multiicon_t wKeyBoxes[3]; // Keycard widgets.
st_percent_t wArmor; // Armor widget.
st_number_t wAmmo[NUM_AMMO_TYPES]; // Ammo widgets.
st_number_t wMaxAmmo[NUM_AMMO_TYPES]; // Max ammo widgets.
} hudstate_t;
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
DEFCC(CCmdStatusBarSize);
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
// PUBLIC DATA DEFINITIONS -------------------------------------------------
// PRIVATE DATA DEFINITIONS ------------------------------------------------
static hudstate_t hudStates[MAXPLAYERS];
// Main bar left.
static dpatch_t statusbar;
// 0-9, tall numbers.
static dpatch_t tallNum[10];
// Tall % sign.
static dpatch_t tallPercent;
// 0-9, short, yellow (,different!) numbers.
static dpatch_t shortNum[10];
// 3 key-cards, 3 skulls.
static dpatch_t keys[NUM_KEY_TYPES];
// Face status patches.
static dpatch_t faces[ST_NUMFACES];
// Face background.
static dpatch_t faceBackground[4];
// Main bar right.
static dpatch_t armsBackground;
// Weapon ownership patches.
static dpatch_t arms[6][2];
// CVARs for the HUD/Statusbar:
cvar_t sthudCVars[] =
{
// HUD scale
{"hud-scale", 0, CVT_FLOAT, &cfg.hudScale, 0.1f, 10},
{"hud-status-size", CVF_PROTECTED, CVT_INT, &cfg.statusbarScale, 1, 20},
// HUD colour + alpha
{"hud-color-r", 0, CVT_FLOAT, &cfg.hudColor[0], 0, 1},
{"hud-color-g", 0, CVT_FLOAT, &cfg.hudColor[1], 0, 1},
{"hud-color-b", 0, CVT_FLOAT, &cfg.hudColor[2], 0, 1},
{"hud-color-a", 0, CVT_FLOAT, &cfg.hudColor[3], 0, 1},
{"hud-icon-alpha", 0, CVT_FLOAT, &cfg.hudIconAlpha, 0, 1},
{"hud-face-ouchfix", 0, CVT_BYTE, &cfg.fixOuchFace, 0, 1},
{"hud-status-alpha", 0, CVT_FLOAT, &cfg.statusbarOpacity, 0, 1},
{"hud-status-icon-a", 0, CVT_FLOAT, &cfg.statusbarCounterAlpha, 0, 1},
{"hud-status-weaponslots-ownedfix", 0, CVT_BYTE, &cfg.fixStatusbarOwnedWeapons, 0, 1},
// HUD icons
{"hud-face", 0, CVT_BYTE, &cfg.hudShown[HUD_FACE], 0, 1},
{"hud-health", 0, CVT_BYTE, &cfg.hudShown[HUD_HEALTH], 0, 1},
{"hud-armor", 0, CVT_BYTE, &cfg.hudShown[HUD_ARMOR], 0, 1},
{"hud-ammo", 0, CVT_BYTE, &cfg.hudShown[HUD_AMMO], 0, 1},
{"hud-keys", 0, CVT_BYTE, &cfg.hudShown[HUD_KEYS], 0, 1},
{"hud-keys-combine", 0, CVT_BYTE, &cfg.hudKeysCombine, 0, 1},
// HUD displays
{"hud-frags", 0, CVT_BYTE, &cfg.hudShown[HUD_FRAGS], 0, 1},
{"hud-timer", 0, CVT_FLOAT, &cfg.hudTimer, 0, 60},
{"hud-unhide-damage", 0, CVT_BYTE, &cfg.hudUnHide[HUE_ON_DAMAGE], 0, 1},
{"hud-unhide-pickup-health", 0, CVT_BYTE, &cfg.hudUnHide[HUE_ON_PICKUP_HEALTH], 0, 1},
{"hud-unhide-pickup-armor", 0, CVT_BYTE, &cfg.hudUnHide[HUE_ON_PICKUP_ARMOR], 0, 1},
{"hud-unhide-pickup-powerup", 0, CVT_BYTE, &cfg.hudUnHide[HUE_ON_PICKUP_POWER], 0, 1},
{"hud-unhide-pickup-weapon", 0, CVT_BYTE, &cfg.hudUnHide[HUE_ON_PICKUP_WEAPON], 0, 1},
{"hud-unhide-pickup-ammo", 0, CVT_BYTE, &cfg.hudUnHide[HUE_ON_PICKUP_AMMO], 0, 1},
{"hud-unhide-pickup-key", 0, CVT_BYTE, &cfg.hudUnHide[HUE_ON_PICKUP_KEY], 0, 1},
{NULL}
};
// Console commands for the HUD/Status bar:
ccmd_t sthudCCmds[] = {
{"sbsize", "s", CCmdStatusBarSize},
{NULL}
};
// CODE --------------------------------------------------------------------
/**
* Register CVARs and CCmds for the HUD/Status bar
*/
void ST_Register(void)
{
int i;
for(i = 0; sthudCVars[i].name; ++i)
Con_AddVariable(sthudCVars + i);
for(i = 0; sthudCCmds[i].name; ++i)
Con_AddCommand(sthudCCmds + i);
}
static void drawStatusBarBackground(int player, float width, float height)
{
float x, y, w, h;
float cw, cw2, ch;
float alpha;
hudstate_t* hud = &hudStates[player];
float armsBGX = ST_ARMSBGX - armsBackground.leftOffset;
DGL_SetPatch(statusbar.lump, DGL_CLAMP_TO_EDGE, DGL_CLAMP_TO_EDGE);
if(hud->blended)
{
alpha = cfg.statusbarOpacity - hud->hideAmount;
if(!(alpha > 0))
return;
alpha = MINMAX_OF(0.f, alpha, 1.f);
}
else
alpha = 1.0f;
DGL_Color4f(1, 1, 1, alpha);
if(!(alpha < 1))
{
// We can draw the full graphic in one go.
DGL_Begin(DGL_QUADS);
DGL_TexCoord2f(0, 0, 0);
DGL_Vertex2f(0, 0);
DGL_TexCoord2f(0, 1, 0);
DGL_Vertex2f(width, 0);
DGL_TexCoord2f(0, 1, 1);
DGL_Vertex2f(width, height);
DGL_TexCoord2f(0, 0, 1);
DGL_Vertex2f(0, height);
DGL_End();
}
else
{
// Alpha blended status bar, we'll need to cut it up into smaller bits...
DGL_Begin(DGL_QUADS);
// Up to faceback if deathmatch, else ST_ARMS.
x = 0;
y = 0;
w = width * (float) ((hud->statusbarActive && !deathmatch) ? armsBGX : ST_FX) / ST_WIDTH;
h = height * (float) ST_HEIGHT / ST_HEIGHT;
cw = w / width;
DGL_TexCoord2f(0, 0, 0);
DGL_Vertex2f(x, y);
DGL_TexCoord2f(0, cw, 0);
DGL_Vertex2f(x + w, y);
DGL_TexCoord2f(0, cw, 1);
DGL_Vertex2f(x + w, y + h);
DGL_TexCoord2f(0, 0, 1);
DGL_Vertex2f(x, y + h);
if(IS_NETGAME)
{
// Fill in any gap left before the faceback due to small ARMS.
if(armsBGX + armsBackground.width < ST_FX)
{
x = width * (float) (armsBGX + armsBackground.width) / ST_WIDTH;
y = 0;
w = width * (float) (ST_FX - armsBGX - armsBackground.width) / ST_WIDTH;
h = height * (float) (ST_HEIGHT) / ST_HEIGHT;
cw = x / width;
cw2 = (x + w) / width;
ch = h / height;
DGL_TexCoord2f(0, cw, 0);
DGL_Vertex2f(x, y);
DGL_TexCoord2f(0, cw2, 0);
DGL_Vertex2f(x + w, y);
DGL_TexCoord2f(0, cw2, ch);
DGL_Vertex2f(x + w, y + h);
DGL_TexCoord2f(0, cw, ch);
DGL_Vertex2f(x, y + h);
}
// Awkward, 2 pixel tall strip above faceback.
x = width * (float) (ST_FX) / ST_WIDTH;
y = 0;
w = width * (float) (ST_WIDTH - ST_FX - 141 - 2) / ST_WIDTH;
h = height * (float) (ST_HEIGHT - 30) / ST_HEIGHT;
cw = x / width;
cw2 = (x + w) / width;
ch = h / height;
DGL_TexCoord2f(0, cw, 0);
DGL_Vertex2f(x, y);
DGL_TexCoord2f(0, cw2, 0);
DGL_Vertex2f(x + w, y);
DGL_TexCoord2f(0, cw2, ch);
DGL_Vertex2f(x + w, y + h);
DGL_TexCoord2f(0, cw, ch);
DGL_Vertex2f(x, y + h);
// Awkward, 1 pixel tall strip bellow faceback.
x = width * (float) (ST_FX) / ST_WIDTH;
y = height * (float) (ST_HEIGHT - 1) / ST_HEIGHT;
w = width * (float) (ST_WIDTH - ST_FX - 141 - 2) / ST_WIDTH;
h = height * (float) (ST_HEIGHT - 31) / ST_HEIGHT;
cw = x / width;
cw2 = (x + w) / width;
ch = (ST_HEIGHT - 1) / height;
DGL_TexCoord2f(0, cw, ch);
DGL_Vertex2f(x, y);
DGL_TexCoord2f(0, cw2, ch);
DGL_Vertex2f(x + w, y);
DGL_TexCoord2f(0, cw2, 1);
DGL_Vertex2f(x + w, y + h);
DGL_TexCoord2f(0, cw, 1);
DGL_Vertex2f(x, y + h);
// After faceback.
x = width * (float) (ST_FX + (ST_WIDTH - ST_FX - 141 - 2)) / ST_WIDTH;
y = 0;
w = width * (float) (ST_WIDTH - (ST_FX + (ST_WIDTH - ST_FX - 141 - 2))) / ST_WIDTH;
h = height * (float) ST_HEIGHT / ST_HEIGHT;
cw = x / width;
}
else
{
// Including area behind the face status indicator.
x = width * (float) (armsBGX + armsBackground.width) / ST_WIDTH;
y = 0;
w = width * (float) (ST_WIDTH - armsBGX - armsBackground.width) / ST_WIDTH;
h = height * (float) ST_HEIGHT / ST_HEIGHT;
cw = x / width;
}
DGL_TexCoord2f(0, cw, 0);
DGL_Vertex2f(x, y);
DGL_TexCoord2f(0, 1, 0);
DGL_Vertex2f(x + w, y);
DGL_TexCoord2f(0, 1, 1);
DGL_Vertex2f(x + w, y + h);
DGL_TexCoord2f(0, cw, 1);
DGL_Vertex2f(x, y + h);
DGL_End();
}
if(!deathmatch)
{ // Draw the ARMS background.
DGL_SetPatch(armsBackground.lump, DGL_CLAMP_TO_EDGE, DGL_CLAMP_TO_EDGE);
x = width * ((float) armsBGX - ST_X) / ST_WIDTH;
y = height * ((float) armsBackground.topOffset) / ST_HEIGHT;
w = width * ((float) armsBackground.width) / ST_WIDTH;
h = height * ((float) armsBackground.height) / ST_HEIGHT;
DGL_Begin(DGL_QUADS);
DGL_TexCoord2f(0, 0, 0);
DGL_Vertex2f(x, y);
DGL_TexCoord2f(0, 1, 0);
DGL_Vertex2f(x + w, y);
DGL_TexCoord2f(0, 1, 1);
DGL_Vertex2f(x + w, y + h);
DGL_TexCoord2f(0, 0, 1);
DGL_Vertex2f(x, y + h);
DGL_End();
}
if(IS_NETGAME) // Faceback.
{
int plrColor = cfg.playerColor[player];
dpatch_t* patch = &faceBackground[plrColor];
DGL_SetPatch(patch->lump, DGL_CLAMP_TO_EDGE, DGL_CLAMP_TO_EDGE);
x = width * (float) (ST_FX - ST_X) / ST_WIDTH;
y = height * (float) (ST_HEIGHT - 30) / ST_HEIGHT;
w = width * (float) (ST_WIDTH - ST_FX - 141 - 2) / ST_WIDTH;
h = height * (float) (ST_HEIGHT - 3) / ST_HEIGHT;
cw = (float) (1) / patch->width;
cw2 = (float) (patch->width - 1) / patch->width;
ch = (float) (patch->height - 1) / patch->height;
DGL_Begin(DGL_QUADS);
DGL_TexCoord2f(0, cw, 0);
DGL_Vertex2f(x, y);
DGL_TexCoord2f(0, cw2, 0);
DGL_Vertex2f(x + w, y);
DGL_TexCoord2f(0, cw2, ch);
DGL_Vertex2f(x + w, y + h);
DGL_TexCoord2f(0, cw, ch);
DGL_Vertex2f(x, y + h);
DGL_End();
}
}
/**
* Unhides the current HUD display if hidden.
*
* @param player The player whoose HUD to (maybe) unhide.
* @param event The HUD Update Event type to check for triggering.
*/
void ST_HUDUnHide(int player, hueevent_t ev)
{
player_t* plr;
if(ev < HUE_FORCE || ev > NUMHUDUNHIDEEVENTS)
return;
plr = &players[player];
if(!(plr->plr->inGame && (plr->plr->flags & DDPF_LOCAL)))
return;
if(ev == HUE_FORCE || cfg.hudUnHide[ev])
{
hudStates[player].hideTics = (cfg.hudTimer * TICSPERSEC);
hudStates[player].hideAmount = 0;
}
}
static int calcPainOffset(hudstate_t* hud)
{
player_t* plr = &players[hud - hudStates];
int health = (plr->health > 100 ? 100 : plr->health);
return ST_FACESTRIDE * (((100 - health) * ST_NUMPAINFACES) / 101);
}
/**
* This is a not-very-pretty routine which handles the face states
* and their timing. the precedence of expressions is:
*
* dead > evil grin > turned head > straight ahead
*/
void ST_updateFaceWidget(int player)
{
int i;
angle_t badGuyAngle;
angle_t diffAng;
boolean doEvilGrin;
player_t* plr = &players[player];
hudstate_t* hud = &hudStates[player];
if(hud->priority < 10)
{ // Player is dead.
if(!plr->health)
{
hud->priority = 9;
hud->faceIndex = ST_DEADFACE;
hud->faceCount = 1;
}
}
if(hud->priority < 9)
{
if(plr->bonusCount)
{ // Picking up a bonus.
doEvilGrin = false;
for(i = 0; i < NUM_WEAPON_TYPES; ++i)
{
if(hud->oldWeaponsOwned[i] != plr->weapons[i].owned)
{
doEvilGrin = true;
hud->oldWeaponsOwned[i] = plr->weapons[i].owned;
}
}
if(doEvilGrin)
{ // Evil grin if just picked up weapon.
hud->priority = 8;
hud->faceCount = ST_EVILGRINCOUNT;
hud->faceIndex = calcPainOffset(hud) + ST_EVILGRINOFFSET;
}
}
}
if(hud->priority < 8)
{
if(plr->damageCount && plr->attacker &&
plr->attacker != plr->plr->mo)
{ // Being attacked.
hud->priority = 7;
// DOOM BUG
// This test was inversed, thereby the OUCH face was NEVER used
// in normal gameplay as it requires the player recieving damage
// to end up with MORE health than he started with.
// Also, priority was not changed which would have resulted in a
// frame duration of only 1 tic.
// if(plr->health - oldHealth > ST_MUCHPAIN)
if((cfg.fixOuchFace?
(hud->oldHealth - plr->health) :
(plr->health - hud->oldHealth)) > ST_MUCHPAIN)
{
hud->faceCount = ST_TURNCOUNT;
hud->faceIndex = calcPainOffset(hud) + ST_OUCHOFFSET;
if(cfg.fixOuchFace)
hud->priority = 8; // Added to fix 1 tic issue.
}
else
{
badGuyAngle =
R_PointToAngle2(FLT2FIX(plr->plr->mo->pos[VX]),
FLT2FIX(plr->plr->mo->pos[VY]),
FLT2FIX(plr->attacker->pos[VX]),
FLT2FIX(plr->attacker->pos[VY]));
if(badGuyAngle > plr->plr->mo->angle)
{ // Whether right or left.
diffAng = badGuyAngle - plr->plr->mo->angle;
i = diffAng > ANG180;
}
else
{ // Whether left or right.
diffAng = plr->plr->mo->angle - badGuyAngle;
i = diffAng <= ANG180;
}
hud->faceCount = ST_TURNCOUNT;
hud->faceIndex = calcPainOffset(hud);
if(diffAng < ANG45)
{ // Head-on.
hud->faceIndex += ST_RAMPAGEOFFSET;
}
else if(i)
{ // Turn face right.
hud->faceIndex += ST_TURNOFFSET;
}
else
{ // Turn face left.
hud->faceIndex += ST_TURNOFFSET + 1;
}
}
}
}
if(hud->priority < 7)
{ // Getting hurt because of your own damn stupidity.
if(plr->damageCount)
{
// DOOM BUG
// This test was inversed, thereby the OUCH face was NEVER used
// in normal gameplay as it requires the player recieving damage
// to end up with MORE health than he started with.
// if(plr->health - oldHealth > ST_MUCHPAIN)
if((cfg.fixOuchFace?
(hud->oldHealth - plr->health) :
(plr->health - hud->oldHealth)) > ST_MUCHPAIN)
{
hud->priority = 7;
hud->faceCount = ST_TURNCOUNT;
hud->faceIndex = calcPainOffset(hud) + ST_OUCHOFFSET;
}
else
{
hud->priority = 6;
hud->faceCount = ST_TURNCOUNT;
hud->faceIndex = calcPainOffset(hud) + ST_RAMPAGEOFFSET;
}
}
}
if(hud->priority < 6)
{ // Rapid firing.
if(plr->attackDown)
{
if(hud->lastAttackDown == -1)
{
hud->lastAttackDown = ST_RAMPAGEDELAY;
}
else if(!--hud->lastAttackDown)
{
hud->priority = 5;
hud->faceIndex = calcPainOffset(hud) + ST_RAMPAGEOFFSET;
hud->faceCount = 1;
hud->lastAttackDown = 1;
}
}
else
{
hud->lastAttackDown = -1;
}
}
if(hud->priority < 5)
{ // Invulnerability.
if((P_GetPlayerCheats(plr) & CF_GODMODE) ||
plr->powers[PT_INVULNERABILITY])
{
hud->priority = 4;
hud->faceIndex = ST_GODFACE;
hud->faceCount = 1;
}
}
// Look left or look right if the facecount has timed out.
if(!hud->faceCount)
{
hud->faceIndex = calcPainOffset(hud) + (M_Random() % 3);
hud->faceCount = ST_STRAIGHTFACECOUNT;
hud->priority = 0;
}
hud->faceCount--;
}
void ST_updateWidgets(int player)
{
static int largeAmmo = 1994; // Means "n/a".
int i;
ammotype_t ammoType;
boolean found;
hudstate_t* hud = &hudStates[player];
player_t* plr = &players[player];
if(hud->blended)
{
hud->statusbarCounterAlpha =
MINMAX_OF(0.f, cfg.statusbarCounterAlpha - hud->hideAmount, 1.f);
}
else
hud->statusbarCounterAlpha = 1.0f;
// Must redirect the pointer if the ready weapon has changed.
found = false;
for(ammoType=0; ammoType < NUM_AMMO_TYPES && !found; ++ammoType)
{
if(!weaponInfo[plr->readyWeapon][plr->class].mode[0].ammoType[ammoType])
continue; // Weapon does not use this type of ammo.
//// \todo Only supports one type of ammo per weapon
hud->wReadyWeapon.num = &plr->ammo[ammoType].owned;
found = true;
}
if(!found) // Weapon takes no ammo at all.
{
hud->wReadyWeapon.num = &largeAmmo;
}
// Update keycard multiple widgets.
for(i = 0; i < 3; ++i)
{
hud->keyBoxes[i] = plr->keys[i] ? i : -1;
if(plr->keys[i + 3])
hud->keyBoxes[i] = i + 3;
}
// Refresh everything if this is him coming back to life.
ST_updateFaceWidget(player);
// Used by wFrags widget.
hud->currentFragsCount = 0;
for(i = 0; i < MAXPLAYERS; ++i)
{
if(!players[i].plr->inGame)
continue;
hud->currentFragsCount += plr->frags[i] * (i != player ? 1 : -1);
}
}
void ST_Ticker(void)
{
int i;
for(i = 0; i < MAXPLAYERS; ++i)
{
player_t* plr = &players[i];
hudstate_t* hud = &hudStates[i];
if(!(plr->plr->inGame && (plr->plr->flags & DDPF_LOCAL)))
continue;
if(!P_IsPaused())
{
if(cfg.hudTimer == 0)
{
hud->hideTics = hud->hideAmount = 0;
}
else
{
if(hud->hideTics > 0)
hud->hideTics--;
if(hud->hideTics == 0 && cfg.hudTimer > 0 && hud->hideAmount < 1)
hud->hideAmount += 0.1f;
}
ST_updateWidgets(i);
hud->oldHealth = plr->health;
}
}
}
void ST_doPaletteStuff(int player)
{
int palette = 0, cnt, bzc;
player_t* plr = &players[player];
cnt = plr->damageCount;
if(plr->powers[PT_STRENGTH])
{ // Slowly fade the berzerk out.
bzc = 12 - (plr->powers[PT_STRENGTH] >> 6);
if(bzc > cnt)
cnt = bzc;
}
if(cnt)
{
palette = (cnt + 7) >> 3;
if(palette >= NUMREDPALS)
palette = NUMREDPALS - 1;
palette += STARTREDPALS;
}
else if(plr->bonusCount)
{
palette = (plr->bonusCount + 7) >> 3;
if(palette >= NUMBONUSPALS)
palette = NUMBONUSPALS - 1;
palette += STARTBONUSPALS;
}
else if(plr->powers[PT_IRONFEET] > 4 * 32 ||
plr->powers[PT_IRONFEET] & 8)
{
palette = RADIATIONPAL;
}
// $democam
if(palette)
{
plr->plr->flags |= DDPF_VIEW_FILTER;
R_GetFilterColor(plr->plr->filterColor, palette);
}
else
plr->plr->flags &= ~DDPF_VIEW_FILTER;
}
typedef struct {
hudstate_t* hud;
int slot;
float alpha;
} drawownedweapondisply_params_t;
int drawOwnedWeaponDisplay(weapontype_t type, void* context)
{
drawownedweapondisply_params_t* params =
(drawownedweapondisply_params_t*) context;
const player_t* plr = &players[params->hud - hudStates];
if(cfg.fixStatusbarOwnedWeapons)
{
if(!plr->weapons[type].owned)
return 1; // Continue iteration.
}
STlib_DrawMultiIcon(¶ms->hud->wArms[params->slot],
plr->weapons[type].owned ? 1 : 0, params->alpha);
return 0; // Stop iteration.
}
static void drawWidgets(hudstate_t* hud)
{
int i;
float alpha = hud->statusbarCounterAlpha;
STlib_DrawNum(&hud->wReadyWeapon, alpha);
for(i = 0; i < 4; ++i)
{
STlib_DrawNum(&hud->wAmmo[i], alpha);
STlib_DrawNum(&hud->wMaxAmmo[i], alpha);
}
STlib_DrawPercent(&hud->wHealth, alpha);
STlib_DrawPercent(&hud->wArmor, alpha);
if(!deathmatch)
{
for(i = 0; i < 6; ++i)
{
int result;
drawownedweapondisply_params_t params;
params.hud = hud;
params.slot = i;
params.alpha = alpha;
result =
P_IterateWeaponsInSlot(i+1, true, drawOwnedWeaponDisplay,
¶ms);
if(cfg.fixStatusbarOwnedWeapons && result)
{ // No weapon bound to slot is owned by player.
STlib_DrawMultiIcon(&hud->wArms[i], 0, alpha);
}
}
}
else
STlib_DrawNum(&hud->wFrags, alpha);
STlib_DrawMultiIcon(&hud->wFaces, hud->faceIndex, alpha);
for(i = 0; i < 3; ++i)
{
if(hud->keyBoxes[i] != -1)
{
STlib_DrawMultiIcon(&hud->wKeyBoxes[i], hud->keyBoxes[i], alpha);
}
}
}
void ST_doRefresh(int player)
{
hudstate_t* hud;
boolean statusbarVisible;
float fscale, h;
if(player < 0 || player > MAXPLAYERS)
return;
hud = &hudStates[player];
statusbarVisible = (cfg.statusbarScale < 20 ||
(cfg.statusbarScale == 20 && hud->showBar < 1.0f));
hud->firstTime = false;
fscale = cfg.statusbarScale / 20.0f;
h = SCREENHEIGHT * (1 - fscale);
DGL_MatrixMode(DGL_MODELVIEW);
DGL_PushMatrix();
DGL_Translatef((SCREENWIDTH/2) - SCREENWIDTH * fscale / 2,
h / hud->showBar, 0);
DGL_Scalef(fscale, fscale, 1);
DGL_Translatef(ST_X, ST_Y, 0);
// Draw background.
drawStatusBarBackground(player, ST_WIDTH, ST_HEIGHT);
DGL_Translatef(-ST_X, -ST_Y, 0);
drawWidgets(hud);
// Restore the normal modelview matrix.
DGL_MatrixMode(DGL_MODELVIEW);
DGL_PopMatrix();
}
void ST_HUDSpriteSize(int sprite, int *w, int *h)
{
spriteinfo_t sprInfo;
R_GetSpriteInfo(sprite, 0, &sprInfo);