The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
mapbuilder.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2016 by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
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  */
18 
19 #ifndef WB_MAPBUILDER_HPP_
20 #define WB_MAPBUILDER_HPP_
21 
22 #include "side_actions.hpp"
23 
24 #include <boost/ptr_container/ptr_vector.hpp>
25 #include <list>
26 
27 #include "utility.hpp"
28 
30 
32 
33 namespace wb
34 {
35 
36 /**
37  * Class that collects and applies unit_map modifications from the actions it visits
38  * and reverts all changes on destruction.
39  */
41 {
42 
43 public:
45  virtual ~mapbuilder();
46 
47  /**
48  * Builds every team's actions as far into the future as possible, in the correct order.
49  */
50  void build_map();
51 
52 private:
53  /** Function called on each action. */
54  void process(side_actions &sa, side_actions::iterator action_it);
55 
56  /** Function called after visiting a team. */
57  void post_visit_team(size_t turn);
58 
59  /** Does various preliminary actions on the unit map such as resetting moves for some units. */
60  void pre_build();
61 
62  void restore_normal_map();
63 
64  unit_map& unit_map_;
65 
68 
69  //Used by pre_build()
70  boost::ptr_vector<unit_movement_resetter> resetters_;
71  boost::ptr_vector<temporary_unit_remover> removers_;
72 
73  //Used by process()
74  std::set<unit const*> acted_this_turn_;
75  std::set<unit const*> has_invalid_actions_;
76  std::list<side_actions::iterator> invalid_actions_; ///< Conserved invalid actions.
77 };
78 
79 }
80 
81 #endif /* WB_MAPBUILDER_HPP_ */
container::iterator iterator
void process(side_actions &sa, side_actions::iterator action_it)
Function called on each action.
Definition: mapbuilder.cpp:116
std::set< unit const * > acted_this_turn_
Definition: mapbuilder.hpp:74
boost::ptr_vector< temporary_unit_remover > removers_
Definition: mapbuilder.hpp:71
std::set< unit const * > has_invalid_actions_
Definition: mapbuilder.hpp:75
void restore_normal_map()
Definition: mapbuilder.cpp:197
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:70
unit_map & unit_map_
Definition: mapbuilder.hpp:64
Object which temporarily resets a unit's movement.
Definition: unit.hpp:561
mapbuilder(unit_map &unit_map)
Definition: mapbuilder.cpp:37
action_queue applied_actions_
Definition: mapbuilder.hpp:66
This object is used to temporary remove a unit from the unit map.
Definition: game_board.hpp:183
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:40
virtual ~mapbuilder()
Definition: mapbuilder.cpp:49
action_queue applied_actions_this_turn_
Definition: mapbuilder.hpp:67
Container associating units to locations.
Definition: map.hpp:90
std::deque< action_ptr > action_queue
Definition: typedefs.hpp:73
void build_map()
Builds every team'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:47
void post_visit_team(size_t turn)
Function called after visiting a team.
Definition: mapbuilder.cpp:174