| 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 Ammo Text HUD Component |
| 16 |
// |
| 17 |
|
| 18 |
#include "base.h" |
| 19 |
|
| 20 |
#include "ammo_text.h" |
| 21 |
|
| 22 |
typedef struct { |
| 23 |
dsda_text_t component[6]; |
| 24 |
dboolean show_names; |
| 25 |
} local_component_t; |
| 26 |
|
| 27 |
static local_component_t* local; |
| 28 |
|
| 29 |
typedef struct { |
| 30 |
const char** ammo_name; |
| 31 |
const int* ammo_type; |
| 32 |
const int count; |
| 33 |
} ammo_component_config_t; |
| 34 |
|
| 35 |
static const char* doom_ammo_name[4] = { |
| 36 |
"BULL", |
| 37 |
"SHEL", |
| 38 |
"RCKT", |
| 39 |
"CELL", |
| 40 |
}; |
| 41 |
|
| 42 |
static const int doom_ammo_type[4] = { 0, 1, 3, 2 }; |
| 43 |
|
| 44 |
static const char* heretic_ammo_name[6] = { |
| 45 |
"CRYS", |
| 46 |
"BOLT", |
| 47 |
"CLAW", |
| 48 |
"RUNE", |
| 49 |
"FLAM", |
| 50 |
"MACE", |
| 51 |
}; |
| 52 |
|
| 53 |
static const int heretic_ammo_type[6] = { 0, 1, 2, 3, 4, 5 }; |
| 54 |
|
| 55 |
static const char* hexen_ammo_name[2] = { |
| 56 |
"BLUE", |
| 57 |
"GREN", |
| 58 |
}; |
| 59 |
|
| 60 |
static const int hexen_ammo_type[2] = { 0, 1 }; |
| 61 |
|
| 62 |
static const ammo_component_config_t doom_ammo = { doom_ammo_name, doom_ammo_type, 4 }; |
| 63 |
static const ammo_component_config_t heretic_ammo = { heretic_ammo_name, heretic_ammo_type, 6 }; |
| 64 |
static const ammo_component_config_t hexen_ammo = { hexen_ammo_name, hexen_ammo_type, 2 }; |
| 65 |
|
| 66 |
static const ammo_component_config_t* component_config; |
| 67 |
|
| 68 |
static void dsda_UpdateComponentText(char* str, size_t max_size, int i) { |
| 69 |
player_t* player; |
| 70 |
int current_ammo, max_ammo; |
| 71 |
const char* name; |
| 72 |
|
| 73 |
player = &players[displayplayer]; |
| 74 |
name = component_config->ammo_name[i]; |
| 75 |
i = component_config->ammo_type[i]; |
| 76 |
current_ammo = player->ammo[i]; |
| 77 |
max_ammo = hexen ? MAX_MANA : player->maxammo[i]; |
| 78 |
|
| 79 |
if (local->show_names) |
| 80 |
snprintf( |
| 81 |
str, |
| 82 |
max_size, |
| 83 |
"%s%s %s%3d\x1b\x01/\x1b\x01%3d", |
| 84 |
dsda_TextColor(dsda_tc_exhud_ammo_label), |
| 85 |
name, |
| 86 |
dsda_TextColor(dsda_tc_exhud_ammo_value), |
| 87 |
current_ammo, |
| 88 |
max_ammo |
| 89 |
); |
| 90 |
else |
| 91 |
snprintf( |
| 92 |
str, |
| 93 |
max_size, |
| 94 |
"%s%3d\x1b\x01/\x1b\x01%3d", |
| 95 |
dsda_TextColor(dsda_tc_exhud_ammo_value), |
| 96 |
current_ammo, |
| 97 |
max_ammo |
| 98 |
); |
| 99 |
} |
| 100 |
|
| 101 |
void dsda_InitAmmoTextHC(int x_offset, int y_offset, int vpt, int* args, int arg_count, void** data) { |
| 102 |
int i; |
| 103 |
int y_delta; |
| 104 |
|
| 105 |
*data = Z_Calloc(1, sizeof(local_component_t)); |
| 106 |
local = *data; |
| 107 |
|
| 108 |
if (arg_count > 0) |
| 109 |
local->show_names = args[0]; |
| 110 |
else |
| 111 |
local->show_names = true; |
| 112 |
|
| 113 |
if (heretic) |
| 114 |
component_config = &heretic_ammo; |
| 115 |
else if (hexen) |
| 116 |
component_config = &hexen_ammo; |
| 117 |
else |
| 118 |
component_config = &doom_ammo; |
| 119 |
|
| 120 |
y_delta = BOTTOM_ALIGNMENT(vpt & VPT_ALIGN_MASK) ? -8 : 8; |
| 121 |
|
| 122 |
for (i = 0; i < component_config->count; ++i) |
| 123 |
dsda_InitTextHC(&local->component[i], x_offset, y_offset + i * y_delta, vpt); |
| 124 |
} |
| 125 |
|
| 126 |
void dsda_UpdateAmmoTextHC(void* data) { |
| 127 |
int i; |
| 128 |
|
| 129 |
local = data; |
| 130 |
|
| 131 |
for (i = 0; i < component_config->count; ++i) { |
| 132 |
dsda_UpdateComponentText(local->component[i].msg, sizeof(local->component[i].msg), i); |
| 133 |
dsda_RefreshHudText(&local->component[i]); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
void dsda_DrawAmmoTextHC(void* data) { |
| 138 |
int i; |
| 139 |
|
| 140 |
local = data; |
| 141 |
|
| 142 |
for (i = 0; i < component_config->count; ++i) |
| 143 |
dsda_DrawBasicText(&local->component[i]); |
| 144 |
} |