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