The Battle for Wesnoth  1.19.17+dev
abilities.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006 - 2025
3  by Dominic Bolin <dominic.bolin@exong.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include "map/location.hpp"
19 #include "units/ptr.hpp"
20 #include "units/unit.hpp"
21 
22 class unit_ability_list;
23 namespace unit_abilities
24 {
25 bool filter_base_matches(const config& cfg, int def);
26 
28 
30 
31 /**
32  * Substitute gettext variables in name and description of abilities and specials
33  * @param str The string in which the substitution is to be done
34  * @param tag_name Tag name of the special (plague, leadership, chance_to_hit etc.)
35  * @param ability_or_special The config for the special (for example, contents inside [plague][/plague] etc.)
36  *
37  * @return The string `str` with all gettext variables substitutes with corresponding special properties
38  */
39 std::string substitute_variables(const std::string& str, const std::string& tag_name, const config& ability_or_special);
40 
41 int individual_value(const config::attribute_value *v, int def, const unit_ability & ability, const map_location& loc, const const_attack_ptr& att);
42 
43 int individual_double_value(const config::attribute_value *v, int def, const unit_ability & ability, const map_location& loc, const const_attack_ptr& att);
44 
46 {
48  loc(map_location::null_location()) {}
49  void set(value_modifier t, int val, const config *abil,const map_location &l);
51  int value;
52  const config *ability;
54 };
55 
56 class effect
57 {
58  public:
59  effect(const unit_ability_list& list, int def, const const_attack_ptr& attacker = const_attack_ptr(), EFFECTS wham = EFFECT_DEFAULT);
60  // Provide read-only access to the effect list:
61  typedef std::vector<individual_effect>::const_iterator iterator;
62  typedef std::vector<individual_effect>::const_iterator const_iterator;
63 
64  int get_composite_value() const
65  { return composite_value_; }
67  { return composite_double_value_; }
69  { return effect_list_.begin(); }
71  { return effect_list_.end(); }
72  private:
73  std::vector<individual_effect> effect_list_;
76 };
77 
78 
79 }
map_location loc
Definition: move.cpp:172
double t
Definition: astarsearch.cpp:63
Variant for storing WML attributes.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:157
int get_composite_value() const
Definition: abilities.hpp:64
std::vector< individual_effect > effect_list_
Definition: abilities.hpp:73
const_iterator end() const
Definition: abilities.hpp:70
double get_composite_double_value() const
Definition: abilities.hpp:66
effect(const unit_ability_list &list, int def, const const_attack_ptr &attacker=const_attack_ptr(), EFFECTS wham=EFFECT_DEFAULT)
Definition: abilities.cpp:2433
std::vector< individual_effect >::const_iterator const_iterator
Definition: abilities.hpp:62
double composite_double_value_
Definition: abilities.hpp:75
std::vector< individual_effect >::const_iterator iterator
Definition: abilities.hpp:61
const_iterator begin() const
Definition: abilities.hpp:68
const config * cfg
std::string substitute_variables(const std::string &str, const std::string &tag_name, const config &ability_or_special)
Substitute gettext variables in name and description of abilities and specials.
Definition: abilities.cpp:2399
int individual_double_value(const config::attribute_value *v, int def, const unit_ability &ability, const map_location &loc, const const_attack_ptr &att)
bool filter_base_matches(const config &cfg, int def)
Definition: abilities.cpp:2378
int individual_value(const config::attribute_value *v, int def, const unit_ability &ability, const map_location &loc, const const_attack_ptr &att)
@ EFFECT_WITHOUT_CLAMP_MIN_MAX
Definition: abilities.hpp:29
std::shared_ptr< const attack_type > const_attack_ptr
Definition: ptr.hpp:34
Encapsulates the map of the game.
Definition: location.hpp:46
void set(value_modifier t, int val, const config *abil, const map_location &l)
Definition: abilities.cpp:2370
Data typedef for unit_ability_list.
Definition: unit.hpp:37