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 #pragma once
15 
16 #include "vision.hpp"
17 #include "map/location.hpp"
18 #include "units/ptr.hpp"
19 
20 namespace actions
21 {
22 /// base class for classes that clear srhoud (move/recruit/recall)
23 struct shroud_clearing_action
24 {
25 
shroud_clearing_actionactions::shroud_clearing_action26 	shroud_clearing_action(const config& cfg)
27 		: route()
28 		, view_info(cfg.child_or_empty("unit"))
29 		, original_village_owner(cfg["village_owner"].to_int())
30 		, take_village_timebonus(cfg["village_timebonus"].to_bool())
31 	{
32 		read_locations(cfg, route);
33 	}
34 
shroud_clearing_actionactions::shroud_clearing_action35 	shroud_clearing_action(const unit_const_ptr u, const map_location& loc, int village_owner, bool village_bonus)
36 		: route(1, loc)
37 		, view_info(*u)
38 		, original_village_owner(village_owner)
39 		, take_village_timebonus(village_bonus)
40 	{
41 
42 	}
43 
44 	typedef std::vector<map_location> route_t;
45 
shroud_clearing_actionactions::shroud_clearing_action46 	shroud_clearing_action(const unit_const_ptr u, const route_t::const_iterator& begin, const route_t::const_iterator& end, int village_owner, bool village_bonus)
47 		: route(begin, end)
48 		, view_info(*u)
49 		, original_village_owner(village_owner)
50 		, take_village_timebonus(village_bonus)
51 	{
52 
53 	}
54 
55 	/// The hexes occupied by the affected unit during this action.
56 	/// For recruits and recalls this only contains one hex.
57 	route_t route;
58 	/// A record of the affected unit's ability to see.
59 	clearer_info view_info;
60 	/// The number of the side that preivously owned the village that the unit stepped on
61 	/// Note, that recruit/recall actions can also take a village if the unit was recruits/recalled onto a village.
62 	int original_village_owner;
63 	/// Whether this actions got a timebonus because it took a village.
64 	bool take_village_timebonus;
65 
66 	/// Change village owner on undo.
67 	void return_village();
68 	/// Change village owner on redo.
69 	void take_village();
70 
writeactions::shroud_clearing_action71 	void write(config & cfg) const
72 	{
73 		write_locations(route, cfg);
74 		view_info.write(cfg.add_child("unit"));
75 		cfg["village_owner"] = original_village_owner;
76 		cfg["village_timebonus"] = take_village_timebonus;
77 	}
78 
~shroud_clearing_actionactions::shroud_clearing_action79 	virtual ~shroud_clearing_action() {}
80 };
81 }
82