mail[Wesnoth-commits] r33488 - in /trunk/src: actions.cpp statistics.cpp statistics.hpp statistics_dialog.cpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by guillaume . melquiond on March 09, 2009 - 19:17:
Author: silene
Date: Mon Mar  9 19:17:10 2009
New Revision: 33488

URL: http://svn.gna.org/viewcvs/wesnoth?rev=33488&view=rev
Log:
Fixed display of negative "expected" values. Cleaned code and fixed typos.

Modified:
    trunk/src/actions.cpp
    trunk/src/statistics.cpp
    trunk/src/statistics.hpp
    trunk/src/statistics_dialog.cpp

Modified: trunk/src/actions.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/actions.cpp?rev=33488&r1=33487&r2=33488&view=diff
==============================================================================
--- trunk/src/actions.cpp (original)
+++ trunk/src/actions.cpp Mon Mar  9 19:17:10 2009
@@ -962,7 +962,7 @@
                const double attacker_inflict = 
static_cast<double>(d_.get_unit().hitpoints()) - defender.average_hp();
                const double defender_inflict = 
static_cast<double>(a_.get_unit().hitpoints()) - attacker.average_hp();
 
-               
attack_stats.attack_excepted_damage(attacker_inflict,defender_inflict);
+               
attack_stats.attack_expected_damage(attacker_inflict,defender_inflict);
        }
 
        a_.orig_attacks_ = a_stats_->num_blows;

Modified: trunk/src/statistics.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/statistics.cpp?rev=33488&r1=33487&r2=33488&view=diff
==============================================================================
--- trunk/src/statistics.cpp (original)
+++ trunk/src/statistics.cpp Mon Mar  9 19:17:10 2009
@@ -87,10 +87,10 @@
 
 } // end anon namespace
 
-static stats& get_stats(std::string save_id)
+static stats &get_stats(const std::string &save_id)
 {
        if(master_stats.empty()) {
-               master_stats.push_back(scenario_stats(""));
+               master_stats.push_back(scenario_stats(std::string()));
        }
 
        std::map<std::string,stats>& team_stats = 
master_stats.back().team_stats;
@@ -504,96 +504,101 @@
        return get_stats(defender_side);
 }
 
-void attack_context::attack_excepted_damage(double attacker_inflict_, double 
defender_inflict_)
-{
-       const long long attacker_inflict = static_cast<long 
long>(attacker_inflict_ * stats::desimal_shift);
-       const long long defender_inflict = static_cast<long 
long>(defender_inflict_ * stats::desimal_shift);
-       attacker_stats().new_expected_damage_inflicted  += attacker_inflict;
-       attacker_stats().new_expected_damage_taken      += defender_inflict;
-       defender_stats().new_expected_damage_inflicted  += defender_inflict;
-       defender_stats().new_expected_damage_taken      += attacker_inflict;
-       attacker_stats().new_turn_expected_damage_inflicted += 
attacker_inflict;
-       attacker_stats().new_turn_expected_damage_taken     += 
defender_inflict;
-       defender_stats().new_turn_expected_damage_inflicted += 
defender_inflict;
-       defender_stats().new_turn_expected_damage_taken     += 
attacker_inflict;
-}
-
-
-void attack_context::attack_result(attack_context::ATTACK_RESULT res, long 
long damage, long long drain)
+void attack_context::attack_expected_damage(double attacker_inflict_, double 
defender_inflict_)
+{
+       int attacker_inflict = static_cast<int>(attacker_inflict_ * 
stats::decimal_shift);
+       int defender_inflict = static_cast<int>(defender_inflict_ * 
stats::decimal_shift);
+       stats &att_stats = attacker_stats(), &def_stats = defender_stats();
+       att_stats.new_expected_damage_inflicted += attacker_inflict;
+       att_stats.new_expected_damage_taken     += defender_inflict;
+       def_stats.new_expected_damage_inflicted += defender_inflict;
+       def_stats.new_expected_damage_taken     += attacker_inflict;
+       att_stats.new_turn_expected_damage_inflicted += attacker_inflict;
+       att_stats.new_turn_expected_damage_taken     += defender_inflict;
+       def_stats.new_turn_expected_damage_inflicted += defender_inflict;
+       def_stats.new_turn_expected_damage_taken     += attacker_inflict;
+}
+
+
+void attack_context::attack_result(hit_result res, int damage, int drain)
 {
        if(stats_disabled > 0)
                return;
 
        attacker_res.push_back(res == MISSES ? '0' : '1');
+       stats &att_stats = attacker_stats(), &def_stats = defender_stats();
 
        if(res != MISSES) {
                // handle drain
-               attacker_stats().damage_taken -= drain;
-               defender_stats().damage_inflicted -= drain;
-               attacker_stats().turn_damage_taken -= drain;
-               defender_stats().turn_damage_inflicted -= drain;
-
-               attacker_stats().damage_inflicted += damage;
-               defender_stats().damage_taken += damage;
-               attacker_stats().turn_damage_inflicted += damage;
-               defender_stats().turn_damage_taken += damage;
-       }
-       const int exp_damage = damage * chance_to_hit_defender * 10;
-       const int exp_drain  = drain  * chance_to_hit_defender * 10;
-
-       attacker_stats().expected_damage_taken -= exp_drain;
-       defender_stats().expected_damage_inflicted -= exp_drain;
-       attacker_stats().turn_expected_damage_taken -= exp_drain;
-       defender_stats().turn_expected_damage_inflicted -= exp_drain;
+               att_stats.damage_taken          -= drain;
+               def_stats.damage_inflicted      -= drain;
+               att_stats.turn_damage_taken     -= drain;
+               def_stats.turn_damage_inflicted -= drain;
+
+               att_stats.damage_inflicted      += damage;
+               def_stats.damage_taken          += damage;
+               att_stats.turn_damage_inflicted += damage;
+               def_stats.turn_damage_taken     += damage;
+       }
+
+       int exp_damage = damage * chance_to_hit_defender * 
(stats::decimal_shift / 100);
+       int exp_drain  = drain  * chance_to_hit_defender * 
(stats::decimal_shift / 100);
+
+       att_stats.expected_damage_taken          -= exp_drain;
+       def_stats.expected_damage_inflicted      -= exp_drain;
+       att_stats.turn_expected_damage_taken     -= exp_drain;
+       def_stats.turn_expected_damage_inflicted -= exp_drain;
 
        // handle drain
