Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] Re: (PR#12660) RFC Proposed Jenner patch
Home

[Freeciv-Dev] Re: (PR#12660) RFC Proposed Jenner patch

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#12660) RFC Proposed Jenner patch
From: "(Eddie Anderson)" <saywhat@xxxxxxxxxxxx>
Date: Sun, 27 Mar 2005 19:37:00 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12660 >

"Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx> wrote:
>
><URL: http://bugs.freeciv.org/Ticket/Display.html?id=12660 >
>
>The idea here may be workable.  But the patch has many problems.  The
>biggest thing is you should create a new server setting for this, not
>reuse the cityfactor setting which already means something else.  Also
>the patch is buggy and won't every allow a city to be founded AFAICT.

    My restricted city founding code *does* have a problem but I'm
not sure what it is.  It worked before I encapsulated it into a
function.  So I fixed that.

    (Obviously I don't understand how C functions work yet (because
the function that I created apparently was not doing it's job).
Maybe it wasn't even being called.  I don't know why.)

    So I reworked the code.  I scrapped the function and moved that
code back into the auto_settler_findwork function.  While I was at
it I put back the (admittedly crude) debugging stmts that I had used
(and added player name and year to each output line).  They helped
me to track the city and settler building (to show the code's effect
on the game).

    So here's a new version of the patch.  It's intended strictly
for testing (obviously).

    I ran an autogame with it.  It still completes successfully but
now the AI civs build as many cities as they are allowed to.  One
civ even conquered its way up to 12 cities (this was with cityfactor
= 6).

    As to creating a separate server variable for this, I'm all for
it (see my response to Benoit's comments).  But Per opposed it (when
I proposed this on the AI list a few weeks ago).

-Eddie

--- server/settlers.c.orig      Wed Mar 16 12:32:21 2005
+++ server/settlers.c   Sun Mar 27 20:35:54 2005
@@ -1033,6 +1033,8 @@
   enum unit_activity best_act;
   struct tile *best_tile = NULL;
   struct ai_data *ai = ai_data_get(pplayer);
+  bool player_has_max_cities;
+  int city_count;
 
   CHECK_UNIT(punit);
 
@@ -1048,10 +1050,30 @@
     struct tile *ptile = punit->goto_tile;
     int sanity = punit->id;
 
+    /* Count the cities that this player has. */
+    city_count = 0;
+    city_list_iterate(pplayer->cities, pcity) {
+      city_count++;
+    } city_list_iterate_end;
+
+    freelog(LOG_ERROR, "yr %d pl %s cc %d cf %d esm %d", game.year, 
+       pplayer->name, city_count, game.cityfactor,
+       get_gov_pplayer(pplayer)->empire_size_mod);
+
+    /* If that count meets or exceeds this limit, then return TRUE. */
+    if (city_count >= game.cityfactor 
+        + get_gov_pplayer(pplayer)->empire_size_mod) {
+      player_has_max_cities = TRUE;
+    } else {
+      player_has_max_cities = FALSE;
+    }
+
     /* Check that the mission is still possible.  If the tile has become
-     * unavailable or the player has been autotoggled, call it off. */
+     * unavailable, the player has been autotoggled, or the player already
+     * has the maximum number of buildable cities, then call it off. */
     if (!unit_owner(punit)->ai.control
-       || !city_can_be_built_here(ptile, punit)) {
+       || !city_can_be_built_here(ptile, punit)
+        || player_has_max_cities) {
       UNIT_LOG(LOG_SETTLER, punit, "city founding mission failed");
       ai_unit_new_role(punit, AIUNIT_NONE, NULL);
       set_unit_activity(punit, ACTIVITY_IDLE);
@@ -1436,6 +1458,9 @@
 {
   struct player *pplayer = city_owner(pcity);
   struct unit *virtualunit;
+  int city_count = 0;
+  int settlers_in_existence_count = 0;
+  int settlers_being_built_count = 0;
   Unit_Type_id unit_type = best_role_unit(pcity, F_CITIES); 
 
   if (unit_type == U_LAST) {
@@ -1443,6 +1468,38 @@
     return;
   }
 
+  /* Count the cities that this player has. 
+   * Also count how many of those cities are building a settler. */
+  city_list_iterate(pplayer->cities, pcity) {
+    city_count++;
+    if (unit_type_flag(pcity->currently_building, F_CITIES)) {
+      settlers_being_built_count++;
+    }
+  } city_list_iterate_end;
+
+  /* Count the settlers that this player has. */  
+  unit_list_iterate(pplayer->units, punit) {
+    if (unit_flag(punit, F_CITIES)) {
+      settlers_in_existence_count++;
+    }
+  } unit_list_iterate_end;
+  
+  freelog(LOG_ERROR, "yr %d pl %s cc %d siec %d sbbc %d cf %d esm %d", 
+     game.year, pplayer->name, city_count,
+     settlers_in_existence_count, settlers_being_built_count,
+     game.cityfactor, get_gov_pplayer(pplayer)->empire_size_mod);
+
+  /* If the total of cities, potential cities (i.e. settlers), and 
+   * potential settlers (i.e. settlers under construction), exceeds
+   * this limit then we don't want to build yet another settler 
+   * (because we won't be able to use it to build a city). */
+  if (city_count + settlers_in_existence_count 
+      + settlers_being_built_count >= game.cityfactor 
+      + get_gov_pplayer(pplayer)->empire_size_mod) {
+    pcity->ai.founder_want = 0;
+    return;
+  }
+      
   /* Create a localized "virtual" unit to do operations with. */
   virtualunit = create_unit_virtual(pplayer, pcity, unit_type, 0);
   virtualunit->tile = pcity->tile;

[Prev in Thread] Current Thread [Next in Thread]