The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
udisplay.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 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 /**
16  * @file
17  * Display units performing various actions: moving, attacking, and dying.
18  */
19 
20 #ifndef UNIT_DISPLAY_HPP_INCLUDED
21 #define UNIT_DISPLAY_HPP_INCLUDED
22 
23 #include "fake_unit_ptr.hpp"
24 #include "map/location.hpp"
25 #include "units/animation.hpp"
26 
27 class attack_type;
28 class fake_unit_manager;
29 class game_board;
30 class game_display;
31 class unit;
32 class vconfig;
33 
34 /**
35  * Contains a number of free functions which display units
36  *
37  * performing various on-screen actions - moving, attacking, and dying.
38  */
39 namespace unit_display
40 {
41 
42 /**
43  * A class to encapsulate the steps of drawing a unit's move.
44  * If control over how far the unit moves is not needed, move_unit() may
45  * be a more convenient interface.
46  */
47 class unit_mover : public boost::noncopyable {
48 public:
49  explicit unit_mover(const std::vector<map_location>& path, bool animate=true, bool force_scroll=false);
50  ~unit_mover();
51 
52  void start(unit_ptr u);
53  void proceed_to(unit_ptr u, size_t path_index, bool update=false, bool wait=true);
54  void wait_for_anims();
56 
57 private: // functions
59  void update_shown_unit();
60 
61 private: // data
63  const bool can_draw_;
64  const bool animate_;
65  const bool force_scroll_;
67  int wait_until_; /// The animation potential to wait until. INT_MIN for no wait; INT_MAX to wait for end.
68  unit_ptr shown_unit_; /// The unit to be (re-)shown after an animation finishes.
69  const std::vector<map_location>& path_;
70  size_t current_;
73  bool is_enemy_;
74 };
75 
76 
77 /**
78  * Display a unit moving along a given path.
79  */
80 void move_unit(const std::vector<map_location>& path, unit_ptr u,
81  bool animate=true,
83  bool force_scroll=false);
84 
85 /**
86  * Play a pre-fight animation
87  * First unit is the attacker, second unit the defender
88  */
89 void unit_draw_weapon( const map_location& loc, unit& u, const attack_type* attack=nullptr, const attack_type*secondary_attack=nullptr,const map_location& defender_loc = map_location::null_location(), unit * defender=nullptr);
90 
91 /**
92  * Play a post-fight animation
93  * Both unit can be set to null, only valid units will play their animation
94  */
95 void unit_sheath_weapon( const map_location& loc, unit* u=nullptr, const attack_type* attack=nullptr, const attack_type*secondary_attack=nullptr,const map_location& defender_loc = map_location::null_location(), unit * defender=nullptr);
96 
97 /**
98  * Show a unit fading out.
99  *
100  * Note: this only shows the effect, it doesn't actually kill the unit.
101  */
102  void unit_die( const map_location& loc, unit& u,
103  const attack_type* attack=nullptr, const attack_type* secondary_attack=nullptr,
104  const map_location& winner_loc=map_location::null_location(),
105  unit* winner=nullptr);
106 
107 
108 /**
109  * Make the unit on tile 'a' attack the unit on tile 'b'.
110  *
111  * The 'damage' will be subtracted from the unit's hitpoints,
112  * and a die effect will be displayed if the unit dies.
113  *
114  * @retval true if the defending unit is dead, should be
115  * removed from the playing field.
116  */
117 void unit_attack(display * disp, game_board & board, //TODO: Would be nice if this could be purely a display function and defer damage dealing to its caller
118  const map_location& a, const map_location& b, int damage,
119  const attack_type& attack, const attack_type* secondary_attack,
120  int swing, std::string hit_text, int drain_amount, std::string att_text, const std::vector<std::string>* extra_hit_sounds=nullptr);
121 
122 
123 void unit_recruited(const map_location& loc,
124  const map_location& leader_loc=map_location::null_location());
125 
126 /**
127  * This will use a poisoning anim if healing<0.
128  */
129 void unit_healing(unit &healed, const std::vector<unit *> &healers, int healing,
130  const std::string & extra_text="");
131 
132 
133 /**
134  * Parse a standard WML for animations and play the corresponding animation.
135  * Returns once animation is played.
136  *
137  * This is used for the animate_unit action, but can easily be generalized if
138  * other wml-described animations are needed.
139  */
140 void wml_animation(const vconfig &cfg,
141  const map_location& default_location=map_location::null_location());
142 
143 }
144 
145 #endif
Game board class.
Definition: game_board.hpp:55
game_display *const disp_
Definition: udisplay.hpp:62
Definition: unit.hpp:95
void unit_attack(display *disp, game_board &board, const map_location &a, const map_location &b, int damage, const attack_type &attack, const attack_type *secondary_attack, int swing, std::string hit_text, int drain_amount, std::string att_text, const std::vector< std::string > *extra_hit_sounds)
Make the unit on tile 'a' attack the unit on tile 'b'.
Definition: udisplay.cpp:572
Manages a list of fake units for the display object.
void wml_animation(const vconfig &cfg, const map_location &default_location)
Parse a standard WML for animations and play the corresponding animation.
Definition: udisplay.cpp:771
Contains a number of free functions which display units.
Definition: udisplay.cpp:154
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
unit_ptr shown_unit_
The animation potential to wait until. INT_MIN for no wait; INT_MAX to wait for end.
Definition: udisplay.hpp:68
unit_mover(const std::vector< map_location > &path, bool animate=true, bool force_scroll=false)
The path must remain unchanged for the life of this object.
Definition: udisplay.cpp:160
GLsizei const char ** path
Definition: glew.h:4654
void finish(unit_ptr u, map_location::DIRECTION dir=map_location::NDIRECTIONS)
Finishes the display of movement for the supplied unit.
Definition: udisplay.cpp:414
void proceed_to(unit_ptr u, size_t path_index, bool update=false, bool wait=true)
Visually moves a unit from the last hex we drew to the one specified by path_index.
Definition: udisplay.cpp:315
const bool force_scroll_
Definition: udisplay.hpp:65
unit_animator animator_
Definition: udisplay.hpp:66
void update_shown_unit()
Switches the display back to *shown_unit_ after animating.
Definition: udisplay.cpp:229
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:7319
A class to encapsulate the steps of drawing a unit's move.
Definition: udisplay.hpp:47
void unit_healing(unit &healed, const std::vector< unit * > &healers, int healing, const std::string &extra_text)
This will use a poisoning anim if healing<0.
Definition: udisplay.cpp:731
const std::vector< map_location > & path_
The unit to be (re-)shown after an animation finishes.
Definition: udisplay.hpp:69
void wait_for_anims()
Waits for the final animation of the most recent proceed_to() to finish.
Definition: udisplay.cpp:387
static const map_location & null_location()
Definition: location.hpp:195
void unit_draw_weapon(const map_location &loc, unit &attacker, const attack_type *attack, const attack_type *secondary_attack, const map_location &defender_loc, unit *defender)
Play a pre-fight animation First unit is the attacker, second unit the defender.
Definition: udisplay.cpp:500
Encapsulates the map of the game.
Definition: location.hpp:38
void unit_die(const map_location &loc, unit &loser, const attack_type *attack, const attack_type *secondary_attack, const map_location &winner_loc, unit *winner)
Show a unit fading out.
Definition: udisplay.cpp:548
void replace_temporary(unit_ptr u)
Makes the temporary unit used by this match the supplied unit.
Definition: udisplay.cpp:203
void start(unit_ptr u)
Initiates the display of movement for the supplied unit.
Definition: udisplay.cpp:244
DIRECTION
Valid directions which can be moved in our hexagonal world.
Definition: location.hpp:40
void unit_sheath_weapon(const map_location &primary_loc, unit *primary_unit, const attack_type *primary_attack, const attack_type *secondary_attack, const map_location &secondary_loc, unit *secondary_unit)
Play a post-fight animation Both unit can be set to null, only valid units will play their animation...
Definition: udisplay.cpp:518
void unit_recruited(const map_location &loc, const map_location &leader_loc)
Definition: udisplay.cpp:703
A variable-expanding proxy for the config class.
Definition: variable.hpp:36
fake_unit_ptr temp_unit_ptr_
Definition: udisplay.hpp:71
GLsizei const GLcharARB ** string
Definition: glew.h:4503
Holds a temporary unit that can be drawn on the map without being placed in the unit_map.
void move_unit(const std::vector< map_location > &path, unit_ptr u, bool animate, map_location::DIRECTION dir, bool force_scroll)
Display a unit moving along a given path.
Definition: udisplay.cpp:486