improve SUF greatly

This commit is contained in:
Jérémy Rosen 2006-11-19 12:45:31 +00:00
parent 8c95b17a36
commit 1907efea54
4 changed files with 62 additions and 23 deletions

View file

@ -43,6 +43,8 @@ Version 1.3-svn:
* WML engine
* added prerecruit event that takes place after the unit is created but before it is displayed.
* added ability to define color ranges and palettes in scenario, units, and unit modification effects. Added ability to add image modifications in a unit modification [effect] tag
* SUF can now filter on anything that is also available throught unit
variables
* overhaul of team coloring engine. Now possible to apply multiple TC to an image.
* added fourth color in team_rgb definitions for representative color in minimap
* added a 'hide_help' key that prevents a unit type from being listed in the

View file

@ -570,6 +570,34 @@ config config::merge_with(const config& c) const
return n;
}
bool config::matches(const config &filter) const
{
// first match values. all values should match
for(string_map::const_iterator j = filter.values.begin(); j != filter.values.end(); ++j) {
if(!this->values.count(j->first)) return false;
if(this->values.find(j->first)->second != j->second) return false;
}
//now, match the kids
for(all_children_iterator i = filter.ordered_begin(); i != filter.ordered_end(); ++i) {
if(*(*i).first == "not") continue;
child_list interesting_children = get_children(*(*i).first);
bool found = false;
for(child_list::iterator j = interesting_children.begin(); j != interesting_children.end(); ++j) {
if((*j)->matches(*(*i).second)) {
found = true;
}
}
if(!found) return false;
}
child_list negative_children = filter.get_children("not");
for(child_list::iterator j = negative_children.begin() ; j != negative_children.end() ; j++) {
if(matches(**j)) return false;
}
return true;
}
void config::prune() {
string_map::iterator val = values.begin();
while(val != values.end()) {

View file

@ -125,6 +125,8 @@ public:
config merge_with(const config& c) const;
bool matches(const config &filter) const;
//removes keys with empty values
void prune();

View file

@ -883,11 +883,6 @@ bool unit::matches_filter(const config& cfg,const gamemap::location& loc,bool us
const std::string& ability = cfg["ability"];
const std::string& side = cfg["side"];
const std::string& weapon = cfg["has_weapon"];
const std::string& role = cfg["role"];
const std::string& race = cfg["race"];
const std::string& gender = cfg["gender"];
const std::string& canrecruit = cfg["canrecruit"];
const std::string& level = cfg["level"];
if(description.empty() == false && description != this->underlying_description()) {
return false;
@ -948,16 +943,7 @@ bool unit::matches_filter(const config& cfg,const gamemap::location& loc,bool us
}
}
if(race.empty() == false && race_->name() != race) {
return false;
}
if(gender.empty() == false) {
const unit_race::GENDER gender_type = gender == "female" ? unit_race::FEMALE : unit_race::MALE;
if(gender_type != this->gender()) {
return false;
}
}
if(side.empty() == false && this->side() != (unsigned)atoi(side.c_str()))
{
@ -988,16 +974,7 @@ bool unit::matches_filter(const config& cfg,const gamemap::location& loc,bool us
return false;
}
if(role.empty() == false && role_ != role) {
return false;
}
if (canrecruit.empty() == false && (canrecruit == "1") != can_recruit())
return false;
if(level.empty() == false && level_ != lexical_cast_default<int>(level,-1)) {
return false;
}
//if there are [not] tags below this tag, it means that the filter
//should not match if what is in the [not] tag does match
@ -1008,6 +985,36 @@ bool unit::matches_filter(const config& cfg,const gamemap::location& loc,bool us
}
}
// now start with the new WML based comparison
// if a key is in the unit and in the filter, they should match
// filter only => not for us
// unit only => not filtered
config unit_cfg;
write(unit_cfg);
for(string_map::const_iterator j = cfg.values.begin(); j != cfg.values.end(); ++j) {
if(!unit_cfg.values.count(j->first)) continue;
if(j->first == "x") continue;
if(j->first == "y") continue;
if(unit_cfg.values.find(j->first)->second != j->second) return false;
}
//now, match the kids, WML based
for(config::all_children_iterator i = cfg.ordered_begin(); i != cfg.ordered_end(); ++i) {
if(*(*i).first == "not") continue;
config::child_list interesting_children = unit_cfg.get_children(*(*i).first);
bool found = false;
if(interesting_children.empty()) continue;
for(config::child_list::iterator j = interesting_children.begin(); j != interesting_children.end(); ++j) {
if((*j)->matches(*(*i).second)) {
found = true;
}
}
if(!found) return false;
}
/*child_list negative_children = cfg.get_children("not");
for(child_list::iterator j = negative_children.begin() ; j != negative_children.end() ; j++) {
if(matches(**j)) return false;
}*/
return true;
}
void unit::add_overlay(const std::string& overlay)