Author: sveinung
Date: Wed Aug 12 12:29:38 2015
New Revision: 29470

URL: http://svn.gna.org/viewcvs/freeciv?rev=29470&view=rev
Log:
Allow joining cities at the neighbor tile

This allows rulesets to let units join non allied cities.

See patch #6218

Modified:
    trunk/common/actions.c
    trunk/common/unit.c
    trunk/common/unit.h
    trunk/doc/README.actions
    trunk/fc_version
    trunk/server/unithand.c

Modified: trunk/common/actions.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.c?rev=29470&r1=29469&r2=29470&view=diff
==============================================================================
--- trunk/common/actions.c      (original)
+++ trunk/common/actions.c      Wed Aug 12 12:29:38 2015
@@ -709,15 +709,8 @@
   }
 
   if (wanted_action == ACTION_JOIN_CITY) {
-    /* Reason: The Freeciv code assumes that the migrant unit is located
-     * inside the city it is trying to join. */
-    /* Info leak: The actor player knows where his unit is. */
-    if (unit_tile(actor_unit) != target_tile) {
-      return FALSE;
-    }
-
     /* TODO: Move more individual requirements to the action enabler. */
-    if (!unit_can_add_to_city(actor_unit)) {
+    if (!unit_can_add_to_city(actor_unit, target_city)) {
       return FALSE;
     }
   }

Modified: trunk/common/unit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.c?rev=29470&r1=29469&r2=29470&view=diff
==============================================================================
--- trunk/common/unit.c (original)
+++ trunk/common/unit.c Wed Aug 12 12:29:38 2015
@@ -351,10 +351,11 @@
   Return TRUE iff this unit may be disbanded to add its pop_cost to a
   city at its current location.
 ****************************************************************************/
-bool unit_can_add_to_city(const struct unit *punit)
+bool unit_can_add_to_city(const struct unit *punit,
+                          const struct city *tgt_city)
 {
   return (unit_can_do_action(punit, ACTION_JOIN_CITY)
-          && unit_join_city_test(punit) == UAB_ADD_OK);
+          && unit_join_city_test(punit, tgt_city) == UAB_ADD_OK);
 }
 
 /****************************************************************************
@@ -373,7 +374,11 @@
 ****************************************************************************/
 bool unit_can_add_or_build_city(const struct unit *punit)
 {
-  return unit_can_build_city(punit) || unit_can_add_to_city(punit);
+  struct city *tgt_city;
+
+  return (unit_can_build_city(punit)
+          || ((tgt_city = tile_city(unit_tile(punit)))
+              && unit_can_add_to_city(punit, tgt_city)));
 }
 
 /**************************************************************************
@@ -417,10 +422,8 @@
   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);
+unit_join_city_test(const struct unit *punit, const struct city *pcity)
+{
   int new_pop;
 
   /* Test if we can build. */

Modified: trunk/common/unit.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.h?rev=29470&r1=29469&r2=29470&view=diff
==============================================================================
--- trunk/common/unit.h (original)
+++ trunk/common/unit.h Wed Aug 12 12:29:38 2015
@@ -305,13 +305,14 @@
                          const struct tile *ptile, bool omniscient);
 bool is_field_unit(const struct unit *punit);              /* ships+aero */
 bool is_hiding_unit(const struct unit *punit);
-bool unit_can_add_to_city(const struct unit *punit);
+bool unit_can_add_to_city(const struct unit *punit,
+                          const struct city *tgt_city);
 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);
 enum unit_add_build_city_result
-unit_join_city_test(const struct unit *punit);
+unit_join_city_test(const struct unit *punit, const struct city *pcity);
 
 bool kills_citizen_after_attack(const struct unit *punit);
 

Modified: trunk/doc/README.actions
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/doc/README.actions?rev=29470&r1=29469&r2=29470&view=diff
==============================================================================
--- trunk/doc/README.actions    (original)
+++ trunk/doc/README.actions    Wed Aug 12 12:29:38 2015
@@ -211,7 +211,7 @@
 "Join City" - Add the actor to the target city's population.
  * UI name can be set using ui_name_join_city
  * actor must have population to add (set in pop_cost)
- * actor must be on the same tile as the target.
+ * actor must be on the same tile as the target or on the tile next to it.
  * target city population must not become higher that the add_to_size_limit
    setting permits.
  * target must be able to grow to the size that adding the unit would

Modified: trunk/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=29470&r1=29469&r2=29470&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Wed Aug 12 12:29:38 2015
@@ -54,7 +54,7 @@
 #   - Avoid adding a new mandatory capability to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2015.Aug.12"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2015.Aug.12b"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=29470&r1=29469&r2=29470&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Wed Aug 12 12:29:38 2015
@@ -115,7 +115,8 @@
                            const struct tile *target_tile,
                            const struct city *target_city,
                            const struct unit *target_unit);
-static bool city_add_unit(struct player *pplayer, struct unit *punit);
+static bool city_add_unit(struct player *pplayer, struct unit *punit,
+                          struct city *pcity);
 static bool city_build(struct player *pplayer, struct unit *punit,
                        const char *name);
 static bool do_unit_establish_trade(struct player *pplayer,
@@ -1569,14 +1570,14 @@
                                          actor_unit, pcity)) {
         ACTION_STARTED_UNIT_CITY(action_type, actor_unit, pcity);
 
-        return city_add_unit(pplayer, actor_unit);
+        return city_add_unit(pplayer, actor_unit, pcity);
       } else if (unit_can_do_action(actor_unit, ACTION_JOIN_CITY)
-                 && !unit_can_add_to_city(actor_unit)) {
+                 && !unit_can_add_to_city(actor_unit, pcity)) {
         /* Keep the rules like they was before action enabler control:
          *  - detailed explanation of why something is illegal. */
         /* TODO: improve explanation about why an action failed. */
         city_add_or_build_error(pplayer, actor_unit,
-                                unit_join_city_test(actor_unit));
+                                unit_join_city_test(actor_unit, pcity));
       } else {
         illegal_action(pplayer, actor_unit, action_type,
                        city_owner(pcity), NULL, pcity, NULL);
@@ -1904,17 +1905,15 @@
 }
 
 /**************************************************************************
- This function assumes that there is a valid city at punit->(x,y) It
- should only be called after a call to a function like
- test_unit_add_or_build_city, which does the checking.
+  This function assumes that the target city is valid. It should only be
+  called after checking that the unit legally can join the target city.
 
   Returns TRUE iff action could be done, FALSE if it couldn't. Even if
   this returns TRUE, unit may have died during the action.
 **************************************************************************/
-static bool city_add_unit(struct player *pplayer, struct unit *punit)
-{
-  struct city *pcity = tile_city(unit_tile(punit));
-
+static bool city_add_unit(struct player *pplayer, struct unit *punit,
+                          struct city *pcity)
+{
   /* Sanity check: The actor is still alive. */
   if (!unit_alive(punit->id)) {
     return FALSE;


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

Reply via email to