The Battle for Wesnoth  1.15.12+dev
shroud_clearing_action.hpp
Go to the documentation of this file.
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) */
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  /**
56  * The hexes occupied by the affected unit during this action.
57  * For recruits and recalls this only contains one hex.
58  */
59  route_t route;
60  /** A record of the affected unit's ability to see. */
62  /**
63  * The number of the side that preivously owned the village that the unit stepped on
64  * Note, that recruit/recall actions can also take a village if the unit was recruits/recalled onto a village
65  */
67  /** Whether this actions got a timebonus because it took a village. */
69 
70  /** Change village owner on undo. */
71  void return_village();
72  /** Change village owner on redo. */
73  void take_village();
74 
75  void write(config & cfg) const
76  {
77  write_locations(route, cfg);
78  view_info.write(cfg.add_child("unit"));
79  cfg["village_owner"] = original_village_owner;
80  cfg["village_timebonus"] = take_village_timebonus;
81  }
82 
84 };
85 }
Class that stores the part of a unit&#39;s data that is needed for fog clearing.
Definition: vision.hpp:52
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:442
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)
std::shared_ptr< const unit > unit_const_ptr
Definition: ptr.hpp:26
void return_village()
Change village owner on undo.
Encapsulates the map of the game.
Definition: location.hpp:37
clearer_info view_info
A record of the affected unit&#39;s ability to see.
std::vector< map_location > route_t
void write(config &cfg) const
Writes to a config.
Definition: vision.cpp:121
config & add_child(config_key_type key)
Definition: config.cpp:500
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:59
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:454