Author: sveinung
Date: Wed Aug 12 12:29:04 2015
New Revision: 29469

URL: http://svn.gna.org/viewcvs/freeciv?rev=29469&view=rev
Log:
Split the hard coded join and found city requirements from each other

Found City and Join City are different actions. Split their hard coded
requirements in two different functions.

See patch #6217

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

Modified: trunk/common/unit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.c?rev=29469&r1=29468&r2=29469&view=diff
==============================================================================
--- trunk/common/unit.c (original)
+++ trunk/common/unit.c Wed Aug 12 12:29:04 2015
@@ -354,7 +354,7 @@
 bool unit_can_add_to_city(const struct unit *punit)
 {
   return (unit_can_do_action(punit, ACTION_JOIN_CITY)
-          && (UAB_ADD_OK == unit_add_or_build_city_test(punit)));
+          && unit_join_city_test(punit) == UAB_ADD_OK);
 }
 
 /****************************************************************************
@@ -364,7 +364,7 @@
 bool unit_can_build_city(const struct unit *punit)
 {
   return (unit_can_do_action(punit, ACTION_FOUND_CITY)
-          && (UAB_BUILD_OK == unit_add_or_build_city_test(punit)));
+          && unit_build_city_test(punit) == UAB_BUILD_OK);
 }
 
 /****************************************************************************
@@ -373,32 +373,19 @@
 ****************************************************************************/
 bool unit_can_add_or_build_city(const struct unit *punit)
 {
-  enum unit_add_build_city_result res;
-
-  if (!unit_can_do_action(punit, ACTION_FOUND_CITY)
-      && !unit_can_do_action(punit, ACTION_JOIN_CITY)) {
-    /* The unit can't ever do any of the actions. The current conditions
-     * don't matter. */
-    return FALSE;
-  }
-
-  res = unit_add_or_build_city_test(punit);
-
-  return (UAB_BUILD_OK == res || UAB_ADD_OK == res);
-}
-
-/****************************************************************************
-  See if the unit can add to an existing city or build a new city at
-  its current location, and return a 'result' value telling what is
-  allowed.
-****************************************************************************/
+  return unit_can_build_city(punit) || unit_can_add_to_city(punit);
+}
+
+/**************************************************************************
+  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_add_or_build_city_test(const struct unit *punit)
+unit_build_city_test(const struct unit *punit)
 {
   struct tile *ptile = unit_tile(punit);
   struct city *pcity = tile_city(ptile);
   bool is_build = unit_is_cityfounder(punit);
-  int new_pop;
 
   /* Test if we can build. */
   if (NULL == pcity) {
@@ -418,6 +405,27 @@
       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. */
+  }
+}
+
+/**************************************************************************
+  See if the unit can add to an existing city at its current location, and
+  return a 'result' value telling what is allowed.
+**************************************************************************/
+enum unit_add_build_city_result
+unit_join_city_test(const struct unit *punit)
+{
+  struct tile *ptile = unit_tile(punit);
+  struct city *pcity = tile_city(ptile);
+  int new_pop;
+
+  /* Test if we can build. */
+  if (NULL == pcity) {
+    /* No city to join. */
     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=29469&r1=29468&r2=29469&view=diff
==============================================================================
--- trunk/common/unit.h (original)
+++ trunk/common/unit.h Wed Aug 12 12:29:04 2015
@@ -309,7 +309,10 @@
 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_add_or_build_city_test(const struct unit *punit);
+unit_build_city_test(const struct unit *punit);
+enum unit_add_build_city_result
+unit_join_city_test(const struct unit *punit);
+
 bool kills_citizen_after_attack(const struct unit *punit);
 
 struct astring; /* Forward declaration. */

Modified: trunk/server/cityhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/cityhand.c?rev=29469&r1=29468&r2=29469&view=diff
==============================================================================
--- trunk/server/cityhand.c     (original)
+++ trunk/server/cityhand.c     Wed Aug 12 12:29:04 2015
@@ -74,7 +74,7 @@
     return;
   }
 
-  res = unit_add_or_build_city_test(punit);
+  res = unit_build_city_test(punit);
 
   switch (res) {
   case UAB_BUILD_OK:

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=29469&r1=29468&r2=29469&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Wed Aug 12 12:29:04 2015
@@ -1576,7 +1576,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_add_or_build_city_test(actor_unit));
+                                unit_join_city_test(actor_unit));
       } else {
         illegal_action(pplayer, actor_unit, action_type,
                        city_owner(pcity), NULL, pcity, NULL);
@@ -1622,7 +1622,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_add_or_build_city_test(actor_unit));
+                                unit_build_city_test(actor_unit));
       } else {
         illegal_action(pplayer, actor_unit, action_type,
                        NULL, target_tile, NULL, NULL);


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

Reply via email to