22 #include "formula/callable_objects.hpp"
37 #define ERR_CF LOG_STREAM(err, log_config)
38 #define WRN_CF LOG_STREAM(warn, log_config)
39 #define LOG_CONFIG LOG_STREAM(info, log_config)
40 #define DBG_CF LOG_STREAM(debug, log_config)
43 #define DBG_UT LOG_STREAM(debug, log_unit)
44 #define ERR_UT LOG_STREAM(err, log_unit)
47 #define ERR_WML LOG_STREAM(err, log_wml)
53 other_attack_(nullptr),
54 description_(cfg[
"description"].t_str()),
59 min_range_(cfg[
"min_range"].to_int(1)),
60 max_range_(cfg[
"max_range"].to_int(1)),
61 damage_(cfg[
"damage"]),
62 num_attacks_(cfg[
"number"]),
63 attack_weight_(cfg[
"attack_weight"].to_double(1.0)),
64 defense_weight_(cfg[
"defense_weight"].to_double(1.0)),
65 accuracy_(cfg[
"accuracy"]),
66 movement_used_(cfg[
"movement_used"].to_int(100000)),
67 attacks_used_(cfg[
"attacks_used"].to_int(1)),
69 specials_(cfg.child_or_empty(
"specials")),
79 icon_ =
"attacks/blank-attack.png";
105 const std::set<std::string> filter_range =
utils::split_set(filter[
"range"].str());
106 const std::string& filter_damage = filter[
"damage"];
107 const std::string& filter_attacks = filter[
"number"];
108 const std::string& filter_accuracy = filter[
"accuracy"];
109 const std::string& filter_parry = filter[
"parry"];
110 const std::string& filter_movement = filter[
"movement_used"];
111 const std::string& filter_attacks_used = filter[
"attacks_used"];
112 const std::set<std::string> filter_name =
utils::split_set(filter[
"name"].str());
113 const std::set<std::string> filter_type =
utils::split_set(filter[
"type"].str());
114 const std::vector<std::string> filter_special =
utils::split(filter[
"special"]);
115 const std::vector<std::string> filter_special_id =
utils::split(filter[
"special_id"]);
116 const std::vector<std::string> filter_special_type =
utils::split(filter[
"special_type"]);
117 const std::vector<std::string> filter_special_active =
utils::split(filter[
"special_active"]);
118 const std::vector<std::string> filter_special_id_active =
utils::split(filter[
"special_id_active"]);
119 const std::vector<std::string> filter_special_type_active =
utils::split(filter[
"special_type_active"]);
120 const std::string filter_formula = filter[
"formula"];
122 if ( !filter_range.empty() && filter_range.count(attack.
range()) == 0 )
143 if ( !filter_name.empty() && filter_name.count(attack.
id()) == 0)
146 if (!filter_type.empty()){
148 if(tag_name ==
"damage_type"){
149 if (filter_type.count(attack.
type()) == 0){
154 std::pair<std::string, std::string> damage_type = attack.
damage_type();
155 if (filter_type.count(damage_type.first) == 0 && filter_type.count(damage_type.second) == 0){
161 if(!filter_special.empty()) {
164 for(
auto& special : filter_special) {
174 if(!filter_special_id.empty()) {
176 for(
auto& special : filter_special_id) {
177 if(attack.
has_special(special,
true,
true,
false)) {
187 if(!filter_special_active.empty()) {
190 for(
auto& special : filter_special_active) {
200 if(!filter_special_id_active.empty()) {
202 for(
auto& special : filter_special_id_active) {
212 if(!filter_special_type.empty()) {
214 for(
auto& special : filter_special_type) {
224 if(!filter_special_type_active.empty()) {
226 for(
auto& special : filter_special_type_active) {
237 if (!filter_formula.empty()) {
245 lg::log_to_chat() <<
"Formula error in weapon filter: " <<
e.type <<
" at " <<
e.filename <<
':' <<
e.line <<
")\n";
246 ERR_WML <<
"Formula error in weapon filter: " <<
e.type <<
" at " <<
e.filename <<
':' <<
e.line <<
")";
268 if ( condition.key ==
"and" )
272 else if ( condition.key ==
"or" )
276 else if ( condition.key ==
"not" )
295 const std::string&
set_name = cfg[
"set_name"];
296 const t_string& set_desc = cfg[
"set_description"];
297 const std::string&
set_type = cfg[
"set_type"];
298 const std::string&
set_range = cfg[
"set_range"];
299 const std::string&
set_icon = cfg[
"set_icon"];
300 const std::string& del_specials = cfg[
"remove_specials"];
302 const std::string& increase_damage = cfg[
"increase_damage"];
303 const std::string&
set_damage = cfg[
"set_damage"];
304 const std::string& increase_attacks = cfg[
"increase_attacks"];
305 const std::string& set_attacks = cfg[
"set_attacks"];
308 const std::string& increase_accuracy = cfg[
"increase_accuracy"];
310 const std::string& increase_parry = cfg[
"increase_parry"];
311 const std::string&
set_parry = cfg[
"set_parry"];
312 const std::string& increase_movement = cfg[
"increase_movement_used"];
313 const std::string& set_movement = cfg[
"set_movement_used"];
314 const std::string& increase_attacks_used = cfg[
"increase_attacks_used"];
323 if(set_desc.
empty() ==
false) {
339 if(del_specials.empty() ==
false) {
340 const std::vector<std::string>& dsl =
utils::split(del_specials);
343 std::vector<std::string>::const_iterator found_id =
344 std::find(dsl.begin(), dsl.end(), vp.cfg[
"id"].str());
345 if (found_id == dsl.end()) {
356 "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.");
359 if(mode !=
"append") {
374 if(increase_damage.empty() ==
false) {
381 if(set_attacks.empty() ==
false) {
389 if(increase_attacks.empty() ==
false) {
397 if(increase_accuracy.empty() ==
false) {
405 if(increase_parry.empty() ==
false) {
409 if(set_movement.empty() ==
false) {
413 if(increase_movement.empty() ==
false) {
421 if(increase_attacks_used.empty() ==
false) {
453 if(description !=
nullptr) {
454 const std::string& increase_damage = cfg[
"increase_damage"];
455 const std::string&
set_damage = cfg[
"set_damage"];
456 const std::string& increase_attacks = cfg[
"increase_attacks"];
457 const std::string& set_attacks = cfg[
"set_attacks"];
458 const std::string& increase_accuracy = cfg[
"increase_accuracy"];
460 const std::string& increase_parry = cfg[
"increase_parry"];
461 const std::string&
set_parry = cfg[
"set_parry"];
462 const std::string& increase_movement = cfg[
"increase_movement_used"];
463 const std::string& set_movement = cfg[
"set_movement_used"];
464 const std::string& increase_attacks_used = cfg[
"increase_attacks_used"];
467 std::vector<t_string> desc;
469 if(!increase_damage.empty()) {
472 "<span color=\"$color\">$number_or_percent</span> damage",
473 "<span color=\"$color\">$number_or_percent</span> damage",
474 std::stoi(increase_damage),
475 {{
"number_or_percent",
utils::print_modifier(increase_damage)}, {
"color", increase_damage[0] ==
'-' ?
"#f00" :
"#0f0"}}));
487 if(!increase_attacks.empty()) {
490 "<span color=\"$color\">$number_or_percent</span> strike",
491 "<span color=\"$color\">$number_or_percent</span> strikes",
492 std::stoi(increase_attacks),
493 {{
"number_or_percent",
utils::print_modifier(increase_attacks)}, {
"color", increase_attacks[0] ==
'-' ?
"#f00" :
"#0f0"}}));
496 if(!set_attacks.empty()) {
501 std::stoi(set_attacks),
502 {{
"number", set_attacks}}));
512 if(!increase_accuracy.empty()) {
515 "<span color=\"$color\">$number_or_percent|%</span> accuracy",
516 {{
"number_or_percent",
utils::print_modifier(increase_accuracy)}, {
"color", increase_accuracy[0] ==
'-' ?
"#f00" :
"#0f0"}}));
526 if(!increase_parry.empty()) {
529 "<span color=\"$color\">$number_or_percent</span> parry",
530 {{
"number_or_percent",
utils::print_modifier(increase_parry)}, {
"color", increase_parry[0] ==
'-' ?
"#f00" :
"#0f0"}}));
533 if(!set_movement.empty()) {
536 "$number movement point",
537 "$number movement points",
538 std::stoi(set_movement),
539 {{
"number", set_movement}}));
542 if(!increase_movement.empty()) {
545 "<span color=\"$color\">$number_or_percent</span> movement point",
546 "<span color=\"$color\">$number_or_percent</span> movement points",
547 std::stoi(increase_movement),
548 {{
"number_or_percent",
utils::print_modifier(increase_movement)}, {
"color", increase_movement[0] ==
'-' ?
"#f00" :
"#0f0"}}));
554 "$number attack used",
555 "$number attacks used",
560 if(!increase_attacks_used.empty()) {
563 "<span color=\"$color\">$number_or_percent</span> attack used",
564 "<span color=\"$color\">$number_or_percent</span> attacks used",
565 std::stoi(increase_attacks_used),
566 {{
"number_or_percent",
utils::print_modifier(increase_attacks_used)}, {
"color", increase_attacks_used[0] ==
'-' ?
"#f00" :
"#0f0"}}));
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 &tag_name)
Returns whether or not *this matches the given filter, ignoring the complexities introduced by [and],...
static lg::log_domain log_config("config")
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
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.
void set_specials(config value)
void set_defense_weight(double value)
void set_changed(bool value)
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)
attack_type(const config &cfg)
void set_type(const std::string &value)
void write(config &cfg) const
bool matches_filter(const config &filter, const std::string &tag_name="") const
Returns whether or not *this matches the given filter.
void set_range(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.
const_all_children_itors all_children_range() const
In-order iteration over all children.
optional_config_impl< config > optional_child(config_key_type key, int n=0)
Euivalent 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.
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)
std::vector< std::pair< int, int > > parse_ranges_int(const std::string &str)
Handles a comma-separated list of inputs to parse_range.
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)
std::string print_modifier(const std::string &mod)
Add a "+" or replace the "-" par Unicode minus.
static map_location::DIRECTION s