The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
attack_prediction_display.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006 - 2016 by Joerg Hinrichs <[email protected]>
3  wesnoth playturn Copyright (C) 2003 by David White <[email protected]>
4  Part of the Battle for Wesnoth Project http://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 #ifndef ATTACK_PREDICTION_DISPLAY_H_INCLUDED
17 #define ATTACK_PREDICTION_DISPLAY_H_INCLUDED
18 
19 class attack_type;
20 class battle_context;
22 struct map_location;
23 class unit;
24 #include "show_dialog.hpp"
25 
26 // This preview pane is shown in the "Damage Calculations" dialog.
28 {
29 public:
30 
31  // Lengthy constructor.
33  const map_location& attacker_loc, const map_location& defender_loc);
34 
35  // This method is called to draw the dialog contents.
36  void draw_contents();
37 
38  // Hack: pretend the preview pane goes to the left.
39  bool left_side() const { return 1; }
40 
41  // Unused.
42  void set_selection(int) {}
43 
44 private:
47  const unit& attacker_;
48  const unit& defender_;
49 
50  // Layout constants.
51  static const int inter_line_gap_;
52  static const int inter_column_gap_;
53  static const int inter_units_gap_;
54  static const int max_hp_distrib_rows_;
55 
56  // Layout computations.
59 
65 
71 
74 
75  // This method builds the strings describing the unit damage modifiers.
76  // Read the code to understand the arguments.
78  const unit& u, const map_location& u_loc, float u_unscathed,
79  const unit& opp, const map_location& opp_loc, const attack_type *opp_weapon,
80  std::vector<std::string>& left_strings, std::vector<std::string>& right_strings,
81  int& left_strings_width, int& right_strings_width, int& strings_width);
82 
83  // Utility method that returns the length of the longest string in a vector of strings.
84  int get_strings_max_length(const std::vector<std::string>& strings);
85 
86  // This method builds the vector containing the <HP, probability> pairs
87  // that are required to draw the image of the hitpoints distribution of
88  // a combatant after a fight. The method takes as input the probability
89  // distribution of the hitpoints of the combatant after the fight.
90  void get_hp_prob_vector(const std::vector<double>& hp_dist,
91  std::vector<std::pair<int, double> >& hp_prob_vector);
92 
93  // This method draws a unit in the dialog pane. Read the code to understand
94  // the arguments.
95  void draw_unit(int x_off, int damage_line_skip, int left_strings_width,
96  const std::vector<std::string>& left_strings,
97  const std::vector<std::string>& right_strings,
98  const std::string& label, int label_width,
99  surface& hp_distrib, int hp_distrib_width);
100 
101  // This method draws the image of the hitpoints distribution of a
102  // combatant after a fight. The method takes as input the
103  // "hp_prob_vector" computed above and the stats of the combatants.
104  // It draws the image in the surface 'surf' and set the width and
105  // height of the image in the fields specified.
106  void get_hp_distrib_surface(const std::vector<std::pair<int, double> >& hp_prob_vector,
107  const battle_context_unit_stats& stats,
108  const battle_context_unit_stats& opp_stats,
109  surface& surf, int& width, int& height);
110 };
111 
112 // This class is used when the user clicks on the button
113 // to show the "Damage Calculations" dialog.
115 {
116 public:
117  attack_prediction_displayer(const std::vector<battle_context>& bc_vector,
118  const map_location& attacker_loc, const map_location& defender_loc)
119  : bc_vector_(bc_vector),
120  attacker_loc_(attacker_loc), defender_loc_(defender_loc) {}
121  // This method is called when the button is pressed.
122  RESULT button_pressed(int selection);
123 
124 private:
125  const std::vector<battle_context>& bc_vector_;
128 };
129 
130 #endif
std::vector< std::string > defender_left_strings_
int get_strings_max_length(const std::vector< std::string > &strings)
void get_hp_prob_vector(const std::vector< double > &hp_dist, std::vector< std::pair< int, double > > &hp_prob_vector)
Definition: unit.hpp:95
const map_location & defender_loc_
battle_prediction_pane(const battle_context &bc, const map_location &attacker_loc, const map_location &defender_loc)
std::vector< std::string > attacker_left_strings_
void get_unit_strings(const battle_context_unit_stats &stats, const unit &u, const map_location &u_loc, float u_unscathed, const unit &opp, const map_location &opp_loc, const attack_type *opp_weapon, std::vector< std::string > &left_strings, std::vector< std::string > &right_strings, int &left_strings_width, int &right_strings_width, int &strings_width)
const std::vector< battle_context > & bc_vector_
void draw_unit(int x_off, int damage_line_skip, int left_strings_width, const std::vector< std::string > &left_strings, const std::vector< std::string > &right_strings, const std::string &label, int label_width, surface &hp_distrib, int hp_distrib_width)
Computes the statistics of a battle between an attacker and a defender unit.
Definition: attack.hpp:135
void get_hp_distrib_surface(const std::vector< std::pair< int, double > > &hp_prob_vector, const battle_context_unit_stats &stats, const battle_context_unit_stats &opp_stats, surface &surf, int &width, int &height)
Structure describing the statistics of a unit involved in the battle.
Definition: attack.hpp:49
surf
Definition: filter.cpp:143
Encapsulates the map of the game.
Definition: location.hpp:38
GLsizei const GLchar ** strings
Definition: glew.h:1812
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
Definition: glew.h:1220
std::vector< std::string > defender_right_strings_
const map_location & attacker_loc_
attack_prediction_displayer(const std::vector< battle_context > &bc_vector, const map_location &attacker_loc, const map_location &defender_loc)
std::vector< std::string > attacker_right_strings_
GLint GLint GLint GLint GLint GLint GLsizei width
Definition: glew.h:1220
GLsizei const GLcharARB ** string
Definition: glew.h:4503