statistics.hpp

Go to the documentation of this file.
00001 /* $Id: statistics.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2003 - 2012 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 as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 /** @file */
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         /*
00045          *  A type that will map a string of hit/miss to the number of times
00046          *  that sequence has occurred.
00047          */
00048         typedef str_int_map battle_sequence_frequency_map;
00049 
00050         /** A type that will map different % chances to hit to different results. */
00051         typedef std::map<int,battle_sequence_frequency_map> battle_result_map;
00052 
00053         battle_result_map attacks, defends;
00054 
00055         long long damage_inflicted, damage_taken;
00056         long long turn_damage_inflicted, turn_damage_taken;
00057 
00058         static const int decimal_shift = 1000;
00059 
00060         // Expected value for damage inflicted/taken * 1000, based on
00061         // probability to hit,
00062         // Use this long term to see how lucky a side is.
00063 
00064         long long expected_damage_inflicted, expected_damage_taken;
00065         long long turn_expected_damage_inflicted, turn_expected_damage_taken;
00066         std::string save_id;
00067     };
00068 
00069     int sum_str_int_map(const stats::str_int_map& m);
00070     int sum_cost_str_int_map(const stats::str_int_map &m);
00071 
00072     struct scenario_context
00073     {
00074         scenario_context(const std::string& name);
00075         ~scenario_context();
00076     };
00077 
00078     struct attack_context
00079     {
00080         attack_context(const unit& a, const unit& d, int a_cth, int d_cth);
00081         ~attack_context();
00082 
00083         enum hit_result { MISSES, HITS, KILLS };
00084 
00085         void attack_expected_damage(double attacker_inflict, double defender_inflict);
00086         void attack_result(hit_result res, int damage, int drain);
00087         void defend_result(hit_result res, int damage, int drain);
00088 
00089     private:
00090 
00091         std::string attacker_type, defender_type;
00092         std::string attacker_side, defender_side;
00093         int chance_to_hit_defender, chance_to_hit_attacker;
00094         std::string attacker_res, defender_res;
00095 
00096         stats& attacker_stats();
00097         stats& defender_stats();
00098     };
00099 
00100     void recruit_unit(const unit& u);
00101     void recall_unit(const unit& u);
00102     void un_recall_unit(const unit& u);
00103     void un_recruit_unit(const unit& u);
00104 
00105     void advance_unit(const unit& u);
00106 
00107     config write_stats();
00108     void write_stats(config_writer &out);
00109     void read_stats(const config& cfg);
00110     void fresh_stats();
00111     void clear_current_scenario();
00112 
00113     void reset_turn_stats(std::string save_id);
00114     stats calculate_stats(int category, std::string save_id);
00115 } // end namespace statistics
00116 
00117 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:10 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs