Author: sveinung
Date: Wed Oct  7 14:52:34 2015
New Revision: 30024

URL: http://svn.gna.org/viewcvs/freeciv?rev=30024&view=rev
Log:
Prepare to let more actions block disband

Prepare the code responsible for reporting that disband is impossible
because an action blocks it for letting other actions than Help Wonder block
it.

See patch #6391

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

Modified: trunk/common/actions.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.c?rev=30024&r1=30023&r2=30024&view=diff
==============================================================================
--- trunk/common/actions.c      (original)
+++ trunk/common/actions.c      Wed Oct  7 14:52:34 2015
@@ -669,41 +669,63 @@
 }
 
 /**************************************************************************
-  Returns TRUE iff an action that blocks regular disband is forced and
-  possible.
-
-  TODO: Make regular disband action enabler controlled and delete this
-  function.
-**************************************************************************/
-bool action_blocks_disband(const struct unit *actor_unit)
-{
-  struct city *target_city;
-
-  /* Hard code that Help Wonder blocks regular disband. This must be done
+  Returns TRUE iff Help Wonder blocks
+**************************************************************************/
+static bool help_wonder_blocks(const struct unit *actor_unit,
+                               const struct city *target_city)
+{
+  /* Hard code that Help Wonder blocks Recycle Unit. This must be done
    * because caravan_shields makes it possible to avoid the consequences of
-   * choosing to disband a unit rather than having it do Help Wonder.
+   * choosing to do Recycle Unit rather than having it do Help Wonder.
    *
-   * Explanation: Disband Unit adds 50% of the shields used to produce the
+   * Explanation: Recycle Unit adds 50% of the shields used to produce the
    * unit to the production of the city where it is located. Help Wonder
-   * adds 100%. If a unit that can do Help Wonder is disbanded in a city
+   * adds 100%. If a unit that can do Help Wonder is recycled in a city
    * and the production later is changed to something that can receive help
    * from Help Wonder the remaining 50% of the shields are added. This can
    * be done because the city remembers them in caravan_shields.
    *
-   * If a unit that can do Help Wonder intentionally is disbanded rather
+   * If a unit that can do Help Wonder intentionally is recycled rather
    * than making it do Help Wonder its shields will still be remembered.
    * The target city that got 50% of the shields can therefore get 100% of
    * them by changing its production. This trick makes the ability to
-   * select disbanding when Help Wonder is legal pointless. */
-  target_city = tile_city(unit_tile(actor_unit));
-
-  if (target_city == NULL) {
-    /* No city to do Help Wonder to. */
-    return FALSE;
-  }
+   * select Recycle Unit when Help Wonder is legal pointless. */
 
   return is_action_enabled_unit_on_city(ACTION_HELP_WONDER,
                                         actor_unit, target_city);
+}
+
+/**************************************************************************
+  Returns the action that blocks regular regular disband or NULL if
+  disband isn't blocked.
+
+  An action that can block disband blocks disband when it is forced and
+  possible.
+
+  TODO: Make regular disband action enabler controlled and delete this
+  function.
+**************************************************************************/
+struct action *action_blocks_disband(const struct unit *actor_unit)
+{
+  struct city *target_city;
+
+  /* Only a city at the current tile would have received production help
+   * from Help Wonder disband or Recycle Unit disband. */
+  target_city = tile_city(unit_tile(actor_unit));
+
+  if (target_city == NULL) {
+    /* No city to do Help Wonder or Recycle Unit to. */
+    return NULL;
+  }
+
+  if (help_wonder_blocks(actor_unit, target_city)) {
+    /* Help Wonder is possible.
+     * Freeciv forbids regular disband when it is. */
+    return action_by_number(ACTION_HELP_WONDER);
+  }
+
+  /* Nothing is blocking disbanding the unit. */
+  return NULL;
 }
 
 /**************************************************************************

Modified: trunk/common/actions.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.h?rev=30024&r1=30023&r2=30024&view=diff
==============================================================================
--- trunk/common/actions.h      (original)
+++ trunk/common/actions.h      Wed Oct  7 14:52:34 2015
@@ -240,7 +240,7 @@
 
 struct action *action_blocks_attack(const struct unit *actor_unit,
                                     const struct tile *target_tile);
-bool action_blocks_disband(const struct unit *actor_unit);
+struct action *action_blocks_disband(const struct unit *actor_unit);
 
 bool is_action_enabled_unit_on_city(const enum gen_action wanted_action,
                                     const struct unit *actor_unit,

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=30024&r1=30023&r2=30024&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Wed Oct  7 14:52:34 2015
@@ -1915,6 +1915,7 @@
 void handle_unit_disband(struct player *pplayer, int unit_id)
 {
   struct city *pcity;
+  struct action *blocker;
   struct unit *punit = player_unit_by_number(pplayer, unit_id);
 
   if (NULL == punit) {
@@ -1932,13 +1933,13 @@
     return;
   }
 
-  if (action_blocks_disband(punit)) {
+  if ((blocker = action_blocks_disband(punit))) {
     /* Disband is blocked by the fact that another action is legal. */
     notify_player(unit_owner(punit), unit_tile(punit),
                   E_BAD_COMMAND, ftc_server,
                   /* TRANS: ... Help Wonder ... */
                   _("Regular disband not allowed. Try %s in stead."),
-                  action_get_ui_name(ACTION_HELP_WONDER));
+                  action_get_ui_name(blocker->id));
     return;
   }
 


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

Reply via email to