[[faction_from_recruit]]

- don't lock the faction if recruit= is set, except if
  faction_from_recruit=yes (it used to lock the faction in all cases).

- get the first best matching faction when choosing a faction from a criteria

PS: It's time to sleep, i'll document this and the existing
undocumented faction= feature tomorrow.

This gives some time to get a better name for this new
"faction_from_recruit" key - feel free to "fix" it in the meantime.
This commit is contained in:
Benoît Timbert 2008-05-18 00:40:26 +00:00
parent bfb88a8e01
commit 71fdce2ae2
2 changed files with 28 additions and 19 deletions

View file

@ -54,6 +54,7 @@
shroud=no
fog=yes
recruit="Peasant,Mage"
faction_from_recruit=yes
[/side]
[side]
@ -67,6 +68,7 @@
shroud=no
fog=yes
recruit="Peasant,Mage"
faction_from_recruit=yes
[/side]
[side]
@ -80,6 +82,7 @@
shroud=no
fog=yes
recruit="Peasant,Mage"
faction_from_recruit=yes
[/side]
[side]
@ -93,6 +96,7 @@
shroud=no
fog=yes
recruit="Peasant,Mage"
faction_from_recruit=yes
[/side]
# AI

View file

@ -265,7 +265,7 @@ connect::side::side(connect& parent, const config& cfg, int index) :
// Choose based on faction
find.push_back(cfg_["faction"]);
search_field = "id";
} else if(!cfg_.get_attribute("recruit").empty()) {
} else if(utils::string_bool(cfg["faction_from_recruit"]) && !cfg_.get_attribute("recruit").empty()) {
// Choose based on recruit
find = utils::split(cfg_["recruit"]);
search_field = "recruit";
@ -275,30 +275,35 @@ connect::side::side(connect& parent, const config& cfg, int index) :
search_field = "leader";
}
std::vector<std::string>::const_iterator search = find.begin();
while(search != find.end()) {
int faction_index = 0;
std::vector<config*>::const_iterator faction = parent.era_sides_.begin();
while(faction_ == 0 && faction != parent.era_sides_.end()) {
const config& side = (**faction);
std::vector<std::string> recruit;
recruit = utils::split(side[search_field]);
int faction_index = 0;
int best_score = 0;
std::vector<config*>::const_iterator faction = parent.era_sides_.begin();
while(faction != parent.era_sides_.end()) {
int faction_score = 0;
const config& side = (**faction);
std::vector<std::string> recruit;
recruit = utils::split(side[search_field]);
std::vector<std::string>::const_iterator search = find.begin();
while(search != find.end()) {
for(itor = recruit.begin(); itor != recruit.end(); ++itor) {
if(*itor == *search) {
faction_ = faction_index;
llm_.update_leader_list(faction_);
llm_.update_gender_list(llm_.get_leader());
combo_faction_.enable(false);
faction_score++;
break;
}
}
++faction;
faction_index++;
++search;
}
// Exit outmost loop if we've found a faction
if(!combo_faction_.enabled()) {
break;
if(faction_score > best_score) {
best_score = faction_score;
faction_ = faction_index;
}
++search;
++faction;
faction_index++;
}
if (faction_) {
llm_.update_leader_list(faction_);
llm_.update_gender_list(llm_.get_leader());
combo_faction_.enable(false);
}
} else {
combo_faction_.enable(false);