50 return move->print(s);
56 return move->print(s);
65 s <<
"Move for unit " <<
get_unit()->name() <<
" [" <<
get_unit()->id() <<
"] " 73 :
action(team_index,hidden),
86 assert(!
route_->steps.empty());
118 route_->move_cost = route_cfg[
"move_cost"];
120 route_->steps.emplace_back(loc_cfg[
"x"],loc_cfg[
"y"],
wml_loc());
125 mark_cfg[
"zoc"].to_bool(),
126 mark_cfg[
"capture"].to_bool(),
127 mark_cfg[
"invisible"].to_bool());
131 const std::vector<map_location>& steps =
route_->steps;
167 if (action != side_actions->end())
169 if (
move_ptr move = std::dynamic_pointer_cast<class move>(*action))
177 std::string arrow_style =
arrow_->get_style();
218 success = complete =
true;
225 const std::vector<map_location> steps =
route_->steps;
230 std::size_t num_steps;
242 if ( num_steps == 0 )
244 LOG_WB <<
"Move execution resulted in zero movement.";
250 WRN_WB <<
"Unit disappeared from map during move execution.";
256 complete = num_steps + 1 == steps.size();
257 success = complete && !interrupted;
263 LOG_WB <<
"Move completed, but interrupted on final hex. Halting.";
265 route_->steps = std::vector<map_location>(1, final_location);
270 LOG_WB <<
"Move finished at (" << final_location <<
") instead of at (" <<
get_dest_hex() <<
"). Setting new path.";
271 route_->steps = std::vector<map_location>(steps.begin() + num_steps, steps.end());
302 return route_->steps.front();
308 return route_->steps.back();
352 assert(unit_it != unit_map.
end());
356 if (
route_->move_cost == -1) {
361 DBG_WB <<
"Move: Changing movement points for unit " << unit->
name() <<
" [" << unit->
id()
365 DBG_WB <<
"Move: Temporarily moving unit " << unit->
name() <<
" [" << unit->
id()
388 DBG_WB <<
"Move: Movement points for unit " << unit->
name() <<
" [" << unit->
id()
389 <<
"] should get changed from " << unit->
movement_left() <<
" to " 402 std::stringstream turn_text;
444 class arrow_texture_setter {
448 current_texture(current_texture),
449 setting_texture(setting_texture) {}
451 ~arrow_texture_setter() {
452 if(current_texture!=setting_texture) {
496 if(checked_route.
marks[checked_route.
steps.back()].turns != 1) {
511 final_cfg[
"type"]=
"move";
518 route_cfg[
"move_cost"]=
route_->move_cost;
522 loc_cfg[
"x"]=loc.
wml_x();
523 loc_cfg[
"y"]=loc.
wml_y();
524 route_cfg.
add_child(
"step", std::move(loc_cfg));
526 typedef std::pair<map_location,pathfind::marked_route::mark> pair_loc_mark;
530 mark_cfg[
"x"]=item.first.wml_x();
531 mark_cfg[
"y"]=item.first.wml_y();
532 mark_cfg[
"turns"]=item.second.turns;
533 mark_cfg[
"zoc"]=item.second.zoc;
534 mark_cfg[
"capture"]=item.second.capture;
535 mark_cfg[
"invisible"]=item.second.invisible;
536 route_cfg.
add_child(
"mark", std::move(mark_cfg));
538 final_cfg.
add_child(
"route_", std::move(route_cfg));
container::iterator iterator
play_controller * controller
virtual void do_hide()
Called by the non-virtual hide() and show(), respectively.
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
Arrows destined to be drawn on the map.
marked_route mark_route(const plain_route &rt, bool update_move_cost)
Add marks on a route rt assuming that the unit located at the first hex of rt travels along it...
static display * get_singleton()
Returns the display object if a display object exists.
virtual const std::vector< team > & teams() const override
void set_arrow_texture(ARROW_TEXTURE x) const
virtual const unit_map & units() const override
int turn_number_
Turn end number to draw if greater than zero.
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
This class represents a single unit of a specific type.
virtual void draw_hex(const map_location &hex)
Gets called by display when drawing a hex, to allow actions to draw to the screen.
virtual void set_route(const pathfind::marked_route &route)
internal_ptr get_unit_ptr()
Get a copy of the internal unit pointer.
Exception used to escape form the ai or ui code to playsingle_controller::play_side.
std::shared_ptr< side_actions > side_actions_ptr
child_itors child_range(config_key_type key)
virtual std::ostream & print(std::ostream &s) const
virtual void visit(move_ptr move)=0
std::shared_ptr< move const > move_const_ptr
virtual const pathfind::marked_route & get_route() const
Contains the exception interfaces used to signal completion of a scenario, campaign or turn...
virtual void remove_temp_modifier(unit_map &unit_map)
Removes the result of this action from the specified unit map.
Definitions for the interface to Wesnoth Markup Language (WML).
std::shared_ptr< unit > unit_ptr
Wrapper class to encapsulate creation and management of an SDL_Texture.
std::size_t team_index() const
Returns the index of the team that owns this action.
static double getNoPathValue()
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...
std::size_t unit_underlying_id_
virtual void accept(visitor &v)
static const std::string STYLE_HIGHLIGHTED
virtual void execute(bool &success, bool &complete)
Output parameters: success: Whether or not to continue an execute-all after this execution complete: ...
bool valid()
Returns whether this action is valid or not.
static const std::string STYLE_FOCUS
static std::string at(const std::string &file, int line)
move(std::size_t team_index, bool hidden, unit &mover, const pathfind::marked_route &route, arrow_ptr arrow, fake_unit_ptr fake_unit)
const std::string & id() const
Gets this unit's id.
Arrows destined to be drawn on the map.
Structure which holds a single route between one location and another.
virtual map_location get_numbering_hex() const
void update_arrow_style()
virtual map_location get_dest_hex() const
std::size_t move_unit_along_route(const std::vector< map_location > &steps, bool &interrupted)
Moves a unit across the board for a player.
unit * get_visible_unit(const map_location &loc, const team ¤t_team, bool see_all=false)
static const std::string STYLE_FOCUS_INVALID
ARROW_BRIGHTNESS arrow_brightness_
virtual error check_validity() const
Check the validity of the action.
const t_string & name() const
Gets this unit's translatable display name.
int calculate_moves_left(unit &u)
fake_unit_manager * fake_units
void draw_text_in_hex(const map_location &loc, const drawing_layer layer, const std::string &text, std::size_t font_size, color_t color, double x_in_hex=0.5, double y_in_hex=0.5)
Draw text on a hex.
virtual unit_ptr get_unit() const
Return the unit targeted by this action.
Structure which holds a single route and marks for special events.
virtual void apply_temp_modifier(unit_map &unit_map)
Applies temporarily the result of this action to the specified unit map.
void redraw()
Redrawing function, called each time the action situation might have changed.
const color_t NORMAL_COLOR
int move_cost
Movement cost for reaching the end of the route.
static std::string get_side_color_id(unsigned side)
Encapsulates the map of the game.
unit_iterator find(std::size_t id)
pointer get_shared_ptr() const
This is exactly the same as operator-> but it's slightly more readable, and can replace &*iter syntax...
virtual config to_config() const
Constructs and returns a config object representing this object.
static lg::log_domain log_whiteboard("whiteboard")
static map_location::DIRECTION s
void init(unit *u=nullptr)
Movement info (defense%, etc...).
std::unique_ptr< temporary_unit_mover > mover_
std::shared_ptr< move > move_ptr
config & add_child(config_key_type key)
ARROW_TEXTURE arrow_texture_
std::shared_ptr< move > shared_from_this()
std::shared_ptr< arrow > arrow_ptr
events::mouse_handler & get_mouse_handler_base() override
Get a reference to a mouse handler member a derived class uses.
virtual map_location get_source_hex() const
int current_side() const
Returns the number of the side whose turn it is.
Container associating units to locations.
std::ostream & operator<<(std::ostream &s, action_ptr action)
static const std::string STYLE_STANDARD
If you add more styles, you should look at move::update_arrow_style()
void modify_unit(unit &new_unit)
int side_number() const
Returns the number of the side that owns this action, i.e.
visitor is an abstract interface : action.accept(visitor) calls visitor.visit(action) ...
Abstract base class for all the whiteboard planned actions.
plain_route a_star_search(const map_location &src, const map_location &dst, double stop_at, const cost_calculator &calc, const std::size_t width, const std::size_t height, const teleport_map *teleports, bool border)
std::unique_ptr< pathfind::marked_route > route_
A config object defines a single node in a WML file, with access to child nodes.
virtual config to_config() const
Constructs and returns a config object representing this object.
void set_arrow_brightness(ARROW_BRIGHTNESS x) const
This internal whiteboard class holds the planned action queues for a team, and offers many utility me...
Holds a temporary unit that can be drawn on the map without being placed in the unit_map.
int movement_left() const
Gets how far a unit can move, considering the incapacitated flag.
A planned move, represented on the map by an arrow and a ghosted unit in the destination hex...
std::size_t underlying_id() const
This unit's unique internal ID.
Display units performing various actions: moving, attacking, and dying.
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.
std::vector< map_location > & steps
std::size_t viewer_team()
This object is used to temporary move a unit in the unit map, swapping out any unit that is already t...
std::pair< std::string, unsigned > item
Abstract base class for all the visitors (cf GoF Visitor Design Pattern) the whiteboard uses...