The Battle for Wesnoth  1.15.0-dev
move.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
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  * Movement.
18  */
19 
20 #include "actions/move.hpp"
21 
22 #include "actions/undo.hpp"
23 #include "actions/vision.hpp"
24 
25 #include "game_events/pump.hpp"
26 #include "preferences/game.hpp"
27 #include "gettext.hpp"
28 #include "hotkey/hotkey_item.hpp"
30 #include "log.hpp"
31 #include "map/map.hpp"
32 #include "mouse_handler_base.hpp"
33 #include "pathfind/pathfind.hpp"
34 #include "pathfind/teleport.hpp"
35 #include "replay.hpp"
36 #include "replay_helper.hpp"
37 #include "synced_context.hpp"
38 #include "play_controller.hpp"
39 #include "resources.hpp"
40 #include "units/udisplay.hpp"
41 #include "font/standard_colors.hpp"
42 #include "formula/string_utils.hpp"
43 #include "team.hpp"
44 #include "units/unit.hpp"
46 #include "whiteboard/manager.hpp"
47 
48 #include <deque>
49 #include <map>
50 #include <set>
51 
52 static lg::log_domain log_engine("engine");
53 #define DBG_NG LOG_STREAM(debug, log_engine)
54 
55 
56 namespace actions {
57 
58 
60 {
61  seen_friends_.push_back(u);
62 }
63 
64 
66 {
67  seen_enemies_.push_back(u);
68 }
69 
70 
72 {
73  return ambusher_;
74 }
75 
76 
78 {
79  return failed_teleport_;
80 }
81 
82 
83 const std::vector<unit_map::const_iterator>& move_unit_spectator::get_seen_enemies() const
84 {
85  return seen_enemies_;
86 }
87 
88 
89 const std::vector<unit_map::const_iterator>& move_unit_spectator::get_seen_friends() const
90 {
91  return seen_friends_;
92 }
93 
94 
96 {
97  return unit_;
98 }
99 
100 
102  : ambusher_(units.end()),failed_teleport_(units.end()),seen_enemies_(),seen_friends_(),unit_(units.end())
103 {
104 }
105 
106 
108 {
109 }
110 
112 {
113  ambusher_ = units.end();
114  failed_teleport_ = units.end();
115  seen_enemies_.clear();
116  seen_friends_.clear();
117  unit_ = units.end();
118 }
119 
120 
122 {
123  ambusher_ = u;
124 }
125 
126 
128 {
129  failed_teleport_ = u;
130 }
131 
132 
134 {
135  unit_ = u;
136 }
137 
138 
139 game_events::pump_result_t get_village(const map_location& loc, int side, bool *action_timebonus, bool fire_event)
140 {
141  std::vector<team> &teams = resources::gameboard->teams();
142  team *t = static_cast<unsigned>(side - 1) < teams.size() ? &teams[side - 1] : nullptr;
143  if (t && t->owns_village(loc)) {
145  }
146 
147  bool not_defeated = t && !resources::gameboard->team_is_defeated(*t);
148 
149  bool grants_timebonus = false;
150 
151  int old_owner_side = 0;
152  // We strip the village off all other sides, unless it is held by an ally
153  // and our side is already defeated (and thus we can't occupy it)
154  for(std::vector<team>::iterator i = teams.begin(); i != teams.end(); ++i) {
155  int i_side = std::distance(teams.begin(), i) + 1;
156  if (!t || not_defeated || t->is_enemy(i_side)) {
157  if(i->owns_village(loc)) {
158  old_owner_side = i_side;
159  i->lose_village(loc);
160  }
161  if (side != i_side && action_timebonus) {
162  grants_timebonus = true;
163  }
164  }
165  }
166 
167  if (!t) {
169  }
170 
171  if(grants_timebonus) {
173  *action_timebonus = true;
174  }
175 
176  if(not_defeated) {
177  return t->get_village(loc, old_owner_side, fire_event ? resources::gamedata : nullptr);
178  }
179 
181 }
182 
183 
184 namespace { // Private helpers for move_unit()
185 
186  /// Helper class for move_unit().
187  class unit_mover {
188  typedef std::vector<map_location>::const_iterator route_iterator;
189 
190  public:
191  unit_mover(const unit_mover&) = delete;
192  unit_mover& operator=(const unit_mover&) = delete;
193 
194  unit_mover(const std::vector<map_location> & route,
195  move_unit_spectator *move_spectator,
196  bool skip_sightings, bool skip_ally_sightings);
197  ~unit_mover();
198 
199  /// Determines how far along the route the unit can expect to move this turn.
200  bool check_expected_movement();
201  /// Attempts to move the unit along the expected path.
202  void try_actual_movement(bool show);
203  /// Does some bookkeeping and event firing, for use after movement.
204  void post_move(undo_list *undo_stack);
205  /// Shows the various on-screen messages, for use after movement.
206  void feedback() const;
207 
208  /// After checking expected movement, this is the expected path.
209  std::vector<map_location> expected_path() const
210  { return std::vector<map_location>(begin_, expected_end_); }
211  /// After moving, this is the final hex reached.
212  const map_location & final_hex() const
213  { return *move_loc_; }
214  /// The number of hexes actually entered.
215  std::size_t steps_travelled() const
216  { return move_loc_ - begin_; }
217  /// After moving, use this to detect if movement was less than expected.
218  bool stopped_early() const { return expected_end_ != real_end_; }
219  /// After moving, use this to detect if something happened that would
220  /// interrupt movement (even if movement ended for a different reason).
221  bool interrupted(bool include_end_of_move_events=true) const
222  {
223  return ambushed_ || blocked() || sighted_ || teleport_failed_ ||
224  (include_end_of_move_events ? (wml_removed_unit_ || wml_move_aborted_): event_mutated_mid_move_ ) ||
225  !move_it_.valid();
226  }
227 
228  private: // functions
229  /// Returns whether or not movement was blocked by a non-ambushing enemy.
230  bool blocked() const { return blocked_loc_ != map_location::null_location(); }
231  /// Checks the expected route for hidden units.
232  void cache_hidden_units(const route_iterator & start,
233  const route_iterator & stop);
234  /// Fires the enter_hex or exit_hex event and updates our data as needed.
235  void fire_hex_event(const std::string & event_name,
236  const route_iterator & current,
237  const route_iterator & other);
238  /// AI moves are supposed to not change the "goto" order.
239  bool is_ai_move() const { return spectator_ != nullptr; }
240  /// Checks how far it appears we can move this turn.
241  route_iterator plot_turn(const route_iterator & start,
242  const route_iterator & stop);
243  /// Updates our stored info after a WML event might have changed something.
244  void post_wml(game_events::pump_result_t pump_res, const route_iterator & step);
245  void post_wml(game_events::pump_result_t pump_res) { return post_wml(pump_res, full_end_); }
246  /// Fires the sighted events that were raised earlier.
247  void pump_sighted(const route_iterator & from);
248  /// Returns the ambush alert (if any) for the given unit.
249  static std::string read_ambush_string(const unit & ambusher);
250  /// Reveals the unit at the indicated location.
251  void reveal_ambusher(const map_location & hex, bool update_alert=true);
252 
253  /// Returns whether or not undoing this move should be blocked.
254  bool undo_blocked() const
255  { return ambushed_ || blocked() || wml_removed_unit_ || wml_undo_disabled_ || fog_changed_ ||
257 
258  // The remaining private functions are suggested to be inlined because
259  // each is used in only one place. (They are separate functions to ease
260  // code reading.)
261 
262  /// Checks for ambushers around @a hex, setting flags as appropriate.
263  inline void check_for_ambushers(const map_location & hex);
264  /// Makes sure the path is not obstructed by a unit.
265  inline bool check_for_obstructing_unit(const map_location & hex,
266  const map_location & prev_hex);
267  /// Moves the unit the next step.
268  inline bool do_move(const route_iterator & step_from,
269  const route_iterator & step_to,
270  unit_display::unit_mover & animator);
271  /// Clears fog/shroud and handles units being sighted.
272  inline void handle_fog(const map_location & hex, bool new_animation);
273  inline bool is_reasonable_stop(const map_location & hex) const;
274  /// Reveals the units stored in ambushers_ (and blocked_loc_).
275  inline void reveal_ambushers();
276  /// Makes sure the units in ambushers_ still exist.
277  inline void validate_ambushers();
278 
279  private: // data
280  // (The order of the fields is somewhat important for the constructor.)
281 
282  // Movement parameters (these decrease the number of parameters needed
283  // for individual functions).
285  const bool skip_sighting_;
288  // Needed to interface with unit_display::unit_mover.
289  const std::vector<map_location> & route_;
290 
291  // The route to traverse.
292  const route_iterator begin_;
293  const route_iterator full_end_; // The end of the plotted route.
294  route_iterator expected_end_; // The end of this turn's portion of the plotted route.
295  route_iterator ambush_limit_; // How far we can go before encountering hidden units, ignoring allied units.
296  route_iterator obstructed_; // Points to either full_end_ or a hex we cannot enter. This is used so that exit_hex can fire before we decide we cannot enter this hex.
297  route_iterator real_end_; // How far we actually can move this turn.
298 
299  // The unit that is moving.
301 
302  // This data stores the state from before the move started.
303  const int orig_side_;
304  const int orig_moves_;
307 
308  // This data tracks the current state as the move is in progress.
310  team * current_team_; // Will default to the original team if the moving unit becomes invalid.
312  route_iterator move_loc_; // Will point to the last moved-to location (in case the moving unit disappears).
313  // Data accumulated while making the move.
315  map_location ambush_stop_; // Could be inaccurate if ambushed_ is false.
316  map_location blocked_loc_; // Location of a blocking, enemy, non-ambusher unit.
317  bool ambushed_;
322  bool event_mutated_mid_move_; // Cache of wml_removed_unit_ || wml_move_aborted_ from just before the end-of-move handling.
324  bool sighted_; // Records if sightings were made that could interrupt movement.
325  bool sighted_stop_; // Records if sightings were made that did interrupt movement (the same as sighted_ unless movement ended for another reason).
327  std::size_t enemy_count_;
328  std::size_t friend_count_;
329  std::string ambush_string_;
330  std::vector<map_location> ambushers_;
331  std::deque<int> moves_left_; // The front value is what the moving unit's remaining moves should be set to after the next step through the route.
332 
333  shroud_clearer clearer_;
334  };
335 
336 
337  /// This constructor assumes @a route is not empty, and it will assert() that
338  /// there is a unit at route.front().
339  /// Iterators into @a route must remain valid for the life of this object.
340  /// It is assumed that move_spectator is only supplied for AI moves (only
341  /// affects whether or not gotos are changed).
342  unit_mover::unit_mover(const std::vector<map_location> & route,
343  move_unit_spectator *move_spectator,
344  bool skip_sightings, bool skip_ally_sightings)
345  : spectator_(move_spectator)
346  , skip_sighting_(skip_sightings)
347  , skip_ally_sighting_(skip_ally_sightings)
348  , playing_team_is_viewing_(display::get_singleton()->playing_team() == display::get_singleton()->viewing_team() || display::get_singleton()->show_everything())
349  , route_(route)
350  , begin_(route.begin())
351  , full_end_(route.end())
355  , real_end_(begin_)
356  // Unit information:
357  , move_it_(resources::gameboard->units().find(*begin_))
358  , orig_side_(( assert(move_it_ != resources::gameboard->units().end()), move_it_->side() ))
359  , orig_moves_(move_it_->movement_left())
360  , orig_dir_(move_it_->facing())
361  , goto_( is_ai_move() ? move_it_->get_goto() : route.back() )
364  , current_uses_fog_(current_team_->fog_or_shroud() && current_team_->auto_shroud_updates())
365  , move_loc_(begin_)
366  // The remaining fields are set to some sort of "zero state".
367  , zoc_stop_(map_location::null_location())
368  , ambush_stop_(map_location::null_location())
369  , blocked_loc_(map_location::null_location())
370  , ambushed_(false)
371  , show_ambush_alert_(false)
372  , wml_removed_unit_(false)
373  , wml_undo_disabled_(false)
374  , wml_move_aborted_(false)
375  , event_mutated_mid_move_(false)
376  , fog_changed_(false)
377  , sighted_(false)
378  , sighted_stop_(false)
379  , teleport_failed_(false)
380  , enemy_count_(0)
381  , friend_count_(0)
382  , ambush_string_()
383  , ambushers_()
384  , moves_left_()
385  , clearer_()
386  {
387  if ( !is_ai_move() )
388  // Clear the "goto" instruction during movement.
389  // (It will be reset in the destructor if needed.)
391  }
392 
393 
394  unit_mover::~unit_mover()
395  {
396  // Set the "goto" order? (Not if WML set it.)
397  if ( !is_ai_move() && move_it_.valid() &&
398  move_it_->get_goto() == map_location::null_location() )
399  {
400  // Only set the goto if movement was not complete and was not
401  // interrupted.
402  if (real_end_ != full_end_ && !interrupted(false)) {
403  // End-of-move-events do not cancel a goto. (Use case: tutorial S2.)
404  move_it_->set_goto(goto_);
405  }
406  }
407  }
408 
409 
410  // Private inlines:
411 
412  /**
413  * Checks for ambushers around @a hex, setting flags as appropriate.
414  */
415  inline void unit_mover::check_for_ambushers(const map_location & hex)
416  {
417  const unit_map &units = resources::gameboard->units();
418 
419  // Need to check each adjacent hex for hidden enemies.
420  adjacent_loc_array_t adjacent;
421  get_adjacent_tiles(hex, adjacent.data());
422  for (unsigned i = 0; i < adjacent.size(); ++i )
423  {
424  const unit_map::const_iterator neighbor_it = units.find(adjacent[i]);
425 
426  if ( neighbor_it != units.end() &&
427  current_team_->is_enemy(neighbor_it->side()) &&
428  neighbor_it->invisible(adjacent[i]) )
429  {
430  // Ambushed!
431  ambushed_ = true;
432  ambush_stop_ = hex;
433  ambushers_.push_back(adjacent[i]);
434  }
435  }
436  }
437 
438 
439  /**
440  * Makes sure the path is not obstructed by a unit.
441  * @param hex The hex to check.
442  * @param prev_hex The previous hex in the route (used to detect a teleport).
443  * @return true if @a hex is obstructed.
444  */
445  inline bool unit_mover::check_for_obstructing_unit(const map_location & hex,
446  const map_location & prev_hex)
447  {
448  const unit_map::const_iterator blocking_unit = resources::gameboard->units().find(hex);
449 
450  // If no unit, then the path is not obstructed.
451  if (blocking_unit == resources::gameboard->units().end()) {
452  return false;
453  }
454 
455  // Check for units blocking a teleport exit. This can now only happen
456  // if these units are not visible to the current side, as otherwise no
457  // valid path is found.
458  if ( !tiles_adjacent(hex, prev_hex) ) {
459  if ( current_team_->is_enemy(blocking_unit->side()) ) {
460  // Enemy units always block the tunnel.
461  teleport_failed_ = true;
462  return true;
463  } else {
464  // By contrast, allied units (of a side which does not share vision) only
465  // block the tunnel if pass_allied_units=true. Whether the teleport is possible
466  // is checked by getting the teleport map with the see_all flag set to true.
467  const pathfind::teleport_map teleports = pathfind::get_teleport_locations(*move_it_, *current_team_, true, false, false);
468  std::set<map_location> allowed_teleports;
469  teleports.get_adjacents(allowed_teleports, prev_hex);
470 
471  bool found_valid_teleport = false;
472  std::set<map_location>::const_iterator it = allowed_teleports.begin();
473  while( it!=allowed_teleports.end() && !found_valid_teleport ) {
474  if ( *it == hex ) {
475  found_valid_teleport = true;
476  }
477  ++it;
478  }
479 
480  if (!found_valid_teleport) {
481  teleport_failed_ = true;
482  return true;
483  }
484  }
485  }
486 
487  if ( current_team_->is_enemy(blocking_unit->side()) ) {
488  // Trying to go through an enemy.
489  blocked_loc_ = hex;
490  return true;
491  }
492 
493  // If we get here, the unit does not interfere with movement.
494  return false;
495  }
496 
497 
498  /**
499  * Moves the unit the next step.
500  * @a step_to is the hex being moved to.
501  * @a step_from is the hex before that in the route.
502  * (The unit is actually at *move_loc_.)
503  * @a animator is the unit_display::unit_mover being used.
504  * @return whether or not we started a new animation.
505  */
506  inline bool unit_mover::do_move(const route_iterator & step_from,
507  const route_iterator & step_to,
508  unit_display::unit_mover & animator)
509  {
511 
512  // Adjust the movement even if we cannot move yet.
513  // We will eventually be able to move if nothing unexpected
514  // happens, and if something does happen, this movement is the
515  // cost to discover it.
516  move_it_->set_movement(moves_left_.front(), true);
517  moves_left_.pop_front();
518 
519  // Attempt actually moving. Fails if *step_to is occupied.
520  unit_map::unit_iterator unit_it;
521  bool success = false;
522 
523  std::tie(unit_it, success) = resources::gameboard->units().move(*move_loc_, *step_to);
524 
525  if(success) {
526  // Update the moving unit.
527  move_it_ = unit_it;
528  move_it_->set_facing(step_from->get_relative_dir(*step_to));
529  // Disable bars. The expectation here is that the animation
530  // unit_mover::finish() will clean after us at a later point. Ugly,
531  // but it works.
532  move_it_->anim_comp().set_standing(false);
533  disp.invalidate_unit_after_move(*move_loc_, *step_to);
534  move_loc_ = step_to;
535 
536  // Show this move.
537  animator.proceed_to(move_it_.get_shared_ptr(), step_to - begin_,
538  move_it_->appearance_changed(), false);
539  move_it_->set_appearance_changed(false);
540  disp.redraw_minimap();
541  }
542 
543  return success;
544  }
545 
546 
547  /**
548  * Clears fog/shroud and raises events for units being sighted.
549  * Only call this if the current team uses fog or shroud.
550  * @a hex is both the center of fog clearing and the filtered location of
551  * the moving unit when the sighted events will be fired.
552  */
553  inline void unit_mover::handle_fog(const map_location & hex,
554  bool new_animation)
555  {
556  // Clear the fog.
557  if ( clearer_.clear_unit(hex, *move_it_, *current_team_, nullptr,
559  !new_animation) )
560  {
561  clearer_.invalidate_after_clear();
562  fog_changed_ = true;
563  }
564 
565  // Check for sighted units?
566  if ( !skip_sighting_ ) {
567  sighted_ = enemy_count_ != 0 ;
568  }
570  {
571  sighted_ |= (friend_count_ != 0);
572  }
573  }
574 
575 
576  /**
577  * @return true if an unscheduled stop at @a hex is not likely to negatively
578  * impact the player's plans.
579  * (E.g. it would not kill movement by making an unintended village capture.)
580  */
581  inline bool unit_mover::is_reasonable_stop(const map_location & hex) const
582  {
583  // We cannot reasonably stop if move_it_ could not be moved to this
584  // hex (the hex was occupied by someone else).
585  if (*move_loc_ != hex) {
586  return false;
587  }
588 
589  // We can reasonably stop if the hex is not an unowned village.
590  return !resources::gameboard->map().is_village(hex) ||
592  }
593 
594 
595  /**
596  * Reveals the units stored in ambushers_ (and blocked_loc_).
597  * Also sets ambush_string_.
598  * May fire "sighted" events.
599  * Only call this if appropriate; this function does not itself check
600  * ambushed_ or blocked().
601  */
602  inline void unit_mover::reveal_ambushers()
603  {
604  // Reveal the blocking unit.
605  if (blocked()) {
606  reveal_ambusher(blocked_loc_, false);
607  }
608  // Reveal ambushers.
609  for(const map_location & reveal : ambushers_) {
610  reveal_ambusher(reveal, true);
611  }
612 
613  // Default "Ambushed!" message?
614  if (ambush_string_.empty()) {
615  ambush_string_ = _("Ambushed!");
616  }
617  }
618 
619 
620  /**
621  * Makes sure the units in ambushers_ still exist.
622  */
623  inline void unit_mover::validate_ambushers()
624  {
625  const unit_map &units = resources::gameboard->units();
626 
627  // Loop through the previously-detected ambushers.
628  std::size_t i = 0;
629  while ( i != ambushers_.size() ) {
630  if (units.count(ambushers_[i]) == 0) {
631  // Ambusher is gone.
632  ambushers_.erase(ambushers_.begin() + i);
633  }
634  else {
635  // Proceed to the next ambusher.
636  ++i;
637  }
638  }
639  }
640 
641 
642  // Private utilities:
643 
644  /**
645  * Checks the expected route for hidden units.
646  * This basically handles all the checks for surprises that can be done
647  * without visibly notifying a player. Thus this can be called at the
648  * start of movement and immediately after events, rather than tie up
649  * CPU time in the middle of animating a move.
650  *
651  * @param[in] start The beginning of the path to check.
652  * @param[in] stop The end of the path to check.
653  */
654  void unit_mover::cache_hidden_units(const route_iterator & start,
655  const route_iterator & stop)
656  {
657  // Clear the old cache.
660  teleport_failed_ = false;
661  // The ambush cache needs special treatment since we cannot re-detect
662  // an ambush if we are already at the ambushed location.
664  if ( ambushed_ ) {
665  validate_ambushers();
666  ambushed_ = !ambushers_.empty();
667  }
668  if ( !ambushed_ ) {
669  ambush_stop_ = map_location::null_location();
670  ambushers_.clear();
671  }
672 
673  // Update the shroud clearer.
674  clearer_.cache_units(current_uses_fog_ ? current_team_ : nullptr);
675 
676 
677  // Abort for null routes.
678  if ( start == stop ) {
680  return;
681  }
682 
683  // This loop will end with ambush_limit_ pointing one element beyond
684  // where the unit would be forced to stop by a hidden unit.
685  for ( ambush_limit_ = start+1; ambush_limit_ != stop; ++ambush_limit_ ) {
686  // Check if we need to stop in the previous hex.
687  if ( ambushed_ ) {
688  break;
689  }
690  // Check for being unable to enter this hex.
691  if ( check_for_obstructing_unit(*ambush_limit_, *(ambush_limit_-1)) ) {
692  // No replay check here? Makes some sense, I guess.
693  obstructed_ = ambush_limit_++; // The limit needs to be after obstructed_ in order for the latter to do anything.
694  break;
695  }
696 
697  // We can enter this hex.
698  // See if we are stopped in this hex.
699  check_for_ambushers(*ambush_limit_);
700  }
701  }
702 
703 
704  /**
705  * Fires the enter_hex or exit_hex event and updates our data as needed.
706  *
707  * @param[in] event_name The name of the event ("enter_hex" or "exit_hex").
708  * @param[in] current The currently occupied hex.
709  * @param[in] other The secondary hex to provide to the event.
710  *
711  */
712  void unit_mover::fire_hex_event(const std::string & event_name,
713  const route_iterator & current,
714  const route_iterator & other)
715  {
716 
717  const game_events::entity_location mover(*move_it_, *current);
718 
719  post_wml(resources::game_events->pump().fire(event_name, mover, *other), current);
720  }
721 
722 
723  /**
724  * Checks how far it appears we can move this turn.
725  *
726  * @param[in] start The beginning of the plotted path.
727  * @param[in] stop The end of the plotted path.
728  *
729  * @return An end iterator for the path that can be traversed this turn.
730  */
731  unit_mover::route_iterator unit_mover::plot_turn(const route_iterator & start,
732  const route_iterator & stop)
733  {
734  const gamemap &map = resources::gameboard->map();
735 
736  // Handle null routes.
737  if (start == stop) {
738  return start;
739  }
740 
741  int remaining_moves = move_it_->movement_left();
743  moves_left_.clear();
744 
745  if ( start != begin_ ) {
746  // Check for being unable to leave the current hex.
747  if ( !move_it_->get_ability_bool("skirmisher", *start) &&
749  zoc_stop_ = *start;
750  }
751 
752  // This loop will end with end pointing one element beyond where the
753  // unit thinks it will stop (the usual notion of "end" for iterators).
754  route_iterator end = start + 1;
755  for ( ; end != stop; ++end )
756  {
757  // Break out of the loop if we cannot leave the previous hex.
759  break;
760  }
761  remaining_moves -= move_it_->movement_cost(map[*end]);
762  if ( remaining_moves < 0 ) {
763  break;
764  }
765 
766  // We can enter this hex. Record the cost.
767  moves_left_.push_back(remaining_moves);
768 
769  // Check for being unable to leave this hex.
770  if (!move_it_->get_ability_bool("skirmisher", *end) &&
772  {
773  zoc_stop_ = *end;
774  }
775  }
776 
777  route_iterator min_end = start == begin_ ? start : start + 1;
778  while (end != min_end && resources::gameboard->has_visible_unit(*(end - 1), *current_team_)) {
779  // Backtrack.
780  --end;
781  }
782 
783  return end;
784  }
785 
786 
787  /**
788  * Updates our stored info after a WML event might have changed something.
789  *
790  * @param step Indicates the position in the path where we might need to start recalculating movement.
791  * Set this to full_end_ (or do not supply it) to skip such recalculations (because movement has finished).
792  *
793  * @returns false if continuing is impossible (i.e. we lost the moving unit).
794  */
795  void unit_mover::post_wml(game_events::pump_result_t pump_res, const route_iterator & step)
796  {
797  wml_move_aborted_ |= std::get<1>(pump_res);
798  wml_undo_disabled_ |= std::get<0>(pump_res);
799 
800  // Re-find the moving unit.
802  const bool found = move_it_ != resources::gameboard->units().end();
803 
804  // Update the current unit data.
805  current_side_ = found ? move_it_->side() : orig_side_;
808  ( current_side_ != orig_side_ ||
810 
811  // Update the path.
812  if ( found && step != full_end_ ) {
813  const route_iterator new_limit = plot_turn(step, expected_end_);
814  cache_hidden_units(step, new_limit);
815  // Just in case: length 0 paths become length 1 paths.
816  if (ambush_limit_ == step) {
817  ++ambush_limit_;
818  }
819  }
820 
821  wml_removed_unit_ |= !found;
822  }
823 
824 
825  /**
826  * Fires the sighted events that were raised earlier.
827  *
828  * @param[in] from Points to the hex the sighting unit currently occupies.
829  *
830  * @return sets event_mutated_ || wml_move_aborted_ to true if this event should interrupt movement.
831  */
832  void unit_mover::pump_sighted(const route_iterator & from)
833  {
834  const std::size_t track = resources::game_events->pump().wml_tracking();
835 
836  auto pump_res = clearer_.fire_events();
837 
838  if (track != resources::game_events->pump().wml_tracking()) {
839  // Some WML fired, so update our status.
840  post_wml(pump_res, from);
841  }
842  }
843 
844 
845  /**
846  * Returns the ambush alert (if any) for the given unit.
847  */
848  std::string unit_mover::read_ambush_string(const unit & ambusher)
849  {
850  for(const unit_ability &hide : ambusher.get_abilities("hides"))
851  {
852  const std::string & ambush_string = (*hide.first)["alert"].str();
853  if (!ambush_string.empty()) {
854  return ambush_string;
855  }
856  }
857 
858  // No string found.
859  return std::string();
860  }
861 
862 
863  /**
864  * Reveals the unit at the indicated location.
865  * Can also update the current ambushed alert.
866  * May fire "sighted" events.
867  */
868  void unit_mover::reveal_ambusher(const map_location & hex, bool update_alert)
869  {
870  // Convenient alias:
871  unit_map &units = resources::gameboard->units();
873 
874  // Find the unit at the indicated location.
875  unit_map::iterator ambusher = units.find(hex);
876  if ( ambusher != units.end() ) {
877  // Prepare for sighted events.
878  std::vector<int> sight_cache(get_sides_not_seeing(*ambusher));
879  // Make sure the unit is visible (during sighted events, and in case
880  // we had to backtrack).
881  ambusher->set_state(unit::STATE_UNCOVERED, true);
882 
883  // Record this in the move spectator.
884  if (spectator_) {
885  spectator_->set_ambusher(ambusher);
886  }
887  // Override the default ambushed message?
888  if ( update_alert ) {
889  // Observers don't get extra information.
890  if ( playing_team_is_viewing_ || !disp.fogged(hex) ) {
891  show_ambush_alert_ = true;
892  // We only support one custom ambush message; use the first one.
893  if (ambush_string_.empty()) {
894  ambush_string_ = read_ambush_string(*ambusher);
895  }
896  }
897  }
898 
899  // Fire sighted events.
900 
901  bool wml_undo_blocked = false;
902  bool wml_move_aborted = false;
903 
904  std::tie(wml_undo_blocked, wml_move_aborted) = actor_sighted(*ambusher, &sight_cache);
905  // TODO: should we call post_wml ?
906  wml_move_aborted_ |= wml_move_aborted;
907  wml_undo_disabled_ |= wml_undo_blocked;
908  }
909  }
910 
911 
912  // Public interface:
913 
914  /**
915  * Determines how far along the route the unit can expect to move this turn.
916  * This is based solely on data known to the player, and will not plot a move
917  * that ends on another (known) unit.
918  * (For example, this prevents a player from plotting a multi-turn move that
919  * has this turn's movement ending on a (slower) unit, and thereby clearing
920  * fog as if the moving unit actually made it on top of that other unit.)
921  *
922  * @returns false if the expectation is to not move at all.
923  */
924  bool unit_mover::check_expected_movement()
925  {
926  expected_end_ = plot_turn(begin_, full_end_);
927  return expected_end_ != begin_;
928  }
929 
930 
931  /**
932  * Attempts to move the unit along the expected path.
933  * (This will do nothing unless check_expected_movement() was called first.)
934  *
935  * @param[in] show Set to false to suppress animations.
936  */
937  void unit_mover::try_actual_movement(bool show)
938  {
939  static const std::string enter_hex_str("enter hex");
940  static const std::string exit_hex_str("exit hex");
941 
942 
943  bool obstructed_stop = false;
944 
945 
946  // Check for hidden units along the expected path before we start
947  // animating and firing events.
948  cache_hidden_units(begin_, expected_end_);
949 
950  if ( begin_ != ambush_limit_ ) {
951  // Cache the moving unit's visibility.
952  std::vector<int> not_seeing = get_sides_not_seeing(*move_it_);
953 
954  // Prepare to animate.
955  unit_display::unit_mover animator(route_, show);
956  animator.start(move_it_.get_shared_ptr());
957 
958  // Traverse the route to the hex where we need to stop.
959  // Each iteration performs the move from real_end_-1 to real_end_.
960  for ( real_end_ = begin_+1; real_end_ != ambush_limit_; ++real_end_ ) {
961  const route_iterator step_from = real_end_ - 1;
962 
963  // See if we can leave *step_from.
964  // Already accounted for: ambusher
966  break;
967  }
968  if ( sighted_ && is_reasonable_stop(*step_from) ) {
969  sighted_stop_ = true;
970  break;
971  }
972  // Already accounted for: ZoC
973  // Already accounted for: movement cost
974  fire_hex_event(exit_hex_str, step_from, real_end_);
976  break;
977  }
978  if ( real_end_ == obstructed_ ) {
979  // We did not check for being a replay when checking for an
980  // obstructed hex, so we do not check can_break here.
981  obstructed_stop = true;
982  break;
983  }
984 
985  // We can leave *step_from. Make the move to *real_end_.
986  bool new_animation = do_move(step_from, real_end_, animator);
987  // Update the fog.
988  if ( current_uses_fog_ )
989  handle_fog(*real_end_, new_animation);
990  animator.wait_for_anims();
991 
992  // Fire the events for this step.
993  // (These return values are not checked since real_end_ still
994  // needs to be incremented. The wml_move_aborted_ check will break
995  // us out of the loop if needed.)
996  fire_hex_event(enter_hex_str, real_end_, step_from);
997  // Sighted events only fire if we could stop due to sighting.
998  if (is_reasonable_stop(*real_end_)) {
999  pump_sighted(real_end_);
1000  }
1001  }//for
1002  // Make sure any remaining sighted events get fired.
1003  pump_sighted(real_end_-1);
1004 
1005  if ( move_it_.valid() ) {
1006  // Finish animating.
1007  animator.finish(move_it_.get_shared_ptr());
1008  // Check for the moving unit being seen.
1009 
1010  bool wml_undo_blocked = false;
1011  bool wml_move_aborted = false;
1012 
1013  std::tie(wml_undo_blocked, wml_move_aborted) = actor_sighted(*move_it_, &not_seeing);
1014  // TODO: should we call post_wml ?
1015  wml_move_aborted_ |= wml_move_aborted;
1016  wml_undo_disabled_ |= wml_undo_blocked;
1017  }
1018  }//if
1019 
1020  // Some flags were set to indicate why we might stop.
1021  // Update those to reflect whether or not we got to them.
1023  if (!obstructed_stop) {
1025  }
1026  teleport_failed_ = teleport_failed_ && obstructed_stop;
1027  // event_mutated_ does not get unset, regardless of other reasons
1028  // for stopping, but we do save its current value.
1030  }
1031 
1032 
1033  /**
1034  * Does some bookkeeping and event firing, for use after movement.
1035  * This includes village capturing and the undo stack.
1036  */
1037  void unit_mover::post_move(undo_list *undo_stack)
1038  {
1039  const map_location & final_loc = final_hex();
1040 
1041  int orig_village_owner = 0;
1042  bool action_time_bonus = false;
1043 
1044  // Reveal ambushers?
1045  if (ambushed_ || blocked()) {
1046  reveal_ambushers();
1047  }
1048  else if (teleport_failed_ && spectator_) {
1049  spectator_->set_failed_teleport(resources::gameboard->units().find(*obstructed_));
1050  }
1052 
1053  if ( move_it_.valid() ) {
1054  // Update the moving unit.
1055  move_it_->set_interrupted_move(
1056  sighted_stop_ && !resources::whiteboard->is_executing_actions() ?
1057  *(full_end_-1) :
1059  if (ambushed_ || final_loc == zoc_stop_) {
1060  move_it_->set_movement(0, true);
1061  }
1062 
1063  // Village capturing.
1064  if ( resources::gameboard->map().is_village(final_loc) ) {
1065  // Is this a capture?
1066  orig_village_owner = resources::gameboard->village_owner(final_loc) + 1;
1067  if ( orig_village_owner != current_side_) {
1068  // Captured. Zap movement and take over the village.
1069  move_it_->set_movement(0, true);
1070  post_wml(get_village(final_loc, current_side_, &action_time_bonus));
1071  }
1072  }
1073  }
1074 
1075  // Finally, the moveto event.
1076  post_wml(resources::game_events->pump().fire("moveto", final_loc, *begin_));
1077 
1078  // Record keeping.
1079  if (spectator_) {
1080  spectator_->set_unit(move_it_);
1081  }
1082  if ( undo_stack ) {
1083  const bool mover_valid = move_it_.valid();
1084 
1085  if ( mover_valid ) {
1086  // MP_COUNTDOWN: added param
1087  undo_stack->add_move(
1089  action_time_bonus, orig_village_owner, orig_dir_);
1090  }
1091 
1092  if ( !mover_valid || undo_blocked() ||
1093  (resources::whiteboard->is_active() && resources::whiteboard->should_clear_undo()) || !synced_context::can_undo())
1094  {
1095  undo_stack->clear();
1096  }
1097  }
1098 
1099  // Update the screen.
1101  }
1102 
1103 
1104  /**
1105  * Shows the various on-screen messages, for use after movement.
1106  */
1107  void unit_mover::feedback() const
1108  {
1109  // Alias some resources.
1111 
1112  // Multiple messages may be displayed simultaneously
1113  // this variable is used to keep them from overlapping
1114  std::string message_prefix = "";
1115 
1116  // Ambush feedback?
1117  if ( ambushed_ && show_ambush_alert_ ) {
1118  disp.announce(message_prefix + ambush_string_, font::BAD_COLOR);
1119  message_prefix += " \n";
1120  }
1121 
1122  display::announce_options announce_options;
1123  announce_options.discard_previous = false;
1124 
1125  // Failed teleport feedback?
1127  std::string teleport_string = _("Failed teleport! Exit not empty");
1128  disp.announce(message_prefix + teleport_string, font::BAD_COLOR, announce_options);
1129  message_prefix += " \n";
1130  }
1131 
1132  // Sighted units feedback?
1133  if ( playing_team_is_viewing_ && (enemy_count_ != 0 || friend_count_ != 0) ) {
1134  // Create the message to display (depends on whether friends,
1135  // enemies, or both were sighted, and on how many of each).
1136  utils::string_map symbols;
1137  symbols["enemies"] = std::to_string(enemy_count_);
1138  symbols["friends"] = std::to_string(friend_count_);
1139  std::string message;
1140  color_t msg_color;
1141  if ( friend_count_ != 0 && enemy_count_ != 0 ) {
1142  // Both friends and enemies sighted -- neutral message.
1143  symbols["friendphrase"] = VNGETTEXT("Part of 'Units sighted! (...)' sentence^1 friendly", "$friends friendly", friend_count_, symbols);
1144  symbols["enemyphrase"] = VNGETTEXT("Part of 'Units sighted! (...)' sentence^1 enemy", "$enemies enemy", enemy_count_, symbols);
1145  message = VGETTEXT("Units sighted! ($friendphrase, $enemyphrase)", symbols);
1146  msg_color = font::NORMAL_COLOR;
1147  } else if ( enemy_count_ != 0 ) {
1148  // Only enemies sighted -- bad message.
1149  message = VNGETTEXT("Enemy unit sighted!", "$enemies enemy units sighted!", enemy_count_, symbols);
1150  msg_color = font::BAD_COLOR;
1151  } else if ( friend_count_ != 0 ) {
1152  // Only friends sighted -- good message.
1153  message = VNGETTEXT("Friendly unit sighted", "$friends friendly units sighted", friend_count_, symbols);
1154  msg_color = font::GOOD_COLOR;
1155  }
1156 
1157  disp.announce(message_prefix + message, msg_color, announce_options);
1158  message_prefix += " \n";
1159  }
1160 
1161  // Suggest "continue move"?
1162  if ( playing_team_is_viewing_ && sighted_stop_ && !resources::whiteboard->is_executing_actions() ) {
1163  // See if the "Continue Move" action has an associated hotkey
1165  if ( !name.empty() ) {
1166  utils::string_map symbols;
1167  symbols["hotkey"] = name;
1168  std::string message = VGETTEXT("(press $hotkey to keep moving)", symbols);
1169  disp.announce(message_prefix + message, font::NORMAL_COLOR, announce_options);
1170  message_prefix += " \n";
1171  }
1172  }
1173  }
1174 
1175 }//end anonymous namespace
1176 
1177 
1179  bool show_move,
1180  bool* interrupted,
1181  unit_mover& mover)
1182 {
1183  const events::command_disabler disable_commands;
1184  // Default return value.
1185  if (interrupted) {
1186  *interrupted = false;
1187  }
1188 
1189  // Attempt moving.
1190  mover.try_actual_movement(show_move);
1191 
1192  config co;
1193  config cn {
1194  "stopped_early", mover.stopped_early(),
1195  "final_hex_x", mover.final_hex().wml_x(),
1196  "final_hex_y", mover.final_hex().wml_y(),
1197  };
1198  bool matches_replay = checkup_instance->local_checkup(cn,co);
1199  if(!matches_replay)
1200  {
1201  replay::process_error("calculated movement destination (x="+ cn["final_hex_x"].str() + " y=" + cn["final_hex_y"].str() +
1202  ") didn't match the original destination(x="+ co["final_hex_x"].str() + " y=" + co["final_hex_y"].str() + ")\n");
1203 
1204  //TODO: move the unit by force to the desired destination with something like mover.reset_final_hex(co["x"], co["y"]);
1205  }
1206 
1207  // Bookkeeping, etc.
1208  // also fires the moveto event
1209  mover.post_move(undo_stack);
1210  if (show_move) {
1211  mover.feedback();
1212  }
1213 
1214  // Set return value.
1215  if (interrupted) {
1216  *interrupted = mover.interrupted();
1217  }
1218 
1219  return mover.steps_travelled();
1220 }
1221 
1222 /**
1223  * Moves a unit across the board.
1224  *
1225  * This function handles actual movement, checking terrain costs as well as
1226  * things that might interrupt movement (e.g. ambushes). If the full path
1227  * cannot be reached this turn, the remainder is stored as the unit's "goto"
1228  * instruction. (The unit itself is whatever unit is at the beginning of the
1229  * supplied path.)
1230  *
1231  * @param[in] steps The route to be traveled. The unit to be moved is at the beginning of this route.
1232  * @param undo_stack If supplied, then either this movement will be added to the stack or the stack will be cleared.
1233  * @param[in] continued_move If set to true, this is a continuation of an earlier move (movement is not interrupted should units be spotted).
1234  * @param[in] show_move Controls whether or not the movement is animated for the player.
1235  * @param[out] interrupted If supplied, then this is set to true if information was uncovered that warrants interrupting a chain of actions (and set to false otherwise).
1236  * @param[out] move_spectator If supplied, this will be given the information uncovered by the move (and the unit's "goto" instruction will be preserved).
1237  *
1238  * @returns The number of hexes entered. This can safely be used as an index
1239  * into @a steps to get the location where movement ended, provided
1240  * @a steps is not empty (the return value is guaranteed to be less
1241  * than steps.size() ).
1242  */
1243 std::size_t move_unit_and_record(const std::vector<map_location> &steps,
1245  bool continued_move, bool show_move,
1246  bool* interrupted,
1247  move_unit_spectator* move_spectator)
1248 {
1249 
1250  // Avoid some silliness.
1251  if ( steps.size() < 2 || (steps.size() == 2 && steps.front() == steps.back()) ) {
1252  DBG_NG << "Ignoring a unit trying to jump on its hex at " <<
1253  ( steps.empty() ? map_location::null_location() : steps.front() ) << ".\n";
1254  return 0;
1255  }
1256  //if we have no fog activated then we always skip sighted
1257  if(resources::gameboard->units().find(steps.front()) != resources::gameboard->units().end())
1258  {
1259  const team &current_team = resources::gameboard->teams()[
1260  resources::gameboard->units().find(steps.front())->side() - 1];
1261  continued_move |= !current_team.fog_or_shroud();
1262  }
1263  const bool skip_ally_sighted = !preferences::interrupt_when_ally_sighted();
1264 
1265  // Evaluate this move.
1266  unit_mover mover(steps, move_spectator, continued_move, skip_ally_sighted);
1267  if ( !mover.check_expected_movement() )
1268  return 0;
1270  {
1271  /*
1272  enter the synced mode and do the actual movement.
1273  */
1274  resources::recorder->add_synced_command("move",replay_helper::get_movement(steps, continued_move, skip_ally_sighted));
1275  set_scontext_synced sync;
1276  std::size_t r = move_unit_internal(undo_stack, show_move, interrupted, mover);
1279  sync.do_final_checkup();
1280  return r;
1281  }
1282  else
1283  {
1284  //we are already in synced mode and don't need to reenter it again.
1285  return move_unit_internal(undo_stack, show_move, interrupted, mover);
1286  }
1287 }
1288 
1289 std::size_t move_unit_from_replay(const std::vector<map_location> &steps,
1291  bool continued_move,bool skip_ally_sighted, bool show_move)
1292 {
1293  // Evaluate this move.
1294  unit_mover mover(steps, nullptr, continued_move,skip_ally_sighted);
1295  if ( !mover.check_expected_movement() )
1296  {
1297  replay::process_error("found corrupt movement in replay.");
1298  return 0;
1299  }
1300 
1301  return move_unit_internal(undo_stack, show_move, nullptr, mover);
1302 }
1303 
1304 
1305 }//namespace actions
bool enemy_zoc(const team &current_team, const map_location &loc, const team &viewing_team, bool see_all)
Determines if a given location is in an enemy zone of control.
Definition: pathfind.cpp:136
play_controller * controller
Definition: resources.cpp:21
std::size_t enemy_count_
Definition: move.cpp:327
bool fog_changed_
Definition: move.cpp:323
int village_owner(const map_location &loc) const
Given the location of a village, will return the 0-based index of the team that currently owns it...
void invalidate_unit_after_move(const map_location &src, const map_location &dst)
Same as invalidate_unit() if moving the displayed unit.
bool discard_previous
An announcement according these options should replace the previous announce (typical of fast announc...
Definition: display.hpp:629
bool ambushed_
Definition: move.cpp:317
unit_iterator end()
Definition: map.hpp:415
map_location zoc_stop_
Definition: move.cpp:314
move_unit_spectator *const spectator_
Definition: move.cpp:284
static display * get_singleton()
Returns the display object if a display object exists.
Definition: display.hpp:99
const std::vector< unit_map::const_iterator > & get_seen_friends() const
get the locations of seen friends
Definition: move.cpp:89
virtual const std::vector< team > & teams() const override
Definition: game_board.hpp:92
std::map< std::string, t_string > string_map
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
Definition: location.cpp:517
virtual const unit_map & units() const override
Definition: game_board.hpp:114
void reset(const unit_map &units)
reset all locations to empty values
Definition: move.cpp:111
This class represents a single unit of a specific type.
Definition: unit.hpp:99
std::size_t friend_count_
Definition: move.cpp:328
bool sighted_stop_
Definition: move.cpp:325
Various functions implementing vision (through fog of war and shroud).
void do_final_checkup(bool dont_throw=false)
The unit is uncovered - it was hiding but has been spotted.
Definition: unit.hpp:744
const unit_map::const_iterator & get_unit() const
get new location of moved unit
Definition: move.cpp:95
std::deque< int > moves_left_
Definition: move.cpp:331
const color_t GOOD_COLOR
route_iterator real_end_
Definition: move.cpp:297
virtual const gamemap & map() const override
Definition: game_board.hpp:109
const int orig_moves_
Definition: move.cpp:304
static config get_movement(const std::vector< map_location > &steps, bool skip_sighted, bool skip_ally_sighted)
Records a move that follows the provided steps.
unit_map::iterator move_it_
Definition: move.cpp:300
unit_map::const_iterator failed_teleport_
Definition: move.hpp:89
std::size_t move_unit_and_record(const std::vector< map_location > &steps, undo_list *undo_stack, bool continued_move, bool show_move, bool *interrupted, move_unit_spectator *move_spectator)
Moves a unit across the board.
Definition: move.cpp:1243
#define VNGETTEXT(msgid, msgid_plural, count,...)
Replay control code.
void check_victory()
Checks to see if a side has won.
static std::size_t move_unit_internal(undo_list *undo_stack, bool show_move, bool *interrupted, unit_mover &mover)
Definition: move.cpp:1178
-file sdl_utils.hpp
const unit_map::const_iterator & get_failed_teleport() const
get the location of a failed teleport
Definition: move.cpp:77
void redraw_minimap()
Schedule the minimap to be redrawn.
Definition: display.hpp:656
map_location ambush_stop_
Definition: move.cpp:315
void add_synced_command(const std::string &name, const config &command)
Definition: replay.cpp:244
static synced_state get_synced_state()
const unit_map::const_iterator & get_ambusher() const
get the location of an ambusher
Definition: move.cpp:71
game_data * gamedata
Definition: resources.cpp:22
std::vector< unit_map::const_iterator > seen_friends_
Definition: move.hpp:91
bool wml_move_aborted_
Definition: move.cpp:321
std::string get_names(const std::string &id)
Returns a comma-separated string of hotkey names.
int action_bonus_count() const
Definition: team.hpp:212
static void clear_status_caches()
Clear this unit status cache for all units.
Definition: unit.cpp:697
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:44
route_iterator expected_end_
Definition: move.cpp:294
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:89
team & get_team(int i)
Definition: game_board.hpp:104
bool event_mutated_mid_move_
Definition: move.cpp:322
bool sighted_
Definition: move.cpp:324
static lg::log_domain log_engine("engine")
void finish(unit_ptr u, map_location::DIRECTION dir=map_location::NDIRECTIONS)
Finishes the display of movement for the supplied unit.
Definition: udisplay.cpp:425
std::pair< const config *, map_location > unit_ability
Definition: unit.hpp:48
void add_seen_enemy(const unit_map::const_iterator &u)
add the location of new seen enemy
Definition: move.cpp:65
void set_failed_teleport(const unit_map::const_iterator &u)
set the location of a failed teleport
Definition: move.cpp:127
game_board * gameboard
Definition: resources.cpp:20
route_iterator move_loc_
Definition: move.cpp:312
bool fog_or_shroud() const
Definition: team.hpp:316
Encapsulates the map of the game.
Definition: map.hpp:34
team * current_team_
Definition: move.cpp:310
bool is_enemy(int n) const
Definition: team.hpp:241
bool show_ambush_alert_
Definition: move.cpp:318
checkup * checkup_instance
umap_retval_pair_t move(const map_location &src, const map_location &dst)
Moves a unit from location src to location dst.
Definition: map.cpp:94
A class to encapsulate the steps of drawing a unit&#39;s move.
Definition: udisplay.hpp:44
static bool can_undo()
replay * recorder
Definition: resources.cpp:28
void wait_for_anims()
Waits for the final animation of the most recent proceed_to() to finish.
Definition: udisplay.cpp:399
std::size_t count(const map_location &loc) const
Definition: map.hpp:400
void set_ambusher(const unit_map::const_iterator &u)
set the location of an ambusher
Definition: move.cpp:121
std::array< map_location, 6 > adjacent_loc_array_t
Definition: location.hpp:170
unit_map::const_iterator ambusher_
Definition: move.hpp:88
game_events::manager * game_events
Definition: resources.cpp:24
const color_t NORMAL_COLOR
bool fogged(const map_location &loc) const
Returns true if location (x,y) is covered in fog.
Definition: display.cpp:616
move_unit_spectator(const unit_map &units)
constructor
Definition: move.cpp:101
Encapsulates the map of the game.
Definition: location.hpp:42
bool auto_shroud_updates() const
Definition: team.hpp:334
std::vector< unit_map::const_iterator > seen_enemies_
Definition: move.hpp:90
Various functions related to moving units.
unit_iterator find(std::size_t id)
Definition: map.cpp:311
std::shared_ptr< wb::manager > whiteboard
Definition: resources.cpp:33
static void process_error(const std::string &msg)
Definition: replay.cpp:195
bool tiles_adjacent(const map_location &a, const map_location &b)
Function which tells if two locations are adjacent.
Definition: location.cpp:557
const route_iterator begin_
Definition: move.cpp:292
pointer get_shared_ptr() const
This is exactly the same as operator-> but it&#39;s slightly more readable, and can replace &*iter syntax...
Definition: map.hpp:220
std::vector< map_location > ambushers_
Definition: move.cpp:330
bool fire_event(const ui_event event, std::vector< std::pair< widget *, ui_event >> &event_chain, widget *dispatcher, widget *w, F &&... params)
Helper function for fire_event.
bool teleport_failed_
Definition: move.cpp:326
std::size_t i
Definition: function.cpp:933
map_location blocked_loc_
Definition: move.cpp:316
int current_side_
Definition: move.cpp:309
void announce(const std::string &msg, const color_t &color=font::GOOD_COLOR, const announce_options &options=announce_options())
Announce a message prominently.
Definition: display.cpp:939
bool interrupt_when_ally_sighted()
Definition: game.cpp:804
Holds options for calls to function &#39;announce&#39; (announce).
Definition: display.hpp:619
void get_adjacents(std::set< map_location > &adjacents, map_location loc) const
Definition: teleport.cpp:228
EXIT_STATUS start(const config &game_conf, const std::string &filename, bool take_screenshot, const std::string &screenshot_filename)
Main interface for launching the editor from the title screen.
Definition: editor_main.cpp:28
void proceed_to(unit_ptr u, std::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:320
Define the game&#39;s event mechanism.
void start(unit_ptr u)
Initiates the display of movement for the supplied unit.
Definition: udisplay.cpp:262
std::string ambush_string_
Definition: move.cpp:329
DIRECTION
Valid directions which can be moved in our hexagonal world.
Definition: location.hpp:44
const bool skip_sighting_
Definition: move.cpp:285
unit_ability_list get_abilities(const std::string &tag_name, const map_location &loc, const_attack_ptr weapon=nullptr, const_attack_ptr opp_weapon=nullptr) const
Gets the unit&#39;s active abilities of a particular type if it were on a specified location.
Definition: abilities.cpp:180
#define VGETTEXT(msgid,...)
std::size_t wml_tracking()
This function can be used to detect when no WML/Lua has been executed.
Definition: pump.cpp:645
route_iterator ambush_limit_
Definition: move.cpp:295
std::size_t move_unit_from_replay(const std::vector< map_location > &steps, undo_list *undo_stack, bool continued_move, bool skip_ally_sighted, bool show_move)
Moves a unit across the board.
Definition: move.cpp:1289
shroud_clearer clearer_
Definition: move.cpp:333
unit_map::const_iterator unit_
Definition: move.hpp:92
void set_unit(const unit_map::const_iterator &u)
set the iterator to moved unit
Definition: move.cpp:133
bool is_village(const map_location &loc) const
Definition: map.cpp:64
game_events::pump_result_t get_village(const map_location &, const int owner_side, game_data *fire_event)
Acquires a village from owner_side. Pointer fire_event should be the game_data for the game if it is ...
Definition: team.cpp:425
game_events::pump_result_t get_village(const map_location &loc, int side, bool *action_timebonus, bool fire_event)
Makes it so the village at the given location is owned by the given side.
Definition: move.cpp:139
Class to store the actions that a player can undo and redo.
Definition: undo.hpp:35
void maybe_throw_return_to_play_side() const
double t
Definition: astarsearch.cpp:63
void add_seen_friend(const unit_map::const_iterator &u)
add a location of a seen friend
Definition: move.cpp:59
const std::vector< unit_map::const_iterator > & get_seen_enemies() const
get the locations of seen enemies
Definition: move.cpp:83
Various functions that implement the undoing (and redoing) of in-game commands.
void set_action_bonus_count(const int count)
Definition: team.hpp:213
Standard logging facilities (interface).
const teleport_map get_teleport_locations(const unit &u, const team &viewing_team, bool see_all, bool ignore_units, bool check_vision)
Definition: teleport.cpp:259
static const map_location & null_location()
Definition: location.hpp:85
Container associating units to locations.
Definition: map.hpp:99
bool wml_undo_disabled_
Definition: move.cpp:320
const bool playing_team_is_viewing_
Definition: move.cpp:287
const map_location goto_
Definition: move.cpp:306
route_iterator obstructed_
Definition: move.cpp:296
bool current_uses_fog_
Definition: move.cpp:311
actions::undo_list * undo_stack
Definition: resources.cpp:32
game_events::wml_event_pump & pump()
Definition: manager.cpp:228
virtual bool local_checkup(const config &expected_data, config &real_data)=0
Compares data to the results calculated during the original game.
const route_iterator full_end_
Definition: move.cpp:293
std::tuple< bool, bool > pump_result_t
Definition: fwd.hpp:28
const map_location::DIRECTION orig_dir_
Definition: move.cpp:305
bool owns_village(const map_location &loc) const
Definition: team.hpp:184
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
bool valid() const
Definition: map.hpp:276
std::vector< int > get_sides_not_seeing(const unit &target)
Returns the sides that cannot currently see target.
Definition: vision.cpp:583
#define DBG_NG
Definition: move.cpp:53
bool team_is_defeated(const team &t) const
Calculates whether a team is defeated.
Definition: game_board.cpp:225
const bool skip_ally_sighting_
Definition: move.cpp:286
This module contains various pathfinding functions and utilities.
std::string::const_iterator iterator
Definition: tokenizer.hpp:24
const int orig_side_
Definition: move.cpp:303
Display units performing various actions: moving, attacking, and dying.
bool wml_removed_unit_
Definition: move.cpp:319
const color_t BAD_COLOR
static const hotkey_command & get_command_by_command(HOTKEY_COMMAND command)
the execute_command argument was changed from HOTKEY_COMMAND to hotkey_command, to be able to call it...
game_events::pump_result_t actor_sighted(const unit &target, const std::vector< int > *cache)
Fires sighted events for the sides that can see target.
Definition: vision.cpp:610
static game_display * get_singleton()
const std::vector< map_location > & route_
Definition: move.cpp:289
void show(const std::string &window_id, const t_string &message, const point &mouse, const SDL_Rect &source_rect)
Shows a tip.
Definition: tooltip.cpp:154
virtual ~move_unit_spectator()
destructor
Definition: move.cpp:107