The Battle for Wesnoth  1.19.0-dev
statistics.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
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 #include "statistics_record.hpp"
19 
20 class unit;
21 #include <string>
22 #include <map>
23 #include <vector>
24 
26 {
27 public:
29 
31 
32  void recruit_unit(const unit& u);
33  void recall_unit(const unit& u);
34  void un_recall_unit(const unit& u);
35  void un_recruit_unit(const unit& u);
36 
37  void advance_unit(const unit& u);
38 
39  void reset_turn_stats(const std::string & save_id);
40  stats calculate_stats(const std::string & save_id);
41  /** Stats (and name) for each scenario. The pointers are never nullptr. */
42  typedef std::vector< std::pair<const std::string *, const stats *>> levels;
43  /** Returns a list of names and stats for each scenario in the current campaign. */
44  levels level_stats(const std::string & save_id);
45  /// returns the stats for the given side in the current scenario.
46  stats& get_stats(const std::string &save_id);
47 
48  static int sum_str_int_map(const std::map<std::string,int>& m);
49  static int sum_cost_str_int_map(const std::map<std::string,int>& m);
50 private:
52 
53  auto& master_stats() {
54  return record_.master_record;
55  }
56 };
57 
59 {
61 
62  statistics_attack_context(statistics_t& stats, const unit& a, const unit& d, int a_cth, int d_cth);
65 
66  void attack_expected_damage(double attacker_inflict, double defender_inflict);
67  void attack_result(hit_result res, int cth, int damage, int drain);
68  void defend_result(hit_result res, int cth, int damage, int drain);
69 private:
70 
71  /// never nullptr
73 
77  std::string attacker_res, defender_res;
78 
81 };
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:246
void recall_unit(const unit &u)
Definition: statistics.cpp:180
std::vector< std::pair< const std::string *, const stats * > > levels
Stats (and name) for each scenario.
Definition: statistics.hpp:42
stats & get_stats(const std::string &save_id)
returns the stats for the given side in the current scenario.
Definition: statistics.cpp:271
void advance_unit(const unit &u)
Definition: statistics.cpp:201
static int sum_cost_str_int_map(const std::map< std::string, int > &m)
Definition: statistics.cpp:290
statistics_t(statistics_record::campaign_stats_t &record)
Definition: statistics.cpp:46
static int sum_str_int_map(const std::map< std::string, int > &m)
Definition: statistics.cpp:280
void un_recall_unit(const unit &u)
Definition: statistics.cpp:187
statistics_record::campaign_stats_t & record_
Definition: statistics.hpp:51
void reset_turn_stats(const std::string &save_id)
Definition: statistics.cpp:207
stats calculate_stats(const std::string &save_id)
Definition: statistics.cpp:219
statistics_record::stats_t stats
Definition: statistics.hpp:28
void un_recruit_unit(const unit &u)
Definition: statistics.cpp:194
auto & master_stats()
Definition: statistics.hpp:53
void recruit_unit(const unit &u)
Definition: statistics.cpp:173
This class represents a single unit of a specific type.
Definition: unit.hpp:133
void attack_result(hit_result res, int cth, int damage, int drain)
Definition: statistics.cpp:103
statistics_attack_context(statistics_t &stats, const unit &a, const unit &d, int a_cth, int d_cth)
Definition: statistics.cpp:52
statistics_t * stats_
never nullptr
Definition: statistics.hpp:72
void attack_expected_damage(double attacker_inflict, double defender_inflict)
Definition: statistics.cpp:88
void defend_result(hit_result res, int cth, int damage, int drain)
Definition: statistics.cpp:138
std::vector< scenario_stats_t > master_record
#define d
#define a