Author: sveinung
Date: Tue Dec 16 17:56:00 2014
New Revision: 27319

URL: http://svn.gna.org/viewcvs/freeciv?rev=27319&view=rev
Log:
Allow units that can do action enabler controlled actions to attack.

Creating a unit type that can do caravan actions but still attack was broken
when the caravan actions became action enabler controlled. The action enabler
move handling code evolved from the diplomat move handling code. The diplomat
move handling code was missing this feature. The fact that caravan actions had
it was forgotten.

Let unit types capable of doing action enabler controlled actions that also are
capable of attacking use their ability to attack. This adds the feature for
diplomat / spy actions and fixes it for caravan actions.

See bug #23077

Modified:
    trunk/client/gui-gtk-2.0/action_dialog.c
    trunk/client/gui-gtk-3.0/action_dialog.c
    trunk/client/gui-qt/dialogs.cpp
    trunk/client/gui-sdl2/action_dialog.c
    trunk/client/gui-xaw/action_dialog.c
    trunk/server/unithand.c

Modified: trunk/client/gui-gtk-2.0/action_dialog.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-2.0/action_dialog.c?rev=27319&r1=27318&r2=27319&view=diff
==============================================================================
--- trunk/client/gui-gtk-2.0/action_dialog.c    (original)
+++ trunk/client/gui-gtk-2.0/action_dialog.c    Tue Dec 16 17:56:00 2014
@@ -1161,7 +1161,10 @@
                NULL,
                data);
 
