The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
move.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2016 by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
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  */
18 
19 #ifndef WB_MOVE_HPP_
20 #define WB_MOVE_HPP_
21 
22 #include "action.hpp"
23 #include "game_errors.hpp"
24 
26 
27 namespace wb {
28 
29 /**
30  * A planned move, represented on the map by an arrow and
31  * a ghosted unit in the destination hex.
32  */
33 class move : public action
34 {
35 public:
36  move(size_t team_index, bool hidden, unit& mover, const pathfind::marked_route& route,
37  arrow_ptr arrow, fake_unit_ptr fake_unit);
38  move(config const&, bool hidden); // For deserialization
39  virtual ~move();
40 
41  virtual std::ostream& print(std::ostream& s) const;
42 
43  virtual void accept(visitor& v);
44 
45  virtual void execute(bool& success, bool& complete);
46 
47  /**
48  * Check the validity of the action.
49  *
50  * @return the error preventing the action from being executed.
51  * @retval OK if there isn't any error (the action can be executed.)
52  */
53  virtual error check_validity() const;
54 
55  /** Return the unit targeted by this action. Null if unit doesn't exist. */
56  virtual unit_ptr get_unit() const;
57  /** @return pointer to the fake unit used only for visuals */
58  virtual fake_unit_ptr get_fake_unit() { return fake_unit_; }
59 
60  virtual map_location get_source_hex() const;
61  virtual map_location get_dest_hex() const;
62 
63  virtual void set_route(const pathfind::marked_route& route);
64  virtual const pathfind::marked_route& get_route() const { assert(route_); return *route_; }
65  /// attempts to pathfind a new marked route for this path between these two hexes;
66  /// returns true and assigns it to the internal route if successful.
67  virtual bool calculate_new_route(const map_location& source_hex, const map_location& dest_hex);
68 
69  virtual arrow_ptr get_arrow() { return arrow_; }
70 
71  /** Applies temporarily the result of this action to the specified unit map. */
72  virtual void apply_temp_modifier(unit_map& unit_map);
73  /** Removes the result of this action from the specified unit map. */
74  virtual void remove_temp_modifier(unit_map& unit_map);
75 
76  /** Gets called by display when drawing a hex, to allow actions to draw to the screen. */
77  virtual void draw_hex(map_location const& hex);
78  /** Redrawing function, called each time the action situation might have changed. */
79  void redraw();
80 
81  /** Assigns a turn number to display to this planned move. Assigning zero removes any turn number. */
82  virtual void set_turn_number(int turn) { turn_number_ = turn; }
83 
84  virtual map_location get_numbering_hex() const;
85 
86  virtual config to_config() const;
87 
88  ///@todo Make use of safe_enum idiom?
93 
94 protected:
95 
97  return boost::static_pointer_cast<move>(action::shared_from_this());
98  }
99 
100  void calculate_move_cost();
101 
104  boost::scoped_ptr<pathfind::marked_route> route_;
106  /// Turn end number to draw if greater than zero. Assigned by the map builder.
108 
111 
114 
115 private:
116  virtual void do_hide();
117  virtual void do_show();
118 
119  void hide_fake_unit();
120  void show_fake_unit();
121 
122  void init();
123  void update_arrow_style();
124  boost::scoped_ptr<temporary_unit_mover> mover_;
126 };
127 
128 /** Dumps an move on a stream, for debug purposes. */
129 std::ostream &operator<<(std::ostream &s, move_ptr move);
130 std::ostream &operator<<(std::ostream &s, move_const_ptr move);
131 
132 } // end namespace wb
133 
134 #endif /* WB_MOVE_HPP_ */
virtual void set_turn_number(int turn)
Assigns a turn number to display to this planned move.
Definition: move.hpp:82
std::string unit_id_
Definition: move.hpp:103
bool fake_unit_hidden_
Definition: move.hpp:125
virtual void do_hide()
Called by the non-virtual hide() and show(), respectively.
Definition: move.cpp:396
void init()
Definition: move.cpp:143
virtual map_location get_source_hex() const
Definition: move.cpp:294
void calculate_move_cost()
Definition: move.cpp:529
virtual config to_config() const
Constructs and returns a config object representing this object.
Definition: move.cpp:493
size_t unit_underlying_id_
Definition: move.hpp:102
int movement_cost_
Definition: move.hpp:105
int turn_number_
Turn end number to draw if greater than zero. Assigned by the map builder.
Definition: move.hpp:107
Definition: unit.hpp:95
virtual map_location get_dest_hex() const
Definition: move.cpp:300
bool hidden() const
Definition: action.hpp:64
virtual void set_route(const pathfind::marked_route &route)
Definition: move.cpp:306
ARROW_BRIGHTNESS
Definition: move.hpp:89
virtual error check_validity() const
Check the validity of the action.
Definition: move.cpp:429
arrow_ptr arrow_
Definition: move.hpp:109
virtual std::ostream & print(std::ostream &s) const
Definition: move.cpp:56
ARROW_TEXTURE
Definition: move.hpp:91
virtual void remove_temp_modifier(unit_map &unit_map)
Removes the result of this action from the specified unit map.
Definition: move.cpp:362
virtual bool calculate_new_route(const map_location &source_hex, const map_location &dest_hex)
attempts to pathfind a new marked route for this path between these two hexes; returns true and assig...
Definition: move.cpp:313
virtual void accept(visitor &v)
Definition: move.cpp:200
virtual void execute(bool &success, bool &complete)
Output parameters: success: Whether or not to continue an execute-all after this execution complete: ...
Definition: move.cpp:205
size_t team_index() const
Returns the index of the team that owns this action.
Definition: action.hpp:82
Arrows destined to be drawn on the map.
Definition: arrow.hpp:30
void update_arrow_style()
Definition: move.cpp:563
boost::shared_ptr< move > shared_from_this()
Definition: move.hpp:96
error
Possible errors.
Definition: action.hpp:104
fake_unit_ptr fake_unit_
Definition: move.hpp:110
const GLdouble * v
Definition: glew.h:1359
ARROW_BRIGHTNESS arrow_brightness_
Definition: move.hpp:112
virtual fake_unit_ptr get_fake_unit()
Definition: move.hpp:58
boost::scoped_ptr< temporary_unit_mover > mover_
Definition: move.hpp:124
boost::scoped_ptr< pathfind::marked_route > route_
Definition: move.hpp:104
Structure which holds a single route and marks for special events.
Definition: pathfind.hpp:141
virtual void apply_temp_modifier(unit_map &unit_map)
Applies temporarily the result of this action to the specified unit map.
Definition: move.cpp:327
void redraw()
Redrawing function, called each time the action situation might have changed.
Definition: move.cpp:554
virtual unit_ptr get_unit() const
Return the unit targeted by this action.
Definition: move.cpp:285
Encapsulates the map of the game.
Definition: location.hpp:38
void hide_fake_unit()
Definition: move.cpp:410
void show_fake_unit()
Definition: move.cpp:417
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
move(size_t team_index, bool hidden, unit &mover, const pathfind::marked_route &route, arrow_ptr arrow, fake_unit_ptr fake_unit)
Definition: move.cpp:63
ARROW_TEXTURE arrow_texture_
Definition: move.hpp:113
void set_arrow_texture(ARROW_TEXTURE x) const
Definition: move.hpp:92
virtual arrow_ptr get_arrow()
Definition: move.hpp:69
Container associating units to locations.
Definition: map.hpp:90
std::ostream & operator<<(std::ostream &s, action_ptr action)
Definition: action.cpp:33
virtual void draw_hex(map_location const &hex)
Gets called by display when drawing a hex, to allow actions to draw to the screen.
Definition: move.cpp:385
virtual const pathfind::marked_route & get_route() const
Definition: move.hpp:64
Abstract base class for all the whiteboard planned actions.
Definition: action.hpp:33
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
virtual void do_show()
Definition: move.cpp:403
GLdouble s
Definition: glew.h:1358
virtual ~move()
Definition: move.cpp:198
void set_arrow_brightness(ARROW_BRIGHTNESS x) const
Definition: move.hpp:90
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.
A planned move, represented on the map by an arrow and a ghosted unit in the destination hex...
Definition: move.hpp:33
virtual map_location get_numbering_hex() const
Definition: move.cpp:424
Definition: display.hpp:47
This object is used to temporary move a unit in the unit map, swapping out any unit that is already t...
Definition: game_board.hpp:201
Abstract base class for all the visitors (cf GoF Visitor Design Pattern) the whiteboard uses...
Definition: visitor.hpp:32