attack_prediction_display.hpp

Go to the documentation of this file.
00001 /* $Id: attack_prediction_display.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2006 - 2012 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
00004    wesnoth playturn Copyright (C) 2003 by David White <dave@whitevine.net>
00005    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2 of the License, or
00010    (at your option) any later version.
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY.
00013 
00014    See the COPYING file for more details.
00015 */
00016 
00017 #ifndef ATTACK_PREDICTION_DISPLAY_H_INCLUDED
00018 #define ATTACK_PREDICTION_DISPLAY_H_INCLUDED
00019 
00020 #include "actions.hpp"
00021 #include "show_dialog.hpp"
00022 
00023 // This preview pane is shown in the "Damage Calculations" dialog.
00024 class battle_prediction_pane : public gui::preview_pane
00025 {
00026 public:
00027 
00028     // Lengthy constructor.
00029     battle_prediction_pane(const battle_context& bc,
00030         const map_location& attacker_loc, const map_location& defender_loc);
00031 
00032     // This method is called to draw the dialog contents.
00033     void draw_contents();
00034 
00035     // Hack: pretend the preview pane goes to the left.
00036     bool left_side() const { return 1; }
00037 
00038     // Unused.
00039     void set_selection(int) {}
00040 
00041 private:
00042     const battle_context& bc_;
00043     const map_location& attacker_loc_;
00044     const map_location& defender_loc_;
00045     const unit& attacker_;
00046     const unit& defender_;
00047 
00048     // Layout constants.
00049     static const int inter_line_gap_;
00050     static const int inter_column_gap_;
00051     static const int inter_units_gap_;
00052     static const int max_hp_distrib_rows_;
00053 
00054     // Layout computations.
00055     std::string attacker_label_, defender_label_;
00056     int attacker_label_width_, defender_label_width_;
00057 
00058     std::vector<std::string> attacker_left_strings_, attacker_right_strings_;
00059     std::vector<std::string> defender_left_strings_, defender_right_strings_;
00060     int attacker_strings_width_, attacker_left_strings_width_, attacker_right_strings_width_;
00061     int defender_strings_width_, defender_left_strings_width_, defender_right_strings_width_;
00062     int units_strings_height_;
00063 
00064     std::string hp_distrib_string_;
00065     surface attacker_hp_distrib_, defender_hp_distrib_;
00066     int hp_distrib_string_width_;
00067     int attacker_hp_distrib_width_, defender_hp_distrib_width_;
00068     int attacker_hp_distrib_height_, defender_hp_distrib_height_, hp_distribs_height_;
00069 
00070     int attacker_width_, defender_width_, units_width_;
00071     int dialog_width_, dialog_height_;
00072 
00073     // This method builds the strings describing the unit damage modifiers.
00074     // Read the code to understand the arguments.
00075     void get_unit_strings(const battle_context_unit_stats& stats,
00076                       const unit& u, const map_location& u_loc, float u_unscathed,
00077                       const unit& opp, const map_location& opp_loc, const attack_type *opp_weapon,
00078                       std::vector<std::string>& left_strings, std::vector<std::string>& right_strings,
00079                       int& left_strings_width, int& right_strings_width, int& strings_width);
00080 
00081     // Utility method that returns the length of the longest string in a vector of strings.
00082     int get_strings_max_length(const std::vector<std::string>& strings);
00083 
00084     // This method builds the vector containing the <HP, probability> pairs
00085     // that are required to draw the image of the hitpoints distribution of
00086     // a combatant after a fight. The method takes as input the probability
00087     // distribution of the hitpoints of the combatant after the fight.
00088     void get_hp_prob_vector(const std::vector<double>& hp_dist,
00089                             std::vector<std::pair<int, double> >& hp_prob_vector);
00090 
00091     // This method draws a unit in the dialog pane. Read the code to understand
00092     // the arguments.
00093     void draw_unit(int x_off, int damage_line_skip, int left_strings_width,
00094                    const std::vector<std::string>& left_strings,
00095                    const std::vector<std::string>& right_strings,
00096                    const std::string& label, int label_width,
00097                    surface& hp_distrib, int hp_distrib_width);
00098 
00099     // This method draws the image of the hitpoints distribution of a
00100     // combatant after a fight. The method takes as input the
00101     // "hp_prob_vector" computed above and the stats of the combatants.
00102     // It draws the image in the surface 'surf' and set the width and
00103     // height of the image in the fields specified.
00104     void get_hp_distrib_surface(const std::vector<std::pair<int, double> >& hp_prob_vector,
00105                             const battle_context_unit_stats& stats,
00106                                 const battle_context_unit_stats& opp_stats,
00107                                 surface& surf, int& width, int& height);
00108 
00109     // This method blends a RGB color. The method takes as input a surface,
00110     // the RGB color to blend and a value specifying how much blending to
00111     // apply. The blended color is returned. Caution: if you use a
00112     // transparent color, make sure the resulting color is not equal to the
00113     // transparent color.
00114     Uint32 blend_rgb(const surface& surf, unsigned char r, unsigned char g, unsigned char b, unsigned char drop);
00115 };
00116 
00117 // This class is used when the user clicks on the button
00118 // to show the "Damage Calculations" dialog.
00119 class attack_prediction_displayer : public gui::dialog_button_action
00120 {
00121 public:
00122     attack_prediction_displayer(const std::vector<battle_context>& bc_vector,
00123                                 const map_location& attacker_loc, const map_location& defender_loc)
00124         : bc_vector_(bc_vector),
00125               attacker_loc_(attacker_loc), defender_loc_(defender_loc) {}
00126     // This method is called when the button is pressed.
00127     RESULT button_pressed(int selection);
00128 
00129 private:
00130     const std::vector<battle_context>& bc_vector_;
00131     const map_location& attacker_loc_;
00132     const map_location& defender_loc_;
00133 };
00134 
00135 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Wed May 23 2012 01:02:34 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs