Author: sveinung
Date: Thu Aug 11 02:20:35 2016
New Revision: 33555

URL: http://svn.gna.org/viewcvs/freeciv?rev=33555&view=rev
Log:
Action not enabled explain actor tgt distance.

Explain when an action fails because the actor was too near or too far away
from the target.

See patch #7582

Modified:
    trunk/server/unithand.c

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=33555&r1=33554&r2=33555&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Thu Aug 11 02:20:35 2016
@@ -110,6 +110,10 @@
   ANEK_TGT_IS_CLAIMED,
   /* Explanation: can't be done to unclaimed target tiles. */
   ANEK_TGT_IS_UNCLAIMED,
+  /* Explanation: can't be done because target is too near. */
+  ANEK_DISTANCE_NEAR,
+  /* Explanation: can't be done because target is too far away. */
+  ANEK_DISTANCE_FAR,
   /* Explanation: actor can't reach unit at target. */
   ANEK_TGT_UNREACHABLE,
   /* Explanation: the action is disabled in this scenario. */
@@ -147,6 +151,9 @@
 
     /* The action that blocks the action. */
     struct action *blocker;
+
+    /* The required distance. */
+    int distance;
   };
 };
 
@@ -942,6 +949,34 @@
                                              CITYT_CLAIMED,
                                              FALSE)) {
     explnat->kind = ANEK_TGT_IS_UNCLAIMED;
+  } else if (action_id_is_valid(action_id) && punit
+             && ((target_tile
+                  && real_map_distance(unit_tile(punit), target_tile)
+                      > action_by_number(action_id)->max_distance)
+                 || (target_city
+                     && real_map_distance(unit_tile(punit),
+                                          city_tile(target_city))
+                        > action_by_number(action_id)->max_distance)
+                 || (target_unit
+                     && real_map_distance(unit_tile(punit),
+                                          unit_tile(target_unit))
+                        > action_by_number(action_id)->max_distance))) {
+    explnat->kind = ANEK_DISTANCE_FAR;
+    explnat->distance = action_by_number(action_id)->max_distance;
+  } else if (action_id_is_valid(action_id) && punit
+             && ((target_tile
+                  && real_map_distance(unit_tile(punit), target_tile)
+                      < action_by_number(action_id)->min_distance)
+                 || (target_city
+                     && real_map_distance(unit_tile(punit),
+                                          city_tile(target_city))
+                        < action_by_number(action_id)->min_distance)
+                 || (target_unit
+                     && real_map_distance(unit_tile(punit),
+                                          unit_tile(target_unit))
+                        < action_by_number(action_id)->min_distance))) {
+    explnat->kind = ANEK_DISTANCE_NEAR;
+    explnat->distance = action_by_number(action_id)->min_distance;
   } else if (target_city
              && (action_id == ACTION_JOIN_CITY
                  && action_actor_utype_hard_reqs_ok(ACTION_JOIN_CITY,
@@ -1122,6 +1157,14 @@
     notify_player(pplayer, unit_tile(punit), E_BAD_COMMAND, ftc_server,
                   _("This unit cannot act against unclaimed tiles."));
     break;
+  case ANEK_DISTANCE_NEAR:
+    notify_player(pplayer, unit_tile(punit), E_BAD_COMMAND, ftc_server,
+                  _("This unit is to near its target to act."));
+    break;
+  case ANEK_DISTANCE_FAR:
+    notify_player(pplayer, unit_tile(punit), E_BAD_COMMAND, ftc_server,
+                  _("This unit is to far away from its target to act."));
+    break;
   case ANEK_SCENARIO_DISABLED:
     notify_player(pplayer, unit_tile(punit), E_BAD_COMMAND, ftc_server,
                   _("Can't perform any action this scenario permits."));
@@ -1511,6 +1554,26 @@
                   event, ftc_server,
                   _("Your %s can't do %s to unclaimed tiles."),
                   unit_name_translation(actor),
+                  action_get_ui_name(stopped_action));
+    break;
+  case ANEK_DISTANCE_NEAR:
+    notify_player(pplayer, unit_tile(actor),
+                  event, ftc_server,
+                  PL_("Your %s must be at least %d tile away to do %s.",
+                      "Your %s must be at least %d tiles away to do %s.",
+                      explnat->distance),
+                  unit_name_translation(actor),
+                  explnat->distance,
+                  action_get_ui_name(stopped_action));
+    break;
+  case ANEK_DISTANCE_FAR:
+    notify_player(pplayer, unit_tile(actor),
+                  event, ftc_server,
+                  PL_("Your %s can't be more than %d tile away to do %s.",
+                      "Your %s can't be more than %d tiles away to do %s.",
+                      explnat->distance),
+                  unit_name_translation(actor),
+                  explnat->distance,
                   action_get_ui_name(stopped_action));
     break;
   case ANEK_SCENARIO_DISABLED:


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

Reply via email to