32 #define DBG_NG LOG_STREAM(debug, log_engine)
33 #define ERR_NG LOG_STREAM(err, log_engine)
38 std::string get_team_save_id(
const unit& u)
55 , attacker_type(a.type_id())
56 , defender_type(
d.type_id())
57 , attacker_side(get_team_save_id(a))
58 , defender_side(get_team_save_id(
d))
59 , chance_to_hit_defender(a_cth)
60 , chance_to_hit_attacker(d_cth)
95 def_stats.expected_damage_inflicted += defender_inflict;
96 def_stats.expected_damage_taken += attacker_inflict;
99 def_stats.turn_expected_damage_inflicted += defender_inflict;
100 def_stats.turn_expected_damage_taken += attacker_inflict;
111 ++def_stats.by_cth_taken[cth].hits;
112 ++def_stats.turn_by_cth_taken[cth].hits;
116 ++def_stats.by_cth_taken[cth].strikes;
117 ++def_stats.turn_by_cth_taken[cth].strikes;
122 def_stats.damage_inflicted -= drain;
124 def_stats.turn_damage_inflicted -= drain;
127 def_stats.damage_taken += damage;
129 def_stats.turn_damage_taken += damage;
144 ++def_stats.by_cth_inflicted[cth].hits;
145 ++def_stats.turn_by_cth_inflicted[cth].hits;
149 ++def_stats.by_cth_inflicted[cth].strikes;
150 ++def_stats.turn_by_cth_inflicted[cth].strikes;
156 def_stats.damage_taken -= drain;
158 def_stats.turn_damage_taken -= drain;
162 def_stats.damage_inflicted += damage;
164 def_stats.turn_damage_inflicted += damage;
177 s.recruit_cost += u.
cost();
184 s.recall_cost += u.
cost();
191 s.recall_cost -= u.
cost();
198 s.recruit_cost -= u.
cost();
210 s.turn_damage_inflicted = 0;
211 s.turn_damage_taken = 0;
212 s.turn_expected_damage_inflicted = 0;
213 s.turn_expected_damage_taken = 0;
214 s.turn_by_cth_inflicted.clear();
215 s.turn_by_cth_taken.clear();
223 DBG_NG <<
"calculate_stats, side: " << save_id <<
" master_stats.size: " <<
master_stats().size();
248 static const stats null_stats;
249 static const std::string null_name(
"");
256 auto find_it = team_stats.find(save_id);
257 if(find_it != team_stats.end()) {
264 if(level_list.empty()) {
265 level_list.emplace_back(&null_name, &null_stats);
283 for(
const auto& pair: m) {
293 for(
const auto& pair : m) {
296 ERR_NG <<
"Statistics refer to unknown unit type '" << pair.first <<
"'. Discarding.";
298 cost += pair.second *
t->cost();
levels level_stats(const std::string &save_id)
Returns a list of names and stats for each scenario in the current campaign.
void recall_unit(const unit &u)
std::vector< std::pair< const std::string *, const stats * > > levels
Stats (and name) for each scenario.
stats & get_stats(const std::string &save_id)
returns the stats for the given side in the current scenario.
void advance_unit(const unit &u)
static int sum_cost_str_int_map(const std::map< std::string, int > &m)
statistics_t(statistics_record::campaign_stats_t &record)
static int sum_str_int_map(const std::map< std::string, int > &m)
void un_recall_unit(const unit &u)
void reset_turn_stats(const std::string &save_id)
stats calculate_stats(const std::string &save_id)
void un_recruit_unit(const unit &u)
void recruit_unit(const unit &u)
std::string save_id_or_number() const
const unit_type * find(const std::string &key, unit_type::BUILD_STATUS status=unit_type::FULL) const
Finds a unit_type by its id() and makes sure it is built to the specified level.
A single unit type that the player may recruit.
const std::string & parent_id() const
The id of the original type from which this (variation) descended.
This class represents a single unit of a specific type.
int cost() const
How much gold is required to recruit this unit.
const std::string & type_id() const
The id of this unit's type.
const unit_type & type() const
This unit's type, accounting for gender and variation.
int side() const
The side this unit belongs to.
Standard logging facilities (interface).
static lg::log_domain log_engine("engine")
std::string attacker_type
int chance_to_hit_defender
void attack_result(hit_result res, int cth, int damage, int drain)
std::string defender_type
statistics_attack_context(statistics_t &stats, const unit &a, const unit &d, int a_cth, int d_cth)
int chance_to_hit_attacker
~statistics_attack_context()
std::string attacker_side
statistics_t * stats_
never nullptr
void attack_expected_damage(double attacker_inflict, double defender_inflict)
void defend_result(hit_result res, int cth, int damage, int drain)
std::string defender_side
void merge_with(const stats_t &other)
long long turn_damage_taken
long long turn_expected_damage_taken
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.
hitrate_map by_cth_inflicted
hitrate_map turn_by_cth_inflicted
long long turn_damage_inflicted
static const int decimal_shift
battle_result_map attacks_taken
Statistics of enemies' counter attacks on this side's turns.
long long turn_expected_damage_inflicted
hitrate_map turn_by_cth_taken
long long expected_damage_inflicted
long long expected_damage_taken
battle_result_map defends_taken
Statistics of enemies' attacks against this side on their turns.
long long damage_inflicted
static map_location::direction s
unit_type_data unit_types