The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
attack_prediction.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 - 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 ATTACK_PREDICTION_H_INCLUDED
18 #define ATTACK_PREDICTION_H_INCLUDED
19 
20 #include "global.hpp"
21 
22 #include <vector>
23 
24 #include <cstring>
25 
27 
28 // This encapsulates all we need to know for this combat.
29 /** All combat-related info. */
30 struct combatant
31 {
32  /** Construct a combatant. */
33  combatant(const battle_context_unit_stats &u, const combatant *prev = nullptr);
34 
35  /** Copy constructor */
36  combatant(const combatant &that, const battle_context_unit_stats &u);
37 
38  /** Simulate a fight! Can be called multiple times for cumulative calculations. */
39  void fight(combatant &opponent, bool levelup_considered=true);
40 
41  /** Resulting probability distribution (might be not as large as max_hp) */
42  std::vector<double> hp_dist;
43 
44  /** Resulting chance we were not hit by this opponent (important if it poisons) */
45  double untouched;
46 
47  /** Resulting chance we are poisoned. */
48  double poisoned;
49 
50  /** Resulting chance we are slowed. */
51  double slowed;
52 
53  /** What's the average hp (weighted average of hp_dist). */
54  double average_hp(unsigned int healing = 0) const;
55 
56 #if defined(BENCHMARK) || defined(CHECK)
57  // Functions used in the stand-alone version of attack_prediction.cpp
58  void print(const char label[], unsigned int battle, unsigned int fighter) const;
59  void reset();
60 #endif
61 
62 private:
63  combatant(const combatant &that);
64  combatant& operator=(const combatant &);
65 
66  struct combat_slice;
67  /** Split the combat by number of attacks per combatant (for swarm). */
68  std::vector<combat_slice> split_summary() const;
69 
71 
72  /** Summary of matrix used to calculate last battle (unslowed & slowed).
73  * Invariant: summary[1].size() == summary[0].size() or summary[1].empty() */
74  std::vector<double> summary[2];
75 };
76 
77 #endif
double untouched
Resulting chance we were not hit by this opponent (important if it poisons)
std::vector< double > hp_dist
Resulting probability distribution (might be not as large as max_hp)
std::vector< combat_slice > split_summary() const
Split the combat by number of attacks per combatant (for swarm).
const battle_context_unit_stats & u_
A struct to describe one possible combat scenario.
combatant(const battle_context_unit_stats &u, const combatant *prev=nullptr)
Construct a combatant.
void fight(combatant &opponent, bool levelup_considered=true)
Simulate a fight! Can be called multiple times for cumulative calculations.
Structure describing the statistics of a unit involved in the battle.
Definition: attack.hpp:49
GLboolean reset
Definition: glew.h:3799
double slowed
Resulting chance we are slowed.
All combat-related info.
static void print(std::stringstream &sstr, const std::string &queue, const std::string &id)
Definition: fire_event.cpp:29
combatant & operator=(const combatant &)
map_location prev
Definition: astarsearch.cpp:67
double average_hp(unsigned int healing=0) const
What's the average hp (weighted average of hp_dist).
double poisoned
Resulting chance we are poisoned.
std::vector< double > summary[2]
Summary of matrix used to calculate last battle (unslowed & slowed).