allow [variation] to inherit from the base [unit] by specifiying 'inherit=yes'
This commit is contained in:
parent
10434e1460
commit
d4ca0c4a58
2 changed files with 13 additions and 10 deletions
13
src/unit.cpp
13
src/unit.cpp
|
@ -1130,16 +1130,11 @@ void unit::write(config& cfg) const
|
|||
|
||||
cfg["facing"] = gamemap::location::write_direction(facing_);
|
||||
|
||||
char buf[50];
|
||||
snprintf(buf,sizeof(buf),"%d",goto_.x+1);
|
||||
cfg["goto_x"] = buf;
|
||||
snprintf(buf,sizeof(buf),"%d",goto_.y+1);
|
||||
cfg["goto_y"] = buf;
|
||||
cfg["goto_x"] = lexical_cast_default<std::string>(goto_.x+1);
|
||||
cfg["goto_y"] = lexical_cast_default<std::string>(goto_.y+1);
|
||||
|
||||
snprintf(buf,sizeof(buf),"%d",movement_);
|
||||
cfg["moves"] = buf;
|
||||
snprintf(buf,sizeof(buf),"%d",max_movement_b_);
|
||||
cfg["max_moves"] = buf;
|
||||
cfg["moves"] = lexical_cast_default<std::string>(movement_);
|
||||
cfg["max_moves"] = lexical_cast_default<std::string>(max_movement_b_);
|
||||
|
||||
cfg["resting"] = resting_ ? "yes" : "no";
|
||||
|
||||
|
|
|
@ -737,7 +737,15 @@ unit_type::unit_type(const config& cfg, const movement_type_map& mv_types,
|
|||
{
|
||||
const config::child_list& variations = cfg.get_children("variation");
|
||||
for(config::child_list::const_iterator var = variations.begin(); var != variations.end(); ++var) {
|
||||
variations_.insert(std::pair<std::string,unit_type*>((**var)["variation_name"],new unit_type(**var,mv_types,races,traits)));
|
||||
const config& var_cfg = **var;
|
||||
if(var_cfg["inherit"] == "yes") {
|
||||
config nvar_cfg = cfg;
|
||||
nvar_cfg = nvar_cfg.merge_with(var_cfg);
|
||||
nvar_cfg.clear_children("variation");
|
||||
variations_.insert(std::pair<std::string,unit_type*>(nvar_cfg["variation_name"],new unit_type(nvar_cfg,mv_types,races,traits)));
|
||||
} else {
|
||||
variations_.insert(std::pair<std::string,unit_type*>((**var)["variation_name"],new unit_type(**var,mv_types,races,traits)));
|
||||
}
|
||||
}
|
||||
|
||||
gender_types_[0] = NULL;
|
||||
|
|
Loading…
Add table
Reference in a new issue