reset unit overlay & image_mods on advance_to
this fixes remove_modification for these effects, and also a bug where these effect would be applied twice after a unit advances. fixes #3264 fixes #3220 This also changes the implementation of [unit_overlay] to use [effect]s now so tht changesdone via [unit_overlay] ae persistent as they were before.
This commit is contained in:
parent
03ea39b4af
commit
1a7724e547
2 changed files with 18 additions and 11 deletions
|
@ -349,13 +349,18 @@ end
|
|||
function wml_actions.unit_overlay(cfg)
|
||||
local img = cfg.image or helper.wml_error( "[unit_overlay] missing required image= attribute" )
|
||||
for i,u in ipairs(wesnoth.get_units(cfg)) do
|
||||
local ucfg = u.__cfg
|
||||
for w in utils.split(ucfg.overlays) do
|
||||
if w == img then ucfg = nil end
|
||||
local has_already = false
|
||||
for i, w in ipairs(u.overlays) do
|
||||
if w == img then has_already = true end
|
||||
end
|
||||
if ucfg then
|
||||
ucfg.overlays = ucfg.overlays .. ',' .. img
|
||||
wesnoth.put_unit(ucfg)
|
||||
if has_already == false then
|
||||
u:add_modification("object" {
|
||||
id = cfg.object_id,
|
||||
wml.tag.effect {
|
||||
apply_to = "overlay",
|
||||
add = img,
|
||||
}
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -475,11 +475,6 @@ void unit::init(const config& cfg, bool use_traits, const vconfig* vcfg)
|
|||
underlying_id_ = n_unit::unit_id(cfg["underlying_id"].to_size_t());
|
||||
set_underlying_id(resources::gameboard ? resources::gameboard->unit_id_manager() : n_unit::id_manager::global_instance());
|
||||
|
||||
overlays_ = utils::parenthetical_split(cfg["overlays"], ',');
|
||||
if(overlays_.size() == 1 && overlays_.front().empty()) {
|
||||
overlays_.clear();
|
||||
}
|
||||
|
||||
if(vcfg) {
|
||||
const vconfig& filter_recall = vcfg->child("filter_recall");
|
||||
if(!filter_recall.null())
|
||||
|
@ -514,6 +509,11 @@ void unit::init(const config& cfg, bool use_traits, const vconfig* vcfg)
|
|||
// Apply the unit type's data to this unit.
|
||||
advance_to(*type_, use_traits);
|
||||
|
||||
overlays_ = utils::parenthetical_split(cfg["overlays"], ',');
|
||||
if(overlays_.size() == 1 && overlays_.front().empty()) {
|
||||
overlays_.clear();
|
||||
}
|
||||
|
||||
if(const config& variables = cfg.child("variables")) {
|
||||
variables_ = variables;
|
||||
}
|
||||
|
@ -897,6 +897,8 @@ void unit::advance_to(const unit_type& u_type, bool use_traits)
|
|||
trait_descriptions_.clear(),
|
||||
is_fearless_ = false;
|
||||
is_healthy_ = false;
|
||||
image_mods_.clear();
|
||||
overlays_.clear();
|
||||
|
||||
// Clear modification-related caches
|
||||
modification_descriptions_.clear();
|
||||
|
|
Loading…
Add table
Reference in a new issue