Add concat_to_* key for config merging (eg, unit type inheritance)

Works similarly to add_to_*, but uses string concatenation instead of
numerical addition.

This also changes add_to_* to use floating-point addition instead of
integer addition.
This commit is contained in:
Celtic Minstrel 2017-05-02 17:24:55 -04:00
parent c825ff7a80
commit fc204ea1c5
2 changed files with 7 additions and 1 deletions

View file

@ -70,6 +70,7 @@ Version 1.13.7+dev:
* New [zoom] tag allows changing the zoom level from an event
* [kill]animate=yes now plays victory animations if applicable
* Fix [volume] not accepting 100% as the new volume.
* New concat_to_* keys in unit_type inheritance allow amending keys
* Miscellaneous and bug fixes:
* Fixed base animation showing on walking corpse & soulless bats (bug #25673)

View file

@ -928,7 +928,12 @@ void config::merge_attributes(const config &cfg)
std::string key = v.first;
if (key.substr(0,7) == "add_to_") {
std::string add_to = key.substr(7);
values[add_to] = values[add_to].to_int() + v.second.to_int();
values[add_to] = values[add_to].to_double() + v.second.to_double();
} else if(key.substr(0,10) == "concat_to_") {
std::string concat_to = key.substr(10);
// TODO: Only use t_string if one or both are actually translatable?
// That probably requires using a visitor though.
values[concat_to] = values[concat_to].t_str() + v.second.t_str();
} else
values[v.first] = v.second;
}