The Battle for Wesnoth  1.19.7+dev
move.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2024
3  by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
4  Part of the Battle for Wesnoth Project https://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 /**
17  * @file
18  */
19 
20 #include "whiteboard/move.hpp"
21 
22 #include <utility>
23 
24 #include "whiteboard/visitor.hpp"
26 #include "whiteboard/utility.hpp"
27 
28 #include "arrow.hpp"
29 #include "config.hpp"
30 #include "fake_unit_ptr.hpp"
31 #include "font/standard_colors.hpp"
32 #include "game_board.hpp"
33 #include "game_end_exceptions.hpp"
34 #include "map/map.hpp"
35 #include "mouse_events.hpp"
36 #include "play_controller.hpp"
37 #include "resources.hpp"
38 #include "team.hpp"
39 #include "units/unit.hpp"
41 #include "units/udisplay.hpp"
42 #include "units/map.hpp"
43 
44 namespace wb {
45 
46 std::ostream& operator<<(std::ostream &s, const move_ptr& move)
47 {
48  assert(move);
49  return move->print(s);
50 }
51 
52 std::ostream& operator<<(std::ostream &s, const move_const_ptr& move)
53 {
54  assert(move);
55  return move->print(s);
56 }
57 
58 std::ostream& move::print(std::ostream &s) const
59 {
60  if(!get_unit()) {
61  s << "Move for unknown unit [" << unit_underlying_id_ << "] " << "from (" << get_source_hex() << ") to (" << get_dest_hex() << ")";
62  }
63  else {
64  s << "Move for unit " << get_unit()->name() << " [" << get_unit()->id() << "] "
65  << "from (" << get_source_hex() << ") to (" << get_dest_hex() << ")";
66  }
67  return s;
68 }
69 
70 move::move(std::size_t team_index, bool hidden, unit& u, const pathfind::marked_route& route,
71  arrow_ptr arrow, fake_unit_ptr fake_unit)
72 : action(team_index,hidden),
73  unit_underlying_id_(u.underlying_id()),
74  unit_id_(),
75  route_(new pathfind::marked_route(route)),
76  movement_cost_(0),
77  turn_number_(0),
78  arrow_(std::move(arrow)),
79  fake_unit_(std::move(fake_unit)),
80  arrow_brightness_(),
81  arrow_texture_(),
82  mover_(),
83  fake_unit_hidden_(false)
84 {
85  assert(!route_->steps.empty());
86 
87  if(hidden)
88  fake_unit_->set_hidden(true);
89 
90  this->init();
91 }
92 
93 move::move(const config& cfg, bool hidden)
94  : action(cfg,hidden)
95  , unit_underlying_id_(0)
96  , unit_id_()
97  , route_(new pathfind::marked_route())
98  , movement_cost_(0)
99  , turn_number_(0)
100  , arrow_(new arrow(hidden))
101  , fake_unit_()
102  , arrow_brightness_()
103  , arrow_texture_()
104  , mover_()
105  , fake_unit_hidden_(false)
106 {
107  // Construct and validate unit_
108  unit_map::iterator unit_itor = resources::gameboard->units().find(cfg["unit_"].to_size_t());
109  if(unit_itor == resources::gameboard->units().end())
110  throw action::ctor_err("move: Invalid underlying_id");
111  unit_underlying_id_ = unit_itor->underlying_id();
112 
113  // Construct and validate route_
114  auto route_cfg = cfg.optional_child("route_");
115  if(!route_cfg)
116  throw action::ctor_err("move: Invalid route_");
117  route_->move_cost = route_cfg["move_cost"].to_int();
118  for(const config& loc_cfg : route_cfg->child_range("step")) {
119  route_->steps.emplace_back(loc_cfg["x"],loc_cfg["y"], wml_loc());
120  }
121  for(const config& mark_cfg : route_cfg->child_range("mark")) {
122  route_->marks[map_location(mark_cfg["x"],mark_cfg["y"], wml_loc())]
123  = pathfind::marked_route::mark(mark_cfg["turns"].to_int(),
124  mark_cfg["zoc"].to_bool(),
125  mark_cfg["capture"].to_bool(),
126  mark_cfg["invisible"].to_bool());
127  }
128 
129  // Validate route_ some more
130  const std::vector<map_location>& steps = route_->steps;
131  if(steps.empty())
132  throw action::ctor_err("move: Invalid route_");
133 
134  // Construct arrow_
136  arrow_->set_style(arrow::STYLE_STANDARD);
137  arrow_->set_path(route_->steps);
138 
139  // Construct fake_unit_
141  if(hidden)
142  fake_unit_->set_hidden(true);
143  fake_unit_->anim_comp().set_ghosted(true);
144  unit_display::move_unit(route_->steps, fake_unit_.get_unit_ptr(), false); //get facing right
145  fake_unit_->set_location(route_->steps.back());
146 
147  this->init();
148 }
149 
150 void move::init(unit* u)
151 {
152  if(get_unit()) {
153  unit_id_ = get_unit()->id();
154  }
155  else if(u) {
156  unit_id_ = u->id();
157  }
158  //This action defines the future position of the unit, make its fake unit more visible
159  //than previous actions' fake units
160  if (fake_unit_)
161  {
162  fake_unit_->anim_comp().set_ghosted(true);
163  }
164  side_actions_ptr side_actions = resources::gameboard->teams().at(team_index()).get_side_actions();
166  if (action != side_actions->end())
167  {
168  if (move_ptr move = std::dynamic_pointer_cast<class move>(*action))
169  {
170  if (move->fake_unit_)
171  move->fake_unit_->anim_comp().set_disabled_ghosted(true);
172  }
173  }
174 
175  // Initialize arrow_brightness_ and arrow_texture_ using arrow_->style_
176  std::string arrow_style = arrow_->get_style();
177  if(arrow_style == arrow::STYLE_STANDARD)
178  {
181  }
182  else if(arrow_style == arrow::STYLE_HIGHLIGHTED)
183  {
186  }
187  else if(arrow_style == arrow::STYLE_FOCUS)
188  {
191  }
192  else if(arrow_style == arrow::STYLE_FOCUS_INVALID)
193  {
196  }
197 }
198 
200 
202 {
203  v.visit(shared_from_this());
204 }
205 
206 void move::execute(bool& success, bool& complete)
207 {
208  if(!valid()) {
209  success = false;
210  //Setting complete to true signifies to side_actions to delete the planned action.
211  complete = true;
212  return;
213  }
214 
215  if(get_source_hex() == get_dest_hex()) {
216  //zero-hex move, used by attack subclass
217  success = complete = true;
218  return;
219  }
220 
221  LOG_WB << "Executing: " << shared_from_this();
222 
223  // Copy the current route to ensure it remains valid throughout the animation.
224  const std::vector<map_location> steps = route_->steps;
225 
227  hide_fake_unit();
228 
229  std::size_t num_steps;
230  bool interrupted;
231  try {
233  num_steps = mouse_handler.move_unit_along_route(steps, interrupted);
234  } catch (const return_to_play_side_exception&) {
236  throw; // we rely on the caller to delete this action
237  }
238  const map_location & final_location = steps[num_steps];
239  unit_map::const_iterator unit_it = resources::gameboard->units().find(final_location);
240 
241  if ( num_steps == 0 )
242  {
243  LOG_WB << "Move execution resulted in zero movement.";
244  success = false;
245  complete = true;
246  }
247  else if ( unit_it == resources::gameboard->units().end() || (unit_id_.empty() && ( unit_it->id() != unit_id_ )))
248  {
249  WRN_WB << "Unit disappeared from map during move execution.";
250  success = false;
251  complete = true;
252  }
253  else
254  {
255  complete = num_steps + 1 == steps.size();
256  success = complete && !interrupted;
257 
258  if ( !success )
259  {
260  if ( complete )
261  {
262  LOG_WB << "Move completed, but interrupted on final hex. Halting.";
263  //reset to a single-hex path, just in case *this is a wb::attack
264  route_->steps = std::vector<map_location>(1, final_location);
265  arrow_.reset();
266  }
267  else
268  {
269  LOG_WB << "Move finished at (" << final_location << ") instead of at (" << get_dest_hex() << "). Setting new path.";
270  route_->steps = std::vector<map_location>(steps.begin() + num_steps, steps.end());
271  //FIXME: probably better to use the new calculate_new_route() instead of the above:
272  //calculate_new_route(final_location, steps.back());
273  // Of course, "better" would need to be verified.
274 
275  //Update route_->move_cost
276  route_.reset(new pathfind::marked_route(mark_route(route_->route, true)));
277  arrow_->set_path(route_->steps);
278  }
279  }
280  }
281 
282  if(!complete)
283  {
285  show_fake_unit();
286  }
287 }
288 
290 {
292  if (itor.valid())
293  return itor.get_shared_ptr();
294  else
295  return unit_ptr();
296 }
297 
299 {
300  assert(route_ && !route_->steps.empty());
301  return route_->steps.front();
302 }
303 
305 {
306  assert(route_ && !route_->steps.empty());
307  return route_->steps.back();
308 }
309 
311 {
312  route_.reset(new pathfind::marked_route(route));
313  arrow_->set_path(route_->steps);
314 }
315 
316 void move::modify_unit(unit& new_unit)
317 {
318  unit_underlying_id_ = new_unit.underlying_id();
319  unit_id_ = new_unit.id();
320 }
321 
322 bool move::calculate_new_route(const map_location& source_hex, const map_location& dest_hex)
323 {
324  pathfind::plain_route new_plain_route;
326  resources::gameboard->teams().at(team_index()),
327  resources::gameboard->teams(), resources::gameboard->map());
328  new_plain_route = pathfind::a_star_search(source_hex,
329  dest_hex, 10000, path_calc, resources::gameboard->map().w(), resources::gameboard->map().h());
330  if (new_plain_route.move_cost >= path_calc.getNoPathValue()) return false;
331  route_.reset(new pathfind::marked_route(pathfind::mark_route(new_plain_route)));
332  return true;
333 }
334 
336 {
337  if (get_source_hex() == get_dest_hex())
338  return; //zero-hex move, used by attack subclass
339 
340  // Safety: Make sure the old temporary_unit_mover (if any) is destroyed
341  // before creating a new one.
342  mover_.reset();
343 
344  //@todo: deal with multi-turn moves, which may for instance end their first turn
345  // by capturing a village
346 
347  //@todo: we may need to change unit status here and change it back in remove_temp_modifier
348  unit* unit;
349  {
351  assert(unit_it != unit_map.end());
352  unit = &*unit_it;
353  }
354 
355  if (route_->move_cost == -1) {
356  // TODO: check_validity also calls pathfind::mark_route(get_route().route), optimize/refactor this to only call that once.
357  route_->move_cost = pathfind::mark_route(get_route().route, true).move_cost;
358  }
359  //Modify movement points
360  DBG_WB <<"Move: Changing movement points for unit " << unit->name() << " [" << unit->id()
361  << "] from " << unit->movement_left() << " to "
362  << calculate_moves_left(*unit) << ".";
363  // Move the unit
364  DBG_WB << "Move: Temporarily moving unit " << unit->name() << " [" << unit->id()
365  << "] from (" << get_source_hex() << ") to (" << get_dest_hex() <<")";
367 
368  //Update status of fake unit (not undone by remove_temp_modifiers)
369  //@todo this contradicts the name "temp_modifiers"
370  fake_unit_->set_movement(unit->movement_left(), true);
371 }
372 
374 {
375  if (get_source_hex() == get_dest_hex())
376  return; //zero-hex move, probably used by attack subclass
377 
378  // Debug movement points
379  if ( !lg::debug().dont_log(log_whiteboard) )
380  {
381  unit* unit;
382  {
384  assert(unit_it != resources::gameboard->units().end());
385  unit = &*unit_it;
386  }
387  DBG_WB << "Move: Movement points for unit " << unit->name() << " [" << unit->id()
388  << "] should get changed from " << unit->movement_left() << " to "
389  << calculate_moves_left(*unit) << ".";
390  }
391 
392  // Restore the unit to its original position and movement.
393  mover_.reset();
394 }
395 
396 void move::draw_hex(const map_location& hex)
397 {
398  //display turn info for turns 2 and above
399  if (hex == get_dest_hex() && turn_number_ >= 2)
400  {
401  std::stringstream turn_text;
402  turn_text << turn_number_;
404  }
405 }
406 
408 {
409  arrow_->hide();
410  if(!fake_unit_hidden_)
411  fake_unit_->set_hidden(true);
412 }
413 
415 {
416  arrow_->show();
417  if(!fake_unit_hidden_)
418  fake_unit_->set_hidden(false);
419 }
420 
422 {
423  fake_unit_hidden_ = true;
424  if(!hidden())
425  fake_unit_->set_hidden(true);
426 }
427 
429 {
430  fake_unit_hidden_ = false;
431  if(!hidden())
432  fake_unit_->set_hidden(false);
433 }
434 
436 {
437  return get_dest_hex();
438 }
439 
441 {
442  // Used to deal with multiple return paths.
443  class arrow_texture_setter {
444  public:
445  arrow_texture_setter(const move *target, move::ARROW_TEXTURE current_texture, move::ARROW_TEXTURE setting_texture):
446  target(target),
447  current_texture(current_texture),
448  setting_texture(setting_texture) {}
449 
450  ~arrow_texture_setter() {
451  if(current_texture!=setting_texture) {
452  target->set_arrow_texture(setting_texture);
453  }
454  }
455 
456  void set_texture(move::ARROW_TEXTURE texture) { setting_texture=texture; }
457 
458  private:
459  const move *target;
460  move::ARROW_TEXTURE current_texture, setting_texture;
461  };
462 
463  arrow_texture_setter setter(this, arrow_texture_, ARROW_TEXTURE_INVALID);
464 
465  if(!(get_source_hex().valid() && get_dest_hex().valid())) {
466  return INVALID_LOCATION;
467  }
468 
469  //Check that the unit still exists in the source hex
470  unit_map::iterator unit_it;
472  if(unit_it == resources::gameboard->units().end()) {
473  return NO_UNIT;
474  }
475 
476  //check if the unit in the source hex has the same unit id as before,
477  //i.e. that it's the same unit
478  if((!unit_id_.empty() && unit_id_ != unit_it->id()) || unit_underlying_id_ != unit_it->underlying_id()) {
479  return UNIT_CHANGED;
480  }
481 
482  //If the path has at least two hexes (it can have less with the attack subclass), ensure destination hex is free
483  if(get_route().steps.size() >= 2 && resources::gameboard->get_visible_unit(get_dest_hex(), display::get_singleton()->viewing_team()) != nullptr) {
484  return LOCATION_OCCUPIED;
485  }
486 
487  //check that the path is good
488  if(get_source_hex() != get_dest_hex()) { //skip zero-hex move used by attack subclass
489 
490  // Mark the plain route to see if the move can still be done in one turn,
491  // which is always the case for planned moves
492  // TODO: this check is rather slow, skip it if the gamestat has not changed.
493  pathfind::marked_route checked_route = pathfind::mark_route(get_route().route);
494 
495  if(checked_route.marks[checked_route.steps.back()].turns != 1) {
496  return TOO_FAR;
497  }
498  }
499 
500  // The move is valid, so correct the setter.
501  setter.set_texture(ARROW_TEXTURE_VALID);
502 
503  return OK;
504 }
505 
507 {
508  config final_cfg = action::to_config();
509 
510  final_cfg["type"]="move";
511  final_cfg["unit_"]=static_cast<int>(unit_underlying_id_);
512 // final_cfg["movement_cost_"]=movement_cost_; //Unnecessary
513 // final_cfg["unit_id_"]=unit_id_; //Unnecessary
514 
515  //Serialize route_
516  config route_cfg;
517  route_cfg["move_cost"]=route_->move_cost;
518  for(const map_location& loc : route_->steps)
519  {
520  config loc_cfg;
521  loc_cfg["x"]=loc.wml_x();
522  loc_cfg["y"]=loc.wml_y();
523  route_cfg.add_child("step", std::move(loc_cfg));
524  }
525  typedef std::pair<map_location,pathfind::marked_route::mark> pair_loc_mark;
526  for(const pair_loc_mark item : route_->marks)
527  {
528  config mark_cfg;
529  mark_cfg["x"]=item.first.wml_x();
530  mark_cfg["y"]=item.first.wml_y();
531  mark_cfg["turns"]=item.second.turns;
532  mark_cfg["zoc"]=item.second.zoc;
533  mark_cfg["capture"]=item.second.capture;
534  mark_cfg["invisible"]=item.second.invisible;
535  route_cfg.add_child("mark", std::move(mark_cfg));
536  }
537  final_cfg.add_child("route_", std::move(route_cfg));
538 
539  return final_cfg;
540 }
541 
543 {
544  assert(route_);
546  {
547 
548  // @todo: find a better treatment of movement points when defining moves out-of-turn
549  if(u.movement_left() - route_->move_cost < 0
551  WRN_WB << shared_from_this() << " defined with insufficient movement left.";
552  }
553 
554  // If unit finishes move in a village it captures, set the move cost to unit's movement_left()
555  if (route_->marks[get_dest_hex()].capture)
556  {
557  return 0;
558  }
559  else
560  {
561  return u.movement_left() - route_->move_cost;
562  }
563  }
564  return 0;
565 }
566 
568 {
572 }
573 
574 //If you add more arrow styles, this will need to change
575 /* private */
577 {
579  {
581  return;
582  }
583 
584  switch(arrow_brightness_)
585  {
587  arrow_->set_style(arrow::STYLE_STANDARD);
588  break;
590  arrow_->set_style(arrow::STYLE_HIGHLIGHTED);
591  break;
593  arrow_->set_style(arrow::STYLE_FOCUS);
594  break;
595  }
596 }
597 
598 } // end namespace wb
map_location loc
Definition: move.cpp:172
const std::vector< map_location > & route_
Definition: move.cpp:384
Arrows destined to be drawn on the map.
Arrows destined to be drawn on the map.
Definition: arrow.hpp:30
static const std::string STYLE_FOCUS_INVALID
Definition: arrow.hpp:70
static const std::string STYLE_FOCUS
Definition: arrow.hpp:69
static const std::string STYLE_STANDARD
If you add more styles, you should look at move::update_arrow_style()
Definition: arrow.hpp:67
static const std::string STYLE_HIGHLIGHTED
Definition: arrow.hpp:68
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
child_itors child_range(config_key_type key)
Definition: config.cpp:272
optional_config_impl< config > optional_child(config_key_type key, int n=0)
Equivalent to mandatory_child, but returns an empty optional if the nth child was not found.
Definition: config.cpp:384
config & add_child(config_key_type key)
Definition: config.cpp:440
const team & viewing_team() const
Definition: display.cpp:342
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.
Definition: display.cpp:1453
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
Definition: display.cpp:3087
static display * get_singleton()
Returns the display object if a display object exists.
Definition: display.hpp:111
std::size_t move_unit_along_route(const std::vector< map_location > &steps, bool &interrupted)
Moves a unit across the board for a player.
Holds a temporary unit that can be drawn on the map without being placed in the unit_map.
internal_ptr get_unit_ptr()
Get a copy of the internal unit pointer.
virtual const std::vector< team > & teams() const override
Definition: game_board.hpp:80
unit * get_visible_unit(const map_location &loc, const team &current_team, bool see_all=false)
Definition: game_board.cpp:213
virtual const unit_map & units() const override
Definition: game_board.hpp:107
events::mouse_handler & get_mouse_handler_base() override
Get a reference to a mouse handler member a derived class uses.
int current_side() const
Returns the number of the side whose turn it is.
Exception used to escape form the ai or ui code to playsingle_controller::play_side.
int side() const
Definition: team.hpp:175
static std::string get_side_color_id(unsigned side)
Definition: team.cpp:971
Wrapper class to encapsulate creation and management of an SDL_Texture.
Definition: texture.hpp:33
Container associating units to locations.
Definition: map.hpp:98
unit_iterator end()
Definition: map.hpp:428
unit_iterator find(std::size_t id)
Definition: map.cpp:302
This class represents a single unit of a specific type.
Definition: unit.hpp:133
Abstract base class for all the whiteboard planned actions.
Definition: action.hpp:34
bool hidden() const
Definition: action.hpp:64
bool valid()
Returns whether this action is valid or not.
Definition: action.hpp:135
std::size_t team_index() const
Returns the index of the team that owns this action.
Definition: action.hpp:84
virtual config to_config() const
Constructs and returns a config object representing this object.
Definition: action.cpp:51
error
Possible errors.
Definition: action.hpp:107
@ INVALID_LOCATION
Definition: action.hpp:109
@ UNIT_CHANGED
Definition: action.hpp:111
@ LOCATION_OCCUPIED
Definition: action.hpp:112
int side_number() const
Returns the number of the side that owns this action, i.e.
Definition: action.hpp:86
A planned move, represented on the map by an arrow and a ghosted unit in the destination hex.
Definition: move.hpp:36
move(std::size_t team_index, bool hidden, unit &mover, const pathfind::marked_route &route, arrow_ptr arrow, fake_unit_ptr fake_unit)
Definition: move.cpp:70
void hide_fake_unit()
Definition: move.cpp:421
void redraw()
Redrawing function, called each time the action situation might have changed.
Definition: move.cpp:567
virtual void accept(visitor &v)
Definition: move.cpp:201
void show_fake_unit()
Definition: move.cpp:428
virtual void remove_temp_modifier(unit_map &unit_map)
Removes the result of this action from the specified unit map.
Definition: move.cpp:373
virtual unit_ptr get_unit() const
Return the unit targeted by this action.
Definition: move.cpp:289
virtual error check_validity() const
Check the validity of the action.
Definition: move.cpp:440
std::string unit_id_
Definition: move.hpp:111
std::unique_ptr< pathfind::marked_route > route_
Definition: move.hpp:112
virtual void draw_hex(const map_location &hex)
Gets called by display when drawing a hex, to allow actions to draw to the screen.
Definition: move.cpp:396
virtual ~move()
Definition: move.cpp:199
void set_arrow_texture(ARROW_TEXTURE x) const
Definition: move.hpp:100
arrow_ptr arrow_
Definition: move.hpp:117
void modify_unit(unit &new_unit)
Definition: move.cpp:316
bool fake_unit_hidden_
Definition: move.hpp:133
virtual void do_hide()
Called by the non-virtual hide() and show(), respectively.
Definition: move.cpp:407
virtual std::ostream & print(std::ostream &s) const
Definition: move.cpp:58
virtual map_location get_dest_hex() const
Definition: move.cpp:304
virtual void do_show()
Definition: move.cpp:414
std::size_t unit_underlying_id_
Definition: move.hpp:110
virtual void set_route(const pathfind::marked_route &route)
Definition: move.cpp:310
void set_arrow_brightness(ARROW_BRIGHTNESS x) const
Definition: move.hpp:98
std::unique_ptr< temporary_unit_mover > mover_
Definition: move.hpp:132
virtual const pathfind::marked_route & get_route() const
Definition: move.hpp:70
ARROW_TEXTURE arrow_texture_
Definition: move.hpp:121
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:322
virtual config to_config() const
Constructs and returns a config object representing this object.
Definition: move.cpp:506
int turn_number_
Turn end number to draw if greater than zero.
Definition: move.hpp:115
int calculate_moves_left(unit &u)
Definition: move.cpp:542
std::shared_ptr< move > shared_from_this()
Definition: move.hpp:104
virtual map_location get_source_hex() const
Definition: move.cpp:298
void init(unit *u=nullptr)
Definition: move.cpp:150
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:206
void update_arrow_style()
Definition: move.cpp:576
ARROW_BRIGHTNESS arrow_brightness_
Definition: move.hpp:120
@ ARROW_BRIGHTNESS_FOCUS
Definition: move.hpp:97
@ ARROW_BRIGHTNESS_STANDARD
Definition: move.hpp:97
@ ARROW_BRIGHTNESS_HIGHLIGHTED
Definition: move.hpp:97
fake_unit_ptr fake_unit_
Definition: move.hpp:118
ARROW_TEXTURE
Definition: move.hpp:99
@ ARROW_TEXTURE_INVALID
Definition: move.hpp:99
@ ARROW_TEXTURE_VALID
Definition: move.hpp:99
virtual map_location get_numbering_hex() const
Definition: move.cpp:435
virtual void apply_temp_modifier(unit_map &unit_map)
Applies temporarily the result of this action to the specified unit map.
Definition: move.cpp:335
This internal whiteboard class holds the planned action queues for a team, and offers many utility me...
iterator find_last_action_of(const unit &unit, iterator start_position)
Finds the last action that belongs to this unit, starting the search backwards from the specified pos...
container::iterator iterator
iterator end()
Returns the iterator for the position after the last executed action within the actions queue.
Abstract base class for all the visitors (cf GoF Visitor Design Pattern) the whiteboard uses.
Definition: visitor.hpp:33
virtual void visit(move_ptr move)=0
Definitions for the interface to Wesnoth Markup Language (WML).
@ move_info
Movement info (defense%, etc...)
int movement_cost_
int w
Contains the exception interfaces used to signal completion of a scenario, campaign or turn.
const std::string & id() const
Gets this unit's id.
Definition: unit.hpp:380
std::size_t underlying_id() const
This unit's unique internal ID.
Definition: unit.hpp:392
const t_string & name() const
Gets this unit's translatable display name.
Definition: unit.hpp:403
int movement_left() const
Gets how far a unit can move, considering the incapacitated flag.
Definition: unit.hpp:1329
const color_t NORMAL_COLOR
logger & debug()
Definition: log.cpp:325
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)
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.
Definition: pathfind.cpp:658
game_board * gameboard
Definition: resources.cpp:20
fake_unit_manager * fake_units
Definition: resources.cpp:30
play_controller * controller
Definition: resources.cpp:21
static std::string at(const std::string &file, int line)
void move_unit(const std::vector< map_location > &path, const unit_ptr &u, bool animate, map_location::direction dir, bool force_scroll)
Display a unit moving along a given path.
Definition: udisplay.cpp:505
Definition: display.hpp:45
std::shared_ptr< move > move_ptr
Definition: typedefs.hpp:68
std::shared_ptr< side_actions > side_actions_ptr
Definition: typedefs.hpp:66
std::shared_ptr< arrow > arrow_ptr
Definition: typedefs.hpp:60
std::shared_ptr< move const > move_const_ptr
Definition: typedefs.hpp:69
std::ostream & operator<<(std::ostream &s, const action_ptr &action)
Definition: action.cpp:34
std::shared_ptr< unit > unit_ptr
Definition: ptr.hpp:26
Encapsulates the map of the game.
Definition: location.hpp:45
int wml_y() const
Definition: location.hpp:184
int wml_x() const
Definition: location.hpp:183
static double getNoPathValue()
Definition: pathfind.hpp:65
Structure which holds a single route and marks for special events.
Definition: pathfind.hpp:142
std::vector< map_location > & steps
Definition: pathfind.hpp:187
Structure which holds a single route between one location and another.
Definition: pathfind.hpp:133
int move_cost
Movement cost for reaching the end of the route.
Definition: pathfind.hpp:137
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:225
bool valid() const
Definition: map.hpp:273
pointer get_shared_ptr() const
This is exactly the same as operator-> but it's slightly more readable, and can replace &*iter syntax...
Definition: map.hpp:217
static map_location::direction s
static std::string mark
Definition: tstring.cpp:70
#define WRN_WB
Definition: typedefs.hpp:26
static lg::log_domain log_whiteboard("whiteboard")
#define DBG_WB
Definition: typedefs.hpp:28
#define LOG_WB
Definition: typedefs.hpp:27
Display units performing various actions: moving, attacking, and dying.
visitor is an abstract interface : action.accept(visitor) calls visitor.visit(action)
#define h