Author: sveinung
Date: Fri Jun 10 12:25:24 2016
New Revision: 32818

URL: http://svn.gna.org/viewcvs/freeciv?rev=32818&view=rev
Log:
Make it possible to attack without questions.

When "Capture Units", "Bombard" and "Explode Nuclear" became action enabler
controlled they started popping up the action selection dialog. Some players
may find this annoying.

Introduce the new client setting popup_attack_actions. If disabled the
client will perform an attack action without popping up the action selection
dialog as long as it is the only interesting action that may be legal. The
current attack actions are "Capture Units", "Bombard" and "Explode Nuclear".
The only non interesting action is "Disband Unit".

See patch #7253

Modified:
    trunk/client/options.c
    trunk/client/options.h
    trunk/client/packhand.c

Modified: trunk/client/options.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/options.c?rev=32818&r1=32817&r2=32818&view=diff
==============================================================================
--- trunk/client/options.c      (original)
+++ trunk/client/options.c      Fri Jun 10 12:25:24 2016
@@ -119,6 +119,7 @@
   .ask_city_name = TRUE,
   .popup_new_cities = TRUE,
   .popup_actor_arrival = TRUE,
+  .popup_attack_actions = TRUE,
   .keyboardless_goto = TRUE,
   .enable_cursor_changes = TRUE,
   .separate_unit_selection = FALSE,
@@ -2187,6 +2188,14 @@
                      "route), 'b' (for building a wonder) or 'd' (for a "
                      "spy action) when the unit is in the city."),
                   COC_INTERFACE, GUI_STUB, TRUE, NULL),
+  GEN_BOOL_OPTION(popup_attack_actions, N_("Pop up attack questions"),
+                  N_("If this option is enabled, when a unit arrives at a "
+                     "target it can attack, a window will pop up asking "
+                     "which action should be performed even if an attack "
+                     "action is legal and no other interesting action are. "
+                     "This allows you to change you mind or to select an "
+                     "uninteresting action."),
+                  COC_INTERFACE, GUI_STUB, TRUE, NULL),
   GEN_BOOL_OPTION(enable_cursor_changes, N_("Enable cursor changing"),
                   N_("This option controls whether the client should "
                      "try to change the mouse cursor depending on what "

Modified: trunk/client/options.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/options.h?rev=32818&r1=32817&r2=32818&view=diff
==============================================================================
--- trunk/client/options.h      (original)
+++ trunk/client/options.h      Fri Jun 10 12:25:24 2016
@@ -140,6 +140,7 @@
   bool ask_city_name;
   bool popup_new_cities;
   bool popup_actor_arrival;
+  bool popup_attack_actions;
   bool update_city_text_in_refresh_tile;
   bool keyboardless_goto;
   bool enable_cursor_changes;

Modified: trunk/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/packhand.c?rev=32818&r1=32817&r2=32818&view=diff
==============================================================================
--- trunk/client/packhand.c     (original)
+++ trunk/client/packhand.c     Fri Jun 10 12:25:24 2016
@@ -4410,6 +4410,70 @@
 }
 
 /**************************************************************************
+  Returns a possibly legal attack action iff it is the only interesting
+  action that currently is legal.
+**************************************************************************/
+static enum gen_action auto_attack_act(const action_probability *act_prob)
+{
+  enum gen_action attack_action = ACTION_COUNT;
+
+  action_iterate(act) {
+    if (action_prob_possible(act_prob[act])) {
+      switch ((enum gen_action)act) {
+      case ACTION_DISBAND_UNIT:
+        /* Not interesting. */
+        break;
+      case ACTION_CAPTURE_UNITS:
+      case ACTION_BOMBARD:
+      case ACTION_NUKE:
+        /* An attack. */
+        if (attack_action == ACTION_COUNT) {
+          /* No previous attack action found. */
+          attack_action = act;
+        } else {
+          /* More than one legal attack action found. */
+          return ACTION_COUNT;
+        }
+        break;
+      case ACTION_ESTABLISH_EMBASSY:
+      case ACTION_SPY_INVESTIGATE_CITY:
+      case ACTION_SPY_POISON:
+      case ACTION_SPY_STEAL_GOLD:
+      case ACTION_SPY_SABOTAGE_CITY:
+      case ACTION_SPY_TARGETED_SABOTAGE_CITY:
+      case ACTION_SPY_STEAL_TECH:
+      case ACTION_SPY_TARGETED_STEAL_TECH:
+      case ACTION_SPY_INCITE_CITY:
+      case ACTION_TRADE_ROUTE:
+      case ACTION_MARKETPLACE:
+      case ACTION_HELP_WONDER:
+      case ACTION_SPY_BRIBE_UNIT:
+      case ACTION_SPY_SABOTAGE_UNIT:
+      case ACTION_FOUND_CITY:
+      case ACTION_JOIN_CITY:
+      case ACTION_STEAL_MAPS:
+      case ACTION_SPY_NUKE:
+      case ACTION_DESTROY_CITY:
+      case ACTION_EXPEL_UNIT:
+      case ACTION_RECYCLE_UNIT:
+      case ACTION_HOME_CITY:
+      case ACTION_UPGRADE_UNIT:
+      case ACTION_PARADROP:
+      case ACTION_AIRLIFT:
+        /* An intersting non attack action has been found. */
+        return ACTION_COUNT;
+        break;
+      case ACTION_COUNT:
+        fc_assert(act != ACTION_COUNT);
+        break;
+      }
+    }
+  } action_iterate_end;
+
+  return attack_action;
+}
+
+/**************************************************************************
   Handle reply to possible actions.
 
   Note that a reply to a foreground request (a reply where disturb_player
@@ -4442,10 +4506,38 @@
   if (valid && disturb_player) {
     /* The player can select an action and should be informed. */
 
-    /* Show the client specific action dialog */
-    popup_action_selection(actor_unit,
-                           target_city, target_unit, target_tile,
-                           act_prob);
+    enum gen_action auto_action;
+
+    if (gui_options.popup_attack_actions) {
+      /* Pop up the action selection dialog no matter what. */
+      auto_action = ACTION_COUNT;
+    } else {
+      /* Pop up the action selection dialog unless the only interesting
+       * action the unit may be able to do is an attack action. */
+      auto_action = auto_attack_act(act_prob);
+    }
+
+    if (auto_action != ACTION_COUNT) {
+      /* No interesting actions except a single attack action has been
+       * found. The player wants it performed without questions. */
+
+      /* Give the order. */
+      fc_assert(action_get_target_kind(auto_action) == ATK_TILE
+                || action_get_target_kind(auto_action) == ATK_UNITS);
+      request_do_action(auto_action,
+                        packet->actor_unit_id, packet->target_tile_id,
+                        0, "");
+
+      /* Clean up. */
+      action_selection_no_longer_in_progress(packet->actor_unit_id);
+      action_decision_clear_want(packet->actor_unit_id);
+      action_selection_next_in_focus(packet->actor_unit_id);
+    } else {
+      /* Show the client specific action dialog */
+      popup_action_selection(actor_unit,
+                             target_city, target_unit, target_tile,
+                             act_prob);
+    }
   } else if (disturb_player) {
     /* Nothing to do. */
     action_selection_no_longer_in_progress(packet->actor_unit_id);


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

Reply via email to