From 7b78a8c019579666613b46acbd4dd7121ec590dc Mon Sep 17 00:00:00 2001 From: josteph Date: Fri, 14 Jun 2019 12:50:56 +0000 Subject: [PATCH] statistics_dialog: Change the hits table format to "1703.2 + 42 | 93.6" This is "Option B" from https://forums.wesnoth.org/viewtopic.php?f=12&t=49785&p=643513#p643495 --- data/gui/window/statistics_dialog.cfg | 6 ++++-- src/gui/dialogs/statistics_dialog.cpp | 13 +++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/data/gui/window/statistics_dialog.cfg b/data/gui/window/statistics_dialog.cfg index 8435dd23e18c..e4b9871447fc 100644 --- a/data/gui/window/statistics_dialog.cfg +++ b/data/gui/window/statistics_dialog.cfg @@ -547,7 +547,8 @@ {_GUI_DAMAGE_STATS_LIST (_ "Damage") damage_this_turn_header stats_list_damage damage_type damage_overall damage_this_turn - (_"stats dialog^Amount of hitpoints (actual / expected)") + (_"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^Ratio of actual to expected")} [/column] @@ -564,7 +565,8 @@ {_GUI_DAMAGE_STATS_LIST (_ "Hits") hits_this_turn_header stats_list_hits hits_type hits_overall hits_this_turn - (_"stats dialog^Number of hits (actual / expected)") + (_"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^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.")} diff --git a/src/gui/dialogs/statistics_dialog.cpp b/src/gui/dialogs/statistics_dialog.cpp index 93522f6cb9e2..bc0ad7773b6e 100644 --- a/src/gui/dialogs/statistics_dialog.cpp +++ b/src/gui/dialogs/statistics_dialog.cpp @@ -129,6 +129,15 @@ void statistics_dialog::add_stat_row(window& window, const std::string& type, co main_stat_table_.push_back(&value); } +// Generate the string for the "A + B" column of the damage and hits tables. +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(std::round(std::abs(expected - actual))); + return str; +} + void statistics_dialog::add_damage_row( window& window, const std::string& type, @@ -154,7 +163,7 @@ void statistics_dialog::add_damage_row( const auto damage_str = [shift](long long damage, long long expected) { const long long shifted = ((expected * 20) + shift) / (2 * shift); std::ostringstream str; - str << damage << " / " << static_cast(shifted) * 0.1; + write_actual_and_expected(str, damage, static_cast(shifted) * 0.1); return str.str(); }; item["label"] = damage_str(damage, expected); @@ -211,7 +220,7 @@ static hitrate_table_element tally(const statistics::stats::hitrate_map& by_cth, } std::ostringstream str, str2; - str << overall_hits << " / " << expected_hits; + write_actual_and_expected(str, overall_hits, expected_hits); // Compute the a priori probability of this actual result, by simulating many attacks against a single defender. {