mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-04 21:40:06 +00:00
[female] now inherits from [unit].
This commit is contained in:
parent
10a73c823f
commit
ec031db2f5
@ -527,6 +527,40 @@ void config::apply_diff(const config& diff)
|
||||
}
|
||||
}
|
||||
|
||||
config config::merge_with(const config& c) const
|
||||
{
|
||||
config n(*this);
|
||||
for(string_map::const_iterator i = c.values.begin(); i != c.values.end(); ++i) {
|
||||
n.values[i->first] = i->second;
|
||||
}
|
||||
const child_map& child_changes = c.all_children();
|
||||
child_map::const_iterator i;
|
||||
// std::map<std::string , size_t> index_map;
|
||||
for(i = child_changes.begin(); i != child_changes.end(); ++i) {
|
||||
// const size_t index = index_map[(*i).first]++;
|
||||
|
||||
size_t index = 0;
|
||||
for(const_child_iterator j = i->second.begin(); j != i->second.end(); ++j) {
|
||||
//const std::pair<const std::string*,const config*> item = *j;
|
||||
const config* item = *j;
|
||||
|
||||
if(i->first.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const child_map::iterator itor = n.children.find(i->first);
|
||||
//const child_map::iterator itor = children.find(*item.first);
|
||||
if(itor == children.end() || index >= itor->second.size()) {
|
||||
throw error("error in merge_with: could not find element '" + i->first + "'");
|
||||
}
|
||||
|
||||
*(itor->second[index]) = itor->second[index]->merge_with(*item);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
void config::reset_translation() const
|
||||
{
|
||||
for(string_map::const_iterator val = values.begin(); val != values.end(); ++val) {
|
||||
|
@ -119,7 +119,9 @@ public:
|
||||
config get_diff(const config& c) const;
|
||||
|
||||
void apply_diff(const config& diff); //throw error
|
||||
|
||||
|
||||
config merge_with(const config& c) const;
|
||||
|
||||
//append data from another config object to this one. attributes in the
|
||||
//latter config object will clobber attributes in this one.
|
||||
void append(const config& cfg);
|
||||
|
@ -615,6 +615,8 @@ unit_type::unit_type(const unit_type& o)
|
||||
}
|
||||
}
|
||||
|
||||
#include "serialization/binary_or_text.hpp"
|
||||
#include <fstream>
|
||||
|
||||
unit_type::unit_type(const config& cfg, const movement_type_map& mv_types,
|
||||
const race_map& races, const std::vector<config*>& traits)
|
||||
@ -630,12 +632,20 @@ unit_type::unit_type(const config& cfg, const movement_type_map& mv_types,
|
||||
|
||||
const config* const male_cfg = cfg.child("male");
|
||||
if(male_cfg != NULL) {
|
||||
gender_types_[unit_race::MALE] = new unit_type(*male_cfg,mv_types,races,traits);
|
||||
config m_cfg(cfg);
|
||||
m_cfg = m_cfg.merge_with(*male_cfg);
|
||||
m_cfg.clear_children("male");
|
||||
m_cfg.clear_children("female");
|
||||
gender_types_[unit_race::MALE] = new unit_type(m_cfg,mv_types,races,traits);
|
||||
}
|
||||
|
||||
const config* const female_cfg = cfg.child("female");
|
||||
if(female_cfg != NULL) {
|
||||
gender_types_[unit_race::FEMALE] = new unit_type(*female_cfg,mv_types,races,traits);
|
||||
config f_cfg(cfg);
|
||||
f_cfg = f_cfg.merge_with(*female_cfg);
|
||||
f_cfg.clear_children("male");
|
||||
f_cfg.clear_children("female");
|
||||
gender_types_[unit_race::FEMALE] = new unit_type(f_cfg,mv_types,races,traits);
|
||||
}
|
||||
|
||||
const std::vector<std::string> genders = utils::split(cfg["gender"]);
|
||||
|
@ -111,7 +111,7 @@ public:
|
||||
bool is_flying() const;
|
||||
|
||||
private:
|
||||
const config& cfg_;
|
||||
config cfg_;
|
||||
|
||||
mutable std::map<gamemap::TERRAIN,int> moveCosts_;
|
||||
mutable std::map<gamemap::TERRAIN,int> defenseMods_;
|
||||
@ -265,7 +265,7 @@ private:
|
||||
typedef std::map<std::string,unit_type*> variations_map;
|
||||
variations_map variations_;
|
||||
|
||||
const config& cfg_;
|
||||
config cfg_;
|
||||
|
||||
const unit_race* race_;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user