The Battle for Wesnoth  1.19.7+dev
mapbuilder.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2024
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 
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 
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 associating units to locations.
Definition: map.hpp:98
Class that collects and applies unit_map modifications from the actions it visits and reverts all cha...
Definition: mapbuilder.hpp:39
std::set< unit const * > acted_this_turn_
Definition: mapbuilder.hpp:72
mapbuilder(unit_map &unit_map)
Definition: mapbuilder.cpp:37
std::set< unit const * > has_invalid_actions_
Definition: mapbuilder.hpp:73
std::list< side_actions::iterator > invalid_actions_
Conserved invalid actions.
Definition: mapbuilder.hpp:75
void build_map()
Builds every team's actions as far into the future as possible, in the correct order.
Definition: mapbuilder.cpp:89
virtual ~mapbuilder()
Definition: mapbuilder.cpp:49
std::vector< std::unique_ptr< temporary_unit_remover > > removers_
Definition: mapbuilder.hpp:69
void restore_normal_map()
Definition: mapbuilder.cpp:200
void process(side_actions &sa, side_actions::iterator action_it, bool is_local_side)
Function called on each action.
Definition: mapbuilder.cpp:116
void post_visit_team(std::size_t turn)
Function called after visiting a team.
Definition: mapbuilder.cpp:177
action_queue applied_actions_
Definition: mapbuilder.hpp:64
void pre_build()
Does various preliminary actions on the unit map such as resetting moves for some units.
Definition: mapbuilder.cpp:57
std::vector< std::unique_ptr< unit_movement_resetter > > resetters_
Definition: mapbuilder.hpp:68
action_queue applied_actions_this_turn_
Definition: mapbuilder.hpp:65
unit_map & unit_map_
Definition: mapbuilder.hpp:62
This internal whiteboard class holds the planned action queues for a team, and offers many utility me...
container::iterator iterator
Definition: display.hpp:45
std::deque< action_ptr > action_queue
Definition: typedefs.hpp:65
This object is used to temporary remove a unit from the unit map.
Definition: game_board.hpp:207
Object which temporarily resets a unit's movement.
Definition: unit.hpp:2152