The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
statistics.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /** @file */
16 
17 #ifndef STATISTICS_HPP_INCLUDED
18 #define STATISTICS_HPP_INCLUDED
19 
20 class config;
21 class config_writer;
22 class unit;
23 #include <string>
24 #include <map>
25 #include <vector>
26 
27 namespace statistics
28 {
29  struct stats
30  {
31  stats();
32  explicit stats(const config& cfg);
33 
34  config write() const;
35  void write(config_writer &out) const;
36  void read(const config& cfg);
37 
38  typedef std::map<std::string,int> str_int_map;
41 
42  /*
43  * A type that will map a string of hit/miss to the number of times
44  * that sequence has occurred.
45  */
46  typedef str_int_map battle_sequence_frequency_map;
47 
48  /** A type that will map different % chances to hit to different results. */
49  typedef std::map<int,battle_sequence_frequency_map> battle_result_map;
50 
51  battle_result_map attacks, defends;
52 
55 
56  static const int decimal_shift = 1000;
57 
58  // Expected value for damage inflicted/taken * 1000, based on
59  // probability to hit,
60  // Use this long term to see how lucky a side is.
61 
65  };
66 
69 
71  {
74  };
75 
77  {
78  attack_context(const unit& a, const unit& d, int a_cth, int d_cth);
80 
82 
83  void attack_expected_damage(double attacker_inflict, double defender_inflict);
84  void attack_result(hit_result res, int damage, int drain);
85  void defend_result(hit_result res, int damage, int drain);
86 
87  private:
88 
93 
96  };
97 
98  void recruit_unit(const unit& u);
99  void recall_unit(const unit& u);
100  void un_recall_unit(const unit& u);
101  void un_recruit_unit(const unit& u);
102  int un_recall_unit_cost(const unit& u);
103 
104  void advance_unit(const unit& u);
105 
107  void write_stats(config_writer &out);
108  void read_stats(const config& cfg);
109  void fresh_stats();
110  void clear_current_scenario();
111 
112  void reset_turn_stats(const std::string & save_id);
113  stats calculate_stats(const std::string & save_id);
114  /// Stats (and name) for each scenario. The pointers are never nullptr.
115  typedef std::vector< std::pair<const std::string *, const stats *> > levels;
116  /// Returns a list of names and stats for each scenario in the current campaign.
117  levels level_stats(const std::string & save_id);
118 } // end namespace statistics
119 
120 #endif
long long damage_inflicted
Definition: statistics.hpp:53
scenario_context(const std::string &name)
Definition: statistics.cpp:370
battle_result_map defends
Definition: statistics.hpp:51
Definition: unit.hpp:95
int sum_str_int_map(const stats::str_int_map &m)
Definition: statistics.cpp:631
void un_recall_unit(const unit &u)
Definition: statistics.cpp:494
long long turn_damage_taken
Definition: statistics.hpp:54
void fresh_stats()
Definition: statistics.cpp:617
int sum_cost_str_int_map(const stats::str_int_map &m)
Definition: statistics.cpp:641
void defend_result(hit_result res, int damage, int drain)
Definition: statistics.cpp:456
#define d
void reset_turn_stats(const std::string &save_id)
Definition: statistics.cpp:522
str_int_map advanced_to
Definition: statistics.hpp:39
void recruit_unit(const unit &u)
Definition: statistics.cpp:480
std::vector< std::pair< const std::string *, const stats * > > levels
Stats (and name) for each scenario. The pointers are never nullptr.
Definition: statistics.hpp:115
long long expected_damage_taken
Definition: statistics.hpp:62
long long turn_expected_damage_inflicted
Definition: statistics.hpp:63
static const int decimal_shift
Definition: statistics.hpp:56
Class for writing a config out to a file in pieces.
std::map< int, battle_sequence_frequency_map > battle_result_map
A type that will map different % chances to hit to different results.
Definition: statistics.hpp:49
int un_recall_unit_cost(const unit &u)
Definition: statistics.cpp:508
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:7319
levels level_stats(const std::string &save_id)
Returns a list of names and stats for each scenario in the current campaign.
Definition: statistics.cpp:559
str_int_map recalls
Definition: statistics.hpp:39
void read_stats(const config &cfg)
Definition: statistics.cpp:607
void read(const config &cfg)
Definition: statistics.cpp:327
str_int_map killed
Definition: statistics.hpp:39
void advance_unit(const unit &u)
Definition: statistics.cpp:516
GLuint res
Definition: glew.h:9258
config write() const
Definition: statistics.cpp:258
str_int_map recruits
Definition: statistics.hpp:39
stats calculate_stats(const std::string &save_id)
Definition: statistics.cpp:532
str_int_map deaths
Definition: statistics.hpp:39
long long damage_taken
Definition: statistics.hpp:53
long long turn_damage_inflicted
Definition: statistics.hpp:54
void recall_unit(const unit &u)
Definition: statistics.cpp:487
attack_context(const unit &a, const unit &d, int a_cth, int d_cth)
Definition: statistics.cpp:384
GLuint const GLchar * name
Definition: glew.h:1782
long long expected_damage_inflicted
Definition: statistics.hpp:62
str_int_map battle_sequence_frequency_map
Definition: statistics.hpp:46
const GLdouble * m
Definition: glew.h:6968
void attack_expected_damage(double attacker_inflict, double defender_inflict)
Definition: statistics.cpp:416
std::map< std::string, int > str_int_map
Definition: statistics.hpp:38
config write_stats()
Definition: statistics.cpp:584
void attack_result(hit_result res, int damage, int drain)
Definition: statistics.cpp:432
long long turn_expected_damage_taken
Definition: statistics.hpp:63
std::string save_id
Definition: statistics.hpp:64
battle_result_map attacks
Definition: statistics.hpp:51
void un_recruit_unit(const unit &u)
Definition: statistics.cpp:501
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
void clear_current_scenario()
Definition: statistics.cpp:623
GLsizei const GLcharARB ** string
Definition: glew.h:4503