statistics_dialog: Change the hits table format to "+2% (1703.2 + 42) | 93.6"

This is a mix of "Option B" and "Option C" from
https://forums.wesnoth.org/viewtopic.php?f=12&t=49785&p=643513#p643495
This commit is contained in:
josteph 2019-06-14 13:14:29 +00:00
parent 7b78a8c019
commit a3efd28010
2 changed files with 19 additions and 17 deletions

View file

@ -216,6 +216,7 @@
horizontal_grow = false
[label]
# This column is empty in the damage table
id = "overall_percent"
definition = "default_small"
text_alignment = "right"
@ -265,6 +266,7 @@
horizontal_grow = false
[label]
# This column is empty in the damage table
id = "this_turn_percent"
definition = "default_small"
text_alignment = "right"
@ -547,8 +549,9 @@
{_GUI_DAMAGE_STATS_LIST
(_ "Damage") damage_this_turn_header stats_list_damage damage_type damage_overall damage_this_turn
(_"stats dialog^The first number is the expected number of hitpoints.
The sum (or difference) of the two numbers is the actual number of hitpoints.")
(_"stats dialog^Difference of actual outcome to expected outcome, as a percentage.
The first number in parentheses is the expected number of hitpoints.
The sum (or difference) of the two numbers in parentheses is the actual number of hitpoints.")
(_"stats dialog^Ratio of actual to expected")}
[/column]
@ -565,8 +568,9 @@ The sum (or difference) of the two numbers is the actual number of hitpoints.")
{_GUI_DAMAGE_STATS_LIST
(_ "Hits") hits_this_turn_header stats_list_hits hits_type hits_overall hits_this_turn
(_"stats dialog^The first number is the expected number of hits.
The sum (or difference) of the two numbers is the actual number of hits.")
(_"stats dialog^Difference of actual outcome to expected outcome, as a percentage.
The first number in parentheses is the expected number of hits.
The sum (or difference) of the two numbers in parentheses is the actual number of hits.")
(_"stats dialog^Estimate of how much randomness of battles favored or disfavored this side.
Values between 0 and 50 suggest the number of hits was less than expected.
Values between 50 and 100 suggest the number of hits was more than expected.")}

View file

@ -133,8 +133,14 @@ void statistics_dialog::add_stat_row(window& window, const std::string& type, co
static std::ostream& write_actual_and_expected(std::ostream& str, const long long actual, const double expected)
{
// This is displayed as a sum or difference, not as "actual/expected", to prevent the string in the next column, str2.str(), from being mistaken for the result of the division.
str << expected << (actual >= expected ? " + " : " ")
<< static_cast<unsigned int>(std::round(std::abs(expected - actual)));
if(expected == 0) {
str << "+0% (0 + 0)";
} else {
str << (formatter() << std::showpos << std::round((actual - expected) * 100 / expected) << "% (").str();
str << expected << (actual >= expected ? " + " : " ")
<< static_cast<unsigned int>(std::round(std::abs(expected - actual)));
str << ')';
}
return str;
}
@ -157,25 +163,17 @@ void statistics_dialog::add_damage_row(
const int shift = statistics::stats::decimal_shift;
const long long dsa = shift * damage - expected;
const long long dst = shift * turn_damage - turn_expected;
const auto damage_str = [shift](long long damage, long long expected) {
const long long shifted = ((expected * 20) + shift) / (2 * shift);
std::ostringstream str;
write_actual_and_expected(str, damage, static_cast<double>(shifted) * 0.1);
return str.str();
};
item["label"] = damage_str(damage, expected);
data.emplace("damage_overall", item);
const auto percent_str = [](long long dsx, long long expected) {
std::ostringstream str;
str << (((dsx < 0) ^ (expected < 0)) ? "" : "+")
<< (expected == 0 ? 0 : 100 * dsx / expected) << '%';
return str.str();
};
item["label"] = percent_str(dsa, expected);
item["label"] = "";
data.emplace("overall_percent", item);
if(show_this_turn) {
@ -185,7 +183,7 @@ void statistics_dialog::add_damage_row(
item["label"] = damage_str(turn_damage, turn_expected);
data.emplace("damage_this_turn", item);
item["label"] = percent_str(dst, turn_expected);
item["label"] = "";
data.emplace("this_turn_percent", item);
} else {
// TODO: Setting the label to "" causes "This Turn" not to be drawn when changing back to the current scenraio view, so set the label to " " (a single space) instead.