Author: noyga
Date: Sun May 18 02:40:26 2008
New Revision: 26679

URL: http://svn.gna.org/viewcvs/wesnoth?rev=26679&view=rev
Log:
- 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.

Modified:
    trunk/data/multiplayer/scenarios/4p_A_New_Land.cfg
    trunk/src/multiplayer_connect.cpp

Modified: trunk/data/multiplayer/scenarios/4p_A_New_Land.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/multiplayer/scenarios/4p_A_New_Land.cfg?rev=26679&r1=26678&r2=26679&view=diff
==============================================================================
--- trunk/data/multiplayer/scenarios/4p_A_New_Land.cfg (original)
+++ trunk/data/multiplayer/scenarios/4p_A_New_Land.cfg Sun May 18 02:40:26 2008
@@ -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

Modified: trunk/src/multiplayer_connect.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/multiplayer_connect.cpp?rev=26679&r1=26678&r2=26679&view=diff
==============================================================================
--- trunk/src/multiplayer_connect.cpp (original)
+++ trunk/src/multiplayer_connect.cpp Sun May 18 02:40:26 2008
@@ -265,7 +265,7 @@
                                // 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 @@
                                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);


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to