Author: sveinung
Date: Mon Dec 21 02:58:49 2015
New Revision: 31127

URL: http://svn.gna.org/viewcvs/freeciv?rev=31127&view=rev
Log:
Action not enabled explain city size limits

Explain when an action can't be performed because it would make a city grow
beyond its city size limits. Use it to replace UAB_NO_SPACE.

See patch #6696

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

Modified: trunk/common/actions.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.c?rev=31127&r1=31126&r2=31127&view=diff
==============================================================================
--- trunk/common/actions.c      (original)
+++ trunk/common/actions.c      Mon Dec 21 02:58:49 2015
@@ -1212,6 +1212,16 @@
       return TRI_NO;
     }
 
+    if (!city_can_grow_to(target_city, new_pop)) {
+      /* Reason: respect city size limits. */
+      /* Info leak: when it is legal to join a foreign city is legal and
+       * the EFT_SIZE_UNLIMIT effect or the EFT_SIZE_ADJ effect depends on
+       * something the actor player don't have access to.
+       * Example: depends on a building (like Aqueduct) that isn't
+       * VisibleByOthers. */
+      return TRI_NO;
+    }
+
     /* TODO: Move more individual requirements to the action enabler. */
     if (!unit_can_add_to_city(actor_unit, target_city)) {
       return TRI_NO;

Modified: trunk/common/unit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.c?rev=31127&r1=31126&r2=31127&view=diff
==============================================================================
--- trunk/common/unit.c (original)
+++ trunk/common/unit.c Mon Dec 21 02:58:49 2015
@@ -405,8 +405,6 @@
 enum unit_add_build_city_result
 unit_join_city_test(const struct unit *punit, const struct city *pcity)
 {
-  int new_pop;
-
   /* Test if we can build. */
   if (NULL == pcity) {
     /* No city to join. */
@@ -414,11 +412,7 @@
   }
 
   fc_assert(unit_pop_value(punit) > 0);
-  new_pop = city_size_get(pcity) + unit_pop_value(punit);
-
-  if (!city_can_grow_to(pcity, new_pop)) {
-    return UAB_NO_SPACE;
-  }
+
   return UAB_ADD_OK;
 }
 

Modified: trunk/common/unit.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.h?rev=31127&r1=31126&r2=31127&view=diff
==============================================================================
--- trunk/common/unit.h (original)
+++ trunk/common/unit.h Mon Dec 21 02:58:49 2015
@@ -61,7 +61,6 @@
   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'. */
-  UAB_NO_SPACE          /* Adding takes city past limit. */
 };
 
 enum unit_upgrade_result {

Modified: trunk/server/cityhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/cityhand.c?rev=31127&r1=31126&r2=31127&view=diff
==============================================================================
--- trunk/server/cityhand.c     (original)
+++ trunk/server/cityhand.c     Mon Dec 21 02:58:49 2015
@@ -89,7 +89,6 @@
     break;
 
   case UAB_ADD_OK:
-  case UAB_NO_SPACE:
     log_verbose("handle_city_name_suggest_req(unit_pos (%d, %d)): "
                 "there is already a city there.", TILE_XY(unit_tile(punit)));
     /* Ignoring. */

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=31127&r1=31126&r2=31127&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Mon Dec 21 02:58:49 2015
@@ -102,6 +102,8 @@
   ANEK_SCENARIO_DISABLED,
   /* Explanation: the target city is too big. */
   ANEK_CITY_TOO_BIG,
+  /* Explanation: the target city's population limit banned the action. */
+  ANEK_CITY_POP_LIMIT,
   /* Explanation: the action is blocked by another action. */
   ANEK_ACTION_BLOCKS,
   /* Explanation not detected. */
@@ -773,6 +775,14 @@
     /* TODO: Check max city size requirements from action enabler target
      * vectors. */
     expl->kind = ANEK_CITY_TOO_BIG;
+  } else if (target_city
+             && (action_id == ACTION_JOIN_CITY
+                 && action_actor_utype_hard_reqs_ok(ACTION_JOIN_CITY,
+                                                    unit_type_get(punit))
+                 && (!city_can_grow_to(target_city,
+                                       city_size_get(target_city)
+                                       + unit_pop_value(punit))))) {
+    expl->kind = ANEK_CITY_POP_LIMIT;
   } else if ((game.scenario.prevent_new_cities
               && utype_can_do_action(unit_type_get(punit), ACTION_FOUND_CITY))
              && (action_id == ACTION_FOUND_CITY
@@ -876,6 +886,14 @@
                   _("%s can't do anything to %s. It is too big."),
                   unit_name_translation(punit),
                   city_name(target_city));
+    break;
+  case ANEK_CITY_POP_LIMIT:
+    notify_player(pplayer, unit_tile(punit), E_BAD_COMMAND, ftc_server,
+                  /* TRANS: London ... Settlers */
+                  _("%s needs an improvement to grow, so "
+                    "%s cannot do anything to it."),
+                  city_name(target_city),
+                  unit_name_translation(punit));
     break;
   case ANEK_ACTION_BLOCKS:
     /* If an action blocked another action the blocking action must be
@@ -1203,6 +1221,16 @@
                   gen_action_translated_name(stopped_action),
                   city_name(target_city));
     break;
+  case ANEK_CITY_POP_LIMIT:
+    notify_player(pplayer, unit_tile(actor),
+                  event, ftc_server,
+                  /* TRANS: London ... Settlers ... Join City */
+                  _("%s needs an improvement to grow, so "
+                    "%s cannot do %s."),
+                  city_name(target_city),
+                  unit_name_translation(actor),
+                  gen_action_translated_name(stopped_action));
+    break;
   case ANEK_ACTION_BLOCKS:
     notify_player(pplayer, unit_tile(actor),
                   event, ftc_server,
@@ -2093,12 +2121,6 @@
     notify_player(pplayer, ptile, E_BAD_COMMAND, ftc_server,
                   _("Can't place a city there because another city is too "
                     "close."));
-    break;
-  case UAB_NO_SPACE:
-    notify_player(pplayer, ptile, E_BAD_COMMAND, ftc_server,
-                  _("%s needs an improvement to grow, so "
-                    "you cannot add %s."),
-                  city_link(pcity), unit_link(punit));
     break;
   case UAB_BUILD_OK:
     /* No action enabler allowed building the city. Happens when called


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

Reply via email to