Author: sveinung
Date: Mon Jan  4 01:03:56 2016
New Revision: 31341

URL: http://svn.gna.org/viewcvs/freeciv?rev=31341&view=rev
Log:
Remove the function unit_build_city_test().

It checked that the target tile didn't have a city. Move this to
unit_can_build_city().

It mapped from city_build_here_test()'s enum city_build_result result to a
enum unit_add_build_city_result. The enum city_build_result covers
everything unit_add_build_city_result is used for. Remove it. Have
unit_build_city_test()'s users call city_build_here_test() directly. Have
them handle its enum city_build_result return value.

See patch #6768

Modified:
    trunk/common/unit.c
    trunk/common/unit.h
    trunk/server/cityhand.c
    trunk/server/unithand.c
    trunk/server/unithand.h

Modified: trunk/common/unit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.c?rev=31341&r1=31340&r2=31341&view=diff
==============================================================================
--- trunk/common/unit.c (original)
+++ trunk/common/unit.c Mon Jan  4 01:03:56 2016
@@ -339,7 +339,8 @@
 {
   return (unit_can_do_action(punit, ACTION_FOUND_CITY)
           && !game.scenario.prevent_new_cities
-          && unit_build_city_test(punit) == UAB_BUILD_OK);
+          && !tile_city(unit_tile(punit))
+          && city_build_here_test(unit_tile(punit), punit) == CB_OK);
 }
 
 /****************************************************************************
@@ -353,38 +354,6 @@
   return (unit_can_build_city(punit)
           || ((tgt_city = tile_city(unit_tile(punit)))
               && unit_can_do_action(punit, ACTION_JOIN_CITY)));
-}
-
-/**************************************************************************
-  See if the unit can build a new city at its current location, and return
-  a 'result' value telling what is allowed.
-**************************************************************************/
-enum unit_add_build_city_result
-unit_build_city_test(const struct unit *punit)
-{
-  struct tile *ptile = unit_tile(punit);
-  struct city *pcity = tile_city(ptile);
-
-  /* Test if we can build. */
-  if (NULL == pcity) {
-    switch (city_build_here_test(ptile, punit)) {
-    case CB_OK:
-      return UAB_BUILD_OK;
-    case CB_BAD_CITY_TERRAIN:
-      return UAB_BAD_CITY_TERRAIN;
-    case CB_BAD_UNIT_TERRAIN:
-      return UAB_BAD_UNIT_TERRAIN;
-    case CB_BAD_BORDERS:
-      return UAB_BAD_BORDERS;
-    case CB_NO_MIN_DIST:
-      return UAB_NO_MIN_DIST;
-    }
-    log_error("%s(): Internal error.", __FUNCTION__);
-    return UAB_BAD_CITY_TERRAIN; /* Returns something prohibitive. */
-  } else {
-    /* There is already a city here... */
-    return UAB_BAD_CITY_TERRAIN; /* Returns something prohibitive. */
-  }
 }
 
 /**************************************************************************

Modified: trunk/common/unit.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.h?rev=31341&r1=31340&r2=31341&view=diff
==============================================================================
--- trunk/common/unit.h (original)
+++ trunk/common/unit.h Mon Jan  4 01:03:56 2016
@@ -52,14 +52,6 @@
 
 enum goto_route_type {
   ROUTE_GOTO, ROUTE_PATROL
-};
-
-enum unit_add_build_city_result {
-  UAB_BUILD_OK,         /* Unit OK to build city. */
-  UAB_BAD_CITY_TERRAIN, /* Equivalent to 'CB_BAD_CITY_TERRAIN'. */
-  UAB_BAD_UNIT_TERRAIN, /* Equivalent to 'CB_BAD_UNIT_TERRAIN'. */
-  UAB_BAD_BORDERS,      /* Equivalent to 'CB_BAD_BORDERS'. */
-  UAB_NO_MIN_DIST,      /* Equivalent to 'CB_NO_MIN_DIST'. */
 };
 
 enum unit_upgrade_result {
@@ -312,8 +304,6 @@
 bool is_hiding_unit(const struct unit *punit);
 bool unit_can_build_city(const struct unit *punit);
 bool unit_can_add_or_build_city(const struct unit *punit);
-enum unit_add_build_city_result
-unit_build_city_test(const struct unit *punit);
 
 bool kills_citizen_after_attack(const struct unit *punit);
 

Modified: trunk/server/cityhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/cityhand.c?rev=31341&r1=31340&r2=31341&view=diff
==============================================================================
--- trunk/server/cityhand.c     (original)
+++ trunk/server/cityhand.c     Mon Jan  4 01:03:56 2016
@@ -54,7 +54,7 @@
 void handle_city_name_suggestion_req(struct player *pplayer, int unit_id)
 {
   struct unit *punit = player_unit_by_number(pplayer, unit_id);
-  enum unit_add_build_city_result res;
+  enum city_build_result res;
 
   if (NULL == punit) {
     /* Probably died or bribed. */
@@ -74,15 +74,15 @@
     return;
   }
 
-  res = unit_build_city_test(punit);
+  res = city_build_here_test(unit_tile(punit), punit);
 
   switch (res) {
-  case UAB_BUILD_OK:
+  case CB_OK:
     /* No action enabler permitted the city to be built. */
-  case UAB_BAD_CITY_TERRAIN:
-  case UAB_BAD_UNIT_TERRAIN:
-  case UAB_BAD_BORDERS:
-  case UAB_NO_MIN_DIST:
+  case CB_BAD_CITY_TERRAIN:
+  case CB_BAD_UNIT_TERRAIN:
+  case CB_BAD_BORDERS:
+  case CB_NO_MIN_DIST:
     log_verbose("handle_city_name_suggest_req(unit_pos (%d, %d)): "
                 "cannot build there.", TILE_XY(unit_tile(punit)));
     city_add_or_build_error(pplayer, punit, res);       /* Message. */

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=31341&r1=31340&r2=31341&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Mon Jan  4 01:03:56 2016
@@ -1918,7 +1918,7 @@
          *  - detailed explanation of why something is illegal. */
         /* TODO: improve explanation about why an action failed. */
         city_add_or_build_error(pplayer, actor_unit,
-                                unit_build_city_test(actor_unit));
+                                city_build_here_test(target_tile, actor_unit));
       } else {
         illegal_action(pplayer, actor_unit, action_type,
                        NULL, target_tile, NULL, NULL,
@@ -2129,35 +2129,35 @@
  consistency checking.
 **************************************************************************/
 void city_add_or_build_error(struct player *pplayer, struct unit *punit,
-                             enum unit_add_build_city_result res)
+                             enum city_build_result res)
 {
   /* Given that res came from unit_add_or_build_city_test(), pcity will
    * be non-null for all required status values. */
   struct tile *ptile = unit_tile(punit);
 
   switch (res) {
-  case UAB_BAD_CITY_TERRAIN:
+  case CB_BAD_CITY_TERRAIN:
     notify_player(pplayer, ptile, E_BAD_COMMAND, ftc_server,
                   /* TRANS: <tile-terrain>. */
                   _("Can't build a city on %s."),
                   terrain_name_translation(tile_terrain(ptile)));
     break;
-  case UAB_BAD_UNIT_TERRAIN:
+  case CB_BAD_UNIT_TERRAIN:
     notify_player(pplayer, ptile, E_BAD_COMMAND, ftc_server,
                   /* TRANS: <unit> ... <tile-terrain>. */
                   _("%s can't build a city on %s."), unit_link(punit),
                   terrain_name_translation(tile_terrain(ptile)));
     break;
-  case UAB_BAD_BORDERS:
+  case CB_BAD_BORDERS:
     notify_player(pplayer, ptile, E_BAD_COMMAND, ftc_server,
                   _("Can't place a city inside foreigner borders."));
     break;
-  case UAB_NO_MIN_DIST:
+  case CB_NO_MIN_DIST:
     notify_player(pplayer, ptile, E_BAD_COMMAND, ftc_server,
                   _("Can't place a city there because another city is too "
                     "close."));
     break;
-  case UAB_BUILD_OK:
+  case CB_OK:
     /* No action enabler allowed building the city. Happens when called
      * from handle_city_name_suggestion_req() because no enabler allowed
      * city founding. */

Modified: trunk/server/unithand.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.h?rev=31341&r1=31340&r2=31341&view=diff
==============================================================================
--- trunk/server/unithand.h     (original)
+++ trunk/server/unithand.h     Mon Jan  4 01:03:56 2016
@@ -28,7 +28,7 @@
                         bool igzoc, bool move_diplomat_city);
 
 void city_add_or_build_error(struct player *pplayer, struct unit *punit,
-                             enum unit_add_build_city_result res);
+                             enum city_build_result res);
 
 bool unit_perform_action(struct player *pplayer,
                          const int actor_id,


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

Reply via email to