The Battle for Wesnoth  1.15.1+dev
mapbuilder.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2018 by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
3  Part of the Battle for Wesnoth Project https://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  */
18 
19 #pragma once
20 
21 #include "side_actions.hpp"
22 
23 #include <boost/ptr_container/ptr_vector.hpp>
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  boost::ptr_vector<unit_movement_resetter> resetters_;
70  boost::ptr_vector<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  std::list<side_actions::iterator> invalid_actions_; ///< Conserved invalid actions.
76 };
77 
78 }
container::iterator iterator
std::set< unit const * > acted_this_turn_
Definition: mapbuilder.hpp:73
boost::ptr_vector< temporary_unit_remover > removers_
Definition: mapbuilder.hpp:70
std::set< unit const * > has_invalid_actions_
Definition: mapbuilder.hpp:74
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
boost::ptr_vector< unit_movement_resetter > resetters_
Definition: mapbuilder.hpp:69
unit_map & unit_map_
Definition: mapbuilder.hpp:63
Object which temporarily resets a unit&#39;s movement.
Definition: unit.hpp:1858
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:213
std::list< side_actions::iterator > invalid_actions_
Conserved invalid actions.
Definition: mapbuilder.hpp:75
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:99
std::deque< action_ptr > action_queue
Definition: typedefs.hpp:64
void build_map()
Builds every team&#39;s actions as far into the future as possible, in the correct order.
Definition: mapbuilder.cpp:89
This internal whiteboard class holds the planned action queues for a team, and offers many utility me...
Definition: display.hpp:48