Author: cazfi
Date: Fri Apr  8 15:48:56 2016
New Revision: 32326

URL: http://svn.gna.org/viewcvs/freeciv?rev=32326&view=rev
Log:
Do not give error message about AI settler being unable to build city when the 
reason is that there's
another one too close.

See bug #24094

Modified:
    branches/S2_5/ai/default/aisettler.c
    branches/S2_5/server/unithand.c
    branches/S2_5/server/unithand.h
    branches/S2_5/server/unittools.c

Modified: branches/S2_5/ai/default/aisettler.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/ai/default/aisettler.c?rev=32326&r1=32325&r2=32326&view=diff
==============================================================================
--- branches/S2_5/ai/default/aisettler.c        (original)
+++ branches/S2_5/ai/default/aisettler.c        Fri Apr  8 15:48:56 2016
@@ -1243,11 +1243,17 @@
               player_name(pplayer), TILE_XY(ptile));
     return FALSE;
   }
-  handle_unit_build_city(pplayer, punit->id,
-                         city_name_suggestion(pplayer, ptile));
+  if (!unit_build_city(pplayer, punit, city_name_suggestion(pplayer, ptile))) {
+    /* It's an error when unit_build_city() says that request was illegal to 
begin with. */
+    log_error("%s: Failed to build city at (%d, %d)",
+              player_name(pplayer), TILE_XY(ptile));
+    return FALSE;
+  }
+
   pcity = tile_city(ptile);
   if (!pcity) {
-    log_error("%s: Failed to build city at (%d, %d)",
+    /* Write just debug log when city building didn't success for acceptable 
reason. */
+    log_debug("%s: Failed to build city at (%d, %d)",
               player_name(pplayer), TILE_XY(ptile));
     return FALSE;
   }

Modified: branches/S2_5/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/unithand.c?rev=32326&r1=32325&r2=32326&view=diff
==============================================================================
--- branches/S2_5/server/unithand.c     (original)
+++ branches/S2_5/server/unithand.c     Fri Apr  8 15:48:56 2016
@@ -680,24 +680,24 @@
 }
 
 /**************************************************************************
-  Handle city building request. Can result in adding to existing city
-  also.
-**************************************************************************/
-void handle_unit_build_city(struct player *pplayer, int unit_id,
-                            const char *name)
+  Try to build city.
+  Return value tells if request was sane. It can be TRUE even if city
+  building failed, as long as the reason was not bad request.
+**************************************************************************/
+bool unit_build_city(struct player *pplayer, struct unit *punit,
+                     const char *name)
 {
   enum unit_add_build_city_result res;
-  struct unit *punit = player_unit_by_number(pplayer, unit_id);
 
   if (NULL == punit) {
     /* Probably died or bribed. */
-    log_verbose("handle_unit_build_city() invalid unit %d", unit_id);
-    return;
+    log_verbose("unit_build_city() invalid unit.");
+    return FALSE;
   }
 
   if (!unit_can_do_action_now(punit)) {
     /* Building a city not possible due to unitwaittime setting. */
-    return;
+    return FALSE;
   }
 
   res = unit_add_or_build_city_test(punit);
@@ -708,7 +708,22 @@
     city_add_unit(pplayer, punit);
   } else {
     city_add_or_build_error(pplayer, punit, res);
-  }
+    if (res != UAB_NO_MIN_DIST) {
+      return FALSE;
+    }
+  }
+
+  return TRUE;
+}
+
+/**************************************************************************
+  Handle city building request. Can result in adding to existing city
+  also.
+**************************************************************************/
+void handle_unit_build_city(struct player *pplayer, int unit_id,
+                            const char *name)
+{
+  unit_build_city(pplayer, player_unit_by_number(pplayer, unit_id), name);
 }
 
 /**************************************************************************

Modified: branches/S2_5/server/unithand.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/unithand.h?rev=32326&r1=32325&r2=32326&view=diff
==============================================================================
--- branches/S2_5/server/unithand.h     (original)
+++ branches/S2_5/server/unithand.h     Fri Apr  8 15:48:56 2016
@@ -13,8 +13,10 @@
 #ifndef FC__UNITHAND_H
 #define FC__UNITHAND_H
 
+/* common */
 #include "unit.h"
 
+/* server */
 #include "hand_gen.h"
 
 void unit_activity_handling(struct unit *punit,
@@ -27,6 +29,9 @@
 bool unit_move_handling(struct unit *punit, struct tile *pdesttile,
                         bool igzoc, bool move_diplomat_city);
 
+bool unit_build_city(struct player *pplayer, struct unit *punit,
+                     const char *name);
+
 void city_add_or_build_error(struct player *pplayer, struct unit *punit,
                              enum unit_add_build_city_result res);
 

Modified: branches/S2_5/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/unittools.c?rev=32326&r1=32325&r2=32326&view=diff
==============================================================================
--- branches/S2_5/server/unittools.c    (original)
+++ branches/S2_5/server/unittools.c    Fri Apr  8 15:48:56 2016
@@ -3944,8 +3944,8 @@
       }
       break;
     case ORDER_BUILD_CITY:
-      handle_unit_build_city(pplayer, unitid,
-                            city_name_suggestion(pplayer, unit_tile(punit)));
+      unit_build_city(pplayer, punit,
+                      city_name_suggestion(pplayer, unit_tile(punit)));
       log_debug("  building city");
       if (player_unit_by_number(pplayer, unitid)) {
        /* Build failed. */


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to