Author: sveinung
Date: Sun Mar 13 01:42:47 2016
New Revision: 32235

URL: http://svn.gna.org/viewcvs/freeciv?rev=32235&view=rev
Log:
"Home City" check action system integration.

Stop calling can_unit_change_homecity_to() from is_action_possible().

Move can_unit_change_homecity_to()'s hard requirements to
is_action_possible().

Start using action probability (meta knowledge + action enablers) in
can_unit_change_homecity_to() to find out if changing home city is legal.
This makes it able to consider the action enabler rules rather than just
the hard coded requirements.

See patch #7053

Modified:
    trunk/common/actions.c
    trunk/common/unit.c

Modified: trunk/common/actions.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.c?rev=32235&r1=32234&r2=32235&view=diff
==============================================================================
--- trunk/common/actions.c      (original)
+++ trunk/common/actions.c      Sun Mar 13 01:42:47 2016
@@ -1121,6 +1121,7 @@
     return TRI_NO;
   }
 
+  /* Info leak: The player knows where his unit is. */
   if (action_get_target_kind(wanted_action) != ATK_SELF) {
     if (!action_id_distance_accepted(wanted_action,
                                     real_map_distance(actor_tile,
@@ -1407,11 +1408,17 @@
   }
 
   if (wanted_action == ACTION_HOME_CITY) {
-    /* Reason: Keep the old rules. */
-    /* Info leak: The player knows if his own unit is homeless. The player
-     * knows where his unit is. The player knows his unit's current home
-     * city. */
-    if (!can_unit_change_homecity_to(actor_unit, target_city)) {
+    /* Reason: being homeless is a big benefit (no upkeep). */
+    /* Info leak: The player knows if his own unit is homeless. */
+    if (actor_unit->homecity <= 0) {
+      /* Don't home a homeless unit. */
+      return TRI_NO;
+    }
+
+    /* Reason: can't change to what is. */
+    /* Info leak: The player knows his unit's current home city. */
+    if (actor_unit->homecity == target_city->id) {
+      /* This is already the unit's home city. */
       return TRI_NO;
     }
   }

Modified: trunk/common/unit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.c?rev=32235&r1=32234&r2=32235&view=diff
==============================================================================
--- trunk/common/unit.c (original)
+++ trunk/common/unit.c Sun Mar 13 01:42:47 2016
@@ -363,18 +363,13 @@
 bool can_unit_change_homecity_to(const struct unit *punit,
                                 const struct city *pcity)
 {
-  struct city *acity = tile_city(unit_tile(punit));
-
-  /* Requirements to change homecity:
-   *
-   * 1. Homeless units can't change homecity (this is a feature since
-   *    being homeless is a big benefit).
-   * 2. The unit must be inside the city it is rehoming to.
-   * 3. You can't rehome to the current homecity. */
-  return (punit && pcity
-         && punit->homecity > 0
-          && acity
-         && punit->homecity != acity->id);
+  if (pcity == NULL) {
+    /* Can't change home city to a non existing city. */
+    return FALSE;
+  }
+
+  return action_prob_possible(action_prob_vs_city(punit, ACTION_HOME_CITY,
+                                                  pcity));
 }
 
 /**************************************************************************


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

Reply via email to