Debian Codegraph @

prboom2/src/dsda/hud_components/big_ammo.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 Ammo HUD Component
16 //
17
18 #include "base.h"
19
20 #include "big_ammo.h"
21
22 #define PATCH_DELTA_X 14
23
24 typedef struct {
25 dsda_patch_component_t component;
26 } local_component_t;
27
28 static local_component_t* local;
29
30 int dsda_AmmoColorBig(player_t* player) {
31 int ammo_percent;
32
33 ammo_percent = P_AmmoPercent(player, player->readyweapon);
34
35 if (ammo_percent < hud_ammo_red)
36 return dsda_tc_stbar_ammo_bad;
37 else if (ammo_percent < hud_ammo_yellow)
38 return dsda_tc_stbar_ammo_warning;
39 else if (ammo_percent < 100)
40 return dsda_tc_stbar_ammo_ok;
41 else
42 return dsda_tc_stbar_ammo_full;
43 }
44
45 static void dsda_DrawComponent(void) {
46 player_t* player;
47 ammotype_t ammo_type;
48 int ammo;
49
50 if (hexen)
51 return;
52
53 player = &players[displayplayer];
54 ammo_type = weaponinfo[player->readyweapon].ammo;
55
56 if (ammo_type == am_noammo || !player->maxammo[ammo_type])
57 return;
58
59 ammo = player->ammo[ammo_type];
60
61 dsda_DrawBigNumber(local->component.x, local->component.y, PATCH_DELTA_X, 0,
62 dsda_TextCR(dsda_AmmoColorBig(player)), local->component.vpt, 3, ammo);
63 }
64
65 void dsda_InitBigAmmoHC(int x_offset, int y_offset, int vpt, int* args, int arg_count, void** data) {
66 *data = Z_Calloc(1, sizeof(local_component_t));
67 local = *data;
68
69 dsda_InitPatchHC(&local->component, x_offset, y_offset, vpt);
70 }
71
72 void dsda_UpdateBigAmmoHC(void* data) {
73 local = data;
74 }
75
76 void dsda_DrawBigAmmoHC(void* data) {
77 local = data;
78
79 dsda_DrawComponent();
80 }