The Battle for Wesnoth  1.15.9+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 <list>
24 
25 #include "utility.hpp"
26 
28 
30 
31 namespace wb
32 {
33 
34 /**
35  * Class that collects and applies unit_map modifications from the actions it visits
36  * and reverts all changes on destruction.
37  */
39 {
40 
41 public:
43  virtual ~mapbuilder();
44 
45  /**
46  * Builds every team's actions as far into the future as possible, in the correct order.
47  */
48  void build_map();
49 
50 private:
51  /** Function called on each action. */
52  void process(side_actions &sa, side_actions::iterator action_it, bool is_local_side);
53 
54  /** Function called after visiting a team. */
55  void post_visit_team(std::size_t turn);
56 
57  /** Does various preliminary actions on the unit map such as resetting moves for some units. */
58  void pre_build();
59 
60  void restore_normal_map();
61 
62  unit_map& unit_map_;
63 
66 
67  //Used by pre_build()
68  std::vector<std::unique_ptr<unit_movement_resetter>> resetters_;
69  std::vector<std::unique_ptr<temporary_unit_remover>> removers_;
70 
71  //Used by process()
72  std::set<unit const*> acted_this_turn_;
73  std::set<unit const*> has_invalid_actions_;
74  /** Conserved invalid actions. */
75  std::list<side_actions::iterator> invalid_actions_;
76 };
77 
78 }
container::iterator iterator
std::set< unit const * > acted_this_turn_
Definition: mapbuilder.hpp:72
std::set< unit const * > has_invalid_actions_
Definition: mapbuilder.hpp:73
std::vector< std::unique_ptr< unit_movement_resetter > > resetters_
Definition: mapbuilder.hpp:68
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:62
Object which temporarily resets a unit&#39;s movement.
Definition: unit.hpp:1951
mapbuilder(unit_map &unit_map)
Definition: mapbuilder.cpp:37
action_queue applied_actions_
Definition: mapbuilder.hpp:64
This object is used to temporary remove a unit from the unit map.
Definition: game_board.hpp:208
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:38
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:65
Container associating units to locations.
Definition: map.hpp:97
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
std::vector< std::unique_ptr< temporary_unit_remover > > removers_
Definition: mapbuilder.hpp:69
This internal whiteboard class holds the planned action queues for a team, and offers many utility me...
Definition: display.hpp:48