The Battle for Wesnoth  1.17.0-dev
undo_dismiss_action.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 - 2021
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 
16 #include "game_board.hpp"
17 #include "replay.hpp"
18 #include "resources.hpp"
19 #include "team.hpp"
20 #include "units/unit.hpp"
21 
22 namespace actions
23 {
24 namespace undo
25 {
26 
27 /**
28  * Writes this into the provided config.
29  */
30 void dismiss_action::write(config & cfg) const
31 {
32  undo_action::write(cfg);
33  dismissed_unit->write(cfg.add_child("unit"));
34 }
35 
36 /**
37  * Undoes this action.
38  * @return true on success; false on an error.
39  */
40 bool dismiss_action::undo(int side)
41 {
42  team &current_team = resources::gameboard->get_team(side);
43 
44  current_team.recall_list().add(dismissed_unit);
46  return true;
47 }
48 
49 }
50 }
Replay control code.
virtual void write(config &cfg) const
Writes this into the provided config.
virtual void write(config &cfg) const
Writes this into the provided config.
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:72
team & get_team(int i)
Definition: game_board.hpp:97
game_board * gameboard
Definition: resources.cpp:21
config & add_child(config_key_type key)
Definition: config.cpp:514
void add(const unit_ptr &ptr, int pos=-1)
Add a unit to the list.
recall_list_manager & recall_list()
Definition: team.hpp:227
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
virtual bool undo(int side)
Undoes this action.