-  if (unit_can_move_to_tile(actor_unit, target_tile, FALSE)) {
+  if (unit_can_move_to_tile(actor_unit, target_tile, FALSE)
+      || (is_military_unit(actor_unit) || is_attack_unit(actor_unit))
+      || (can_unit_bombard(actor_unit) && !is_ocean_tile(target_tile))
+      || (!target_city && unit_has_type_flag(actor_unit, UTYF_CAPTURER))) {
     action_button_map[BUTTON_MOVE] =
         choice_dialog_get_number_of_buttons(shl);
     choice_dialog_add(shl, _("_Keep moving"),

Modified: trunk/client/gui-gtk-3.0/action_dialog.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.0/action_dialog.c?rev=27319&r1=27318&r2=27319&view=diff
==============================================================================
--- trunk/client/gui-gtk-3.0/action_dialog.c    (original)
+++ trunk/client/gui-gtk-3.0/action_dialog.c    Tue Dec 16 17:56:00 2014
@@ -1171,7 +1171,10 @@
                NULL,
                data);
 
-  if (unit_can_move_to_tile(actor_unit, target_tile, FALSE)) {
+  if (unit_can_move_to_tile(actor_unit, target_tile, FALSE)
+      || (is_military_unit(actor_unit) || is_attack_unit(actor_unit))
+      || (can_unit_bombard(actor_unit) && !is_ocean_tile(target_tile))
+      || (!target_city && unit_has_type_flag(actor_unit, UTYF_CAPTURER))) {
     action_button_map[BUTTON_MOVE] =
         choice_dialog_get_number_of_buttons(shl);
     choice_dialog_add(shl, _("_Keep moving"),

Modified: trunk/client/gui-qt/dialogs.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/dialogs.cpp?rev=27319&r1=27318&r2=27319&view=diff
==============================================================================
--- trunk/client/gui-qt/dialogs.cpp     (original)
+++ trunk/client/gui-qt/dialogs.cpp     Tue Dec 16 17:56:00 2014
@@ -1397,7 +1397,10 @@
                "",
                qv1, qv2);
 
-  if (unit_can_move_to_tile(actor_unit, target_tile, FALSE)) {
+  if (unit_can_move_to_tile(actor_unit, target_tile, FALSE)
+      || (is_military_unit(actor_unit) || is_attack_unit(actor_unit))
+      || (can_unit_bombard(actor_unit) && !is_ocean_tile(target_tile))
+      || (!target_city && unit_has_type_flag(actor_unit, UTYF_CAPTURER))) {
     qv2 = target_tile->index;
 
     func = diplomat_keep_moving;

Modified: trunk/client/gui-sdl2/action_dialog.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/action_dialog.c?rev=27319&r1=27318&r2=27319&view=diff
==============================================================================
--- trunk/client/gui-sdl2/action_dialog.c       (original)
+++ trunk/client/gui-sdl2/action_dialog.c       Tue Dec 16 17:56:00 2014
@@ -950,7 +950,10 @@
                pWindow, &area);
 
   /* ---------- */
-  if (unit_can_move_to_tile(actor_unit, target_tile, FALSE)) {
+  if (unit_can_move_to_tile(actor_unit, target_tile, FALSE)
+      || (is_military_unit(actor_unit) || is_attack_unit(actor_unit))
+      || (can_unit_bombard(actor_unit) && !is_ocean_tile(target_tile))
+      || (!target_city && unit_has_type_flag(actor_unit, UTYF_CAPTURER))) {
     create_active_iconlabel(pBuf, pWindow->dst, pStr,
                             _("Keep moving"),
                             diplomat_keep_moving_callback);

Modified: trunk/client/gui-xaw/action_dialog.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-xaw/action_dialog.c?rev=27319&r1=27318&r2=27319&view=diff
==============================================================================
--- trunk/client/gui-xaw/action_dialog.c        (original)
+++ trunk/client/gui-xaw/action_dialog.c        Tue Dec 16 17:56:00 2014
@@ -945,7 +945,11 @@
                ACTION_SPY_STEAL_GOLD,
                act_probs);
 
-  if (!unit_can_move_to_tile(actor_unit, target_tile, FALSE)) {
+  if (!(unit_can_move_to_tile(actor_unit, target_tile, FALSE)
+      || (is_military_unit(actor_unit) || is_attack_unit(actor_unit))
+      || (can_unit_bombard(actor_unit) && !is_ocean_tile(target_tile))
+      || (!target_city && unit_has_type_flag(actor_unit,
+                                             UTYF_CAPTURER)))) {
     XtSetSensitive(XtNameToWidget(diplomat_dialog, "*button14"), FALSE);
   }
 

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=27319&r1=27318&r2=27319&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Tue Dec 16 17:56:00 2014
@@ -207,6 +207,48 @@
 
 /**************************************************************************
   Returns TRUE iff, from the point of view of the owner of the actor unit,
+  it looks like the actor unit may be able to perform a non action
+  enabler controlled action against a unit or city on the target_tile by
+  "moving" to it.
+**************************************************************************/
+static bool may_non_act_move(struct unit *actor_unit,
+                             struct city *target_city,
+                             struct tile *target_tile,
+                             bool igzoc)
+{
+  if (unit_can_move_to_tile(actor_unit, target_tile, igzoc)) {
+    /* Move. Includes occupying a foreign city. */
+    return TRUE;
+  }
+
+  if (unit_attack_units_at_tile_result(actor_unit, target_tile)
+      == ATT_OK) {
+    /* Attack. Includes nuking. */
+    return TRUE;
+  }
+
+  if (!is_ocean_tile(target_tile) && can_unit_bombard(actor_unit)) {
+    /* Bombard. May be possible even if regular attack isn't. */
+    return TRUE;
+  }
+
+  if (!target_city && unit_has_type_flag(actor_unit, UTYF_CAPTURER)) {
+    /* Capture. May be possible even if regular attack isn't. */
+
+    unit_list_iterate(target_tile->units, to_capture) {
+      if (!unit_has_type_flag(to_capture, UTYF_CAPTURABLE)) {
+        return FALSE;
+      }
+    } unit_list_iterate_end;
+
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
+/**************************************************************************
+  Returns TRUE iff, from the point of view of the owner of the actor unit,
   it looks like the actor unit may be able to do any action to the target
   city.
 
@@ -693,7 +735,7 @@
     break;
   case ACTION_MOVE:
     if (target_tile
-        && unit_can_move_to_tile(actor_unit, target_tile, FALSE)) {
+        && may_non_act_move(actor_unit, pcity, target_tile, FALSE)) {
       (void) unit_move_handling(actor_unit, target_tile, FALSE, TRUE);
     }
     break;
@@ -1794,7 +1836,7 @@
 
     if ((0 < unit_list_size(pdesttile->units) || pcity)
         && !(move_diplomat_city
-             && unit_can_move_to_tile(punit, pdesttile, igzoc))) {
+             && may_non_act_move(punit, pcity, pdesttile, igzoc))) {
       /* A target (unit or city) exists at the tile. If a target is an ally
        * it still looks like a target since move_diplomat_city isn't set.
        * Assume that the intention is to do an action. */
@@ -1819,9 +1861,9 @@
                                                 punit->id,
                                                 pdesttile->index);
         return FALSE;
-      } else if (!unit_can_move_to_tile(punit, pdesttile, igzoc)) {
-        /* No action can be done. No regular move can be done. Try to
-         * explain it to the player. */
+      } else if (!may_non_act_move(punit, pcity, pdesttile, igzoc)) {
+        /* No action can be done. No regular move can be done. Attack isn't
+         * possible. Try to explain it to the player. */
         explain_why_no_action_enabled(punit);
 
         return FALSE;


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

Reply via email to