The Battle for Wesnoth  1.19.0-dev
shroud_clearing_action.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 - 2024
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 
15 #pragma once
16 
17 #include "vision.hpp"
18 #include "map/location.hpp"
19 #include "units/ptr.hpp"
20 
21 namespace actions
22 {
23 /** base class for classes that clear srhoud (move/recruit/recall) */
25 {
26 
28  : route()
29  , view_info(cfg.child_or_empty("unit"))
30  , original_village_owner(cfg["village_owner"].to_int())
31  , take_village_timebonus(cfg["village_timebonus"].to_bool())
32  {
33  read_locations(cfg, route);
34  }
35 
36  shroud_clearing_action(const unit_const_ptr u, const map_location& loc, int village_owner, bool village_bonus)
37  : route(1, loc)
38  , view_info(*u)
39  , original_village_owner(village_owner)
40  , take_village_timebonus(village_bonus)
41  {
42 
43  }
44 
45  typedef std::vector<map_location> route_t;
46 
47  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)
48  : route(begin, end)
49  , view_info(*u)
50  , original_village_owner(village_owner)
51  , take_village_timebonus(village_bonus)
52  {
53 
54  }
55 
56  /**
57  * The hexes occupied by the affected unit during this action.
58  * For recruits and recalls this only contains one hex.
59  */
61  /** A record of the affected unit's ability to see. */
63  /**
64  * The number of the side that preivously owned the village that the unit stepped on
65  * Note, that recruit/recall actions can also take a village if the unit was recruits/recalled onto a village
66  */
68  /** Whether this actions got a timebonus because it took a village. */
70 
71  /** Change village owner on undo. */
72  void return_village();
73  /** Change village owner on redo. */
74  void take_village();
75 
76  void write(config & cfg) const
77  {
78  write_locations(route, cfg);
79  view_info.write(cfg.add_child("unit"));
80  cfg["village_owner"] = original_village_owner;
81  cfg["village_timebonus"] = take_village_timebonus;
82  }
83 
85 };
86 }
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
config & add_child(config_key_type key)
Definition: config.cpp:441
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,.....
Definition: location.cpp:454
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
std::shared_ptr< const unit > unit_const_ptr
Definition: ptr.hpp:27
Class that stores the part of a unit's data that is needed for fog clearing.
Definition: vision.hpp:53
void write(config &cfg) const
Writes to a config.
Definition: vision.cpp:120
base class for classes that clear srhoud (move/recruit/recall)
shroud_clearing_action(const unit_const_ptr u, const map_location &loc, int village_owner, bool village_bonus)
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)
route_t route
The hexes occupied by the affected unit during this action.
void return_village()
Change village owner on undo.
std::vector< map_location > route_t
int original_village_owner
The number of the side that preivously owned the village that the unit stepped on Note,...
clearer_info view_info
A record of the affected unit's ability to see.
void take_village()
Change village owner on redo.
bool take_village_timebonus
Whether this actions got a timebonus because it took a village.
Encapsulates the map of the game.
Definition: location.hpp:38
Various functions implementing vision (through fog of war and shroud).