The Battle for Wesnoth  1.19.0-dev
move.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
3  by David White <dave@whitevine.net>
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  * Various functions related to moving units.
19  */
20 
21 #pragma once
22 
23 struct map_location;
24 
25 #include "units/map.hpp"
26 #include "game_events/fwd.hpp"
27 
28 #include <vector>
29 
30 
31 namespace actions {
32  class undo_list;
33 
34 
36 public:
37  /** add a location of a seen friend */
39 
40 
41  /** add the location of new seen enemy */
43 
44 
45  /** get the location of an ambusher */
47 
48 
49  /** get the location of a failed teleport */
51 
52 
53  /** get the locations of seen enemies */
54  const std::vector<unit_map::const_iterator>& get_seen_enemies() const;
55 
56 
57  /** get the locations of seen friends */
58  const std::vector<unit_map::const_iterator>& get_seen_friends() const;
59 
60 
61  /** get new location of moved unit */
62  const unit_map::const_iterator& get_unit() const;
63 
64 
65  /** constructor */
66  move_unit_spectator(const unit_map &units);
67 
68 
69  /** destructor */
70  virtual ~move_unit_spectator();
71 
72  /** reset all locations to empty values*/
73  void reset(const unit_map &units);
74 
75 
76  /** set the location of an ambusher */
78 
79 
80  /** set the location of a failed teleport */
82 
83 
84  /** set the iterator to moved unit*/
85  void set_unit(const unit_map::const_iterator &u);
86 private:
89  std::vector<unit_map::const_iterator> seen_enemies_;
90  std::vector<unit_map::const_iterator> seen_friends_;
92 };
93 
94 /**
95  * Makes it so the village at the given location is owned by the given side.
96  * Returns true if getting the village triggered a mutating event.
97  * side can be 0 to make the village uncaptured.
98  */
99 game_events::pump_result_t get_village(const map_location& loc, int side, bool *time_bonus = nullptr, bool fire_event = true);
100 
101 /**
102  * Moves a unit across the board.
103  * And enters the synced context.
104  */
105 std::size_t move_unit_and_record(
106  const std::vector<map_location> &steps,
108  bool continued_move = false,
109  bool show_move = true,
110  bool* interrupted = nullptr,
111  move_unit_spectator* move_spectator = nullptr);
112 
113 /**
114  * Moves a unit across the board.
115  * to be called from replay when we are already in the synced context.
116  */
117 std::size_t move_unit_from_replay(
118  const std::vector<map_location> &steps,
120  bool continued_move,
121  bool skip_ally_sighted,
122  bool show_move = true);
123 
124 }//namespace actions
void set_ambusher(const unit_map::const_iterator &u)
set the location of an ambusher
Definition: move.cpp:121
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
const unit_map::const_iterator & get_ambusher() const
get the location of an ambusher
Definition: move.cpp:71
void add_seen_enemy(const unit_map::const_iterator &u)
add the location of new seen enemy
Definition: move.cpp:65
const unit_map::const_iterator & get_unit() const
get new location of moved unit
Definition: move.cpp:95
unit_map::const_iterator ambusher_
Definition: move.hpp:87
unit_map::const_iterator unit_
Definition: move.hpp:91
void reset(const unit_map &units)
reset all locations to empty values
Definition: move.cpp:111
void set_unit(const unit_map::const_iterator &u)
set the iterator to moved unit
Definition: move.cpp:133
std::vector< unit_map::const_iterator > seen_enemies_
Definition: move.hpp:89
void set_failed_teleport(const unit_map::const_iterator &u)
set the location of a failed teleport
Definition: move.cpp:127
std::vector< unit_map::const_iterator > seen_friends_
Definition: move.hpp:90
virtual ~move_unit_spectator()
destructor
Definition: move.cpp:107
const std::vector< unit_map::const_iterator > & get_seen_friends() const
get the locations of seen friends
Definition: move.cpp:89
const unit_map::const_iterator & get_failed_teleport() const
get the location of a failed teleport
Definition: move.cpp:77
unit_map::const_iterator failed_teleport_
Definition: move.hpp:88
move_unit_spectator(const unit_map &units)
constructor
Definition: move.cpp:101
Class to store the actions that a player can undo and redo.
Definition: undo.hpp:34
Container associating units to locations.
Definition: map.hpp:98
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:1273
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:1229
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
std::tuple< bool, bool > pump_result_t
Definition: fwd.hpp:29
bool fire_event(const ui_event event, const std::vector< std::pair< widget *, ui_event >> &event_chain, widget *dispatcher, widget *w, F &&... params)
Helper function for fire_event.
actions::undo_list * undo_stack
Definition: resources.cpp:32
Encapsulates the map of the game.
Definition: location.hpp:38