The Battle for Wesnoth  1.17.14+dev
mapbuilder.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2022
3  by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
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  */
19 
20 #pragma once
21 
22 #include "side_actions.hpp"
23 
24 #include <list>
25 
26 #include "utility.hpp"
27 
29 
31 
32 namespace wb
33 {
34 
35 /**
36  * Class that collects and applies unit_map modifications from the actions it visits
37  * and reverts all changes on destruction.
38  */
40 {
41 
42 public:
44  virtual ~mapbuilder();
45 
46  /**
47  * Builds every team's actions as far into the future as possible, in the correct order.
48  */
49  void build_map();
50 
51 private:
52  /** Function called on each action. */
53  void process(side_actions &sa, side_actions::iterator action_it, bool is_local_side);
54 
55  /** Function called after visiting a team. */
56  void post_visit_team(std::size_t turn);
57 
58  /** Does various preliminary actions on the unit map such as resetting moves for some units. */
59  void pre_build();
60 
61  void restore_normal_map();
62 
63  unit_map& unit_map_;
64 
67 
68  //Used by pre_build()
69  std::vector<std::unique_ptr<unit_movement_resetter>> resetters_;
70  std::vector<std::unique_ptr<temporary_unit_remover>> removers_;
71 
72  //Used by process()
73  std::set<unit const*> acted_this_turn_;
74  std::set<unit const*> has_invalid_actions_;
75  /** Conserved invalid actions. */
76  std::list<side_actions::iterator> invalid_actions_;
77 };
78 
79 }
container::iterator iterator
std::set< unit const * > acted_this_turn_
Definition: mapbuilder.hpp:73
std::set< unit const * > has_invalid_actions_
Definition: mapbuilder.hpp:74
std::vector< std::unique_ptr< unit_movement_resetter > > resetters_
Definition: mapbuilder.hpp:69
void process(side_actions &sa, side_actions::iterator action_it, bool is_local_side)
Function called on each action.
Definition: mapbuilder.cpp:116
void restore_normal_map()
Definition: mapbuilder.cpp:200
void pre_build()
Does various preliminary actions on the unit map such as resetting moves for some units...
Definition: mapbuilder.cpp:57
unit_map & unit_map_
Definition: mapbuilder.hpp:63
Object which temporarily resets a unit&#39;s movement.
Definition: unit.hpp:2006
mapbuilder(unit_map &unit_map)
Definition: mapbuilder.cpp:37
action_queue applied_actions_
Definition: mapbuilder.hpp:65
This object is used to temporary remove a unit from the unit map.
Definition: game_board.hpp:212
std::list< side_actions::iterator > invalid_actions_
Conserved invalid actions.
Definition: mapbuilder.hpp:76
Class that collects and applies unit_map modifications from the actions it visits and reverts all cha...
Definition: mapbuilder.hpp:39
void post_visit_team(std::size_t turn)
Function called after visiting a team.
Definition: mapbuilder.cpp:177
virtual ~mapbuilder()
Definition: mapbuilder.cpp:49
action_queue applied_actions_this_turn_
Definition: mapbuilder.hpp:66
Container associating units to locations.
Definition: map.hpp:98
std::deque< action_ptr > action_queue
Definition: typedefs.hpp:65
void build_map()
Builds every team&#39;s actions as far into the future as possible, in the correct order.
Definition: mapbuilder.cpp:89
std::vector< std::unique_ptr< temporary_unit_remover > > removers_
Definition: mapbuilder.hpp:70
This internal whiteboard class holds the planned action queues for a team, and offers many utility me...
Definition: display.hpp:49