23 #include "formula/callable_objects.hpp"
38 #define ERR_CF LOG_STREAM(err, log_config)
39 #define WRN_CF LOG_STREAM(warn, log_config)
40 #define LOG_CONFIG LOG_STREAM(info, log_config)
41 #define DBG_CF LOG_STREAM(debug, log_config)
44 #define DBG_UT LOG_STREAM(debug, log_unit)
45 #define ERR_UT LOG_STREAM(err, log_unit)
48 #define ERR_WML LOG_STREAM(err, log_wml)
54 , other_attack_(nullptr)
55 , description_(cfg[
"description"].t_str())
59 , range_(cfg[
"range"])
60 , min_range_(cfg[
"min_range"].to_int(1))
61 , max_range_(cfg[
"max_range"].to_int(1))
63 , damage_(cfg[
"damage"].to_int())
64 , num_attacks_(cfg[
"number"].to_int())
65 , attack_weight_(cfg[
"attack_weight"].to_double(1.0))
66 , defense_weight_(cfg[
"defense_weight"].to_double(1.0))
67 , accuracy_(cfg[
"accuracy"].to_int())
68 , movement_used_(cfg[
"movement_used"].to_int(100000))
69 , attacks_used_(cfg[
"attacks_used"].to_int(1))
70 , parry_(cfg[
"parry"].to_int())
71 , specials_(cfg.child_or_empty(
"specials"))
81 icon_ =
"attacks/blank-attack.png";
107 const std::set<std::string> filter_range =
utils::split_set(filter[
"range"].str());
108 const std::string& filter_min_range = filter[
"min_range"];
109 const std::string& filter_max_range = filter[
"max_range"];
110 const std::string& filter_damage = filter[
"damage"];
111 const std::string& filter_attacks = filter[
"number"];
112 const std::string& filter_accuracy = filter[
"accuracy"];
113 const std::string& filter_parry = filter[
"parry"];
114 const std::string& filter_movement = filter[
"movement_used"];
115 const std::string& filter_attacks_used = filter[
"attacks_used"];
116 const std::set<std::string> filter_alignment =
utils::split_set(filter[
"alignment"].str());
117 const std::set<std::string> filter_name =
utils::split_set(filter[
"name"].str());
118 const std::set<std::string> filter_type =
utils::split_set(filter[
"type"].str());
119 const std::vector<std::string> filter_special =
utils::split(filter[
"special"]);
120 const std::vector<std::string> filter_special_id =
utils::split(filter[
"special_id"]);
121 const std::vector<std::string> filter_special_type =
utils::split(filter[
"special_type"]);
122 const std::vector<std::string> filter_special_active =
utils::split(filter[
"special_active"]);
123 const std::vector<std::string> filter_special_id_active =
utils::split(filter[
"special_id_active"]);
124 const std::vector<std::string> filter_special_type_active =
utils::split(filter[
"special_type_active"]);
125 const std::string filter_formula = filter[
"formula"];
133 if ( !filter_range.empty() && filter_range.count(attack.
range()) == 0 )
154 if(!filter_alignment.empty() && filter_alignment.count(attack.
alignment_str()) == 0)
157 if ( !filter_name.empty() && filter_name.count(attack.
id()) == 0)
160 if (!filter_type.empty()){
165 if(check_if_recursion ==
"damage_type"){
166 if (filter_type.count(attack.
type()) == 0){
171 std::pair<std::string, std::string> damage_type = attack.
damage_type();
172 if (filter_type.count(damage_type.first) == 0 && filter_type.count(damage_type.second) == 0){
178 if(!filter_special.empty()) {
181 for(
auto& special : filter_special) {
191 if(!filter_special_id.empty()) {
193 for(
auto& special : filter_special_id) {
194 if(attack.
has_special(special,
true,
true,
false)) {
204 if(!filter_special_active.empty()) {
207 for(
auto& special : filter_special_active) {
217 if(!filter_special_id_active.empty()) {
219 for(
auto& special : filter_special_id_active) {
229 if(!filter_special_type.empty()) {
231 for(
auto& special : filter_special_type) {
241 if(!filter_special_type_active.empty()) {
243 for(
auto& special : filter_special_type_active) {
256 if(
auto sub_filter_special = filter.
optional_child(
"filter_special")) {
262 if (!filter_formula.empty()) {
270 lg::log_to_chat() <<
"Formula error in weapon filter: " <<
e.type <<
" at " <<
e.filename <<
':' <<
e.line <<
")\n";
271 ERR_WML <<
"Formula error in weapon filter: " <<
e.type <<
" at " <<
e.filename <<
':' <<
e.line <<
")";
294 matches = matches &&
matches_filter(condition_cfg, check_if_recursion);
297 else if ( key ==
"or" )
298 matches = matches ||
matches_filter(condition_cfg, check_if_recursion);
301 else if ( key ==
"not" )
302 matches = matches && !
matches_filter(condition_cfg, check_if_recursion);
332 const std::string&
set_name = cfg[
"set_name"];
333 const t_string& set_desc = cfg[
"set_description"];
334 const std::string&
set_type = cfg[
"set_type"];
335 const std::string&
set_range = cfg[
"set_range"];
337 const std::string&
set_icon = cfg[
"set_icon"];
338 const std::string& del_specials = cfg[
"remove_specials"];
340 const std::string& increase_min_range = cfg[
"increase_min_range"];
342 const std::string& increase_max_range = cfg[
"increase_max_range"];
345 const std::string& increase_damage = cfg[
"increase_damage"];
346 const std::string&
set_damage = cfg[
"set_damage"];
347 const std::string& increase_attacks = cfg[
"increase_attacks"];
348 const std::string& set_attacks = cfg[
"set_attacks"];
351 const std::string& increase_accuracy = cfg[
"increase_accuracy"];
353 const std::string& increase_parry = cfg[
"increase_parry"];
354 const std::string&
set_parry = cfg[
"set_parry"];
355 const std::string& increase_movement = cfg[
"increase_movement_used"];
356 const std::string& set_movement = cfg[
"set_movement_used"];
357 const std::string& increase_attacks_used = cfg[
"increase_attacks_used"];
366 if(set_desc.
empty() ==
false) {
386 if(del_specials.empty() ==
false) {
387 const std::vector<std::string>& dsl =
utils::split(del_specials);
390 std::vector<std::string>::const_iterator found_id =
391 std::find(dsl.begin(), dsl.end(), cfg[
"id"].str());
392 if (found_id == dsl.end()) {
403 "The mode defaults to 'replace', but should often be 'append' instead. The default may change in a future version, or the attribute may become mandatory.");
406 if(mode !=
"append") {
409 for(
const auto [key, cfg] :
set_specials->all_children_view()) {
418 if(increase_min_range.empty() ==
false) {
426 if(increase_max_range.empty() ==
false) {
430 if(remove_specials) {
441 if(increase_damage.empty() ==
false) {
448 if(set_attacks.empty() ==
false) {
456 if(increase_attacks.empty() ==
false) {
464 if(increase_accuracy.empty() ==
false) {
472 if(increase_parry.empty() ==
false) {
476 if(set_movement.empty() ==
false) {
480 if(increase_movement.empty() ==
false) {
488 if(increase_attacks_used.empty() ==
false) {
520 if(description !=
nullptr) {
521 const std::string& increase_min_range = cfg[
"increase_min_range"];
523 const std::string& increase_max_range = cfg[
"increase_max_range"];
525 const std::string& increase_damage = cfg[
"increase_damage"];
526 const std::string&
set_damage = cfg[
"set_damage"];
527 const std::string& increase_attacks = cfg[
"increase_attacks"];
528 const std::string& set_attacks = cfg[
"set_attacks"];
529 const std::string& increase_accuracy = cfg[
"increase_accuracy"];
531 const std::string& increase_parry = cfg[
"increase_parry"];
532 const std::string&
set_parry = cfg[
"set_parry"];
533 const std::string& increase_movement = cfg[
"increase_movement_used"];
534 const std::string& set_movement = cfg[
"set_movement_used"];
535 const std::string& increase_attacks_used = cfg[
"increase_attacks_used"];
538 std::vector<t_string> desc;
547 if(!increase_min_range.empty()) {
550 "<span color=\"$color\">$number_or_percent</span> min range",
551 {{
"number_or_percent",
utils::print_modifier(increase_min_range)}, {
"color", increase_min_range[0] ==
'-' ?
"#f00" :
"#0f0"}}));
561 if(!increase_max_range.empty()) {
564 "<span color=\"$color\">$number_or_percent</span> max range",
565 {{
"number_or_percent",
utils::print_modifier(increase_max_range)}, {
"color", increase_max_range[0] ==
'-' ?
"#f00" :
"#0f0"}}));
568 if(!increase_damage.empty()) {
571 "<span color=\"$color\">$number_or_percent</span> damage",
572 "<span color=\"$color\">$number_or_percent</span> damage",
574 {{
"number_or_percent",
utils::print_modifier(increase_damage)}, {
"color", increase_damage[0] ==
'-' ?
"#f00" :
"#0f0"}}));
586 if(!increase_attacks.empty()) {
589 "<span color=\"$color\">$number_or_percent</span> strike",
590 "<span color=\"$color\">$number_or_percent</span> strikes",
592 {{
"number_or_percent",
utils::print_modifier(increase_attacks)}, {
"color", increase_attacks[0] ==
'-' ?
"#f00" :
"#0f0"}}));
595 if(!set_attacks.empty()) {
601 {{
"number", set_attacks}}));
611 if(!increase_accuracy.empty()) {
614 "<span color=\"$color\">$number_or_percent|%</span> accuracy",
615 {{
"number_or_percent",
utils::print_modifier(increase_accuracy)}, {
"color", increase_accuracy[0] ==
'-' ?
"#f00" :
"#0f0"}}));
625 if(!increase_parry.empty()) {
628 "<span color=\"$color\">$number_or_percent</span> parry",
629 {{
"number_or_percent",
utils::print_modifier(increase_parry)}, {
"color", increase_parry[0] ==
'-' ?
"#f00" :
"#0f0"}}));
632 if(!set_movement.empty()) {
635 "$number movement point",
636 "$number movement points",
638 {{
"number", set_movement}}));
641 if(!increase_movement.empty()) {
644 "<span color=\"$color\">$number_or_percent</span> movement point",
645 "<span color=\"$color\">$number_or_percent</span> movement points",
647 {{
"number_or_percent",
utils::print_modifier(increase_movement)}, {
"color", increase_movement[0] ==
'-' ?
"#f00" :
"#0f0"}}));
653 "$number attack used",
654 "$number attacks used",
659 if(!increase_attacks_used.empty()) {
662 "<span color=\"$color\">$number_or_percent</span> attack used",
663 "<span color=\"$color\">$number_or_percent</span> attacks used",
665 {{
"number_or_percent",
utils::print_modifier(increase_attacks_used)}, {
"color", increase_attacks_used[0] ==
'-' ?
"#f00" :
"#0f0"}}));
685 : parent(weapon.shared_from_this())
687 parent->open_queries_.emplace_back(&special);
695 attack_type::recursion_guard::operator bool()
const {
704 assert(
this != &other);
715 assert(!parent->open_queries_.empty());
716 parent->open_queries_.pop_back();
static lg::log_domain log_unit("unit")
static lg::log_domain log_wml("wml")
static bool matches_simple_filter(const attack_type &attack, const config &filter, const std::string &check_if_recursion)
Returns whether or not *this matches the given filter, ignoring the complexities introduced by [and],...
static lg::log_domain log_config("config")
Helper similar to std::unique_lock for detecting when calculations such as has_special have entered i...
recursion_guard & operator=(recursion_guard &&)
std::shared_ptr< const attack_type > parent
recursion_guard()
Construct an empty instance, only useful for extending the lifetime of a recursion_guard returned fro...
std::string alignment_str() const
Returns alignment specified by alignment() for filtering when exist.
void set_min_range(int value)
bool has_special(const std::string &special, bool simple_check=false, bool special_id=true, bool special_tags=true) const
Returns whether or not *this has a special with a tag or id equal to special.
const std::string & range() const
void set_attacks_used(int value)
int movement_used() const
bool has_special_or_ability_with_filter(const config &filter) const
void set_accuracy(int value)
const std::string & type() const
std::string accuracy_parry_description() const
bool apply_modification(const config &cfg)
Modifies *this using the specifications in cfg, but only if *this matches cfg viewed as a filter.
bool matches_filter(const config &filter, const std::string &check_if_recursion="") const
Returns whether or not *this matches the given filter.
void set_specials(config value)
void set_defense_weight(double value)
void set_changed(bool value)
recursion_guard update_variables_recursion(const config &special) const
Tests which might otherwise cause infinite recursion should call this, check that the returned object...
void set_parry(int value)
void set_attack_weight(double value)
void set_damage(int value)
bool describe_modification(const config &cfg, std::string *description)
Trimmed down version of apply_modification(), with no modifications actually made.
const std::string & id() const
void set_icon(const std::string &value)
std::vector< const config * > open_queries_
While processing a recursive match, all the filters that are currently being checked,...
bool special_matches_filter(const config &cfg, const std::string &tag_name, const config &filter) const
Filter a list of abilities or weapon specials.
void remove_special_by_filter(const config &filter)
remove special if matche condition
void set_max_range(int value)
utils::optional< unit_alignments::type > alignment_
attack_type(const config &cfg)
void set_type(const std::string &value)
void write(config &cfg) const
void set_range(const std::string &value)
void set_attack_alignment(const std::string &value)
bool has_special_or_ability(const std::string &special, bool special_id=true, bool special_tags=true) const
used for abilities used like weapon and true specials
void set_name(const t_string &value)
std::pair< std::string, std::string > damage_type() const
return a modified damage type and/or add a secondary_type for hybrid use if special is active.
A config object defines a single node in a WML file, with access to child nodes.
all_children_iterator erase(const all_children_iterator &i)
const_all_children_iterator ordered_begin() const
auto all_children_view() const
In-order iteration over all children.
const_all_children_iterator ordered_end() const
optional_config_impl< config > optional_child(config_key_type key, int n=0)
Equivalent to mandatory_child, but returns an empty optional if the nth child was not found.
config & add_child(config_key_type key)
bool as_bool() const
Returns a boolean state of the variant value.
void swap(config &lhs, config &rhs)
Implement non-member swap function for std::swap (calls config::swap).
std::string deprecated_message(const std::string &elem_name, DEP_LEVEL level, const version_info &version, const std::string &detail)
Interfaces for manipulating version numbers of engine, add-ons, etc.
New lexcical_cast header.
Standard logging facilities (interface).
General math utility functions.
bool in_ranges(const Cmp c, const std::vector< std::pair< Cmp, Cmp >> &ranges)
std::stringstream & log_to_chat()
Use this to show WML errors in the ingame chat.
std::string egettext(char const *msgid)
std::set< std::string > split_set(std::string_view s, char sep, const int flags)
int stoi(std::string_view str)
Same interface as std::stoi and meant as a drop in replacement, except:
std::vector< std::pair< int, int > > parse_ranges_int(const std::string &str)
Handles a comma-separated list of inputs to parse_range.
bool contains(const Container &container, const Value &value)
Returns true iff value is found in container.
std::vector< std::pair< int, int > > parse_ranges_unsigned(const std::string &str)
Handles a comma-separated list of inputs to parse_range, in a context that does not expect negative v...
int apply_modifier(const int number, const std::string &amount, const int minimum)
std::string format_conjunct_list(const t_string &empty, const std::vector< t_string > &elems)
Format a conjunctive list.
std::string signed_percent(int val)
Convert into a percentage (using the Unicode "−" and +0% convention.
std::vector< std::string > split(const config_attribute_value &val)
auto * find(Container &container, const Value &value)
Convenience wrapper for using find on a container without needing to comare to end()
std::string print_modifier(const std::string &mod)
Add a "+" or replace the "-" par Unicode minus.
The base template for associating string values with enum values.
static constexpr utils::optional< enum_type > get_enum(const std::string_view value)
Converts a string into its enum equivalent.
static map_location::direction s