The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
shroud_clearing_action.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 the Battle for Wesnoth Project http://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)
24 {
25 
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 
35  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 
46  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.
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.
63  /// Whether this actions got a timebonus because it took a village.
65 
66  /// Change village owner on undo.
67  void return_village();
68  /// Change village owner on redo.
69  void take_village();
70 
71  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 
80 };
81 }
Class that stores the part of a unit's data that is needed for fog clearing.
Definition: vision.hpp:41
boost::intrusive_ptr< const unit > unit_const_ptr
Definition: ptr.hpp:30
base class for classes that clear srhoud (move/recruit/recall)
void read_locations(const config &cfg, std::vector< map_location > &locs)
Parse x,y keys of a config into a vector of locations.
Definition: location.cpp:446
void take_village()
Change village owner on redo.
Various functions implementing vision (through fog of war and shroud).
bool take_village_timebonus
Whether this actions got a timebonus because it took a village.
shroud_clearing_action(const unit_const_ptr u, const map_location &loc, int village_owner, bool village_bonus)
void return_village()
Change village owner on undo.
Encapsulates the map of the game.
Definition: location.hpp:40
clearer_info view_info
A record of the affected unit's ability to see.
std::vector< map_location > route_t
config & add_child(config_key_type key)
Definition: config.cpp:456
void write(config &cfg) const
Writes to a config.
Definition: vision.cpp:124
int original_village_owner
The number of the side that preivously owned the village that the unit stepped on Note...
route_t route
The hexes occupied by the affected unit during this action.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
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)
void write_locations(const std::vector< map_location > &locs, config &cfg)
Write a vector of locations into a config adding keys x=x1,x2,..,xn and y=y1,y2,..,yn.
Definition: location.cpp:458