1 /*
2    Copyright (C) 2017-2018 the Battle for Wesnoth Project https://www.wesnoth.org/
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2 of the License, or
7    (at your option) any later version.
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY.
10 
11    See the COPYING file for more details.
12 */
13 
14 #include "actions/undo_dismiss_action.hpp"
15 #include "game_board.hpp"
16 #include "replay.hpp"
17 #include "resources.hpp"
18 #include "team.hpp"
19 #include "units/unit.hpp"
20 
21 namespace actions
22 {
23 namespace undo
24 {
25 
26 /**
27  * Writes this into the provided config.
28  */
write(config & cfg) const29 void dismiss_action::write(config & cfg) const
30 {
31 	undo_action::write(cfg);
32 	dismissed_unit->write(cfg.add_child("unit"));
33 }
34 
35 /**
36  * Undoes this action.
37  * @return true on success; false on an error.
38  */
undo(int side)39 bool dismiss_action::undo(int side)
40 {
41 	team &current_team = resources::gameboard->get_team(side);
42 
43 	current_team.recall_list().add(dismissed_unit);
44 	execute_undo_umc_wml();
45 	return true;
46 }
47 
48 }
49 }
50