The Battle for Wesnoth  1.15.2+dev
advancement.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2018 by 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 /**
15  * @file
16  * Various functions that implement advancements of units.
17  */
18 
19 #pragma once
20 
21 struct map_location;
22 class team;
23 class unit;
24 class config;
25 #include "units/types.hpp"
26 
27 #include <string>
28 #include <vector>
29 
30 /**
31  advances the unit at loc if it has enough experience, maximum 20 times.
32  if the unit is on the currently active side, and that side is controlled by a human, a dialog pops up.
33  if we are in a non mp game, and the side is controlled by a human then a dialog is shown too.
34  if the side is controlled by an ai, and if ai_advancement is passed, then ai_advancement will be used.
35  otherwise a random decision will be taken.
36 */
38 {
39  advance_unit_params(const map_location& loc) : loc_(loc), force_dialog_(false), fire_events_(true), animate_(true) {}
40  advance_unit_params& force_dialog(bool value) {force_dialog_ = value; return *this;}
41  advance_unit_params& fire_events(bool value) {fire_events_ = value; return *this;}
42  advance_unit_params& animate(bool value) {animate_ = value; return *this;}
43  friend void advance_unit_at(const advance_unit_params&);
44 private:
48  bool animate_;
49 };
50 void advance_unit_at(const advance_unit_params& params);
51 /**
52  * Returns the advanced version of a unit (with traits and items retained).
53  */
54 unit_ptr get_advanced_unit(const unit &u, const std::string &advance_to);
55 
56 /**
57  * Returns the AMLA-advanced version of a unit (with traits and items retained).
58  */
59 unit_ptr get_amla_unit(const unit &u, const config &mod_option);
60 
61 using advancement_option = boost::variant<std::string /*change type*/, const config* /*apply amla*/>;
62 
63 /**
64  * Function which will advance the unit at @a loc to 'advance_to'.
65  * which is eigher a type to advance to or a config containing the
66  * [advancement] to perform an amla.
67  * Note that 'loc' is not a reference, because if it were a reference,
68  * we couldn't safely pass in a reference to the item in the map
69  * that we're going to delete, since deletion would invalidate the reference.
70  */
71 void advance_unit(map_location loc, const advancement_option &advance_to, bool fire_event = true);
This class represents a single unit of a specific type.
Definition: unit.hpp:106
void advance_unit(map_location loc, const advancement_option &advance_to, bool fire_event=true)
Function which will advance the unit at loc to &#39;advance_to&#39;.
friend void advance_unit_at(const advance_unit_params &)
advance_unit_params & force_dialog(bool value)
Definition: advancement.hpp:40
advance_unit_params & fire_events(bool value)
Definition: advancement.hpp:41
map_location loc_
Definition: advancement.hpp:45
advance_unit_params & animate(bool value)
Definition: advancement.hpp:42
boost::variant< std::string, const config *> advancement_option
Definition: advancement.hpp:61
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:44
unit_ptr get_advanced_unit(const unit &u, const std::string &advance_to)
Returns the advanced version of a unit (with traits and items retained).
advances the unit at loc if it has enough experience, maximum 20 times.
Definition: advancement.hpp:37
Encapsulates the map of the game.
Definition: location.hpp:42
bool fire_event(const ui_event event, std::vector< std::pair< widget *, ui_event >> &event_chain, widget *dispatcher, widget *w, F &&... params)
Helper function for fire_event.
advance_unit_params(const map_location &loc)
Definition: advancement.hpp:39
boost::intrusive_ptr< unit > unit_ptr
Definition: ptr.hpp:29
unit_ptr get_amla_unit(const unit &u, const config &mod_option)
Returns the AMLA-advanced version of a unit (with traits and items retained).
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68