When patching movetypes, don't let default= override everything
This commit is contained in:
parent
53680bf53e
commit
e046f713ed
1 changed files with 18 additions and 12 deletions
|
@ -1005,11 +1005,15 @@ namespace { // Helpers for set_config()
|
|||
const boost::regex fai_identifier("[a-zA-Z_]+");
|
||||
|
||||
template<typename MoveT>
|
||||
void patch_movetype(MoveT& mt, const std::string& new_key, const std::string& formula_str, int default_val) {
|
||||
void patch_movetype(MoveT& mt, const std::string& new_key, const std::string& formula_str, int default_val, bool replace) {
|
||||
config temp_cfg, original_cfg;
|
||||
mt.write(original_cfg);
|
||||
if (!replace && !original_cfg[new_key].blank()) {
|
||||
// Don't replace if the key already exists in the config (even if empty).
|
||||
return;
|
||||
}
|
||||
gui2::tformula<int> formula(formula_str);
|
||||
game_logic::map_formula_callable original;
|
||||
mt.write(original_cfg);
|
||||
boost::sregex_iterator m(formula_str.begin(), formula_str.end(), fai_identifier);
|
||||
BOOST_FOREACH(const boost::sregex_iterator::value_type& p, std::make_pair(m, boost::sregex_iterator())) {
|
||||
const std::string var_name = p.str();
|
||||
|
@ -1056,14 +1060,15 @@ void unit_type_data::set_config(config &cfg)
|
|||
if (mt == "id" || mt == "default" || movement_types_.find(mt) == movement_types_.end()) {
|
||||
continue;
|
||||
}
|
||||
patch_movetype(movement_types_[mt].get_resistances(), dmg_type, attr.second, 100);
|
||||
patch_movetype(movement_types_[mt].get_resistances(), dmg_type, attr.second, 100, true);
|
||||
}
|
||||
if (r.has_attribute("default")) {
|
||||
BOOST_FOREACH(movement_type_map::value_type &mt, movement_types_) {
|
||||
// Don't apply a default if a value is explicitly specified.
|
||||
if (r.has_attribute(mt.first)) {
|
||||
continue;
|
||||
}
|
||||
patch_movetype(mt.second.get_resistances(), dmg_type, r["default"], 100);
|
||||
patch_movetype(mt.second.get_resistances(), dmg_type, r["default"], 100, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1085,28 +1090,29 @@ void unit_type_data::set_config(config &cfg)
|
|||
continue;
|
||||
}
|
||||
if (tag == "defense") {
|
||||
patch_movetype(movement_types_[mt].get_defense(), ter_type, attr.second, 100);
|
||||
patch_movetype(movement_types_[mt].get_defense(), ter_type, attr.second, 100, true);
|
||||
} else if (tag == "vision") {
|
||||
patch_movetype(movement_types_[mt].get_vision(), ter_type, attr.second, 99);
|
||||
patch_movetype(movement_types_[mt].get_vision(), ter_type, attr.second, 99, true);
|
||||
} else if (tag == "movement") {
|
||||
patch_movetype(movement_types_[mt].get_movement(), ter_type, attr.second, 99);
|
||||
patch_movetype(movement_types_[mt].get_movement(), ter_type, attr.second, 99, true);
|
||||
} else if (tag == "jamming") {
|
||||
patch_movetype(movement_types_[mt].get_jamming(), ter_type, attr.second, 99);
|
||||
patch_movetype(movement_types_[mt].get_jamming(), ter_type, attr.second, 99, true);
|
||||
}
|
||||
}
|
||||
if (info.has_attribute("default")) {
|
||||
BOOST_FOREACH(movement_type_map::value_type &mt, movement_types_) {
|
||||
// Don't apply a default if a value is explicitly specified.
|
||||
if (info.has_attribute(mt.first)) {
|
||||
continue;
|
||||
}
|
||||
if (tag == "defense") {
|
||||
patch_movetype(mt.second.get_defense(), ter_type, info["default"], 100);
|
||||
patch_movetype(mt.second.get_defense(), ter_type, info["default"], 100, false);
|
||||
} else if (tag == "vision") {
|
||||
patch_movetype(mt.second.get_vision(), ter_type, info["default"], 99);
|
||||
patch_movetype(mt.second.get_vision(), ter_type, info["default"], 99, false);
|
||||
} else if (tag == "movement") {
|
||||
patch_movetype(mt.second.get_movement(), ter_type, info["default"], 99);
|
||||
patch_movetype(mt.second.get_movement(), ter_type, info["default"], 99, false);
|
||||
} else if (tag == "jamming") {
|
||||
patch_movetype(mt.second.get_jamming(), ter_type, info["default"], 99);
|
||||
patch_movetype(mt.second.get_jamming(), ter_type, info["default"], 99, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue