/
st_stuff.c
3849 lines (3289 loc) · 113 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 st_stuff.c
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2011 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2006-2011 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
*/
/**
* 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 <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "jdoom.h"
#include "d_net.h"
#include "hu_stuff.h"
#include "hu_lib.h"
#include "hu_chat.h"
#include "hu_log.h"
#include "hu_automap.h"
#include "p_mapsetup.h"
#include "p_tick.h" // for P_IsPaused
#include "p_player.h"
#include "p_user.h"
#include "r_common.h"
#include "am_map.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_FX (144)
// 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 (0)
#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)
// HEALTH number pos.
#define ST_HEALTHWIDTH (3)
#define ST_HEALTHX (90)
#define ST_HEALTHY (3)
// Weapon pos.
#define ST_ARMSX (111)
#define ST_ARMSY (4)
#define ST_ARMSBGX (104)
#define ST_ARMSBGY (1)
#define ST_ARMSXSPACE (12)
#define ST_ARMSYSPACE (10)
// Frags pos.
#define ST_FRAGSX (138)
#define ST_FRAGSY (3)
#define ST_FRAGSWIDTH (2)
// ARMOR number pos.
#define ST_ARMORWIDTH (3)
#define ST_ARMORX (221)
#define ST_ARMORY (3)
// Key icon positions.
#define ST_KEY0WIDTH (8)
#define ST_KEY0HEIGHT (5)
#define ST_KEY0X (239)
#define ST_KEY0Y (3)
#define ST_KEY1WIDTH (ST_KEY0WIDTH)
#define ST_KEY1X (239)
#define ST_KEY1Y (13)
#define ST_KEY2WIDTH (ST_KEY0WIDTH)
#define ST_KEY2X (239)
#define ST_KEY2Y (23)
// Ready Ammunition counter.
#define ST_READYAMMOWIDTH (3)
#define ST_READYAMMOX (44)
#define ST_READYAMMOY (3)
// Ammo counters.
#define ST_AMMOWIDTH (3)
#define ST_AMMOHEIGHT (6)
#define ST_AMMOX (288)
#define ST_AMMOY (5)
#define ST_MAXAMMOWIDTH (3)
#define ST_MAXAMMOHEIGHT (6)
#define ST_MAXAMMOX (314)
#define ST_MAXAMMOY (5)
// TYPES -------------------------------------------------------------------
typedef enum {
HOT_TLEFT,
HOT_TRIGHT,
HOT_BRIGHT,
HOT_BLEFT,
HOT_B,
HOT_LEFT
} hotloc_t;
enum {
UWG_STATUSBAR = 0,
UWG_MAPNAME,
UWG_BOTTOMLEFT,
UWG_BOTTOMLEFT2,
UWG_BOTTOMRIGHT,
UWG_BOTTOM,
UWG_TOP,
UWG_COUNTERS,
UWG_AUTOMAP,
NUM_UIWIDGET_GROUPS
};
typedef struct {
boolean inited;
boolean stopped;
int hideTics;
float hideAmount;
float alpha; // Fullscreen hud alpha value.
float showBar; // Slide statusbar amount 1.0 is fully open.
boolean statusbarActive; // Whether the statusbar is active.
int automapCheatLevel; /// \todo Belongs in player state?
int widgetGroupIds[NUM_UIWIDGET_GROUPS];
int automapWidgetId;
int chatWidgetId;
int logWidgetId;
// Statusbar:
guidata_health_t sbarHealth;
guidata_readyammo_t sbarReadyammo;
guidata_ammo_t sbarAmmos[NUM_AMMO_TYPES];
guidata_ammo_t sbarMaxammos[NUM_AMMO_TYPES];
guidata_weaponslot_t sbarWeaponslots[6];
guidata_armor_t sbarArmor;
guidata_frags_t sbarFrags;
guidata_keyslot_t sbarKeyslots[3];
guidata_face_t sbarFace;
// Fullscreen:
guidata_health_t health;
guidata_armoricon_t armoricon;
guidata_keys_t keys;
guidata_armor_t armor;
guidata_readyammoicon_t readyammoicon;
guidata_readyammo_t readyammo;
guidata_face_t face;
guidata_frags_t frags;
// Other:
guidata_automap_t automap;
guidata_chat_t chat;
guidata_log_t log;
guidata_secrets_t secrets;
guidata_items_t items;
guidata_kills_t kills;
} hudstate_t;
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void updateViewWindow(void);
void unhideHUD(void);
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
int ST_ChatResponder(int player, event_t* ev);
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
// PUBLIC DATA DEFINITIONS -------------------------------------------------
// PRIVATE DATA DEFINITIONS ------------------------------------------------
static hudstate_t hudStates[MAXPLAYERS];
// Main bar left.
static patchinfo_t pStatusbar;
// 3 key-cards, 3 skulls.
static patchinfo_t pKeys[NUM_KEY_TYPES];
// Face status patches.
static patchinfo_t pFaces[ST_NUMFACES];
// Face background.
static patchinfo_t pFaceBackground[4];
// Main bar right.
static patchinfo_t pArmsBackground;
// Weapon ownership patches.
static patchinfo_t pArms[6][2];
// CODE --------------------------------------------------------------------
/**
* Register CVARs and CCmds for the HUD/Status bar
*/
void ST_Register(void)
{
cvartemplate_t cvars[] = {
{ "hud-scale", 0, CVT_FLOAT, &cfg.hudScale, 0.1f, 1, unhideHUD },
{ "hud-wideoffset", 0, CVT_FLOAT, &cfg.hudWideOffset, 0, 1, unhideHUD },
{ "hud-status-size", 0, CVT_FLOAT, &cfg.statusbarScale, 0.1f, 1, updateViewWindow },
// HUD color + alpha
{ "hud-color-r", 0, CVT_FLOAT, &cfg.hudColor[0], 0, 1, unhideHUD },
{ "hud-color-g", 0, CVT_FLOAT, &cfg.hudColor[1], 0, 1, unhideHUD },
{ "hud-color-b", 0, CVT_FLOAT, &cfg.hudColor[2], 0, 1, unhideHUD },
{ "hud-color-a", 0, CVT_FLOAT, &cfg.hudColor[3], 0, 1, unhideHUD },
{ "hud-icon-alpha", 0, CVT_FLOAT, &cfg.hudIconAlpha, 0, 1, unhideHUD },
{ "hud-face-ouchfix", 0, CVT_BYTE, &cfg.fixOuchFace, 0, 1 },
{ "hud-status-alpha", 0, CVT_FLOAT, &cfg.statusbarOpacity, 0, 1, unhideHUD },
{ "hud-status-icon-a", 0, CVT_FLOAT, &cfg.statusbarCounterAlpha, 0, 1, unhideHUD },
{ "hud-status-weaponslots-ownedfix", 0, CVT_BYTE, &cfg.fixStatusbarOwnedWeapons, 0, 1, unhideHUD },
// HUD icons
{ "hud-face", 0, CVT_BYTE, &cfg.hudShown[HUD_FACE], 0, 1, unhideHUD },
{ "hud-health", 0, CVT_BYTE, &cfg.hudShown[HUD_HEALTH], 0, 1, unhideHUD },
{ "hud-armor", 0, CVT_BYTE, &cfg.hudShown[HUD_ARMOR], 0, 1, unhideHUD },
{ "hud-ammo", 0, CVT_BYTE, &cfg.hudShown[HUD_AMMO], 0, 1, unhideHUD },
{ "hud-keys", 0, CVT_BYTE, &cfg.hudShown[HUD_KEYS], 0, 1, unhideHUD },
{ "hud-keys-combine", 0, CVT_BYTE, &cfg.hudKeysCombine, 0, 1, unhideHUD },
// HUD displays
{ "hud-frags", 0, CVT_BYTE, &cfg.hudShown[HUD_FRAGS], 0, 1, unhideHUD },
{ "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 },
{ "hud-cheat-counter", 0, CVT_BYTE, &cfg.hudShownCheatCounters, 0, 63, unhideHUD },
{ "hud-cheat-counter-scale", 0, CVT_FLOAT, &cfg.hudCheatCounterScale, .1f, 1, unhideHUD },
{ NULL }
};
ccmdtemplate_t ccmds[] = {
{ "beginchat", NULL, CCmdChatOpen },
{ "chatcancel", "", CCmdChatAction },
{ "chatcomplete", "", CCmdChatAction },
{ "chatdelete", "", CCmdChatAction },
{ "chatsendmacro", NULL, CCmdChatSendMacro },
{ NULL }
};
int i;
for(i = 0; cvars[i].name; ++i)
Con_AddVariable(cvars + i);
for(i = 0; ccmds[i].name; ++i)
Con_AddCommand(ccmds + i);
}
static int fullscreenMode(void)
{
return (cfg.screenBlocks < 10? 0 : cfg.screenBlocks - 10);
}
void SBarBackground_Drawer(uiwidget_t* obj, int xOffset, int yOffset)
{
#define WIDTH (ST_WIDTH)
#define HEIGHT (ST_HEIGHT)
#define ORIGINX ((int)(-WIDTH/2))
#define ORIGINY ((int)(-HEIGHT * hud->showBar))
assert(NULL != obj);
{
const hudstate_t* hud = &hudStates[obj->player];
float x = ORIGINX, y = ORIGINY, w = WIDTH, h = HEIGHT;
float armsBGX = ST_ARMSBGX + pArmsBackground.offset;
int fullscreen = fullscreenMode();
const float textAlpha = (fullscreen == 0? 1 : uiRendState->pageAlpha * cfg.statusbarOpacity);
const float iconAlpha = (fullscreen == 0? 1 : uiRendState->pageAlpha * cfg.statusbarOpacity);
float cw, cw2, ch;
if(ST_AutomapIsActive(obj->player) && cfg.automapHudDisplay == 0)
return;
if(P_MobjIsCamera(players[obj->player].plr->mo) && Get(DD_PLAYBACK))
return;
DGL_MatrixMode(DGL_MODELVIEW);
DGL_PushMatrix();
DGL_Translatef(xOffset, yOffset, 0);
DGL_Scalef(cfg.statusbarScale, cfg.statusbarScale, 1);
DGL_SetPatch(pStatusbar.id, DGL_CLAMP_TO_EDGE, DGL_CLAMP_TO_EDGE);
DGL_Enable(DGL_TEXTURE_2D);
DGL_Color4f(1, 1, 1, iconAlpha);
if(!(iconAlpha < 1))
{
// We can draw the full graphic in one go.
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();
}
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.
w = !deathmatch ? armsBGX : ST_FX;
h = 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 + pArmsBackground.width < ST_FX)
{
int sectionWidth = armsBGX + pArmsBackground.width;
x = ORIGINX + sectionWidth;
y = ORIGINY;
w = ST_FX - armsBGX - pArmsBackground.width;
h = HEIGHT;
cw = (float)sectionWidth / WIDTH;
cw2 = (sectionWidth + w) / WIDTH;
DGL_TexCoord2f(0, cw, 0);
DGL_Vertex2f(x, y);
DGL_TexCoord2f(0, cw2, 0);
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);
}
// Awkward, 2 pixel tall strip above faceback.
x = ORIGINX + ST_FX;
y = ORIGINY;
w = WIDTH - ST_FX - 141 - 2;
h = HEIGHT - 30;
cw = (float)ST_FX / WIDTH;
cw2 = (float)(ST_FX + 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 = ORIGINX + ST_FX;
y = ORIGINY + (HEIGHT - 1);
w = WIDTH - ST_FX - 141 - 2;
h = HEIGHT - 31;
cw = (float)ST_FX / WIDTH;
cw2 = (float)(ST_FX + w) / WIDTH;
ch = (float)(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.
{
int sectionWidth = ST_FX + (WIDTH - ST_FX - 141 - 2);
x = ORIGINX + sectionWidth;
y = ORIGINY;
w = WIDTH - sectionWidth;
h = HEIGHT;
cw = (float)sectionWidth / WIDTH;
}
}
else
{
// Including area behind the face status indicator.
int sectionWidth = armsBGX + pArmsBackground.width;
x = ORIGINX + sectionWidth;
y = ORIGINY;
w = WIDTH - sectionWidth;
h = HEIGHT;
cw = (float)sectionWidth / 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(pArmsBackground.id, DGL_CLAMP_TO_EDGE, DGL_CLAMP_TO_EDGE);
x = ORIGINX + armsBGX;
y = ORIGINY + pArmsBackground.topOffset;
w = pArmsBackground.width;
h = pArmsBackground.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();
}
// Faceback?
if(IS_NETGAME)
{
const patchinfo_t* patch = &pFaceBackground[cfg.playerColor[obj->player%MAXPLAYERS]%4];
DGL_SetPatch(patch->id, DGL_CLAMP_TO_EDGE, DGL_CLAMP_TO_EDGE);
x = ORIGINX + (ST_FX - ST_X);
y = ORIGINY + (HEIGHT - 30);
w = WIDTH - ST_FX - 141 - 2;
h = HEIGHT - 3;
cw = 1.f / 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();
}
DGL_Disable(DGL_TEXTURE_2D);
DGL_MatrixMode(DGL_MODELVIEW);
DGL_PopMatrix();
}
#undef ORIGINY
#undef ORIGINX
#undef HEIGHT
#undef WIDTH
}
void SBarBackground_UpdateDimensions(uiwidget_t* obj)
{
#define WIDTH (ST_WIDTH)
#define HEIGHT (ST_HEIGHT)
assert(NULL != obj);
obj->dimensions.width = 0;
obj->dimensions.height = 0;
if(ST_AutomapIsActive(obj->player) && cfg.automapHudDisplay == 0)
return;
if(P_MobjIsCamera(players[obj->player].plr->mo) && Get(DD_PLAYBACK))
return;
obj->dimensions.width = WIDTH * cfg.statusbarScale;
obj->dimensions.height = HEIGHT * cfg.statusbarScale;
#undef HEIGHT
#undef WIDTH
}
/**
* 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(int player)
{
player_t* plr = &players[player];
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 Face_Ticker(uiwidget_t* obj, timespan_t ticLength)
{
assert(NULL != obj);
{
guidata_face_t* face = (guidata_face_t*)obj->typedata;
const player_t* plr = &players[obj->player];
angle_t badGuyAngle, diffAng;
boolean doEvilGrin;
int i;
if(P_IsPaused() || !GUI_GameTicTriggerIsSharp())
return;
if(face->priority < 10)
{ // Player is dead.
if(!plr->health)
{
face->priority = 9;
face->faceIndex = ST_DEADFACE;
face->faceCount = 1;
}
}
if(face->priority < 9)
{
if(plr->bonusCount)
{ // Picking up a bonus.
doEvilGrin = false;
for(i = 0; i < NUM_WEAPON_TYPES; ++i)
{
if(face->oldWeaponsOwned[i] != plr->weapons[i].owned)
{
doEvilGrin = true;
face->oldWeaponsOwned[i] = plr->weapons[i].owned;
}
}
if(doEvilGrin)
{ // Evil grin if just picked up weapon.
face->priority = 8;
face->faceCount = ST_EVILGRINCOUNT;
face->faceIndex = calcPainOffset(obj->player) + ST_EVILGRINOFFSET;
}
}
}
if(face->priority < 8)
{
if(plr->damageCount && plr->attacker &&
plr->attacker != plr->plr->mo)
{ // Being attacked.
face->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?
(face->oldHealth - plr->health) :
(plr->health - face->oldHealth)) > ST_MUCHPAIN)
{
face->faceCount = ST_TURNCOUNT;
face->faceIndex = calcPainOffset(obj->player) + ST_OUCHOFFSET;
if(cfg.fixOuchFace)
face->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;
}
face->faceCount = ST_TURNCOUNT;
face->faceIndex = calcPainOffset(obj->player);
if(diffAng < ANG45)
{ // Head-on.
face->faceIndex += ST_RAMPAGEOFFSET;
}
else if(i)
{ // Turn face right.
face->faceIndex += ST_TURNOFFSET;
}
else
{ // Turn face left.
face->faceIndex += ST_TURNOFFSET + 1;
}
}
}
}
if(face->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?
(face->oldHealth - plr->health) :
(plr->health - face->oldHealth)) > ST_MUCHPAIN)
{
face->priority = 7;
face->faceCount = ST_TURNCOUNT;
face->faceIndex = calcPainOffset(obj->player) + ST_OUCHOFFSET;
}
else
{
face->priority = 6;
face->faceCount = ST_TURNCOUNT;
face->faceIndex = calcPainOffset(obj->player) + ST_RAMPAGEOFFSET;
}
}
}
if(face->priority < 6)
{ // Rapid firing.
if(plr->attackDown)
{
if(face->lastAttackDown == -1)
{
face->lastAttackDown = ST_RAMPAGEDELAY;
}
else if(!--face->lastAttackDown)
{
face->priority = 5;
face->faceIndex = calcPainOffset(obj->player) + ST_RAMPAGEOFFSET;
face->faceCount = 1;
face->lastAttackDown = 1;
}
}
else
{
face->lastAttackDown = -1;
}
}
if(face->priority < 5)
{ // Invulnerability.
if((P_GetPlayerCheats(plr) & CF_GODMODE) || plr->powers[PT_INVULNERABILITY])
{
face->priority = 4;
face->faceIndex = ST_GODFACE;
face->faceCount = 1;
}
}
// Look left or look right if the facecount has timed out.
if(!face->faceCount)
{
face->faceIndex = calcPainOffset(obj->player) + (M_Random() % 3);
face->faceCount = ST_STRAIGHTFACECOUNT;
face->priority = 0;
}
face->oldHealth = plr->health;
--face->faceCount;
}
}
int ST_Responder(event_t* ev)
{
int i, eaten;
for(i = 0; i < MAXPLAYERS; ++i)
{
eaten = ST_ChatResponder(i, ev);
if(0 != eaten)
return eaten;
}
return false;
}
void ST_Ticker(timespan_t ticLength)
{
/// \kludge
boolean runGameTic = GUI_RunGameTicTrigger(ticLength);
/// kludge end.
int i;
for(i = 0; i < MAXPLAYERS; ++i)
{
player_t* plr = &players[i];
hudstate_t* hud = &hudStates[i];
if(!plr->plr->inGame)
continue;
// Either slide the statusbar in or fade out the fullscreen HUD.
if(hud->statusbarActive)
{
if(hud->alpha > 0.0f)
{
hud->statusbarActive = 0;
hud->alpha -= 0.1f;
}
else if(hud->showBar < 1.0f)
{
hud->showBar += 0.1f;
}
}
else
{
if(cfg.screenBlocks == 13)
{
if(hud->alpha > 0.0f)
{
hud->alpha -= 0.1f;
}
}
else
{
if(hud->showBar > 0.0f)
{
hud->showBar -= 0.1f;
hud->statusbarActive = 1;
}
else if(hud->alpha < 1.0f)
{
hud->alpha += 0.1f;
}
}
}
// The following is restricted to fixed 35 Hz ticks.
if(runGameTic && !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;
}
}
if(hud->inited)
{
int j;
for(j = 0; j < NUM_UIWIDGET_GROUPS; ++j)
{
UIWidget_RunTic(GUI_MustFindObjectById(hud->widgetGroupIds[j]), ticLength);
}
}
}
}
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;
}
void ReadyAmmo_Ticker(uiwidget_t* obj, timespan_t ticLength)
{
assert(NULL != obj);
{
guidata_readyammo_t* ammo = (guidata_readyammo_t*)obj->typedata;
int player = obj->player;
player_t* plr = &players[player];
ammotype_t ammoType;
boolean found;
if(P_IsPaused() || !GUI_GameTicTriggerIsSharp())
return;
// 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.
ammo->value = plr->ammo[ammoType].owned;
found = true;
}
if(!found) // Weapon takes no ammo at all.
{
ammo->value = 1994; // Means "n/a".
}
}
}
void SBarReadyAmmo_Drawer(uiwidget_t* obj, int x, int y)
{
#define ORIGINX (-ST_WIDTH/2)
#define ORIGINY (-ST_HEIGHT)
#define X (ORIGINX+ST_READYAMMOX)
#define Y (ORIGINY+ST_READYAMMOY)
assert(NULL != obj);
{
const guidata_readyammo_t* ammo = (guidata_readyammo_t*)obj->typedata;
const hudstate_t* hud = &hudStates[obj->player];
int yOffset = ST_HEIGHT*(1-hud->showBar);
int fullscreen = fullscreenMode();
const float textAlpha = (fullscreen == 0? 1 : uiRendState->pageAlpha * cfg.statusbarCounterAlpha);
const float iconAlpha = (fullscreen == 0? 1 : uiRendState->pageAlpha * cfg.statusbarCounterAlpha);
char buf[20];
if(ST_AutomapIsActive(obj->player) && cfg.automapHudDisplay == 0)
return;
if(P_MobjIsCamera(players[obj->player].plr->mo) && Get(DD_PLAYBACK))
return;
if(ammo->value == 1994)
return;
dd_snprintf(buf, 20, "%i", ammo->value);
DGL_MatrixMode(DGL_MODELVIEW);
DGL_PushMatrix();
DGL_Translatef(x, y, 0);
DGL_Scalef(cfg.statusbarScale, cfg.statusbarScale, 1);
DGL_Translatef(0, yOffset, 0);
DGL_Enable(DGL_TEXTURE_2D);
FR_SetFont(obj->fontId);
FR_SetColorAndAlpha(defFontRGB2[CR], defFontRGB2[CG], defFontRGB2[CB], textAlpha);
FR_DrawText3(buf, X, Y, ALIGN_TOPRIGHT, DTF_NO_EFFECTS);
DGL_Disable(DGL_TEXTURE_2D);
DGL_MatrixMode(DGL_MODELVIEW);
DGL_PopMatrix();
}
#undef Y
#undef X
#undef ORIGINY
#undef ORIGINX
}
void SBarReadyAmmo_UpdateDimensions(uiwidget_t* obj)
{
assert(NULL != obj);
{
const guidata_readyammo_t* ammo = (guidata_readyammo_t*)obj->typedata;
char buf[20];