The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
undo_dismiss_action.cpp
Go to the documentation of this file.
2 #include "resources.hpp"
3 #include "team.hpp"
4 #include "replay.hpp"
5 
6 namespace actions
7 {
8 namespace undo
9 {
10 
11 /**
12  * Writes this into the provided config.
13  */
14 void dismiss_action::write(config & cfg) const
15 {
16  undo_action::write(cfg);
17  dismissed_unit->write(cfg.add_child("unit"));
18 }
19 
20 /**
21  * Undoes this action.
22  * @return true on success; false on an error.
23  */
24 bool dismiss_action::undo(int side)
25 {
26  team &current_team = (*resources::teams)[side-1];
27 
28  current_team.recall_list().add(dismissed_unit);
30  return true;
31 }
32 
33 /**
34  * Redoes this action.
35  * @return true on success; false on an error.
36  */
37 bool dismiss_action::redo(int side)
38 {
39  team &current_team = (*resources::teams)[side-1];
40 
43  current_team.recall_list().erase_if_matches_id(dismissed_unit->id());
45  return true;
46 }
47 
48 }
49 }
virtual bool redo(int side)
Redoes this action.
Replay control code.
void clear()
Definition: config.cpp:1055
-file sdl_utils.hpp
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:50
void redo(const config &dst)
Definition: replay.cpp:410
config & add_child(const std::string &key)
Definition: config.cpp:743
replay * recorder
Definition: resources.cpp:30
void erase_if_matches_id(const std::string &unit_id)
Erase any unit with this id.
virtual void write(config &cfg) const
Writes this into the provided config.
virtual void write(config &cfg) const
Writes this into the provided config.
recall_list_manager & recall_list()
Definition: team.hpp:220
void add(const unit_ptr &ptr)
Add a unit to the list.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
config replay_data
the replay data to do this action, this is only !empty() when this action is on the redo stack we nee...
Definition: undo_action.hpp:69
virtual bool undo(int side)
Undoes this action.