The Battle for Wesnoth  1.17.23+dev
statistics_record.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2023
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 class config;
19 class config_writer;
20 
21 #include <string>
22 #include <map>
23 #include <vector>
24 
25 namespace statistics_record
26 {
27  struct stats_t
28  {
29  stats_t();
30  explicit stats_t(const config& cfg);
31 
32  config write() const;
33  void write(config_writer &out) const;
34  void read(const config& cfg);
35 
36  void merge_with(const stats_t& other);
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  */
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  /** Statistics of this side's attacks on its own turns. */
53  /** Statistics of this side's attacks on enemies' turns. */
55  /** Statistics of enemies' counter attacks on this side's turns. */
57  /** Statistics of enemies' attacks against this side on their turns. */
59 
62 
63  struct hitrate_t
64  {
65  int strikes; //< Number of strike attempts at the given CTH
66  int hits; //< Number of strikes that hit at the given CTH
67  hitrate_t() = default;
68  explicit hitrate_t(const config& cfg);
69  config write() const;
70  };
71  /** A type that maps chance-to-hit percentage to number of hits and strikes at that CTH. */
72  typedef std::map<int, hitrate_t> hitrate_map;
75 
76  static const int decimal_shift = 1000;
77 
78  // Expected value for damage inflicted/taken * 1000, based on
79  // probability to hit,
80  // Use this long term to see how lucky a side is.
81 
84  std::string save_id;
85  };
86 
87 
88  using team_stats_t = std::map<std::string, stats_t>;
89 
91  {
92  explicit scenario_stats_t(const std::string& name) :
93  team_stats(),
94  scenario_name(name)
95  {}
96 
97  explicit scenario_stats_t(const config& cfg);
98 
99  config write() const;
100  void write(config_writer &out) const;
101 
103  std::string scenario_name;
104  };
105 
107  {
108  campaign_stats_t() = default;
109  explicit campaign_stats_t(const config& cfg)
110  : master_record()
111  {
112  read(cfg);
113  }
114  config to_config() const;
115  void write(config_writer &out) const;
116  void read(const config& cfg, bool append = false);
117  /** Adds an entry for anew scenario to wrte to. */
118  void new_scenario(const std::string & scenario_name);
119  /** Delete the current scenario from the stats. */
120  void clear_current_scenario();
121 
122  std::vector<scenario_stats_t> master_record;
123  };
124 
125 }
126 
127 std::ostream& operator<<(std::ostream& outstream, const statistics_record::stats_t::hitrate_t& by_cth);
Class for writing a config out to a file in pieces.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:161
std::map< std::string, stats_t > team_stats_t
std::ostream & operator<<(std::ostream &outstream, const statistics_record::stats_t::hitrate_t &by_cth)
std::vector< scenario_stats_t > master_record
void new_scenario(const std::string &scenario_name)
Adds an entry for anew scenario to wrte to.
void read(const config &cfg, bool append=false)
void clear_current_scenario()
Delete the current scenario from the stats.
void write(config_writer &out) const
scenario_stats_t(const std::string &name)
void merge_with(const stats_t &other)
battle_result_map attacks_inflicted
Statistics of this side's attacks on its own turns.
battle_result_map defends_inflicted
Statistics of this side's attacks on enemies' turns.
std::map< int, battle_sequence_frequency_map > battle_result_map
A type that will map different % chances to hit to different results.
void read(const config &cfg)
std::map< int, hitrate_t > hitrate_map
A type that maps chance-to-hit percentage to number of hits and strikes at that CTH.
std::map< std::string, int > str_int_map
battle_result_map attacks_taken
Statistics of enemies' counter attacks on this side's turns.
battle_result_map defends_taken
Statistics of enemies' attacks against this side on their turns.