statistics_dialog: Restore color in the hits table

The color scale is reversed between Taken and Inflicted:

Row           Color of "hitting less than actual"    Color of "hitting more than actual"
---           -----------------------------------    -----------------------------------
Inflicted     green to red                           red to green
Taken         red to green                           green to red

This way, in both rows green means "It could have been better" and red
means "It could have been worse". Basically, green means the RNG
favored the enemy sides, and red means the RNG favored the current side.

The _a priori_ probability of the actual result is intentionally left uncolored.
This commit is contained in:
josteph 2019-05-19 22:30:49 +00:00
parent a932ebee58
commit 061edc2bb3
2 changed files with 16 additions and 8 deletions

View file

@ -189,7 +189,7 @@ struct hitrate_table_element {
};
// Return the strings to use in the "Hits" table, showing actual and expected number of hits.
static hitrate_table_element tally(const statistics::stats::hitrate_map& by_cth)
static hitrate_table_element tally(const statistics::stats::hitrate_map& by_cth, const bool more_is_better)
{
unsigned int overall_hits = 0;
double expected_hits = 0;
@ -265,13 +265,17 @@ static hitrate_table_element tally(const statistics::stats::hitrate_map& by_cth)
// Start of turn
str2 << "0%";
} else {
// TODO: add coloring
const auto& add_probability = [&str2](double probability, bool more_is_better) {
str2 << font::span_color(game_config::red_to_green((more_is_better ? probability : 1.0 - probability) * 100.0, true))
<< get_probability_string(probability) << "</span>";
};
// TODO: document for users what these values are.
str2 << get_probability_string(probability_lt);
add_probability(probability_lt, !more_is_better);
str2 << ", ";
str2 << get_probability_string(probability_eq);
str2 << ", ";
str2 << get_probability_string(probability_gt);
add_probability(probability_gt, more_is_better);
}
}
@ -281,6 +285,7 @@ static hitrate_table_element tally(const statistics::stats::hitrate_map& by_cth)
void statistics_dialog::add_hits_row(
window& window,
const std::string& type,
const bool more_is_better,
const statistics::stats::hitrate_map& by_cth,
const statistics::stats::hitrate_map& turn_by_cth,
const bool show_this_turn)
@ -295,14 +300,14 @@ void statistics_dialog::add_hits_row(
item["label"] = type;
data.emplace("hits_type", item);
element = tally(by_cth);
element = tally(by_cth, more_is_better);
item["label"] = element.hitrate_str;
data.emplace("hits_overall", item);
item["label"] = element.percentage_str;
data.emplace("overall_percent", item);
if(show_this_turn) {
element = tally(turn_by_cth);
element = tally(turn_by_cth, more_is_better);
item["label"] = element.hitrate_str;
data.emplace("hits_this_turn", item);
item["label"] = element.percentage_str;
@ -358,7 +363,7 @@ void statistics_dialog::update_lists(window& window)
stats.turn_expected_damage_inflicted,
show_this_turn
);
add_hits_row(window, _("Inflicted"),
add_hits_row(window, _("Inflicted"), true,
stats.by_cth_inflicted,
stats.turn_by_cth_inflicted,
show_this_turn
@ -371,7 +376,7 @@ void statistics_dialog::update_lists(window& window)
stats.turn_expected_damage_taken,
show_this_turn
);
add_hits_row(window, _("Taken"),
add_hits_row(window, _("Taken"), false,
stats.by_cth_taken,
stats.turn_by_cth_taken,
show_this_turn

View file

@ -56,9 +56,12 @@ private:
const bool show_this_turn);
/// Add a row to the Hits table
///
/// @param more_is_better True for "Inflicted" and false for "Taken". Affects coloring.
void add_hits_row(
window& window,
const std::string& type,
const bool more_is_better,
const statistics::stats::hitrate_map& by_cth,
const statistics::stats::hitrate_map& turn_by_cth,
const bool show_this_turn);