Debian Codegraph @

prboom2/src/dsda/hud_components/map_totals.c

raw
1 //
2 // Copyright(C) 2023 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 Map Totals HUD Component
16 //
17
18 #include "dsda/skill_info.h"
19
20 #include "base.h"
21
22 #include "map_totals.h"
23
24 typedef struct {
25 dsda_text_t component;
26 dboolean include_kills, include_items, include_secrets;
27 dboolean hide_totals;
28 } local_component_t;
29
30 static local_component_t* local;
31
32 static void dsda_UpdateComponentText(char* str, size_t max_size) {
33 int i;
34 size_t length;
35 int fullkillcount, fullitemcount, fullsecretcount;
36 const char* killcolor;
37 const char* itemcolor;
38 const char* secretcolor;
39 int kill_percent_count;
40 int max_kill_requirement;
41
42 length = 0;
43 fullkillcount = 0;
44 fullitemcount = 0;
45 fullsecretcount = 0;
46 kill_percent_count = 0;
47 max_kill_requirement = dsda_MaxKillRequirement();
48
49 for (i = 0; i < g_maxplayers; ++i) {
50 if (playeringame[i]) {
51 fullkillcount += players[i].killcount - players[i].maxkilldiscount;
52 fullitemcount += players[i].itemcount;
53 fullsecretcount += players[i].secretcount;
54 kill_percent_count += players[i].killcount;
55 }
56 }
57
58 if (skill_info.respawn_time) {
59 fullkillcount = kill_percent_count;
60 max_kill_requirement = totalkills;
61 }
62
63 killcolor = (fullkillcount >= max_kill_requirement ? dsda_TextColor(dsda_tc_map_totals_max) :
64 dsda_TextColor(dsda_tc_map_totals_value));
65 secretcolor = (fullsecretcount >= totalsecret ? dsda_TextColor(dsda_tc_map_totals_max) :
66 dsda_TextColor(dsda_tc_map_totals_value));
67 itemcolor = (fullitemcount >= totalitems ? dsda_TextColor(dsda_tc_map_totals_max) :
68 dsda_TextColor(dsda_tc_map_totals_value));
69
70 if (local->include_kills) {
71 if (!local->hide_totals || fullkillcount >= max_kill_requirement)
72 length += snprintf(
73 str,
74 max_size,
75 "%sMonsters: %s%d/%d\n",
76 dsda_TextColor(dsda_tc_map_totals_label),
77 killcolor, fullkillcount, max_kill_requirement
78 );
79 else
80 length += snprintf(
81 str,
82 max_size,
83 "%sMonsters: %s%d\n",
84 dsda_TextColor(dsda_tc_map_totals_label),
85 killcolor, fullkillcount
86 );
87 }
88
89 if (local->include_secrets) {
90 if (!local->hide_totals || fullsecretcount >= totalsecret)
91 length += snprintf(
92 str + length,
93 max_size - length,
94 "%sSecrets: %s%d/%d\n",
95 dsda_TextColor(dsda_tc_map_totals_label),
96 secretcolor, fullsecretcount, totalsecret
97 );
98 else
99 length += snprintf(
100 str + length,
101 max_size - length,
102 "%sSecrets: %s%d\n",
103 dsda_TextColor(dsda_tc_map_totals_label),
104 secretcolor, fullsecretcount
105 );
106 }
107
108 if (local->include_items) {
109 if (!local->hide_totals || fullitemcount >= totalitems)
110 snprintf(
111 str + length,
112 max_size - length,
113 "%sItems: %s%d/%d",
114 dsda_TextColor(dsda_tc_map_totals_label),
115 itemcolor, fullitemcount, totalitems
116 );
117 else
118 snprintf(
119 str + length,
120 max_size - length,
121 "%sItems: %s%d",
122 dsda_TextColor(dsda_tc_map_totals_label),
123 itemcolor, fullitemcount
124 );
125 }
126 }
127
128 void dsda_InitMapTotalsHC(int x_offset, int y_offset, int vpt, int* args, int arg_count, void** data) {
129 *data = Z_Calloc(1, sizeof(local_component_t));
130 local = *data;
131
132 local->include_kills = args[0];
133 local->include_items = args[1];
134 local->include_secrets = args[2];
135
136 local->hide_totals = args[3];
137
138 if (!local->include_kills && !local->include_items && !local->include_secrets)
139 local->include_kills = local->include_items = local->include_secrets = true;
140
141 dsda_InitBlockyHC(&local->component, x_offset, y_offset, vpt);
142 }
143
144 void dsda_UpdateMapTotalsHC(void* data) {
145 local = data;
146
147 dsda_UpdateComponentText(local->component.msg, sizeof(local->component.msg));
148 dsda_RefreshHudText(&local->component);
149 }
150
151 void dsda_DrawMapTotalsHC(void* data) {
152 local = data;
153
154 dsda_DrawBasicText(&local->component);
155 }