The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 the Battle for Wesnoth Project
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,
11  See the COPYING file for more details.
12 */
15 #include "actions/create.hpp"
18 #include "game_board.hpp"
19 #include "resources.hpp"
20 #include "team.hpp"
21 #include "replay.hpp"
22 #include "units/map.hpp"
23 #include "statistics.hpp"
24 #include "log.hpp"
25 #include "game_display.hpp"
27 static lg::log_domain log_engine("engine");
28 #define ERR_NG LOG_STREAM(err, log_engine)
29 #define LOG_NG LOG_STREAM(info, log_engine)
31 namespace actions
32 {
33 namespace undo
34 {
36 /**
37  * Writes this into the provided config.
38  */
39 void recruit_action::write(config & cfg) const
40 {
41  undo_action::write(cfg);
44  recruit_from.write(cfg.add_child("leader"));
45  config & child = cfg.child("unit");
46  child["type"] = u_type.base_id();
47 }
49 /**
50  * Undoes this action.
51  * @return true on success; false on an error.
52  */
53 bool recruit_action::undo(int side)
54 {
57  team &current_team = resources::gameboard->get_team(side);
59  const map_location & recruit_loc = route.front();
60  unit_map::iterator un_it = units.find(recruit_loc);
61  if ( un_it == units.end() ) {
62  return false;
63  }
65  const unit &un = *un_it;
67  current_team.spend_gold(-un.type().cost());
69  //MP_COUNTDOWN take away recruit bonus
70  current_team.set_action_bonus_count(current_team.action_bonus_count() - 1);
72  // invalidate before erasing allow us
73  // to also do the overlapped hexes
74  gui.invalidate(recruit_loc);
75  units.erase(recruit_loc);
76  this->return_village();
78  return true;
79 }
81 }
82 }
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
Definition: config.cpp:352
virtual const unit_map & units() const
Definition: game_board.hpp:97
unit_iterator end()
Definition: map.hpp:415
virtual bool undo(int side)
Undoes this action.
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
Definition: display.cpp:2981
This class represents a single unit of a specific type.
Definition: unit.hpp:101
game_display * screen
Definition: resources.cpp:27
General purpose widgets.
Replay control code.
-file sdl_utils.hpp
void return_village()
Change village owner on undo.
virtual void write(config &cfg) const
Writes this into the provided config.
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:44
team & get_team(int i)
Definition: game_board.hpp:94
game_board * gameboard
Definition: resources.cpp:20
void spend_gold(const int amount)
Definition: team.hpp:207
void write(config &cfg) const
Definition: location.cpp:210
int cost() const
Definition: types.hpp:159
Encapsulates the map of the game.
Definition: location.hpp:40
virtual void write(config &cfg) const
Writes this into the provided config.
Various functions related to the creation of units (recruits, recalls, and placed units)...
const unit_type & type() const
This unit's type, accounting for gender and variation.
Definition: unit.hpp:257
config & add_child(config_key_type key)
Definition: config.cpp:408
size_t erase(const map_location &l)
Erases the unit at location l, if any.
Definition: map.cpp:298
const std::string & base_id() const
The id of the original type from which this (variation) descended.
Definition: types.hpp:144
void set_action_bonus_count(const int count)
Definition: team.hpp:213
Standard logging facilities (interface).
Container associating units to locations.
Definition: map.hpp:99
route_t route
The hexes occupied by the affected unit during this action.
unit_iterator find(size_t id)
Definition: map.cpp:311
static lg::log_domain log_engine("engine")
void un_recruit_unit(const unit &u)
Definition: statistics.cpp:527
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
int action_bonus_count() const
Definition: team.hpp:212
unit_map * units
Definition: resources.cpp:34