-       attacker_stats().expected_damage_inflicted += exp_damage;
-       defender_stats().expected_damage_taken += exp_damage;
-       attacker_stats().turn_expected_damage_inflicted += exp_damage;
-       defender_stats().turn_expected_damage_taken += exp_damage;
+       att_stats.expected_damage_inflicted      += exp_damage;
+       def_stats.expected_damage_taken          += exp_damage;
+       att_stats.turn_expected_damage_inflicted += exp_damage;
+       def_stats.turn_expected_damage_taken     += exp_damage;
 
        if(res == KILLS) {
-               attacker_stats().killed[defender_type]++;
-               defender_stats().deaths[defender_type]++;
-       }
-}
-
-void attack_context::defend_result(attack_context::ATTACK_RESULT res, long 
long damage, long long drain)
+               ++att_stats.killed[defender_type];
+               ++def_stats.deaths[defender_type];
+       }
+}
+
+void attack_context::defend_result(hit_result res, int damage, int drain)
 {
        if(stats_disabled > 0)
                return;
 
        defender_res.push_back(res == MISSES ? '0' : '1');
-
+       stats &att_stats = attacker_stats(), &def_stats = defender_stats();
 
        if(res != MISSES) {
                //handle drain
-               defender_stats().damage_taken -= drain;
-               attacker_stats().damage_inflicted -= drain;
-               defender_stats().turn_damage_taken -= drain;
-               attacker_stats().turn_damage_inflicted -= drain;
-
-               attacker_stats().damage_taken += damage;
-               defender_stats().damage_inflicted += damage;
-               attacker_stats().turn_damage_taken += damage;
-               defender_stats().turn_damage_inflicted += damage;
-       }
-       const long long exp_damage = damage * chance_to_hit_attacker * 10;
-       const long long exp_drain = drain * chance_to_hit_attacker * 10;
+               def_stats.damage_taken          -= drain;
+               att_stats.damage_inflicted      -= drain;
+               def_stats.turn_damage_taken     -= drain;
+               att_stats.turn_damage_inflicted -= drain;
+
+               att_stats.damage_taken          += damage;
+               def_stats.damage_inflicted      += damage;
+               att_stats.turn_damage_taken     += damage;
+               def_stats.turn_damage_inflicted += damage;
+       }
+
+       int exp_damage = damage * chance_to_hit_attacker * 
(stats::decimal_shift / 100);
+       int exp_drain  = drain  * chance_to_hit_attacker * 
(stats::decimal_shift / 100);
+
        //handle drain
