Implementation of FR #10600:

Random factions can now be defined on a subset of the available non
random factions.

Works with two new keys :

- choices (empty by default) :

  If non empty it is the list of the factions that can be choosen
  randomly from this random faction.

  If empty all non random faction are allowed to be choosen randomly
  from this random faction.

- except (empty by default) :
  List of the factions that cannot be choosen randomly from this random faction.
This commit is contained in:
Benoît Timbert 2008-01-06 10:24:53 +00:00
parent 3591a0a5e7
commit e643e8d7ea
3 changed files with 48 additions and 5 deletions

View file

@ -33,6 +33,8 @@ Version 1.3.13+svn:
(bug #7252)
* it is now possible to play [sound] repeatedly using a "repeat" attribute
* Added boolean variable disallow_observers to side defination
* Random factions can be defined on a subset of the non-random faction
(FR #10600)
* miscellaneous and bug fixes:
* set the default resistance to 100 (no resistance) instead of 0 (immune)
(bug #10661)

View file

@ -610,12 +610,32 @@ bool game_controller::play_multiplayer_mode()
}
if ((*side)["random_faction"] == "yes") {
const config::child_list& eras = era_cfg->get_children("multiplayer_side");
for(unsigned int i = 0, j = 0; i < eras.size(); ++i) {
if ((*eras[i])["random_faction"] != "yes") {
const config::child_list& factions = era_cfg->get_children("multiplayer_side");
std::vector<std::string> faction_choices, faction_excepts;
faction_choices = utils::split((*side)["choices"]);
if(faction_choices.size() == 1 && faction_choices.front() == "") {
faction_choices.clear();
}
faction_excepts = utils::split((*side)["except"]);;
if(faction_excepts.size() == 1 && faction_excepts.front() == "") {
faction_excepts.clear();
}
for(unsigned int i = 0, j = 0; i < factions.size(); ++i) {
if ((*factions[i])["random_faction"] != "yes") {
const std::string& faction_id = (*factions[i])["id"];
if (
!faction_choices.empty() &&
std::find(faction_choices.begin(),faction_choices.end(),faction_id) == faction_choices.end()
)
continue;
if (
!faction_excepts.empty() &&
std::find(faction_excepts.begin(),faction_excepts.end(),faction_id) != faction_excepts.end()
)
continue;
j++;
if (rand()%j == 0) {
side = eras[i];
side = factions[i];
}
}
}

View file

@ -801,11 +801,32 @@ void connect::side::resolve_random()
(*parent_->era_sides_[faction_]).get_attribute("random_faction"),
false))
{
// Builds the list of sides which aren't random
std::vector<std::string> faction_choices, faction_excepts;
faction_choices = utils::split((*parent_->era_sides_[faction_]).get_attribute("choices"));
if(faction_choices.size() == 1 && faction_choices.front() == "") {
faction_choices.clear();
}
faction_excepts = utils::split((*parent_->era_sides_[faction_]).get_attribute("except"));
if(faction_excepts.size() == 1 && faction_excepts.front() == "") {
faction_excepts.clear();
}
// Builds the list of sides eligible for choice (nonrandom factions)
std::vector<int> nonrandom_sides;
for(config::child_iterator itor = parent_->era_sides_.begin();
itor != parent_->era_sides_.end(); ++itor) {
if((**itor)["random_faction"] != "yes") {
const std::string& faction_id = (**itor)["id"];
if (
!faction_choices.empty() &&
std::find(faction_choices.begin(),faction_choices.end(),faction_id) == faction_choices.end()
)
continue;
if (
!faction_excepts.empty() &&
std::find(faction_excepts.begin(),faction_excepts.end(),faction_id) != faction_excepts.end()
)
continue;
nonrandom_sides.push_back(itor - parent_->era_sides_.begin());
}
}