Support events in [abilities] and [specials] tags
This commit is contained in:
parent
fb42d4b5ac
commit
bddbf060a5
3 changed files with 92 additions and 1 deletions
|
@ -43,6 +43,8 @@
|
|||
{FILTER_TAG "filter_adjacent_location" adjacent_location ()}
|
||||
{FILTER_TAG "filter_base_value" base_value ()}
|
||||
{WML_MERGE_KEYS}
|
||||
|
||||
{LINK_TAG "event"}
|
||||
[/tag]
|
||||
[tag]
|
||||
name="heals"
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
{FILTER_TAG "filter_attacker" unit {FILTER_TAG "filter_weapon" weapon ()}}
|
||||
{FILTER_TAG "filter_defender" unit {FILTER_TAG "filter_weapon" weapon ()}}
|
||||
{WML_MERGE_KEYS}
|
||||
|
||||
{LINK_TAG "event"}
|
||||
[/tag]
|
||||
# A few specials inheriting from ~generic~ are included here so that unit abilities can then inherit from them.
|
||||
[tag]
|
||||
|
|
|
@ -434,12 +434,51 @@ void unit::init(const config& cfg, bool use_traits, const vconfig* vcfg)
|
|||
for(const vconfig& e : events) {
|
||||
events_.add_child("event", e.get_config());
|
||||
}
|
||||
const vconfig::child_list& abilities_tags = vcfg->get_children("abilities");
|
||||
for(const vconfig& abilities_tag : abilities_tags) {
|
||||
for(const auto& [key, child] : abilities_tag.all_ordered()) {
|
||||
const vconfig::child_list& ability_events = child.get_children("event");
|
||||
for(const vconfig& ability_event : ability_events) {
|
||||
events_.add_child("event", ability_event.get_config());
|
||||
}
|
||||
}
|
||||
}
|
||||
const vconfig::child_list& attacks = vcfg->get_children("attack");
|
||||
for(const vconfig& attack : attacks) {
|
||||
const vconfig::child_list& specials_tags = attack.get_children("specials");
|
||||
for(const vconfig& specials_tag : specials_tags) {
|
||||
for(const auto& [key, child] : specials_tag.all_ordered()) {
|
||||
const vconfig::child_list& special_events = child.get_children("event");
|
||||
for(const vconfig& special_event : special_events) {
|
||||
events_.add_child("event", special_event.get_config());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
filter_recall_ = cfg.child_or_empty("filter_recall");
|
||||
|
||||
for(const config& unit_event : cfg.child_range("event")) {
|
||||
events_.add_child("event", unit_event);
|
||||
}
|
||||
for(const config& abilities : cfg.child_range("abilities")) {
|
||||
for(const config::any_child child : abilities.all_children_range()) {
|
||||
const config& ability = child.cfg;
|
||||
for(const config& ability_event : ability.child_range("event")) {
|
||||
events_.add_child("event", ability_event);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(const config& attack : cfg.child_range("attack")) {
|
||||
for(const config& specials : attack.child_range("specials")) {
|
||||
for(const config::any_child child : specials.all_children_range()) {
|
||||
const config& special = child.cfg;
|
||||
for(const config& special_event : special.child_range("event")) {
|
||||
events_.add_child("event", special_event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(resources::game_events && resources::lua_kernel) {
|
||||
|
@ -1037,7 +1076,30 @@ void unit::advance_to(const unit_type& u_type, bool use_traits)
|
|||
|
||||
// In case the unit carries EventWML, apply it now
|
||||
if(resources::game_events && resources::lua_kernel) {
|
||||
resources::game_events->add_events(new_type.events(), *resources::lua_kernel, new_type.id());
|
||||
config events;
|
||||
const config& cfg = new_type.get_cfg();
|
||||
for(const config& unit_event : cfg.child_range("event")) {
|
||||
events.add_child("event", unit_event);
|
||||
}
|
||||
for(const config& abilities : cfg.child_range("abilities")) {
|
||||
for(const config::any_child child : abilities.all_children_range()) {
|
||||
const config& ability = child.cfg;
|
||||
for(const config& ability_event : ability.child_range("event")) {
|
||||
events.add_child("event", ability_event);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(const config& attack : cfg.child_range("attack")) {
|
||||
for(const config& specials : attack.child_range("specials")) {
|
||||
for(const config::any_child child : specials.all_children_range()) {
|
||||
const config& special = child.cfg;
|
||||
for(const config& special_event : special.child_range("event")) {
|
||||
events.add_child("event", special_event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
resources::game_events->add_events(events.child_range("event"), *resources::lua_kernel, new_type.id());
|
||||
}
|
||||
bool bool_small_profile = get_attr_changed(UA_SMALL_PROFILE);
|
||||
bool bool_profile = get_attr_changed(UA_PROFILE);
|
||||
|
@ -1970,6 +2032,7 @@ std::string unit::describe_builtin_effect(std::string apply_to, const config& ef
|
|||
|
||||
void unit::apply_builtin_effect(std::string apply_to, const config& effect)
|
||||
{
|
||||
config events;
|
||||
appearance_changed_ = true;
|
||||
if(apply_to == "fearless") {
|
||||
set_attr_changed(UA_IS_FEARLESS);
|
||||
|
@ -2005,6 +2068,14 @@ void unit::apply_builtin_effect(std::string apply_to, const config& effect)
|
|||
} else if(apply_to == "new_attack") {
|
||||
set_attr_changed(UA_ATTACKS);
|
||||
attacks_.emplace_back(new attack_type(effect));
|
||||
for(const config& specials : effect.child_range("specials")) {
|
||||
for(const config::any_child child : specials.all_children_range()) {
|
||||
const config& special = child.cfg;
|
||||
for(const config& special_event : special.child_range("event")) {
|
||||
events.add_child("event", special_event);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(apply_to == "remove_attacks") {
|
||||
set_attr_changed(UA_ATTACKS);
|
||||
auto iter = std::remove_if(attacks_.begin(), attacks_.end(), [&effect](attack_ptr a) {
|
||||
|
@ -2016,6 +2087,14 @@ void unit::apply_builtin_effect(std::string apply_to, const config& effect)
|
|||
set_attr_changed(UA_ATTACKS);
|
||||
for(attack_ptr a : attacks_) {
|
||||
a->apply_modification(effect);
|
||||
for(const config& specials : effect.child_range("set_specials")) {
|
||||
for(const config::any_child child : specials.all_children_range()) {
|
||||
const config& special = child.cfg;
|
||||
for(const config& special_event : special.child_range("event")) {
|
||||
events.add_child("event", special_event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(apply_to == "hitpoints") {
|
||||
LOG_UT << "applying hitpoint mod..." << hit_points_ << "/" << max_hit_points_;
|
||||
|
@ -2175,6 +2254,9 @@ void unit::apply_builtin_effect(std::string apply_to, const config& effect)
|
|||
for(const config::any_child ab : ab_effect->all_children_range()) {
|
||||
if(!has_ability_by_id(ab.cfg["id"])) {
|
||||
to_append.add_child(ab.key, ab.cfg);
|
||||
for(const config& event : ab.cfg.child_range("event")) {
|
||||
events.add_child("event", event);
|
||||
}
|
||||
}
|
||||
}
|
||||
abilities_.append(to_append);
|
||||
|
@ -2347,6 +2429,11 @@ void unit::apply_builtin_effect(std::string apply_to, const config& effect)
|
|||
level_ += lexical_cast_default<int>(increase);
|
||||
}
|
||||
}
|
||||
|
||||
// In case the effect carries EventWML, apply it now
|
||||
if(resources::game_events && resources::lua_kernel) {
|
||||
resources::game_events->add_events(events.child_range("event"), *resources::lua_kernel);
|
||||
}
|
||||
}
|
||||
|
||||
void unit::add_modification(const std::string& mod_type, const config& mod, bool no_add)
|
||||
|
|
Loading…
Add table
Reference in a new issue