The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
move.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2017 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  * Various functions related to moving units.
18  */
19 
20 #pragma once
21 
22 struct map_location;
23 class replay;
24 class unit;
25 
26 #include "units/map.hpp"
27 #include "game_events/fwd.hpp"
28 
29 #include <vector>
30 
31 
32 namespace actions {
33  class undo_list;
34 
35 
37 public:
38  /** add a location of a seen friend */
40 
41 
42  /** add the location of new seen enemy */
44 
45 
46  /** get the location of an ambusher */
48 
49 
50  /** get the location of a failed teleport */
52 
53 
54  /** get the locations of seen enemies */
55  const std::vector<unit_map::const_iterator>& get_seen_enemies() const;
56 
57 
58  /** get the locations of seen friends */
59  const std::vector<unit_map::const_iterator>& get_seen_friends() const;
60 
61 
62  /** get new location of moved unit */
63  const unit_map::const_iterator& get_unit() const;
64 
65 
66  /** constructor */
68 
69 
70  /** destructor */
71  virtual ~move_unit_spectator();
72 
73  /** reset all locations to empty values*/
74  void reset(const unit_map &units);
75 
76 
77  /** set the location of an ambusher */
79 
80 
81  /** set the location of a failed teleport */
83 
84 
85  /** set the iterator to moved unit*/
86  void set_unit(const unit_map::const_iterator &u);
87 private:
90  std::vector<unit_map::const_iterator> seen_enemies_;
91  std::vector<unit_map::const_iterator> seen_friends_;
93 };
94 
95 /**
96  * Makes it so the village at the given location is owned by the given side.
97  * Returns true if getting the village triggered a mutating event.
98  * side can be 0 to make teh village uncaptured.
99  */
100 game_events::pump_result_t get_village(const map_location& loc, int side, bool *time_bonus = nullptr, bool fire_event = true);
101 
102 /// Moves a unit across the board.
103 /// And enters the synced context.
104 size_t move_unit_and_record(const std::vector<map_location> &steps,
106  bool continued_move = false,
107  bool show_move = true,
108  bool* interrupted = nullptr,
109  move_unit_spectator* move_spectator = nullptr);
110 
111 /// Moves a unit across the board.
112 /// to be called from replay when we are already in the synced context.
113 size_t move_unit_from_replay(const std::vector<map_location> &steps,
115  bool continued_move, bool skip_ally_sighted,
116  bool show_move = true);
117 
118 }//namespace actions
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.
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:1262
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:101
const std::vector< unit_map::const_iterator > & get_seen_friends() const
get the locations of seen friends
Definition: move.cpp:89
unit_map::const_iterator failed_teleport_
Definition: move.hpp:89
const std::vector< unit_map::const_iterator > & get_seen_enemies() const
get the locations of seen enemies
Definition: move.cpp:83
std::vector< unit_map::const_iterator > seen_friends_
Definition: move.hpp:91
const unit_map::const_iterator & get_failed_teleport() const
get the location of a failed teleport
Definition: move.cpp:77
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
void set_ambusher(const unit_map::const_iterator &u)
set the location of an ambusher
Definition: move.cpp:121
unit_map::const_iterator ambusher_
Definition: move.hpp:88
move_unit_spectator(const unit_map &units)
constructor
Definition: move.cpp:101
Encapsulates the map of the game.
Definition: location.hpp:40
std::vector< unit_map::const_iterator > seen_enemies_
Definition: move.hpp:90
const unit_map::const_iterator & get_ambusher() const
get the location of an ambusher
Definition: move.cpp:71
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:1308
const unit_map::const_iterator & get_unit() const
get new location of moved unit
Definition: move.cpp:95
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
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 add_seen_friend(const unit_map::const_iterator &u)
add a location of a seen friend
Definition: move.cpp:59
Container associating units to locations.
Definition: map.hpp:99
actions::undo_list * undo_stack
Definition: resources.cpp:33
std::tuple< bool, bool > pump_result_t
Definition: fwd.hpp:7
unit_map * units
Definition: resources.cpp:34
virtual ~move_unit_spectator()
destructor
Definition: move.cpp:107