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

 It is not an error that there is already an city when
ai_do_build_city() is called, altough it is very rare situation.
Instead of adding (costly) extra checks before calling
ai_do_build_city(), we do just fine relying in internal checks of
ai_do_build_city().

 This patch turns LOG_ERROR messages to LOG_DEBUG.

 Trunk version also enables (controlled) auto_settler_findwork()
recursion in this situation. Settler is better off seeking new work
immediately and not only next turn.


 - ML

diff -Nurd -X.diff_ignore freeciv/server/settlers.c freeciv/server/settlers.c
--- freeciv/server/settlers.c	2007-08-04 18:36:24.000000000 +0300
+++ freeciv/server/settlers.c	2007-08-08 04:38:09.000000000 +0300
@@ -87,7 +87,9 @@
 
   pcity = tile_get_city(ptile);
   if (pcity) {
-    freelog(LOG_ERROR, "%s: There is already a city at (%d, %d)!", 
+    /* This can happen for instance when there was hut at this tile
+     * and it turned in to a city when settler entered tile. */
+    freelog(LOG_DEBUG, "%s: There is already a city at (%d, %d)!", 
             pplayer->name, TILE_XY(ptile));
     return FALSE;
   }
@@ -991,10 +993,15 @@
       }
       if (same_pos(punit->tile, ptile)) {
         if (!ai_do_build_city(pplayer, punit)) {
-          UNIT_LOG(LOG_ERROR, punit, "could not make city on %s",
+          UNIT_LOG(LOG_DEBUG, punit, "could not make city on %s",
                    tile_get_info_text(punit->tile));
           ai_unit_new_role(punit, AIUNIT_NONE, NULL);
-          return; /* Avoid infinite recursion at all costs! */
+          /* Only known way to end in here is that hut turned in to a city
+           * when settler entered tile. So this is not going to lead in any
+           * serious recursion. */
+          auto_settler_findwork(pplayer, punit, state, recursion + 1);
+
+          return;
         } else {
           return; /* We came, we saw, we built... */
         }
diff -Nurd -X.diff_ignore freeciv/server/settlers.c freeciv/server/settlers.c
--- freeciv/server/settlers.c	2007-07-04 14:04:17.000000000 +0300
+++ freeciv/server/settlers.c	2007-08-08 04:39:50.000000000 +0300
@@ -84,7 +84,9 @@
 
   pcity = tile_get_city(ptile);
   if (pcity) {
-    freelog(LOG_ERROR, "%s: There is already a city at (%d, %d)!", 
+    /* This can happen for instance when there was hut at this tile
+     * and it turned in to a city when settler entered tile. */
+    freelog(LOG_DEBUG, "%s: There is already a city at (%d, %d)!", 
             pplayer->name, TILE_XY(ptile));
     return FALSE;
   }
@@ -1034,7 +1036,7 @@
       }
       if (same_pos(punit->tile, ptile)) {
         if (!ai_do_build_city(pplayer, punit)) {
-          UNIT_LOG(LOG_ERROR, punit, "could not make city on %s",
+          UNIT_LOG(LOG_DEBUG, punit, "could not make city on %s",
                    tile_get_info_text(punit->tile));
           ai_unit_new_role(punit, AIUNIT_NONE, NULL);
           return; /* Avoid infinite recursion at all costs! */
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to