The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
move.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2003 - 2025
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
23struct map_location;
24
25#include "units/map.hpp"
26#include "game_events/fwd.hpp"
27#include "synced_commands.hpp"
28
29#include <vector>
30
31
32namespace actions {
33 class undo_list;
34
35
37public:
38
39 /** ingerited from action_spectator */
40 void error(const std::string& message) override;
41 /** add a location of a seen friend */
43
44
45 /** add the location of new seen enemy */
47
48
49 /** get the location of an ambusher */
51
52
53 /** get the location of a failed teleport */
55
56
57 /** get the locations of seen enemies */
58 const std::vector<unit_map::const_iterator>& get_seen_enemies() const;
59
60
61 /** get the locations of seen friends */
62 const std::vector<unit_map::const_iterator>& get_seen_friends() const;
63
64
65 /** get new location of moved unit */
67
68
69 /** constructor */
70 move_unit_spectator(const unit_map& units);
71
73
74
75 /** destructor */
76 virtual ~move_unit_spectator();
77
78 /** reset all locations to empty values*/
79 void reset(const unit_map &units);
80
81
82 /** set the location of an ambusher */
84
85
86 /** set the location of a failed teleport */
88
89
90 /** set the iterator to moved unit*/
92
93 void set_ai_move(bool ai_move = true) { is_ai_move_ = ai_move; }
94 bool is_ai_move() const { return is_ai_move_; }
95
96 void set_interrupted(bool interrupted) { interrupted_ = interrupted; }
97 bool get_interrupted() const { return interrupted_; }
98
99 void set_tiles_entered(std::size_t tiles_entered) { tiles_entered_ = tiles_entered; }
100 std::size_t get_tiles_entered() const { return tiles_entered_; }
101
102private:
105 std::vector<unit_map::const_iterator> seen_enemies_;
106 std::vector<unit_map::const_iterator> seen_friends_;
108 std::size_t tiles_entered_;
110 bool is_ai_move_ = false;
111};
112
113/**
114 * Makes it so the village at the given location is owned by the given side.
115 * Returns true if getting the village triggered a mutating event.
116 * side can be 0 to make the village uncaptured.
117 */
118game_events::pump_result_t get_village(const map_location& loc, int side, bool *time_bonus = nullptr, bool fire_event = true);
119
120/**
121 * Teleports a unit across the board and enters the synced context.
122 */
123void teleport_unit_and_record(const map_location& teleport_from,
124 const map_location& teleport_to,
125 move_unit_spectator* move_spectator = nullptr);
126
127/**
128 * Teleports a unit across the board.
129 * To be called from replay when we are already in the synced context.
130 */
132 const std::vector<map_location> &steps,
133 bool continued_move,
134 bool skip_ally_sighted,
135 bool show_move);
136
137/**
138 * Moves a unit across the board.
139 * And enters the synced context.
140 */
142 const std::vector<map_location> &steps,
143 bool continued_move,
144 move_unit_spectator& move_spectator);
145
146std::size_t move_unit_and_record(const std::vector<map_location>& steps,
147 bool continued_move = false,
148 bool* interrupted = nullptr);
149
150/**
151 * Moves a unit across the board.
152 * to be called from replay when we are already in the synced context.
153 */
155 const std::vector<map_location> &steps,
156 bool continued_move,
157 bool skip_ally_sighted,
158 move_unit_spectator* move_spectator);
159
160}//namespace actions
map_location loc
Definition move.cpp:172
void set_ambusher(const unit_map::const_iterator &u)
set the location of an ambusher
Definition move.cpp:145
void add_seen_friend(const unit_map::const_iterator &u)
add a location of a seen friend
Definition move.cpp:60
const std::vector< unit_map::const_iterator > & get_seen_enemies() const
get the locations of seen enemies
Definition move.cpp:84
const unit_map::const_iterator & get_ambusher() const
get the location of an ambusher
Definition move.cpp:72
void set_tiles_entered(std::size_t tiles_entered)
Definition move.hpp:99
void error(const std::string &message) override
ingerited from action_spectator
Definition move.cpp:140
void add_seen_enemy(const unit_map::const_iterator &u)
add the location of new seen enemy
Definition move.cpp:66
const unit_map::const_iterator & get_unit() const
get new location of moved unit
Definition move.cpp:96
unit_map::const_iterator ambusher_
Definition move.hpp:103
unit_map::const_iterator unit_
Definition move.hpp:107
void reset(const unit_map &units)
reset all locations to empty values
Definition move.cpp:129
std::size_t get_tiles_entered() const
Definition move.hpp:100
void set_unit(const unit_map::const_iterator &u)
set the iterator to moved unit
Definition move.cpp:157
bool get_interrupted() const
Definition move.hpp:97
std::vector< unit_map::const_iterator > seen_enemies_
Definition move.hpp:105
void set_failed_teleport(const unit_map::const_iterator &u)
set the location of a failed teleport
Definition move.cpp:151
std::vector< unit_map::const_iterator > seen_friends_
Definition move.hpp:106
virtual ~move_unit_spectator()
destructor
Definition move.cpp:125
void set_interrupted(bool interrupted)
Definition move.hpp:96
const std::vector< unit_map::const_iterator > & get_seen_friends() const
get the locations of seen friends
Definition move.cpp:90
void set_ai_move(bool ai_move=true)
Definition move.hpp:93
const unit_map::const_iterator & get_failed_teleport() const
get the location of a failed teleport
Definition move.cpp:78
unit_map::const_iterator failed_teleport_
Definition move.hpp:104
bool is_ai_move() const
Definition move.hpp:94
Container associating units to locations.
Definition map.hpp:98
void teleport_unit_from_replay(const std::vector< map_location > &steps, bool continued_move, bool skip_ally_sighted, bool show_move)
Teleports a unit across the board.
Definition move.cpp:1412
void teleport_unit_and_record(const map_location &teleport_from, const map_location &teleport_to, move_unit_spectator *)
Teleports a unit across the board and enters the synced context.
Definition move.cpp:1403
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:221
std::size_t move_unit_and_record(const std::vector< map_location > &steps, bool continued_move, bool *interrupted)
Wrapper around the other overload.
Definition move.cpp:1435
void execute_move_unit(const std::vector< map_location > &steps, bool continued_move, bool skip_ally_sighted, move_unit_spectator *move_spectator)
Moves a unit across the board.
Definition move.cpp:1388
std::tuple< bool, bool > pump_result_t
Definition fwd.hpp:29
Encapsulates the map of the game.
Definition location.hpp:46