statistics.hpp

Go to the documentation of this file.
00001 /* $Id: statistics.hpp 26619 2008-05-14 14:47:24Z suokko $ */
00002 /*
00003    Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 //! @file statistics.hpp
00016 //!
00017 
00018 #ifndef STATISTICS_HPP_INCLUDED
00019 #define STATISTICS_HPP_INCLUDED
00020 
00021 class config;
00022 class config_writer;
00023 class unit;
00024 //#include "actions.hpp"
00025 #include <string>
00026 #include <map>
00027 #include <vector>
00028 
00029 namespace statistics
00030 {
00031     struct stats
00032     {
00033         stats();
00034         explicit stats(const config& cfg);
00035 
00036         config write() const;
00037         void write(config_writer &out) const;
00038         void read(const config& cfg);
00039 
00040         typedef std::map<std::string,int> str_int_map;
00041         str_int_map recruits, recalls, advanced_to, deaths, killed;
00042         int recruit_cost, recall_cost;
00043 
00044         //! A type that will map a string of hit/miss
00045         //! to the number of times that sequence has occurred.
00046         typedef str_int_map battle_sequence_frequency_map;
00047 
00048         //! A type that will map different % chances to hit to different results.
00049         typedef std::map<int,battle_sequence_frequency_map> battle_result_map;
00050 
00051         battle_result_map attacks, defends;
00052 
00053         long long damage_inflicted, damage_taken;
00054         long long turn_damage_inflicted, turn_damage_taken;
00055 
00056         static const long long desimal_shift = 1000;
00057 
00058         // Expected value for damage inflicted/taken * 1000, based on
00059         // probability to hit,
00060         // Use this long term to see how lucky a side is.
00061         //! @todo FIXME: Since integers are used, rounding errors accumulate.
00062         // Also, slow isn't accounted for properly.
00063         // Rusty's simulator could be used obtain valid values.
00064         long long expected_damage_inflicted, expected_damage_taken;
00065         long long turn_expected_damage_inflicted, turn_expected_damage_taken;
00066         long long new_expected_damage_inflicted, new_expected_damage_taken;
00067         long long new_turn_expected_damage_inflicted, new_turn_expected_damage_taken;
00068     };
00069 
00070     int sum_str_int_map(const stats::str_int_map& m);
00071 
00072     struct disabler
00073     {
00074         disabler();
00075         ~disabler();
00076     };
00077 
00078 
00079     struct scenario_context
00080     {
00081         scenario_context(const std::string& name);
00082         ~scenario_context();
00083     };
00084 
00085     struct attack_context
00086     {
00087         attack_context(const unit& a, const unit& d, int a_cth, int d_cth);
00088         ~attack_context();
00089 
00090         enum ATTACK_RESULT { MISSES, HITS, KILLS };
00091 
00092         void attack_excepted_damage(double attacker_inflict, double defender_inflict);
00093         void attack_result(ATTACK_RESULT res, long long damage, long long drain);
00094         void defend_result(ATTACK_RESULT res, long long damage, long long drain);
00095 
00096     private:
00097 
00098         std::string attacker_type, defender_type;
00099         int attacker_side, defender_side;
00100         int chance_to_hit_defender, chance_to_hit_attacker;
00101         std::string attacker_res, defender_res;
00102 
00103         stats& attacker_stats();
00104         stats& defender_stats();
00105     };
00106 
00107     void recruit_unit(const unit& u);
00108     void recall_unit(const unit& u);
00109     void un_recall_unit(const unit& u);
00110     void un_recruit_unit(const unit& u);
00111 
00112     void advance_unit(const unit& u);
00113 
00114     config write_stats();
00115     void write_stats(config_writer &out);
00116     void read_stats(const config& cfg);
00117     void fresh_stats();
00118     void clear_current_scenario();
00119 
00120     void reset_turn_stats(int side);
00121     stats calculate_stats(int category, int side);
00122 } // end namespace statistics
00123 
00124 #endif

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs