delay/add variable substitution in unit::add_modification (fix for bug #18893)
This commit is contained in:
parent
4bae6d3858
commit
1f539b39c8
6 changed files with 24 additions and 22 deletions
|
@ -1658,7 +1658,7 @@ bool attack::perform_hit(bool attacker_turn, statistics::attack_context &stats)
|
|||
config &variation = mod.add_child("effect");
|
||||
variation["apply_to"] = "variation";
|
||||
variation["name"] = undead_variation;
|
||||
newunit.add_modification("variation",mod);
|
||||
newunit.add_modification("variation", vconfig(mod));
|
||||
newunit.heal_all();
|
||||
}
|
||||
units_.add(death_loc, newunit);
|
||||
|
|
|
@ -99,7 +99,7 @@ int advance_unit_dialog(const map_location &loc)
|
|||
{
|
||||
if (mod["always_display"].to_bool()) always_display = true;
|
||||
sample_units.push_back(::get_advanced_unit(*u, u->type_id()));
|
||||
sample_units.back().add_modification("advance", mod);
|
||||
sample_units.back().add_modification("advance", vconfig(mod));
|
||||
const unit& type = sample_units.back();
|
||||
if (!mod["image"].empty()) {
|
||||
lang_options.push_back(IMAGE_PREFIX + mod["image"].str() + COLUMN_SEPARATOR + mod["description"].str());
|
||||
|
@ -228,7 +228,7 @@ bool animate_unit_advancement(const map_location &loc, size_t choice, const bool
|
|||
}
|
||||
|
||||
amla_unit.set_experience(amla_unit.experience() - amla_unit.max_experience());
|
||||
amla_unit.add_modification("advance",mod_option);
|
||||
amla_unit.add_modification("advance", vconfig(mod_option));
|
||||
resources::units->replace(loc, amla_unit);
|
||||
|
||||
if(fire_event)
|
||||
|
|
|
@ -1101,7 +1101,7 @@ game_display::fake_unit *create_fake_unit(const vconfig& cfg)
|
|||
config &effect = mod.add_child("effect");
|
||||
effect["apply_to"] = "variation";
|
||||
effect["name"] = variation;
|
||||
fake_unit->add_modification("variation",mod);
|
||||
fake_unit->add_modification("variation", vconfig(mod));
|
||||
}
|
||||
|
||||
if(!img_mods.empty()) {
|
||||
|
@ -1109,7 +1109,7 @@ game_display::fake_unit *create_fake_unit(const vconfig& cfg)
|
|||
config &effect = mod.add_child("effect");
|
||||
effect["apply_to"] = "image_mod";
|
||||
effect["add"] = img_mods;
|
||||
fake_unit->add_modification("image_mod",mod);
|
||||
fake_unit->add_modification("image_mod", vconfig(mod));
|
||||
}
|
||||
|
||||
return fake_unit;
|
||||
|
@ -1891,7 +1891,7 @@ WML_HANDLER_FUNCTION(object, event_info, cfg)
|
|||
{
|
||||
text = cfg["description"].str();
|
||||
|
||||
u->add_modification("object", cfg.get_parsed_config());
|
||||
u->add_modification("object", cfg);
|
||||
|
||||
resources::screen->select_hex(event_info.loc1);
|
||||
resources::screen->invalidate_unit();
|
||||
|
|
|
@ -3258,8 +3258,8 @@ static int intf_add_modification(lua_State *L)
|
|||
if (sm != "advance" && sm != "object" && sm != "trait")
|
||||
return luaL_argerror(L, 2, "unknown modification type");
|
||||
|
||||
config cfg = luaW_checkconfig(L, 3);
|
||||
u->add_modification(sm, cfg);
|
||||
const vconfig& vcfg = luaW_checkvconfig(L, 3);
|
||||
u->add_modification(sm, vcfg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
26
src/unit.cpp
26
src/unit.cpp
|
@ -2318,23 +2318,24 @@ static void mod_mdr_merge(config& dst, const config& mod, bool delta)
|
|||
}
|
||||
}
|
||||
|
||||
void unit::add_modification(const std::string& type, const config& mod, bool no_add)
|
||||
void unit::add_modification(const std::string& type, const vconfig& vcfg, bool no_add)
|
||||
{
|
||||
//some trait activate specific flags
|
||||
if(type == "trait") {
|
||||
const std::string& id = mod["id"];
|
||||
const std::string id = vcfg["id"].str();
|
||||
is_fearless_ = is_fearless_ || id == "fearless";
|
||||
is_healthy_ = is_healthy_ || id == "healthy";
|
||||
}
|
||||
|
||||
config *new_child = NULL;
|
||||
if(no_add == false) {
|
||||
new_child = &modifications_.add_child(type,mod);
|
||||
new_child = &modifications_.add_child(type, vcfg.get_config());
|
||||
}
|
||||
config last_effect;
|
||||
std::vector<t_string> effects_description;
|
||||
foreach (const config &effect, mod.child_range("effect"))
|
||||
foreach (const vconfig& veffect, vcfg.get_children("effect"))
|
||||
{
|
||||
const config& effect = veffect.get_parsed_config();
|
||||
// See if the effect only applies to certain unit types
|
||||
const std::string &type_filter = effect["unit_type"];
|
||||
if(type_filter.empty() == false) {
|
||||
|
@ -2354,8 +2355,9 @@ void unit::add_modification(const std::string& type, const config& mod, bool no_
|
|||
}
|
||||
/** @todo The above two filters can be removed in 1.7 they're covered by the SUF. */
|
||||
// Apply SUF. (Filtering on location is probably a bad idea though.)
|
||||
if (const config &afilter = effect.child("filter"))
|
||||
if (!matches_filter(vconfig(afilter), map_location(cfg_, NULL))) continue;
|
||||
const vconfig& afilter = veffect.child("filter");
|
||||
if (!afilter.null())
|
||||
if (!matches_filter(afilter, map_location(cfg_, NULL))) continue;
|
||||
|
||||
const std::string &apply_to = effect["apply_to"];
|
||||
const std::string &apply_times = effect["times"];
|
||||
|
@ -2543,7 +2545,7 @@ void unit::add_modification(const std::string& type, const config& mod, bool no_
|
|||
}
|
||||
} else if (apply_to == "new_ability") {
|
||||
config &ab = cfg_.child_or_add("abilities");
|
||||
if (const config &ab_effect = effect.child("abilities")) {
|
||||
if (const config &ab_effect = veffect.child("abilities").get_config()) {
|
||||
config to_append;
|
||||
foreach (const config::any_child &ab, ab_effect.all_children_range()) {
|
||||
if(!has_ability_by_id(ab.cfg["id"])) {
|
||||
|
@ -2668,7 +2670,7 @@ void unit::add_modification(const std::string& type, const config& mod, bool no_
|
|||
|
||||
t_string description;
|
||||
|
||||
const t_string& mod_description = mod["description"];
|
||||
const t_string mod_description = vcfg["description"].t_str();
|
||||
if (!mod_description.empty()) {
|
||||
description = mod_description + " ";
|
||||
}
|
||||
|
@ -2686,16 +2688,16 @@ void unit::add_modification(const std::string& type, const config& mod, bool no_
|
|||
|
||||
// store trait info
|
||||
if(type == "trait") {
|
||||
add_trait_description(mod, description);
|
||||
add_trait_description(vcfg, description);
|
||||
}
|
||||
|
||||
//NOTE: if not a trait, description is currently not used
|
||||
}
|
||||
|
||||
void unit::add_trait_description(const config& trait, const t_string& description)
|
||||
void unit::add_trait_description(const vconfig& trait, const t_string& description)
|
||||
{
|
||||
const std::string& gender_string = gender_ == unit_race::FEMALE ? "female_name" : "male_name";
|
||||
t_string const &gender_specific_name = trait[gender_string];
|
||||
t_string const gender_specific_name = trait[gender_string].t_str();
|
||||
|
||||
// if this is a t_string& instead of a t_string, msvc9 compiled windows binaries
|
||||
// choke on the case where both gender_specific_name and trait["name"] are empty.
|
||||
|
@ -2745,7 +2747,7 @@ void unit::apply_modifications()
|
|||
const std::string& mod = ModificationTypes[i];
|
||||
foreach (const config &m, modifications_.child_range(mod)) {
|
||||
log_scope("add mod");
|
||||
add_modification(ModificationTypes[i], m, true);
|
||||
add_modification(ModificationTypes[i], vconfig(m), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -260,7 +260,7 @@ public:
|
|||
|
||||
size_t modification_count(const std::string& type, const std::string& id) const;
|
||||
|
||||
void add_modification(const std::string& type, const config& modification,
|
||||
void add_modification(const std::string& type, const vconfig& vcfg,
|
||||
bool no_add=false);
|
||||
|
||||
bool move_interrupted() const { return movement_left() > 0 && interrupted_move_.x >= 0 && interrupted_move_.y >= 0; }
|
||||
|
@ -365,7 +365,7 @@ private:
|
|||
void remove_ability_by_id(const std::string& ability);
|
||||
|
||||
/** register a trait's name and its description for UI's use*/
|
||||
void add_trait_description(const config& trait, const t_string& description);
|
||||
void add_trait_description(const vconfig& trait, const t_string& description);
|
||||
|
||||
void set_underlying_id();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue