Debian Codegraph @

prboom2/src/dsda/hud_components/big_health.c

raw
1 //
2 // Copyright(C) 2022 by Ryan Krafnick
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // DESCRIPTION:
15 // DSDA Big Health HUD Component
16 //
17
18 #include "base.h"
19
20 #include "big_health.h"
21
22 #define PATCH_DELTA_X 14
23 #define PATCH_SPACING 2
24 #define PATCH_VERTICAL_SPACING 2
25
26 typedef struct {
27 dsda_patch_component_t component;
28 } local_component_t;
29
30 static local_component_t* local;
31
32 static int health_lump;
33 static int strength_lump;
34 static int patch_delta_x;
35 static int patch_vertical_spacing;
36 static int patch_spacing;
37
38 static void dsda_DrawComponent(void) {
39 player_t* player;
40 int health;
41 int x, y;
42 int cm;
43
44 player = &players[displayplayer];
45 x = local->component.x;
46 y = local->component.y;
47
48 cm = player->health <= hud_health_red ? dsda_TextCR(dsda_tc_stbar_health_bad) :
49 player->health <= hud_health_yellow ? dsda_TextCR(dsda_tc_stbar_health_warning) :
50 player->health <= hud_health_green ? dsda_TextCR(dsda_tc_stbar_health_ok) :
51 dsda_TextCR(dsda_tc_stbar_health_super);
52
53 V_DrawNumPatch(x, y, FG,
54 player->powers[pw_strength] ? strength_lump : health_lump,
55 CR_DEFAULT, local->component.vpt);
56
57 x += patch_spacing;
58 y += patch_vertical_spacing;
59
60 health = player->health < 0 ? 0 : player->health;
61
62 dsda_DrawBigNumber(x, y, patch_delta_x, 0,
63 cm, local->component.vpt, 3, health);
64 }
65
66 void dsda_InitBigHealthHC(int x_offset, int y_offset, int vpt, int* args, int arg_count, void** data) {
67 *data = Z_Calloc(1, sizeof(local_component_t));
68 local = *data;
69
70 if (heretic) {
71 health_lump = R_NumPatchForSpriteIndex(HERETIC_SPR_PTN2);
72 strength_lump = health_lump;
73 patch_delta_x = 10;
74 patch_vertical_spacing = 6;
75 patch_spacing = 4;
76 }
77 else if (hexen) {
78 health_lump = R_NumPatchForSpriteIndex(HEXEN_SPR_PTN2);
79 strength_lump = health_lump;
80 patch_delta_x = 10;
81 patch_vertical_spacing = 6;
82 patch_spacing = 4;
83 }
84 else {
85 health_lump = R_NumPatchForSpriteIndex(SPR_MEDI);
86 strength_lump = R_NumPatchForSpriteIndex(SPR_PSTR);
87 patch_delta_x = 14;
88 patch_vertical_spacing = 2;
89 patch_spacing = 2;
90 }
91 patch_spacing += R_NumPatchWidth(health_lump);
92 dsda_InitPatchHC(&local->component, x_offset, y_offset, vpt);
93 }
94
95 void dsda_UpdateBigHealthHC(void* data) {
96 local = data;
97 }
98
99 void dsda_DrawBigHealthHC(void* data) {
100 local = data;
101
102 dsda_DrawComponent();
103 }