-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathst_stuff.c
946 lines (750 loc) · 22.7 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
/* Emacs style mode select -*- C++ -*-
*-----------------------------------------------------------------------------
*
*
* PrBoom: a Doom port merged with LxDoom and LSDLDoom
* based on BOOM, a modified and improved DOOM engine
* Copyright (C) 1999 by
* id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
* Copyright (C) 1999-2000 by
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
* Copyright 2005, 2006 by
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
* Copyright 2023, 2024 by
* Frenkel Smeijers
*
* 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.
*
* DESCRIPTION:
* Status bar code.
* Does the face/direction indicator animation.
* Does palette indicators as well (red pain/berserk, bright pickup)
*
*-----------------------------------------------------------------------------*/
#include <stdint.h>
#include "compiler.h"
#include "doomdef.h"
#include "d_player.h"
#include "m_random.h"
#include "i_system.h"
#include "w_wad.h"
#include "st_stuff.h"
#include "r_main.h"
#include "am_map.h"
#include "s_sound.h"
#include "sounds.h"
#include "d_englsh.h"
#include "globdata.h"
//
// Typedefs of widgets
//
// Number widget
typedef struct
{
// upper right-hand corner
// of the number (right-justified)
int16_t x;
int16_t y;
// max # of digits in number
int16_t width;
// last number value
int16_t oldnum;
// pointer to current value
int16_t* num;
// list of patches for 0-9
int16_t* p;
} st_number_t;
// Multiple Icon widget
typedef struct
{
// center-justified location of icons
int16_t x;
int16_t y;
// last icon number
int16_t oldinum;
// pointer to current icon
int16_t* inum;
// list of icons
int16_t* p;
} st_multicon_t;
// 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)
static int16_t statusbarnum;
// 0-9, tall numbers
static int16_t tallnum[10];
// 0-9, short, yellow (,different!) numbers
static int16_t shortnum[10];
static int16_t keys[NUMCARDS];
// face status patches
static int16_t faces[ST_NUMFACES];
// weapon ownership patches
static int16_t arms[6][2];
// ready-weapon widget
static st_number_t w_ready;
// health widget
static st_number_t st_health;
// weapon ownership widgets
static st_multicon_t w_arms[6];
// face status widget
static st_multicon_t w_faces;
// keycard widgets
static st_multicon_t w_keyboxes[3];
// ammo widgets
static st_number_t w_ammo[4];
// max ammo widgets
static st_number_t w_maxammo[4];
// armor widget
static st_number_t st_armor;
// used for evil grin
static boolean oldweaponsowned[NUMWEAPONS];
// count until face changes
static int16_t st_facecount;
// current face index, used by w_faces
static int16_t st_faceindex;
// holds key-type for each key box on bar
static int16_t keyboxes[3];
// a random number per tick
static int16_t st_randomnumber;
static int8_t st_palette;
// Size of statusbar.
// Now sensitive for scaling.
// proff 08/18/98: Changed for high-res
#define ST_Y (SCREENHEIGHT - ST_HEIGHT)
//
// STATUS BAR DATA
//
// Location of status bar
#define ST_X 0
#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)
// proff 08/18/98: Changed for high-res
#define ST_FACESX (ST_X+104)
#define ST_FACESY (ST_Y)
#define ST_EVILGRINCOUNT (2*TICRATE)
//Fix Status bar face timing ~Kippykip
#define ST_STRAIGHTFACECOUNT (18)
#define ST_TURNCOUNT (1*TICRATE)
#define ST_RAMPAGEDELAY (2*TICRATE)
#define ST_MUCHPAIN 20
// Location and size of statistics,
// justified according to widget type.
// Problem is, within which space? STbar? Screen?
// Note: this could be read in by a lump.
// Problem is, is the stuff rendered
// into a buffer,
// or into the frame buffer?
// I dunno, why don't you go and find out!!! killough
// AMMO number pos.
#define ST_AMMOWIDTH 3
// proff 08/18/98: Changed for high-res
#define ST_AMMOX (ST_X+32)
#define ST_AMMOY (ST_Y+6)
// HEALTH number pos.
#define ST_HEALTHWIDTH 3
// proff 08/18/98: Changed for high-res
#define ST_HEALTHX (ST_X+66)
#define ST_HEALTHY (ST_Y+6)
// Weapon pos.
// proff 08/18/98: Changed for high-res
#define ST_ARMSX (ST_X+82)
#define ST_ARMSY (ST_Y+4)
#define ST_ARMSXSPACE 8
#define ST_ARMSYSPACE 10
// ARMOR number pos.
#define ST_ARMORWIDTH 3
// proff 08/18/98: Changed for high-res
#define ST_ARMORX (ST_X+166)
#define ST_ARMORY (ST_Y+6)
// proff 08/18/98: Changed for high-res
#define ST_KEY0X (ST_X+178)
#define ST_KEY0Y (ST_Y+3)
// proff 08/18/98: Changed for high-res
#define ST_KEY1X (ST_X+178)
#define ST_KEY1Y (ST_Y+13)
// proff 08/18/98: Changed for high-res
#define ST_KEY2X (ST_X+178)
#define ST_KEY2Y (ST_Y+23)
// Ammunition counter.
#define ST_AMMO0WIDTH 3
// proff 08/18/98: Changed for high-res
#define ST_AMMO0X (ST_X+220)
#define ST_AMMO0Y (ST_Y+5)
#define ST_AMMO1WIDTH ST_AMMO0WIDTH
// proff 08/18/98: Changed for high-res
#define ST_AMMO1X (ST_X+220)
#define ST_AMMO1Y (ST_Y+11)
#define ST_AMMO2WIDTH ST_AMMO0WIDTH
// proff 08/18/98: Changed for high-res
#define ST_AMMO2X (ST_X+220)
#define ST_AMMO2Y (ST_Y+23)
#define ST_AMMO3WIDTH ST_AMMO0WIDTH
// proff 08/18/98: Changed for high-res
#define ST_AMMO3X (ST_X+220)
#define ST_AMMO3Y (ST_Y+17)
// Indicate maximum ammunition.
// Only needed because backpack exists.
#define ST_MAXAMMO0WIDTH 3
// proff 08/18/98: Changed for high-res
#define ST_MAXAMMO0X (ST_X+238)
#define ST_MAXAMMO0Y (ST_Y+5)
#define ST_MAXAMMO1WIDTH ST_MAXAMMO0WIDTH
// proff 08/18/98: Changed for high-res
#define ST_MAXAMMO1X (ST_X+238)
#define ST_MAXAMMO1Y (ST_Y+11)
#define ST_MAXAMMO2WIDTH ST_MAXAMMO0WIDTH
// proff 08/18/98: Changed for high-res
#define ST_MAXAMMO2X (ST_X+238)
#define ST_MAXAMMO2Y (ST_Y+23)
#define ST_MAXAMMO3WIDTH ST_MAXAMMO0WIDTH
// proff 08/18/98: Changed for high-res
#define ST_MAXAMMO3X (ST_X+238)
#define ST_MAXAMMO3Y (ST_Y+17)
// used to use appopriately pained face
static int16_t st_oldhealth = -1;
//
// STATUS BAR CODE
//
static void ST_Stop(void);
static int16_t ST_calcPainOffset(void)
{
static int16_t lastcalc;
static int16_t oldhealth = -1;
int16_t health = _g_player.health > 100 ? 100 : _g_player.health;
if (health != oldhealth)
{
lastcalc = ST_FACESTRIDE * (((100 - health) * ST_NUMPAINFACES) / 101);
oldhealth = health;
}
return lastcalc;
}
//
// 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
//
static void ST_updateFaceWidget(void)
{
int16_t i;
angle_t badguyangle;
angle_t diffang;
static int16_t lastattackdown = -1;
static int8_t priority = 0;
boolean doevilgrin;
if (priority < 10)
{
// dead
if (!_g_player.health)
{
priority = 9;
st_faceindex = ST_DEADFACE;
st_facecount = 1;
}
}
if (priority < 9)
{
if (_g_player.bonuscount)
{
// picking up bonus
doevilgrin = false;
for (i=0;i<NUMWEAPONS;i++)
{
if (oldweaponsowned[i] != _g_player.weaponowned[i])
{
doevilgrin = true;
oldweaponsowned[i] = _g_player.weaponowned[i];
}
}
if (doevilgrin)
{
// evil grin if just picked up weapon
priority = 8;
st_facecount = ST_EVILGRINCOUNT;
st_faceindex = ST_calcPainOffset() + ST_EVILGRINOFFSET;
}
}
}
//Restore the face looking at enemies direction in this SVN... Cause it's handy! ~Kippykip
if (priority < 8)
{
if (_g_player.damagecount && _g_player.attacker && _g_player.attacker != _g_player.mo)
{
// being attacked
priority = 7;
// haleyjd 10/12/03: classic DOOM problem of missing OUCH face
// was due to inversion of this test:
// if(plyr->health - st_oldhealth > ST_MUCHPAIN)
if(st_oldhealth - _g_player.health > ST_MUCHPAIN)
{
st_facecount = ST_TURNCOUNT;
st_faceindex = ST_calcPainOffset() + ST_OUCHOFFSET;
}
else
{
badguyangle = R_PointToAngle2(_g_player.mo->x,
_g_player.mo->y,
_g_player.attacker->x,
_g_player.attacker->y);
if (badguyangle > _g_player.mo->angle)
{
// whether right or left
diffang = badguyangle - _g_player.mo->angle;
i = diffang > ANG180;
}
else
{
// whether left or right
diffang = _g_player.mo->angle - badguyangle;
i = diffang <= ANG180;
} // confusing, aint it?
st_facecount = ST_TURNCOUNT;
st_faceindex = ST_calcPainOffset();
if (diffang < ANG45)
{
// head-on
st_faceindex += ST_RAMPAGEOFFSET;
}
else if (i)
{
// turn face right
st_faceindex += ST_TURNOFFSET;
}
else
{
// turn face left
st_faceindex += ST_TURNOFFSET+1;
}
}
}
}
if (priority < 7)
{
if (_g_player.damagecount)
{
// haleyjd 10/12/03: classic DOOM problem of missing OUCH face
// was due to inversion of this test:
// if(plyr->health - st_oldhealth > ST_MUCHPAIN)
if(st_oldhealth - _g_player.health > ST_MUCHPAIN)
{
priority = 7;
st_facecount = ST_TURNCOUNT;
st_faceindex = ST_calcPainOffset() + ST_OUCHOFFSET;
}
else
{
priority = 6;
st_facecount = ST_TURNCOUNT;
st_faceindex = ST_calcPainOffset() + ST_RAMPAGEOFFSET;
}
}
}
if (priority < 6)
{
// rapid firing
if (_g_player.attackdown)
{
if (lastattackdown==-1)
lastattackdown = ST_RAMPAGEDELAY;
else if (!--lastattackdown)
{
priority = 5;
st_faceindex = ST_calcPainOffset() + ST_RAMPAGEOFFSET;
st_facecount = 1;
lastattackdown = 1;
}
}
else
lastattackdown = -1;
}
if (priority < 5)
{
// invulnerability
if ((_g_player.cheats & CF_GODMODE)
|| _g_player.powers[pw_invulnerability])
{
priority = 4;
st_faceindex = ST_GODFACE;
st_facecount = 1;
}
}
// look left or look right if the facecount has timed out
if (!st_facecount)
{
st_faceindex = ST_calcPainOffset() + (st_randomnumber % 3);
st_facecount = ST_STRAIGHTFACECOUNT;
priority = 0;
}
st_facecount--;
}
static int16_t largeammo = 1994; // means "n/a"
static void ST_updateWidgets(void)
{
int8_t i;
if(_g_fps_show)
w_ready.num = &_g_fps_framerate;
else if (weaponinfo[_g_player.readyweapon].ammo == am_noammo)
w_ready.num = &largeammo;
else
w_ready.num = &_g_player.ammo[weaponinfo[_g_player.readyweapon].ammo];
// update keycard multiple widgets
for (i=0;i<3;i++)
{
keyboxes[i] = _g_player.cards[i] ? i : -1;
}
// refresh everything if this is him coming back to life
ST_updateFaceWidget();
}
void ST_Ticker(void)
{
st_randomnumber = M_Random();
ST_updateWidgets();
st_oldhealth = _g_player.health;
}
// Palette indices.
// For damage/bonus red-/gold-shifts
#define STARTREDPALS 1
#define STARTBONUSPALS 9
#define NUMREDPALS 8
#define NUMBONUSPALS 4
// Radiation suit, green shift.
#define RADIATIONPAL 13
void ST_doPaletteStuff(void)
{
int8_t palette;
int16_t cnt = _g_player.damagecount;
if (_g_player.powers[pw_strength])
{
// slowly fade the berzerk out
int16_t bzc = 12 - (_g_player.powers[pw_strength] >> 6);
if (bzc > cnt)
cnt = bzc;
}
if (cnt)
{
palette = (cnt + 7) >> 3;
if (palette >= NUMREDPALS)
palette = NUMREDPALS - 1;
/* cph 2006/08/06 - if in the menu, reduce the red tint - navigating to
* load a game can be tricky if the screen is all red */
if (_g_menuactive)
palette >>= 1;
palette += STARTREDPALS;
}
else if (_g_player.bonuscount)
{
palette = (_g_player.bonuscount + 7) >> 3;
if (palette >= NUMBONUSPALS)
palette = NUMBONUSPALS - 1;
palette += STARTBONUSPALS;
}
else if (_g_player.powers[pw_ironfeet] > 4 * 32 || _g_player.powers[pw_ironfeet] & 8)
palette = RADIATIONPAL;
else
palette = 0;
if (palette != st_palette) {
I_SetPalette(st_palette = palette);
}
}
//
// STlib_updateMultIcon()
//
// Draw a st_multicon_t widget, used for a multigraphic display
// like the status bar's keys. Displays each when the control
// numbers change
//
// Passed a st_multicon_t widget
// Returns nothing.
//
static void STlib_updateMultIcon(st_multicon_t* mi)
{
if(!mi->p)
return;
if (*mi->inum != -1) // killough 2/16/98: redraw only if != -1
V_DrawNumPatchNotScaled(mi->x, mi->y, mi->p[*mi->inum]);
mi->oldinum = *mi->inum;
}
/*
* STlib_drawNum()
*
* A fairly efficient way to draw a number based on differences from the
* old number.
*
* Passed a st_number_t widget
* Returns nothing
*
* jff 2/16/98 add color translation to digit output
* cphipps 10/99 - const pointer to colour trans table, made function static
*/
static void STlib_drawNum(st_number_t* n)
{
int16_t numdigits = n->width;
int16_t num = *n->num;
const int16_t w = V_NumPatchWidth(n->p[0]);
int16_t x = n->x;
// CPhipps - compact some code, use num instead of *n->num
if ((n->oldnum = num) < 0)
{
if (numdigits == 2 && num < -9)
num = -9;
else if (numdigits == 3 && num < -99)
num = -99;
num = -num;
}
// clear the area
x = n->x - numdigits*w;
// if non-number, do not draw it
if (num == largeammo)
return;
x = n->x;
// in the special case of 0, you draw 0
if (!num)
V_DrawNumPatchNotScaled(x - w, n->y, n->p[0]);
// draw the new number
while (num && numdigits--)
{
x -= w;
V_DrawNumPatchNotScaled(x, n->y, n->p[num % 10]);
num /= 10;
}
}
static void ST_drawWidgets(void)
{
STlib_drawNum(&w_ready);
// Restore the ammo numbers for backpack stats I guess, etc ~Kippykip
for (int8_t i = 0; i < 4; i++)
{
STlib_drawNum(&w_ammo[i]);
STlib_drawNum(&w_maxammo[i]);
}
STlib_drawNum(&st_health);
STlib_drawNum(&st_armor);
STlib_updateMultIcon(&w_faces);
for (int8_t i = 0; i < 3 ;i++)
STlib_updateMultIcon(&w_keyboxes[i]);
for (int8_t i = 0; i < 6; i++)
STlib_updateMultIcon(&w_arms[i]);
}
static void ST_refreshBackground(void)
{
static const uint16_t st_offset = (SCREENHEIGHT - ST_HEIGHT) * SCREENWIDTH;
V_DrawRaw(statusbarnum, st_offset);
}
void ST_doRefresh(void)
{
#if !defined DISABLE_STATUS_BAR
// draw status bar background to off-screen buff
ST_refreshBackground();
// and refresh all widgets
ST_drawWidgets();
#endif
}
boolean ST_NeedUpdate(void)
{
// ready weapon ammo
if(w_ready.oldnum != *w_ready.num)
return true;
if(st_health.oldnum != *st_health.num)
return true;
if(st_armor.oldnum != *st_armor.num)
return true;
if(w_faces.oldinum != *w_faces.inum)
return true;
// ammo
for(int8_t i=0; i<4; i++)
{
if(w_ammo[i].oldnum != *w_ammo[i].num)
return true;
if(w_maxammo[i].oldnum != *w_maxammo[i].num)
return true;
}
// weapons owned
for(int8_t i=0; i<6; i++)
{
if(w_arms[i].oldinum != *w_arms[i].inum)
return true;
}
for(int8_t i = 0; i < 3; i++)
{
if(w_keyboxes[i].oldinum != *w_keyboxes[i].inum)
return true;
}
return false;
}
//
// ST_loadData
//
// CPhipps - Loads graphics needed for status bar
//
static void ST_loadData(void)
{
int8_t i, facenum;
char namebuf[9];
statusbarnum = W_GetNumForName("STBAR");
// Load the numbers, tall and short
for (i=0;i<10;i++)
{
sprintf(namebuf, "STGANUM%d", i); //Special GBA Doom II Red Numbers ~Kippykip
tallnum[i] = W_GetNumForName(namebuf);
sprintf(namebuf, "STYSNUM%d", i);
shortnum[i] = W_GetNumForName(namebuf);
}
// key cards
for (i=0;i<NUMCARDS;i++)
{
sprintf(namebuf, "STKEYS%d", i);
keys[i] = W_GetNumForName(namebuf);
}
// arms ownership widgets
for (i=0;i<6;i++)
{
sprintf(namebuf, "STGNUM%d", i+2);
// gray #
arms[i][0] = W_GetNumForName(namebuf);
// yellow #
arms[i][1] = shortnum[i+2];
}
// face states
facenum = 0;
for (i=0;i<ST_NUMPAINFACES;i++)
{
for (int8_t j=0;j<ST_NUMSTRAIGHTFACES;j++)
{
sprintf(namebuf, "STFST%d%d", i, j);
faces[facenum++] = W_GetNumForName(namebuf);
}
sprintf(namebuf, "STFTR%d0", i); // turn right
faces[facenum++] = W_GetNumForName(namebuf);
sprintf(namebuf, "STFTL%d0", i); // turn left
faces[facenum++] = W_GetNumForName(namebuf);
sprintf(namebuf, "STFOUCH%d", i); // ouch!
faces[facenum++] = W_GetNumForName(namebuf);
sprintf(namebuf, "STFEVL%d", i); // evil grin ;)
faces[facenum++] = W_GetNumForName(namebuf);
sprintf(namebuf, "STFKILL%d", i); // pissed off
faces[facenum++] = W_GetNumForName(namebuf);
}
faces[facenum++] = W_GetNumForName("STFGOD0");
faces[facenum++] = W_GetNumForName("STFDEAD0");
}
static void ST_initData(void)
{
int8_t i;
st_faceindex = 0;
st_palette = -1;
st_oldhealth = -1;
for (i=0;i<NUMWEAPONS;i++)
oldweaponsowned[i] = _g_player.weaponowned[i];
for (i=0;i<3;i++)
keyboxes[i] = -1;
}
//
// STlib_initMultIcon()
//
// Initialize a st_multicon_t widget, used for a multigraphic display
// like the status bar's keys.
//
// Passed a st_multicon_t widget, the position, the graphic patches, and a pointer
// to the numbers representing what to display
// Returns nothing.
//
static void STlib_initMultIcon(st_multicon_t* i, int16_t x, int16_t y, int16_t* il, int16_t* inum)
{
i->x = x;
i->y = y;
i->oldinum = -1;
i->inum = inum;
i->p = il;
}
//
// STlib_initNum()
//
// Initializes an st_number_t widget
//
// Passed the widget, its position, the patches for the digits, a pointer
// to the value displayed, and the width
// Returns nothing
//
static void STlib_initNum(st_number_t* n, int16_t x, int16_t y, int16_t* pl, int16_t* num, int16_t width)
{
n->x = x;
n->y = y;
n->oldnum = 0;
n->width = width;
n->num = num;
n->p = pl;
}
static void ST_createWidgets(void)
{
// ready weapon ammo
STlib_initNum(&w_ready, ST_AMMOX, ST_AMMOY, tallnum, &_g_player.ammo[weaponinfo[_g_player.readyweapon].ammo], ST_AMMOWIDTH);
// health percentage
STlib_initNum(&st_health, ST_HEALTHX, ST_HEALTHY, tallnum, &_g_player.health, ST_HEALTHWIDTH);
// armor percentage - should be colored later
STlib_initNum(&st_armor, ST_ARMORX, ST_ARMORY, tallnum, &_g_player.armorpoints, ST_ARMORWIDTH);
// weapons owned
for(int8_t i = 0; i < 6; i++)
{
STlib_initMultIcon(&w_arms[i], ST_ARMSX+(i%3)*ST_ARMSXSPACE, ST_ARMSY+(i/3)*ST_ARMSYSPACE, arms[i], &_g_player.weaponowned[i+1]);
}
// keyboxes 0-2
STlib_initMultIcon(&w_keyboxes[0], ST_KEY0X, ST_KEY0Y, keys, &keyboxes[0]);
STlib_initMultIcon(&w_keyboxes[1], ST_KEY1X, ST_KEY1Y, keys, &keyboxes[1]);
STlib_initMultIcon(&w_keyboxes[2], ST_KEY2X, ST_KEY2Y, keys, &keyboxes[2]);
// ammo count (all four kinds)
STlib_initNum(&w_ammo[0], ST_AMMO0X, ST_AMMO0Y, shortnum, &_g_player.ammo[0], ST_AMMO0WIDTH);
STlib_initNum(&w_ammo[1], ST_AMMO1X, ST_AMMO1Y, shortnum, &_g_player.ammo[1], ST_AMMO1WIDTH);
STlib_initNum(&w_ammo[2], ST_AMMO2X, ST_AMMO2Y, shortnum, &_g_player.ammo[2], ST_AMMO2WIDTH);
STlib_initNum(&w_ammo[3], ST_AMMO3X, ST_AMMO3Y, shortnum, &_g_player.ammo[3], ST_AMMO3WIDTH);
// max ammo count (all four kinds)
STlib_initNum(&w_maxammo[0], ST_MAXAMMO0X, ST_MAXAMMO0Y, shortnum, &_g_player.maxammo[0], ST_MAXAMMO0WIDTH);
STlib_initNum(&w_maxammo[1], ST_MAXAMMO1X, ST_MAXAMMO1Y, shortnum, &_g_player.maxammo[1], ST_MAXAMMO1WIDTH);
STlib_initNum(&w_maxammo[2], ST_MAXAMMO2X, ST_MAXAMMO2Y, shortnum, &_g_player.maxammo[2], ST_MAXAMMO2WIDTH);
STlib_initNum(&w_maxammo[3], ST_MAXAMMO3X, ST_MAXAMMO3Y, shortnum, &_g_player.maxammo[3], ST_MAXAMMO3WIDTH);
// faces
STlib_initMultIcon(&w_faces, ST_FACESX, ST_FACESY, faces, &st_faceindex);
}
static boolean st_stopped = true;
void ST_Start(void)
{
if (!st_stopped)
ST_Stop();
ST_initData();
ST_createWidgets();
st_stopped = false;
}
static void ST_Stop(void)
{
if (st_stopped)
return;
I_SetPalette(0);
st_stopped = true;
}
void ST_Init(void)
{
ST_loadData();
}