-       defender_stats().expected_damage_taken -= exp_drain;
-       attacker_stats().expected_damage_inflicted -= exp_drain;
-       defender_stats().turn_expected_damage_taken -= exp_drain;
-       attacker_stats().turn_expected_damage_inflicted -= exp_drain;
-
-       attacker_stats().expected_damage_taken += exp_damage;
-       defender_stats().expected_damage_inflicted += exp_damage;
-       attacker_stats().turn_expected_damage_taken += exp_damage;
-       defender_stats().turn_expected_damage_inflicted += exp_damage;
+       def_stats.expected_damage_taken          -= exp_drain;
+       att_stats.expected_damage_inflicted      -= exp_drain;
+       def_stats.turn_expected_damage_taken     -= exp_drain;
+       att_stats.turn_expected_damage_inflicted -= exp_drain;
+
+       att_stats.expected_damage_taken          += exp_damage;
+       def_stats.expected_damage_inflicted      += exp_damage;
+       att_stats.turn_expected_damage_taken     += exp_damage;
+       def_stats.turn_expected_damage_inflicted += exp_damage;
 
        if(res == KILLS) {
-               attacker_stats().deaths[attacker_type]++;
-               defender_stats().killed[attacker_type]++;
+               ++att_stats.deaths[attacker_type];
+               ++def_stats.killed[attacker_type];
        }
 }
 

Modified: trunk/src/statistics.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/statistics.hpp?rev=33488&r1=33487&r2=33488&view=diff
==============================================================================
--- trunk/src/statistics.hpp (original)
+++ trunk/src/statistics.hpp Mon Mar  9 19:17:10 2009
@@ -54,7 +54,7 @@
                long long damage_inflicted, damage_taken;
                long long turn_damage_inflicted, turn_damage_taken;
 
-               static const long long desimal_shift = 1000;
+               static const int decimal_shift = 1000;
 
                // Expected value for damage inflicted/taken * 1000, based on
                // probability to hit,
@@ -92,11 +92,11 @@
                attack_context(const unit& a, const unit& d, int a_cth, int 
d_cth);
                ~attack_context();
 
-               enum ATTACK_RESULT { MISSES, HITS, KILLS };
+               enum hit_result { MISSES, HITS, KILLS };
 
-               void attack_excepted_damage(double attacker_inflict, double 
defender_inflict);
-               void attack_result(ATTACK_RESULT res, long long damage, long 
long drain);
-               void defend_result(ATTACK_RESULT res, long long damage, long 
long drain);
+               void attack_expected_damage(double attacker_inflict, double 
defender_inflict);
+               void attack_result(hit_result res, int damage, int drain);
+               void defend_result(hit_result res, int damage, int drain);
 
        private:
 

Modified: trunk/src/statistics_dialog.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/statistics_dialog.cpp?rev=33488&r1=33487&r2=33488&view=diff
==============================================================================
--- trunk/src/statistics_dialog.cpp (original)
+++ trunk/src/statistics_dialog.cpp Mon Mar  9 19:17:10 2009
@@ -195,28 +195,26 @@
                                         const long long& turn_damage,
                                         const long long& turn_expected)
 {
-       const int dsa = statistics::stats::desimal_shift * damage
-                     - expected;
-       const int dst = statistics::stats::desimal_shift * turn_damage
-                     - turn_expected;
-
-       std::stringstream str;
+       int shift = statistics::stats::decimal_shift;
+
+       int dsa = shift * damage      - expected;
+       int dst = shift * turn_damage - turn_expected;
+
+       std::ostringstream str;
        str << header << COLUMN_SEPARATOR
                << damage << " / "
-               << (expected/100 / (double)statistics::stats::desimal_shift * 
100.0)
+               << (expected * 10 + shift / 2) / shift * 0.1
                << COLUMN_SEPARATOR
-               << ((dsa > 0) ? "+" : "")
-               << ((expected == 0) ? 0
-                               : 100 * dsa / expected)
-               << "%" << COLUMN_SEPARATOR
+               << ((dsa < 0) ^ (expected < 0) ? "" : "+")
+               << (expected == 0 ? 0 : 100 * dsa / expected)
+               << '%' << COLUMN_SEPARATOR
                << COLUMN_SEPARATOR
                << turn_damage << " / "
-               << (turn_expected/100 / 
(double)statistics::stats::desimal_shift * 100.0)
+               << (turn_expected * 10 + shift / 2) / shift * 0.1
                << COLUMN_SEPARATOR
-               << ((dst > 0) ? "+" : "")
-               << ((turn_expected == 0) ? 0
-                               : 100 * dst / turn_expected)
-               << "%";
+               << ((dst < 0) ^ (turn_expected < 0) ? "" : "+")
+               << (turn_expected == 0 ? 0 : 100 * dst / turn_expected)
+               << '%';
        items.push_back(str.str());
 
 }




Related Messages


Powered by MHonArc, Updated Mon Mar 09 21:20:32 2009