55 #define ERR_NG LOG_STREAM(err, log_engine)
58 #define ERR_WML LOG_STREAM(err, log_wml)
59 #define DEBUG_WML LOG_STREAM(debug, log_wml)
63 using namespace std::string_literals;
64 const std::array numeric_keys{
65 "value"s,
"add"s,
"sub"s,
"multiply"s,
"divide"s,
"max_value"s,
"min_value"s
127 : tag_(std::move(
tag))
128 , id_(
cfg[
"id"].str())
129 , in_specials_tag_(inside_attack)
133 , affects_self_(true)
134 , affects_enemies_(false)
135 , priority_(
cfg[
"priority"].to_double(0.00))
136 , suppress_special_priority_(-100000.00)
137 , suppress_ability_priority_(-100000.00)
138 , cfg_(std::move(
cfg))
139 , currently_checked_(false)
143 if (
tag_ !=
"resistance" &&
tag_ !=
"leadership") {
153 if (
tag_ !=
"leadership") {
163 if (
cfg_[
"affect_allies"].to_bool(
false)) {
166 if (!
cfg_[
"affect_allies"].to_bool(
true)) {
175 else if(
cfg_[
"overwrite_specials"] ==
"one_side" ||
cfg_[
"overwrite_specials"] ==
"both_sides") {
197 auto note_bugfix = [](
const std::string& message) {
200 lg::log_to_chat() << message <<
" (“" <<
_(
"Show deprecation messages in-game") <<
"” is on)\n";
206 deprecated_message(
"backstab= in weapon specials",
DEP_LEVEL::INDEFINITE,
"",
"Use [filter_opponent] with a formula instead; the code can be found in data/core/macros/ in the WEAPON_SPECIAL_BACKSTAB macro.");
208 if (
cfg[
"backstab"].to_bool()) {
209 const std::string& backstab_formula =
"enemy_of(self, flanker) and not flanker.petrified where flanker = unit_at(direction_from(loc, other.facing))";
211 config& filter_opponent2 = filter_opponent.
empty() ? filter_opponent : filter_opponent.
add_child(
"and");
212 filter_opponent2[
"formula"] = backstab_formula;
217 std::string filter_teacher = inside_attack ?
"filter_self" :
"filter";
241 const auto has_dirs = filter_adjacent.has_attribute(
"adjacent");
242 const auto has_count = filter_adjacent.has_attribute(
"count");
244 std::ostringstream ss;
245 ss <<
"Filter [" <<
tag <<
"][filter_adjacent] changed behavior in 1.19.26. Previously this would never match because adjacent= is omitted.";
246 note_bugfix(ss.str());
255 std::ostringstream ss;
256 ss <<
"Filter [" <<
tag <<
"][filter_adjacent] changed behavior in 1.19.26. Previously this would never match because count= is omitted.";
257 note_bugfix(ss.str());
262 std::ostringstream ss;
263 ss <<
"Filter [" <<
tag <<
"][filter_adjacent] changed behavior in 1.19.26. In 1.18 this combination of adjacent= and count= would never match.";
264 note_bugfix(ss.str());
276 const auto has_dirs = filter_adjacent.has_attribute(
"adjacent");
277 const auto has_count = filter_adjacent.has_attribute(
"count");
279 std::ostringstream ss;
280 ss <<
"Filter [" <<
tag <<
"][filter_adjacent_location] changed behavior in 1.19.26. Previously this would never match because adjacent= is omitted.";
281 note_bugfix(ss.str());
284 std::ostringstream ss;
285 ss <<
"Filter [" <<
tag <<
"][filter_adjacent_location] changed behavior in 1.19.26. Previously this would never match because count= is omitted.";
286 note_bugfix(ss.str());
290 std::ostringstream ss;
291 ss <<
"Filter [" <<
tag <<
"][filter_adjacent_location] changed behavior in 1.19.26. In 1.18 this combination of adjacent= and count= would never match.";
292 note_bugfix(ss.str());
298 if (
tag ==
"resistance" ||
tag ==
"leadership") {
309 if (
tag ==
"drains" &&
cfg[
"value"].empty()) {
322 return cfg[
"unique_id"].str(
cfg[
"id"].str());
349 if (p_ab->tag() ==
tag) {
360 res.push_back(std::make_shared<unit_ability_t>(*p_ab));
368 for (
const auto& item : abilities) {
369 item->write(abilities_cfg);
371 return abilities_cfg;
386 if(
tag() ==
"plague") {
396 symbols.emplace(
"type",
type.type_name());
401 for(
const auto& vkey : numeric_keys) {
402 if(
cfg().has_attribute(vkey)) {
403 if(vkey ==
"multiply" || vkey ==
"divide") {
405 std::stringstream formatter_str;
407 formatter_str.imbue(std::locale{lang_locale});
408 }
catch(
const std::runtime_error&) {}
409 formatter_str <<
cfg()[vkey].to_double();
410 symbols.emplace(vkey, formatter_str.str());
422 const config_attribute_value& get_attr_four_fallback(
const config&
cfg,
bool b1,
bool b2, std::string_view s_yes_yes, std::string_view s_yes_no, std::string_view s_no_yes, std::string_view s_no_no)
425 if (
auto* attr =
cfg.
get(s_yes_yes)) {
return *attr; }
428 if (
auto* attr =
cfg.
get(s_yes_no)) {
return *attr; }
431 if (
auto* attr =
cfg.
get(s_no_yes)) {
return *attr; }
440 std::string res = get_attr_four_fallback(
cfg_, is_inactive, is_female,
"female_name_inactive",
"name_inactive",
"female_name",
"name").str();
447 std::string res = get_attr_four_fallback(
cfg_, is_inactive, is_female,
"female_description_inactive",
"description_inactive",
"female_description",
"description").str();
469 if (!
p.currently_checked_) {
470 p.currently_checked_ =
true;
478 parent->currently_checked_ =
false;
482 unit_ability_t::recursion_guard::operator bool()
const {
489 static std::vector<std::tuple<std::string, std::string>> already_shown;
491 auto identifier = std::tuple<std::string, std::string>{ u.
id(),
cfg().
debug()};
494 std::string_view filter_text_view = std::get<1>(identifier);
496 ERR_NG <<
"Looped recursion error for unit '" << u.
id()
497 <<
"' while checking ability '" << filter_text_view <<
"'";
501 if (already_shown.size() > 100) {
502 already_shown.clear();
504 already_shown.push_back(std::move(identifier));
527 const team& get_team(std::size_t side)
547 bool affects_side(
const unit_ability_t& ab, std::size_t side, std::size_t other_side)
549 const team& side_team = get_team(side);
551 if(side == other_side)
566 for(std::size_t j = 0; j < adjacent.size(); ++j) {
567 bool adj_or_dist = distance != 1 ?
distance_between(adjacent[j],
loc) == (distance - 1) : adjacent[j] ==
loc;
577 template<
typename TFunc,
typename... TArgs>
578 bool default_false(
const TFunc&
f,
const TArgs&... args) {
579 if constexpr (std::is_same_v<decltype(
f(args...)),
void>) {
590 const std::string&
tag;
592 bool operator()(
const ability_ptr& p_ab)
const {
return p_ab->tag() ==
tag; }
596 template <
typename T>
597 auto radius_helper(
const unit&u, T
const& check,
int) -> decltype(check.get_unit_radius(u))
599 return check.get_unit_radius(u);
602 template <
typename T>
603 size_t radius_helper(
const unit& u, T
const&,
long)
609 template<
typename TCheck,
typename THandler>
610 bool foreach_distant_active_ability(
const unit& un,
const map_location&
loc, TCheck&& quick_check, THandler&& handler)
614 const unit_map& units = get_unit_map();
620 for (
const unit& u : units) {
624 size_t u_ability_radius = radius_helper(u, quick_check, 0);
625 if (!u_ability_radius) {
630 if (distance > u_ability_radius) {
633 int dir = find_direction(
loc, from_loc, distance);
635 if (!quick_check(p_ab)) {
639 if (default_false(handler, p_ab, u)) {
648 template<
typename TCheck,
typename THandler>
649 bool foreach_self_active_ability(
const unit& un,
map_location loc,
const TCheck& quick_check,
const THandler& handler)
651 for (
const auto& p_ab : un.
abilities()) {
652 if (!quick_check(p_ab)) {
656 if (default_false(handler, p_ab, un)) {
677 template<
typename TCheck,
typename THandler>
678 bool foreach_active_ability(
const unit& un,
map_location loc,
const TCheck& quick_check,
const THandler& handler,
bool skip_adjacent =
false)
682 if (foreach_self_active_ability(un,
loc, quick_check, handler)) {
685 if (!skip_adjacent && foreach_distant_active_ability(un,
loc, quick_check, handler)) {
691 auto return_true = [](
const auto&...) {
return true; };
709 template<
typename TCheck,
typename THandler>
710 bool foreach_active_special(
713 const TCheck& quick_check,
714 const THandler& handler,
715 bool skip_adjacent =
false)
717 auto& other = context.
other(
self);
719 auto handler_self = [&](
const ability_ptr& p_ab,
const auto& source) {
722 auto handler_other = [&](
const ability_ptr& p_ab,
const auto& source) {
729 if (quick_check(p_ab) && handler_self(p_ab, *
self.
at)) {
736 for (
const ability_ptr& p_ab : other.at->specials()) {
737 if (quick_check(p_ab) && handler_other(p_ab, *other.at)) {
744 if (foreach_active_ability(*
self.un,
self.
loc, quick_check, handler_self, skip_adjacent)) {
750 if (foreach_active_ability(*other.un, other.loc, quick_check, handler_other, skip_adjacent)) {
762 return foreach_active_ability(*
this,
loc, tag_check{ tag_name },
771 foreach_active_ability(*
this,
loc, tag_check{ tag_name },
781 std::vector<std::string> res;
783 for(
const auto& p_ab : this->abilities()) {
784 std::string
id = p_ab->id();
786 res.push_back(std::move(
id));
801 auto name = ab.
get_name(!active, gender);
808 res.AGGREGATE_EMPLACE(
819 std::vector<unit_ability_t::tooltip_info> res;
821 for(
const auto& p_ab : abilities())
823 add_ability_tooltip(*p_ab, gender_, res,
true);
831 std::vector<unit_ability_t::tooltip_info> res;
834 for(
const auto& p_ab : abilities())
836 bool active = ability_active(*p_ab,
loc);
837 if(add_ability_tooltip(*p_ab, gender_, res, active))
839 active_list.push_back(active);
852 return ability_active_impl(ab,
loc);
857 bool illuminates = ab.
tag() ==
"illuminates";
873 bool illuminates = ab.
tag() ==
"illuminates";
875 assert(dir >=0 && dir <= 5);
880 if(
i[
"radius"] !=
"all_map") {
881 int radius =
i[
"radius"].to_int(1);
885 if(dist >
size_t(radius)) {
889 if (
i.has_attribute(
"adjacent")) {
894 auto filter =
i.optional_child(
"filter");
907 if (!
filter || !affect_self)
return affect_self;
913 return !abilities(ability).empty();
919 std::string attr_image = image_type +
"_image";
923 bool operator()(
const ability_ptr& p_ab)
const {
return !p_ab->cfg()[attr_image_].empty(); }
925 std::string& attr_image_;
926 } quick_check { attr_image };
930 std::set<std::string> image_list;
931 for(
const auto& p_ab : abilities()){
932 bool is_active = ability_active(*p_ab, loc_);
934 if( !p_ab->cfg()[attr_image].str().empty() &&
is_active && ability_affects_self(*p_ab, loc_)){
935 image_list.insert(p_ab->cfg()[attr_image].str());
938 if(!p_ab->cfg()[image_type +
"_image_self"].str().empty() &&
is_active){
939 image_list.insert(p_ab->cfg()[image_type +
"_image_self"].str());
943 foreach_distant_active_ability(*
this, loc_, quick_check,
945 image_list.insert(p_ab->cfg()[attr_image].str());
948 return std::vector(image_list.begin(), image_list.end());
955 context_->add_formula_context(callable);
962 callable.
add(
"attacker", wfl::make_callable<wfl::unit_callable>(*att));
965 callable.
add(
"defender", wfl::make_callable<wfl::unit_callable>(*def));
972 template<
typename T,
typename TFuncFormula>
973 class get_ability_value_visitor
974 #ifdef USING_BOOST_VARIANT
975 :
public boost::static_visitor<T>
980 get_ability_value_visitor(T def,
const TFuncFormula& formula_handler) : def_(def), formula_handler_(formula_handler) {}
982 T operator()(
const utils::monostate&)
const {
return def_; }
983 T operator()(
bool)
const {
return def_; }
984 T operator()(
int i)
const {
return static_cast<T
>(
i); }
985 T operator()(
unsigned long long u)
const {
return static_cast<T
>(u); }
986 T operator()(
double d)
const {
return static_cast<T
>(
d); }
987 T operator()(
const t_string&)
const {
return def_; }
988 T operator()(
const std::string&
s)
const
990 if(
s.size() >= 2 &&
s[0] ==
'(') {
991 return formula_handler_(
s);
993 return lexical_cast_default<T>(
s, def_);
998 const TFuncFormula& formula_handler_;
1001 template<
typename T,
typename TFuncFormula>
1004 return v.
apply_visitor(get_ability_value_visitor(def, [&](
const std::string&
s) {
1007 const unit_map& units = get_unit_map();
1011 if(u_itor == units.
end()) {
1019 callable.add(
"student", wfl::make_callable<wfl::unit_callable>(*uptr));
1022 callable.add(
"other", wfl::make_callable<wfl::unit_callable>(*uptr));
1026 lg::log_to_chat() <<
"Formula error in ability or weapon special: " <<
e.type <<
" at " <<
e.filename <<
':' <<
e.line <<
")\n";
1027 ERR_WML <<
"Formula error in ability or weapon special: " <<
e.type <<
" at " <<
e.filename <<
':' <<
e.line <<
")";
1034 template<
typename TComp>
1037 if ( cfgs_.empty() ) {
1043 bool only_cumulative =
true;
1053 if (
p.ability_cfg()[
"cumulative"].to_bool()) {
1056 if (only_cumulative && !comp(
value, abs_max)) {
1058 best_loc =
p.teacher_loc;
1060 }
else if (only_cumulative || comp(flat,
value)) {
1061 only_cumulative =
false;
1063 best_loc =
p.teacher_loc;
1066 return std::pair(flat + stack, best_loc);
1069 template std::pair<int, map_location> active_ability_list::get_extremum<std::less<int>>(
const std::string& key,
int def,
const std::less<int>& comp)
const;
1070 template std::pair<int, map_location> active_ability_list::get_extremum<std::greater<int>>(
const std::string& key,
int def,
const std::greater<int>& comp)
const;
1101 : attacker(std::move(att))
1102 , defender(std::move(def))
1103 , is_for_listing(false)
1124 static bool is_enemy(std::size_t side, std::size_t other_side)
1126 const team& side_team = get_team(side);
1127 return side_team.
is_enemy(other_side);
1140 const auto& [
self,
other] = s_a_o;
1142 std::vector<std::string> special_names;
1143 std::set<std::string> ability_names;
1145 for(
const auto& p_ab :
at.specials()) {
1147 std::string name = p_ab->get_name(!active);
1156 const std::set<std::string>& checking_tags = abilities_list::all_weapon_tags();
1158 return checking_tags.count(p_ab->tag()) != 0;
1161 foreach_active_ability(*
self.un,
self.
loc, quick_check,
1169 const std::string& name_affected = p_ab->cfg().get_or(
"name_affected",
"name").str();
1170 ability_names.insert(p_ab->substitute_variables(name_affected));
1174 if(!ability_names.empty()) {
1175 special_names.push_back(
"\n" +
utils::join(ability_names,
", "));
1184 const auto& [
self,
other] = s_a_o;
1188 std::set<std::string> wespon_specials;
1189 std::set<std::string> abilities_self;
1190 std::set<std::string> abilities_allies;
1191 std::set<std::string> abilities_enemies;
1192 std::set<std::string> opponents_abilities;
1195 return checking_tags.count(p_ab->tag()) != 0;
1199 if (&student == &s_a_o.other) {
1200 opponents_abilities.insert(p_ab->substitute_variables(p_ab->cfg()[
"name"].str()));
1202 wespon_specials.insert(p_ab->substitute_variables(p_ab->cfg()[
"name"].str()));
1203 }
else if (&source == s_a_o.self.un.get()) {
1204 const std::string& name_affected = p_ab->cfg().get_or(
"name_affected",
"name").str();
1205 abilities_self.insert(p_ab->substitute_variables(name_affected));
1206 }
else if (!
is_enemy(source.side(), s_a_o.self.un->side())) {
1207 const std::string& name_affected = p_ab->cfg().get_or(
"name_affected",
"name").str();
1208 abilities_allies.insert(p_ab->substitute_variables(name_affected));
1210 const std::string& name_affected = p_ab->cfg().get_or(
"name_affected",
"name").str();
1211 abilities_enemies.insert(p_ab->substitute_variables(name_affected));
1215 auto add_to_res = [&](std::set<std::string>& to_add,
const std::string& category_name) {
1217 if (!to_add.empty()) {
1219 res += (res.empty() ?
"\n" :
"") + category_name +
utils::join(to_add,
", ");
1224 foreach_active_special(*
this,
self, quick_check, add_to_list);
1226 add_to_res(wespon_specials,
"");
1227 add_to_res(abilities_self,
_(
"Owned: "));
1229 add_to_res(abilities_allies,
_(
"Taught: "));
1231 add_to_res(abilities_enemies,
_(
"Taught: (by an enemy): "));
1232 add_to_res(opponents_abilities,
_(
"Used by opponent: "));
1246 bool special_affects_opponent(
const unit_ability_t& ab,
bool is_attacker)
1249 const auto apply_to = ab.
apply_to();
1250 if ( apply_to == apply_to_t::both)
1252 if ( apply_to == apply_to_t::opponent )
1254 if ( is_attacker && apply_to == apply_to_t::defender)
1256 if ( !is_attacker && apply_to == apply_to_t::attacker)
1266 bool special_affects_self(
const unit_ability_t& ab,
bool is_attacker)
1269 const auto apply_to = ab.
apply_to();
1270 if ( apply_to == apply_to_t::both )
1272 if ( apply_to == apply_to_t::self)
1274 if ( is_attacker && apply_to == apply_to_t::attacker)
1276 if ( !is_attacker && apply_to == apply_to_t::defender)
1283 if (ab.
tag() ==
"drains" && them && them->get_state(
"undrainable")) {
1286 if (ab.
tag() ==
"plague" && them &&
1287 (them->get_state(
"unplagueable") ||
1291 if (ab.
tag() ==
"poison" && them &&
1295 if (ab.
tag() ==
"slow" && them &&
1299 if (ab.
tag() ==
"petrifies" && them &&
1300 them->get_state(
"unpetrifiable")) {
1322 const bool for_listing,
1323 const std::string & child_tag,
bool applies_to_checked)
1337 if ( !filter_child )
1356 if (
auto filter_weapon = filter_child->optional_child(
"filter_weapon") ) {
1357 std::string check_if_recursion = applies_to_checked ? ab.
tag() :
"";
1358 if ( !weapon || !weapon->matches_filter(*filter_weapon, check_if_recursion) )
1365 return ufilt.matches(*u,
loc);
1367 return ufilt.matches(*u,
loc, *u2);
1383 boost::dynamic_bitset<>& active_list)
const
1388 std::vector<unit_ability_t::tooltip_info> res;
1389 active_list.clear();
1391 for (
const auto& p_ab :
self.
at->specials()) {
1393 auto name = p_ab->get_name(!active);
1394 auto desc = p_ab->get_description(!active);
1400 res.AGGREGATE_EMPLACE(
1403 p_ab->get_help_topic_id()
1406 active_list.push_back(active);
1421 auto& other = context.
other(
self);
1422 bool is_attacker = &
self == &context.
attacker;
1431 bool whom_is_self = special_affects_self(ab, is_attacker);
1440 if (!special_unit_matches(
self.un, other.un,
self.loc,
self.at, ab, is_for_listing,
"filter_student", applied_both || whom_is_self))
1442 bool applied_to_attacker = applied_both || (whom_is_self && is_attacker);
1443 if (is_attacker && !special_unit_matches(
self.un, other.un,
self.loc,
self.at, ab, is_for_listing,
"filter_attacker", applied_to_attacker))
1445 bool applied_to_defender = applied_both || (whom_is_self && !is_attacker);
1446 if (!is_attacker && !special_unit_matches(
self.un, other.un,
self.loc,
self.at, ab, is_for_listing,
"filter_defender", applied_to_defender))
1456 boost::dynamic_bitset<>& active_list)
const
1459 const auto& [
self,
other] = s_a_o;
1461 std::vector<unit_ability_t::tooltip_info> res;
1462 active_list.clear();
1463 std::set<std::string> checking_name;
1467 foreach_active_ability(*
self.un,
self.
loc,
1472 if (special_tooltip_active(*
this, s_a_o.self, *p_ab)) {
1474 const std::string name = p_ab->substitute_variables(p_ab->cfg()[
"name_affected"]);
1475 const std::string desc = p_ab->substitute_variables(p_ab->cfg()[
"description_affected"]);
1477 if (name.empty() || checking_name.count(name) != 0) {
1480 res.AGGREGATE_EMPLACE(name, desc, p_ab->get_help_topic_id());
1481 checking_name.insert(name);
1482 active_list.push_back(active);
1497 const std::string& apply_to = ab.
cfg()[
"overwrite_specials"];
1498 return (apply_to ==
"one_side" || apply_to ==
"both_sides");
1507 if(overwriters.
empty()) {
1512 for(
const auto& j : overwriters) {
1518 auto overwrite_specials = j.ability_cfg().optional_child(
"overwrite_specials");
1519 if(overwrite_specials) {
1522 if((*overwrite_specials)[
"affect"].str(
"both") ==
"self" &&
loc !=
self.
loc) {
1525 if(other.un && (*overwrite_specials)[
"affect"].str(
"both") ==
"opponent" &&
loc != other.loc) {
1529 auto filter_abilities_specials = (*overwrite_specials).optional_child(
"filter_special");
1530 if(filter_abilities_specials && !ab.
matches_filter(*filter_abilities_specials)) {
1537 if(!overwrite_special_affects(j.ability())) {
1545 if(j.ability_cfg()[
"overwrite_specials"].str() ==
"one_side") {
1546 if(j.student_loc ==
self.loc &&
loc !=
self.loc) {
1549 if(other.un && j.student_loc == other.loc &&
loc != other.loc) {
1554 auto overwrite_filter = j.ability_cfg().optional_child(
"overwrite");
1555 if(overwrite_filter) {
1556 auto filter_abilities_specials = (*overwrite_filter).optional_child(
"filter_specials");
1557 if(!filter_abilities_specials) {
1558 filter_abilities_specials = (*overwrite_filter).optional_child(
"experimental_filter_specials");
1559 if(filter_abilities_specials) {
1563 if(filter_abilities_specials && !ab.
matches_filter(*filter_abilities_specials)) {
1600 return p_ab->tag() == tag_name;
1604 return foreach_active_special(*
this,
self, quick_check, return_true);
1612 if (
at.range().empty()) {
1618 return p_ab->id() == special_id;
1622 return foreach_active_special(*
this,
self, quick_check, return_true);
1628 const auto& [
self,
other] = s_a_o;
1630 const map_location loc =
self.un ?
self.un->get_location() :
self.loc;
1632 const std::set<std::string>& checking_tags = abilities_list::all_weapon_tags();
1634 return checking_tags.count(p_ab->tag()) != 0;
1638 foreach_distant_active_ability(*
self.un,
self.
loc, quick_check,
1641 res.emplace_back(p_ab, s_a_o.self.un->get_location(), u_teacher.get_location());
1649 if (is_special_active(s_a_o.other, *p_ab, unit_ability_t::affects_t::OTHER)) {
1650 res.emplace_back(p_ab, s_a_o.other.un->get_location(), u_teacher.get_location());
1661 const map_location loc =
self.un ?
self.un->get_location() :
self.loc;
1665 return p_ab->tag() == tag_name;
1673 res.
emplace_back(p_ab, student.un->get_location(), source.get_location());
1678 foreach_active_special(*
this,
self, quick_check, add_to_list);
1685 const auto& [
self,
other] = s_a_o;
1702 bool exclude_ability_attributes(
const std::string& tag_name,
const config &
filter)
1705 bool abilities_check = abilities_list::ability_value_tags().count(tag_name) != 0 || abilities_list::ability_no_value_tags().count(tag_name) != 0;
1706 if(
filter.has_attribute(
"active_on") && tag_name !=
"resistance" && abilities_check)
1708 if(
filter.has_attribute(
"apply_to") && tag_name !=
"resistance" && abilities_check)
1711 if(
filter.has_attribute(
"overwrite_specials") && abilities_list::weapon_math_tags().count(tag_name) == 0)
1714 bool no_value_weapon_abilities_check = abilities_list::no_weapon_math_tags().count(tag_name) != 0 || abilities_list::ability_no_value_tags().count(tag_name) != 0;
1715 if(
filter.has_attribute(
"cumulative") && no_value_weapon_abilities_check && (tag_name !=
"swarm" || tag_name !=
"berserk"))
1717 if(
filter.has_attribute(
"value") && (no_value_weapon_abilities_check && tag_name !=
"berserk"))
1719 if(
filter.has_attribute(
"add") && no_value_weapon_abilities_check)
1721 if(
filter.has_attribute(
"sub") && no_value_weapon_abilities_check)
1723 if(
filter.has_attribute(
"multiply") && no_value_weapon_abilities_check)
1725 if(
filter.has_attribute(
"divide") && no_value_weapon_abilities_check)
1727 if(
filter.has_attribute(
"priority") && no_value_weapon_abilities_check)
1730 bool all_engine = abilities_list::no_weapon_math_tags().count(tag_name) != 0 || abilities_list::weapon_math_tags().count(tag_name) != 0 || abilities_list::ability_value_tags().count(tag_name) != 0 || abilities_list::ability_no_value_tags().count(tag_name) != 0;
1731 if(
filter.has_attribute(
"replacement_type") && tag_name !=
"damage_type" && all_engine)
1733 if(
filter.has_attribute(
"alternative_type") && tag_name !=
"damage_type" && all_engine)
1735 if(
filter.has_attribute(
"type") && tag_name !=
"plague" && all_engine)
1746 if(!exclude_ability_attributes(tag_name,
filter))
1760 if(!
filter[
"affect_adjacent"].empty()){
1762 if(
filter[
"affect_adjacent"].to_bool() != adjacent){
1795 if(abilities_list::weapon_math_tags().count(tag_name) != 0 || abilities_list::ability_value_tags().count(tag_name) != 0) {
1807 if(!
filter[
"value"].empty()){
1808 if(tag_name ==
"drains"){
1812 }
else if(tag_name ==
"berserk"){
1816 }
else if(tag_name ==
"heal_on_hit" || tag_name ==
"heals" || tag_name ==
"regenerate" || tag_name ==
"leadership"){
1842 if(tag_name ==
"resistance"){
1871 auto fwml =
filter.optional_child(
"filter_wml");
1882 static bool common_matches_filter(
const config &
cfg,
const std::string& tag_name,
const config &
filter)
1885 bool matches = matches_ability_filter(
cfg, tag_name,
filter);
1888 for(
const auto [key, condition_cfg] :
filter.all_children_view() )
1892 matches = matches && common_matches_filter(
cfg, tag_name, condition_cfg);
1895 else if ( key ==
"or" )
1896 matches = matches || common_matches_filter(
cfg, tag_name, condition_cfg);
1899 else if ( key ==
"not" )
1900 matches = matches && !common_matches_filter(
cfg, tag_name, condition_cfg);
1914 if(
at.range().empty()){
1918 bool skip_adjacent = !
filter[
"affect_adjacent"].to_bool(
true);
1921 return p_ab->matches_filter(
filter);
1925 return foreach_active_special(*
this,
self, quick_check, return_true, skip_adjacent);
1930 bool skip_adjacent = !
filter[
"affect_adjacent"].to_bool(
true);
1933 return p_ab->matches_filter(
filter);
1936 return foreach_active_ability(un,
loc, quick_check, return_true, skip_adjacent);
1942 return p_ab->id() ==
id;
1945 return foreach_active_ability(un,
loc, quick_check, return_true);
1949 class temporary_facing
1955 : save_dir_(u ? u->facing() :
map_location::direction::indeterminate)
1959 u_->set_facing(new_dir);
1965 u_->set_facing(save_dir_);
1979 bool is_attacker = &
self == &
attacker;
1988 if ( !special_affects_self(ab, is_attacker) )
1992 if ( !special_affects_opponent(ab, is_attacker) )
2002 const unit_map& units = get_unit_map();
2010 if(self_u ==
nullptr) {
2016 if(other_u ==
nullptr) {
2033 if (buildin_is_immune(ab, them, their_loc)) {
2044 if (ab.
tag() ==
"firststrike") {
2045 bool whom_is_defender = whom_is_self ? !is_attacker : is_attacker;
2056 const std::string& filter_self = ab.
in_specials_tag() ?
"filter_self" :
"filter_student";
2058 bool applied_to_self = (applied_both || whom_is_self);
2059 if (!special_unit_matches(self_u, other_u,
self.
loc,
self.
at, ab,
is_for_listing, filter_self, applied_to_self))
2061 bool applied_to_opp = (applied_both || !whom_is_self);
2066 bool applied_to_attacker = applied_both || (whom_is_self && is_attacker) || (!whom_is_self && !is_attacker);
2069 bool applied_to_defender = applied_both || (whom_is_self && !is_attacker) || (!whom_is_self && is_attacker);
2080 if(overwriters.
empty()){
2085 for(
const auto& j : overwriters) {
2095 auto overwrite_filter = j.ability_cfg().optional_child(
"overwrite_abilities");
2096 if(overwrite_filter) {
2097 auto filter_abilities = (*overwrite_filter).optional_child(
"filter_ability");
2098 if(filter_abilities && !common_matches_filter(ab.
cfg(), ab.
tag(), *filter_abilities)) {
2114 double l =
i.ability().suppress_ability_priority();
2115 double r = j.
ability().suppress_ability_priority();
2119 return (priority_checking(abil_list,
i));
2144 return (cond_eq.
empty() || def == cond_eq.
to_int()) &&
2165 return formula.
evaluate(callable).as_decimal() / 1000.0 ;
2172 composite_value_(def),
2173 composite_double_value_(def)
2177 apply_ability_suppression(list);
2179 std::map<double, active_ability_list> base_list;
2181 double priority =
i.ability().priority();
2182 if(base_list[priority].empty()) {
2185 base_list[priority].emplace_back(
i);
2188 for(
auto base : base_list) {
2196 int value_set = def;
2197 std::map<std::string,individual_effect> values_add;
2198 std::map<std::string,individual_effect> values_sub;
2199 std::map<std::string,individual_effect> values_mul;
2200 std::map<std::string,individual_effect> values_div;
2205 utils::optional<int> max_value = utils::nullopt;
2206 utils::optional<int> min_value = utils::nullopt;
2209 const config&
cfg = ability.ability_cfg();
2210 const std::string& effect_id =
cfg[
cfg[
"id"].
empty() ?
"name" :
"id"];
2219 set_effect_cum.
set(
SET, set_effect_cum.
value + value_cum, ability.ability_cfg(), ability.teacher_loc);
2221 set_effect_cum.
set(
SET, value_cum, ability.ability_cfg(), ability.teacher_loc);
2225 set_effect_min.
set(
SET, value_cum, ability.ability_cfg(), ability.teacher_loc);
2226 set_effect_max.
set(
SET, value_cum, ability.ability_cfg(), ability.teacher_loc);
2229 if(value_cum > set_effect_max.
value) {
2230 set_effect_max.
set(
SET, value_cum, ability.ability_cfg(), ability.teacher_loc);
2232 if(value_cum < set_effect_min.
value) {
2233 set_effect_min.
set(
SET, value_cum, ability.ability_cfg(), ability.teacher_loc);
2242 max_value = max_value ? std::min(*max_value,
value) :
value;
2246 min_value = min_value ? std::max(*min_value,
value) :
value;
2253 if(add_effect == values_add.end() || add > add_effect->second.value) {
2254 values_add[effect_id].set(
ADD, add, ability.ability_cfg(), ability.teacher_loc);
2260 if(sub_effect == values_sub.end() || sub < sub_effect->second.value) {
2261 values_sub[effect_id].set(
ADD, sub, ability.ability_cfg(), ability.teacher_loc);
2267 if(mul_effect == values_mul.end() || multiply > mul_effect->second.value) {
2268 values_mul[effect_id].set(
MUL, multiply, ability.ability_cfg(), ability.teacher_loc);
2275 ERR_NG <<
"division by zero with divide= in ability/weapon special " << effect_id;
2279 if(div_effect == values_div.end() || divide > div_effect->second.value) {
2280 values_div[effect_id].set(
DIV, divide, ability.ability_cfg(), ability.teacher_loc);
2287 value_set = std::max(set_effect_max.
value, 0) + std::min(set_effect_min.
value, 0);
2288 if(set_effect_max.
value > def) {
2291 if(set_effect_min.
value < def) {
2304 double multiplier = 1.0;
2305 double divisor = 1.0;
2307 for(
const auto& val : values_mul) {
2308 multiplier *= val.second.value/100.0;
2312 for(
const auto& val : values_div) {
2313 divisor *= val.second.value/100.0;
2318 for(
const auto& val : values_add) {
2319 addition += val.second.value;
2325 int substraction = 0;
2326 for(
const auto& val : values_sub) {
2327 substraction += val.second.value;
2332 value_set += set_effect_cum.
value;
2338 if(max_value && min_value && *min_value < *max_value) {
2340 }
else if(max_value && !min_value) {
2342 }
else if(min_value && !max_value) {
static lg::log_domain log_engine("engine")
static bool is_enemy(std::size_t side, std::size_t other_side)
static lg::log_domain log_wml("wml")
std::vector< ability_ptr > ability_vector
const map_location & loc() const
std::pair< int, map_location > get_extremum(const std::string &key, int def, const TComp &comp) const
void emplace_back(T &&... args)
void add_formula_context(wfl::map_formula_callable &) const
std::unique_ptr< specials_context_t > fallback_context(const unit_ptr &self=nullptr) const
bool overwrite_special_checking(active_ability_list &overwriters, const active_ability &overwrited) const
Check whether overwrited would be overwritten by any element of overwriters.
specials_context_t * context_
Variant for storing WML attributes.
int to_int(int def=0) const
auto apply_visitor(const V &visitor) const
Visitor support: Applies a visitor to the underlying variant.
bool empty() const
Tests for an attribute that either was never set or was set to "".
A config object defines a single node in a WML file, with access to child nodes.
void remove_attribute(std::string_view key)
config & add_child(std::string_view key)
optional_config_impl< config > optional_child(std::string_view key, int n=0)
Equivalent to mandatory_child, but returns an empty optional if the nth child was not found.
bool matches(const config &filter) const
config & child_or_add(std::string_view key)
Returns a reference to the first child with the given key.
child_itors child_range(std::string_view key)
const attribute_value * get(std::string_view key) const
Returns a pointer to the attribute with the given key or nullptr if it does not exist.
const_all_children_itors all_children_range() const
In-order iteration over all children.
std::string debug() const
bool has_child(std::string_view key) const
Determine whether a config has a child or not.
void remove_children(std::string_view key, const std::function< bool(const config &)> &p={})
Removes all children with tag key for which p returns true.
const team & get_team(int side) const
This getter takes a 1-based side number, not a 0-based team number.
virtual const unit_map & units() const =0
const display_context & context() const
static display * get_singleton()
Returns the display object if a display object exists.
virtual const unit_map & units() const override
virtual const gamemap & map() const override
bool is_village(const map_location &loc) const
bool get_show_deprecation(bool def)
self_and_other_ref self_and_other(const attack_type &self_att) const
bool has_active_special(const attack_type &at, const std::string &tag) const
Returns whether or not *this has a special ability with a tag or id equal to special.
active_ability_list get_abilities_weapons(const std::string &tag, const unit &un) const
bool is_special_active(const specials_combatant &wep, const unit_ability_t &ab, unit_ability_t::affects_t whom) const
Returns whether or not the given special is active for the specified unit, based on the current conte...
specials_combatant defender
std::vector< unit_ability_t::tooltip_info > special_tooltips(const attack_type &at, boost::dynamic_bitset<> &active_list) const
Returns a vector of names and descriptions for the specials of *this.
static bool has_active_ability_matching_filter(const unit &un, map_location loc, const config &filter)
std::string describe_weapon_specials_value(const attack_type &at, const std::set< std::string > &checking_tags) const
specials_combatant attacker
const specials_combatant & other(const specials_combatant &self) const
std::string describe_weapon_specials(const attack_type &at) const
Returns a comma-separated string of active names for the specials of *this.
void add_formula_context(wfl::map_formula_callable &callable) const
bool has_active_special_id(const attack_type &at, const std::string &id) const
specials_context_t(specials_context_t &&)=delete
std::vector< unit_ability_t::tooltip_info > abilities_special_tooltips(const attack_type &at, boost::dynamic_bitset<> &active_list) const
bool has_active_special_matching_filter(const attack_type &at, const config &filter) const
active_ability_list get_active_specials(const attack_type &at, const std::string &tag) const
static bool has_active_ability_id(const unit &un, map_location loc, const std::string &id)
active_ability_list get_active_combat_teachers(const attack_type &at) const
This class stores all the data for a single 'side' (in game nomenclature).
bool is_enemy(int n) const
std::vector< individual_effect > effect_list_
effect(active_ability_list list, int def, const specials_context_t *ctx=nullptr, EFFECTS wham=EFFECT_DEFAULT)
double composite_double_value_
void effect_impl(const active_ability_list &list, int def, const specials_context_t *ctx, EFFECTS wham)
Part of the constructor, calculates for a group of abilities with equal priority.
const unit_ability_t * parent
std::string substitute_variables(const std::string &str) const
Substitute gettext variables in name and description of abilities and specials.
const std::string & tag() const
double suppress_special_priority_
static std::string get_help_topic_id(const config &cfg)
double suppress_special_priority() const
apply_to_t apply_to() const
static config vector_to_cfg(const ability_vector &abilities)
static void do_compat_fixes(config &cfg, const std::string &tag, bool inside_attack)
const config & cfg() const
static void parse_vector(const config &abilities_cfg, ability_vector &res, bool inside_attack)
bool affects_enemies() const
std::string get_description(bool is_inactive=false, unit_race::GENDER=unit_race::MALE) const
bool matches_filter(const config &filter) const
active_on_t active_on() const
bool in_specials_tag() const
static ability_vector filter_tag(const ability_vector &vec, const std::string &tag)
unit_ability_t(std::string tag, config cfg, bool inside_attack)
double suppress_ability_priority() const
static ability_ptr create(std::string tag, config cfg, bool inside_attack)
affects_allies_t affects_allies_
static ability_vector clone(const ability_vector &vec)
std::string get_name(bool is_inactive=false, unit_race::GENDER=unit_race::MALE) const
std::string get_help_topic_id() const
recursion_guard guard_against_recursion(const unit &u) const
Tests which might otherwise cause infinite recursion should call this, check that the returned object...
void write(config &abilities_cfg)
double suppress_ability_priority_
static ability_vector cfg_to_vector(const config &abilities_cfg, bool inside_attack)
affects_allies_t affects_allies() const
bool active_on_matches(bool student_is_attacker) const
bool affects_self() const
bool matches(const unit &u, const map_location &loc) const
Determine if *this matches filter at a specified location.
unit_filter & set_use_flat_tod(bool value)
Container associating units to locations.
unit_ptr find_unit_ptr(const T &val)
unit_iterator find(std::size_t id)
const unit_type_map & types() const
A single unit type that the player may recruit.
This class represents a single unit of a specific type.
A variable-expanding proxy for the config class.
Represents version numbers.
int as_int(int fallback=0) const
Returns the variant's value as an integer.
std::string deprecated_message(const std::string &elem_name, DEP_LEVEL level, const version_info &version, const std::string &detail)
map_display and display: classes which take care of displaying the map and game-data on the screen.
Interfaces for manipulating version numbers of engine, add-ons, etc.
static std::string _(const char *str)
const ability_vector & abilities() const
bool ability_active_impl(const unit_ability_t &ab, const map_location &loc) const
Check if an ability is active.
bool ability_affects_self(const unit_ability_t &ab, const map_location &loc) const
Check if an ability affects the owning unit.
bool ability_active(const unit_ability_t &ab, const map_location &loc) const
Check if an ability is active.
active_ability_list get_abilities(const std::string &tag_name, const map_location &loc) const
Gets the unit's active abilities of a particular type if it were on a specified location.
bool get_ability_bool(const std::string &tag_name, const map_location &loc) const
Checks whether this unit currently possesses or is affected by a given ability.
bool ability_affects_adjacent(const unit_ability_t &ab, std::size_t dist, int dir, const map_location &loc, const unit &from) const
Check if an ability affects distant units.
bool has_ability_type(const std::string &ability) const
Check if the unit has an ability of a specific type.
std::vector< std::string > get_ability_id_list() const
Get a list of all abilities by ID.
bool get_self_ability_bool(const unit_ability_t &ab, const map_location &loc) const
Checks whether this unit currently possesses a given ability, and that that ability is active.
bool get_adj_ability_bool(const unit_ability_t &ab, std::size_t dist, int dir, const map_location &loc, const unit &from, const map_location &from_loc) const
Checks whether this unit is affected by a given ability, and that that ability is active.
std::vector< unit_ability_t::tooltip_info > ability_tooltips() const
Gets the names and descriptions of this unit's abilities.
bool incapacitated() const
Check if the unit has been petrified.
const std::string & id() const
Gets this unit's id.
int side() const
The side this unit belongs to.
std::size_t underlying_id() const
This unit's unique internal ID.
@ STATE_POISONED
The unit is slowed - it moves slower and does less damage.
std::vector< std::string > halo_or_icon_abilities(const std::string &image_type) const
const map_location & get_location() const
The current map location this unit is at.
std::size_t max_ability_radius_type(const std::string &tag_name) const
If this unit has abilities of tag_name type with [affect_adjacent] subtags, returns the radius of the...
std::size_t max_ability_radius_image() const
If this unit has abilities with [affect_adjacent] subtags and halo_image or overlay_image attributes,...
std::size_t max_ability_radius() const
If this unit has abilities with [affect_adjacent] subtags, returns the radius of the one with the fur...
std::string id
Text to match against addon_info.tags()
const language_def & get_language()
New lexcical_cast header.
std::size_t distance_between(const map_location &a, const map_location &b)
Function which gives the number of hexes between two tiles (i.e.
void get_adjacent_tiles(const map_location &a, utils::span< map_location, 6 > res)
Function which, given a location, will place all adjacent locations in res.
Standard logging facilities (interface).
const color_t INACTIVE_COLOR
const version_info wesnoth_version(VERSION)
static bool is_active(const widget *wgt)
std::stringstream & log_to_chat()
Use this to show WML errors in the ingame chat.
std::string span_color(const color_t &color, Args &&... data)
Applies Pango markup to the input specifying its display color.
std::string tag(std::string_view tag, Args &&... data)
Wraps the given data in the specified tag.
static std::string at(const std::string &file, int line)
static int individual_value_int(const config::attribute_value *v, int def, const active_ability &ability, const map_location &loc, const specials_context_t *ctx)
static int individual_value_double(const config::attribute_value *v, int def, const active_ability &ability, const map_location &loc, const specials_context_t *ctx)
bool filter_base_matches(const config &cfg, int def)
@ EFFECT_WITHOUT_CLAMP_MIN_MAX
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
Utility functions for implementing [filter], [filter_ability], [filter_weapon], etc.
bool int_matches_if_present(const config &filter, const config &cfg, const std::string &attribute, utils::optional< int > def=utils::nullopt)
bool set_includes_if_present(const config &filter, const config &cfg, const std::string &attribute)
filter[attribute] and cfg[attribute] are assumed to be comma-separated lists.
bool double_matches_if_present(const config &filter, const config &cfg, const std::string &attribute, utils::optional< double > def=utils::nullopt)
Checks whether the filter matches the value of cfg[attribute].
bool int_matches_if_present_or_negative(const config &filter, const config &cfg, const std::string &attribute, const std::string &opposite, utils::optional< int > def=utils::nullopt)
Supports filters using "add" and "sub" attributes, for example a filter add=1 matching a cfg containi...
bool string_matches_if_present(const config &filter, const config &cfg, const std::string &attribute, const std::string &def)
bool bool_or_empty(const config &filter, const config &cfg, const std::string &attribute)
bool bool_matches_if_present(const config &filter, const config &cfg, const std::string &attribute, bool def)
Checks whether the filter matches the value of cfg[attribute].
constexpr bool decayed_is_same
Equivalent to as std::is_same_v except both types are passed through std::decay first.
void trim(std::string_view &s)
std::string interpolate_variables_into_string(const std::string &str, const string_map *const symbols)
Function which will interpolate variables, starting with '$' in the string 'str' with the equivalent ...
bool contains(const Container &container, const Value &value)
Returns true iff value is found in container.
std::string join(const Range &v, const std::string &s=",")
Generates a new string joining container items in a list.
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...
void erase_if(Container &container, const Predicate &predicate)
Convenience wrapper for using std::remove_if on a container.
std::map< std::string, t_string > string_map
void sort_if(Container &container, const Predicate &predicate)
Convenience wrapper for using std::sort on a container.
std::vector< std::string > split(const config_attribute_value &val)
std::string to_string(const Range &range, const Func &op)
std::string::const_iterator iterator
std::shared_ptr< const unit > unit_const_ptr
std::shared_ptr< const attack_type > const_attack_ptr
std::shared_ptr< unit_ability_t > ability_ptr
std::unique_ptr< MIX_Audio, decltype(&MIX_DestroyAudio)> value
Data typedef for active_ability_list.
map_location teacher_loc
The location of the teacher, that is the unit who owns the ability tags (different from student becau...
const unit_ability_t & ability() const
map_location student_loc
Used by the formula in the ability.
Encapsulates the map of the game.
static std::vector< direction > parse_directions(const std::string &str)
Parse_directions takes a comma-separated list, and filters out any invalid directions.
direction
Valid directions which can be moved in our hexagonal world.
direction get_relative_dir(const map_location &loc, map_location::RELATIVE_DIR_MODE mode) const
void set(value_modifier t, int val, const config &abil, const map_location &l)
pointer get_shared_ptr() const
This is exactly the same as operator-> but it's slightly more readable, and can replace &*iter syntax...
static map_location::direction s
unit_type_data unit_types