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