Author: esr
Date: Fri Sep 12 12:13:13 2008
New Revision: 29415

URL: http://svn.gna.org/viewcvs/wesnoth?rev=29415&view=rev
Log:
Add a FIXME comment describing a minor easy-coding bug in the AI
recruitment code.

Modified:
    trunk/src/ai.cpp

Modified: trunk/src/ai.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai.cpp?rev=29415&r1=29414&r2=29415&view=diff
==============================================================================
--- trunk/src/ai.cpp (original)
+++ trunk/src/ai.cpp Fri Sep 12 12:13:13 2008
@@ -1787,61 +1787,70 @@
        analyze_potential_recruit_movements();
        analyze_potential_recruit_combat();
 
-       size_t neutral_villages = 0;
-
-       // We recruit the initial allocation of scouts
-       // based on how many neutral villages there are
-       // that are closer to us than to other keeps.
-       const std::vector<location>& villages = map_.villages();
-       for(std::vector<location>::const_iterator v = villages.begin(); v != 
villages.end(); ++v) {
-               const int owner = village_owner(*v,teams_);
-               if(owner == -1) {
-                       const size_t distance = distance_between(start_pos,*v);
-
-                       bool closest = true;
-                       for(std::vector<team>::const_iterator i = 
teams_.begin(); i != teams_.end(); ++i) {
-                               const int index = i - teams_.begin() + 1;
-                               const gamemap::location& loc = 
map_.starting_position(index);
-                               if(loc != start_pos && distance_between(loc,*v) 
< distance) {
-                                       closest = false;
-                                       break;
+       // FIXME: This entire block of code should be conditionalized
+       // on a test for whether the recruitment list of the team contains
+       // any units with scout usage.  Otherwise, the AI will emit a spurious
+       // message beginning "Deprecated WML found: Trying to recruit a: scout 
+        // but no unit of that type (usage=) is available." on teams with no
+       // recruitment list and no scout-type units.  This happens, for example,
+       // when team Gore first recruits in NR:The Eastern Flank.
+       {
+               size_t neutral_villages = 0;
+
+               // We recruit the initial allocation of scouts
+               // based on how many neutral villages there are
+               // that are closer to us than to other keeps.
+               const std::vector<location>& villages = map_.villages();
+               for(std::vector<location>::const_iterator v = villages.begin(); 
v != villages.end(); ++v) {
+                       const int owner = village_owner(*v,teams_);
+                       if(owner == -1) {
+                               const size_t distance = 
distance_between(start_pos,*v);
+
+                               bool closest = true;
+                               for(std::vector<team>::const_iterator i = 
teams_.begin(); i != teams_.end(); ++i) {
+                                       const int index = i - teams_.begin() + 
1;
+                                       const gamemap::location& loc = 
map_.starting_position(index);
+                                       if(loc != start_pos && 
distance_between(loc,*v) < distance) {
+                                               closest = false;
+                                               break;
+                                       }
                                }
-                       }
-
-                       if(closest) {
-                               ++neutral_villages;
-                       }
-               }
-       }
-
-       // The villages per scout is for a two-side battle,
-       // accounting for all neutral villages on the map.
-       // We only look at villages closer to us, so we halve it,
-       // making us get twice as many scouts.
-       const int villages_per_scout = current_team().villages_per_scout()/2;
-
-       // Get scouts depending on how many neutral villages there are.
-       int scouts_wanted = villages_per_scout > 0 ? 
neutral_villages/villages_per_scout : 0;
-
-       LOG_AI << "scouts_wanted: " << neutral_villages << "/"
-               << villages_per_scout << " = " << scouts_wanted << "\n";
-
-       std::map<std::string,int> unit_types;
-
-       for(unit_map::const_iterator u = units_.begin(); u != units_.end(); 
++u) {
-               if(u->second.side() == team_num_) {
-                       ++unit_types[u->second.usage()];
-               }
-       }
-
-       LOG_AI << "we have " << unit_types["scout"] << " scouts already and we 
want "
-               << scouts_wanted << " in total\n";
-
-       while(unit_types["scout"] < scouts_wanted) {
-               if(recruit_usage("scout") == false)
-                       break;
-
-               ++unit_types["scout"];
+
+                               if(closest) {
+                                       ++neutral_villages;
+                               }
+                       }
+               }
+
+               // The villages per scout is for a two-side battle,
+               // accounting for all neutral villages on the map.
+               // We only look at villages closer to us, so we halve it,
+               // making us get twice as many scouts.
+               const int villages_per_scout = 
current_team().villages_per_scout()/2;
+
+               // Get scouts depending on how many neutral villages there are.
+               int scouts_wanted = villages_per_scout > 0 ? 
neutral_villages/villages_per_scout : 0;
+
+               LOG_AI << "scouts_wanted: " << neutral_villages << "/"
+                       << villages_per_scout << " = " << scouts_wanted << "\n";
+
+               std::map<std::string,int> unit_types;
+
+               for(unit_map::const_iterator u = units_.begin(); u != 
units_.end(); ++u) {
+                       if(u->second.side() == team_num_) {
+                               ++unit_types[u->second.usage()];
+                       }
+               }
+
+               LOG_AI << "we have " << unit_types["scout"] << " scouts already 
and we want "
+                       << scouts_wanted << " in total\n";
+
+               while(unit_types["scout"] < scouts_wanted) {
+                       if(recruit_usage("scout") == false)
+                               break;
+
+                       ++unit_types["scout"];
+               }
        }
 
        std::vector<std::string> options;


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

Reply via email to