| 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 Stat Totals HUD Component |
| 16 |
// |
| 17 |
|
| 18 |
#include "dsda/skill_info.h" |
| 19 |
|
| 20 |
#include "base.h" |
| 21 |
|
| 22 |
#include "stat_totals.h" |
| 23 |
|
| 24 |
typedef struct { |
| 25 |
dsda_text_t component; |
| 26 |
dboolean include_kills, include_items, include_secrets; |
| 27 |
dboolean hide_totals; |
| 28 |
const char* label_k; |
| 29 |
const char* label_i; |
| 30 |
const char* label_s; |
| 31 |
const char* stat_separator; |
| 32 |
} local_component_t; |
| 33 |
|
| 34 |
static local_component_t* local; |
| 35 |
|
| 36 |
static void dsda_UpdateComponentText(char* str, size_t max_size) { |
| 37 |
int i; |
| 38 |
size_t length; |
| 39 |
int fullkillcount, fullitemcount, fullsecretcount; |
| 40 |
const char* killcolor; |
| 41 |
const char* itemcolor; |
| 42 |
const char* secretcolor; |
| 43 |
int kill_percent_count; |
| 44 |
int max_kill_requirement; |
| 45 |
|
| 46 |
length = 0; |
| 47 |
fullkillcount = 0; |
| 48 |
fullitemcount = 0; |
| 49 |
fullsecretcount = 0; |
| 50 |
kill_percent_count = 0; |
| 51 |
max_kill_requirement = dsda_MaxKillRequirement(); |
| 52 |
|
| 53 |
for (i = 0; i < g_maxplayers; ++i) { |
| 54 |
if (playeringame[i]) { |
| 55 |
fullkillcount += players[i].killcount - players[i].maxkilldiscount; |
| 56 |
fullitemcount += players[i].itemcount; |
| 57 |
fullsecretcount += players[i].secretcount; |
| 58 |
kill_percent_count += players[i].killcount; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
if (skill_info.respawn_time) { |
| 63 |
fullkillcount = kill_percent_count; |
| 64 |
max_kill_requirement = totalkills; |
| 65 |
} |
| 66 |
|
| 67 |
killcolor = (fullkillcount >= max_kill_requirement ? dsda_TextColor(dsda_tc_exhud_totals_max) : |
| 68 |
dsda_TextColor(dsda_tc_exhud_totals_value)); |
| 69 |
secretcolor = (fullsecretcount >= totalsecret ? dsda_TextColor(dsda_tc_exhud_totals_max) : |
| 70 |
dsda_TextColor(dsda_tc_exhud_totals_value)); |
| 71 |
itemcolor = (fullitemcount >= totalitems ? dsda_TextColor(dsda_tc_exhud_totals_max) : |
| 72 |
dsda_TextColor(dsda_tc_exhud_totals_value)); |
| 73 |
|
| 74 |
if (local->include_kills) { |
| 75 |
if (!local->hide_totals || fullkillcount >= max_kill_requirement) |
| 76 |
length += snprintf( |
| 77 |
str, |
| 78 |
max_size, |
| 79 |
"%s%s%s%d/%d%s", |
| 80 |
dsda_TextColor(dsda_tc_exhud_totals_label), |
| 81 |
local->label_k, |
| 82 |
killcolor, fullkillcount, max_kill_requirement, |
| 83 |
local->stat_separator |
| 84 |
); |
| 85 |
else |
| 86 |
length += snprintf( |
| 87 |
str, |
| 88 |
max_size, |
| 89 |
"%s%s%s%d%s", |
| 90 |
dsda_TextColor(dsda_tc_exhud_totals_label), |
| 91 |
local->label_k, |
| 92 |
killcolor, fullkillcount, |
| 93 |
local->stat_separator |
| 94 |
); |
| 95 |
} |
| 96 |
|
| 97 |
if (local->include_items) { |
| 98 |
if (!local->hide_totals || fullitemcount >= totalitems) |
| 99 |
length += snprintf( |
| 100 |
str + length, |
| 101 |
max_size - length, |
| 102 |
"%s%s%s%d/%d%s", |
| 103 |
dsda_TextColor(dsda_tc_exhud_totals_label), |
| 104 |
local->label_i, |
| 105 |
itemcolor, fullitemcount, totalitems, |
| 106 |
local->stat_separator |
| 107 |
); |
| 108 |
else |
| 109 |
length += snprintf( |
| 110 |
str + length, |
| 111 |
max_size - length, |
| 112 |
"%s%s%s%d%s", |
| 113 |
dsda_TextColor(dsda_tc_exhud_totals_label), |
| 114 |
local->label_i, |
| 115 |
itemcolor, fullitemcount, |
| 116 |
local->stat_separator |
| 117 |
); |
| 118 |
} |
| 119 |
|
| 120 |
if (local->include_secrets) { |
| 121 |
if (!local->hide_totals || fullsecretcount >= totalsecret) |
| 122 |
snprintf( |
| 123 |
str + length, |
| 124 |
max_size - length, |
| 125 |
"%s%s%s%d/%d", |
| 126 |
dsda_TextColor(dsda_tc_exhud_totals_label), |
| 127 |
local->label_s, |
| 128 |
secretcolor, fullsecretcount, totalsecret |
| 129 |
); |
| 130 |
else |
| 131 |
snprintf( |
| 132 |
str + length, |
| 133 |
max_size - length, |
| 134 |
"%s%s%s%d", |
| 135 |
dsda_TextColor(dsda_tc_exhud_totals_label), |
| 136 |
local->label_s, |
| 137 |
secretcolor, fullsecretcount |
| 138 |
); |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
void dsda_InitStatTotalsHC(int x_offset, int y_offset, int vpt, int* args, int arg_count, void** data) { |
| 143 |
*data = Z_Calloc(1, sizeof(local_component_t)); |
| 144 |
local = *data; |
| 145 |
|
| 146 |
local->include_kills = args[0]; |
| 147 |
local->include_items = args[1]; |
| 148 |
local->include_secrets = args[2]; |
| 149 |
|
| 150 |
// vertical orientation |
| 151 |
local->stat_separator = args[3] ? "\n" : " "; |
| 152 |
|
| 153 |
if (arg_count < 5 || args[4]) { |
| 154 |
local->label_k = "K "; |
| 155 |
local->label_i = "I "; |
| 156 |
local->label_s = "S "; |
| 157 |
} |
| 158 |
else { |
| 159 |
local->label_k = ""; |
| 160 |
local->label_i = ""; |
| 161 |
local->label_s = ""; |
| 162 |
} |
| 163 |
|
| 164 |
local->hide_totals = args[5]; |
| 165 |
|
| 166 |
if (!local->include_kills && !local->include_items && !local->include_secrets) { |
| 167 |
local->include_kills = local->include_items = local->include_secrets = true; |
| 168 |
} |
| 169 |
|
| 170 |
dsda_InitTextHC(&local->component, x_offset, y_offset, vpt); |
| 171 |
} |
| 172 |
|
| 173 |
void dsda_UpdateStatTotalsHC(void* data) { |
| 174 |
local = data; |
| 175 |
|
| 176 |
dsda_UpdateComponentText(local->component.msg, sizeof(local->component.msg)); |
| 177 |
dsda_RefreshHudText(&local->component); |
| 178 |
} |
| 179 |
|
| 180 |
void dsda_DrawStatTotalsHC(void* data) { |
| 181 |
local = data; |
| 182 |
|
| 183 |
dsda_DrawBasicText(&local->component); |
| 184 |
} |