Author: sveinung
Date: Fri Sep 16 04:01:41 2016
New Revision: 33811

URL: http://svn.gna.org/viewcvs/freeciv?rev=33811&view=rev
Log:
Stop interpreting action max_distance everywhere.

An action's max_distance can now be a regular value or
ACTION_DISTANCE_UNLIMITED. The latter is a special value signaling that the
action has unlimited range. At the moment this doesn't cause any issues
because the special value representing "unlimited" is larger than any legal
regular distance value.

Introduce the new function action_distance_inside_max(). Have it replace
checking if a given distance is inside an action's max_distance.

See patch #7689

Modified:
    trunk/client/control.c
    trunk/client/gui-gtk-3.0/menu.c
    trunk/client/gui-gtk-3.x/menu.c
    trunk/client/gui-qt/menu.cpp
    trunk/common/actions.c
    trunk/common/actions.h
    trunk/server/rssanity.c
    trunk/server/unithand.c

Modified: trunk/client/control.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/control.c?rev=33811&r1=33810&r2=33811&view=diff
==============================================================================
--- trunk/client/control.c      (original)
+++ trunk/client/control.c      Fri Sep 16 04:01:41 2016
@@ -1108,7 +1108,7 @@
      * target that isn't at or next to the actor unit's tile.
      *
      * Full explanation in handle_unit_orders(). */
-    fc_assert_ret(action_by_number(action_id)->max_distance <= 1);
+    fc_assert_ret(!action_id_distance_inside_max(action_id, 2));
 
     unit_list_iterate(punits, punit) {
       if (!unit_can_do_action(punit, action_id)) {

Modified: trunk/client/gui-gtk-3.0/menu.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.0/menu.c?rev=33811&r1=33810&r2=33811&view=diff
==============================================================================
--- trunk/client/gui-gtk-3.0/menu.c     (original)
+++ trunk/client/gui-gtk-3.0/menu.c     Fri Sep 16 04:01:41 2016
@@ -2713,7 +2713,7 @@
           continue;
         }
 
-        if (action_by_number(action_id)->max_distance > 1) {
+        if (action_id_distance_inside_max(action_id, 2)) {
           /* The order system doesn't support actions that can be done to a
            * target that isn't at or next to the actor unit's tile.
            *

Modified: trunk/client/gui-gtk-3.x/menu.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.x/menu.c?rev=33811&r1=33810&r2=33811&view=diff
==============================================================================
--- trunk/client/gui-gtk-3.x/menu.c     (original)
+++ trunk/client/gui-gtk-3.x/menu.c     Fri Sep 16 04:01:41 2016
@@ -2698,7 +2698,7 @@
           continue;
         }
 
-        if (action_by_number(action_id)->max_distance > 1) {
+        if (action_id_distance_inside_max(action_id, 2)) {
           /* The order system doesn't support actions that can be done to a
            * target that isn't at or next to the actor unit's tile.
            *

Modified: trunk/client/gui-qt/menu.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/menu.cpp?rev=33811&r1=33810&r2=33811&view=diff
==============================================================================
--- trunk/client/gui-qt/menu.cpp        (original)
+++ trunk/client/gui-qt/menu.cpp        Fri Sep 16 04:01:41 2016
@@ -839,7 +839,7 @@
         continue;
       }
 
-      if (action_by_number(action_id)->max_distance > 1) {
+      if (action_id_distance_inside_max(action_id, 2)) {
         /* The order system doesn't support actions that can be done to a
          * target that isn't at or next to the actor unit's tile.
          *

Modified: trunk/common/actions.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.c?rev=33811&r1=33810&r2=33811&view=diff
==============================================================================
--- trunk/common/actions.c      (original)
+++ trunk/common/actions.c      Fri Sep 16 04:01:41 2016
@@ -470,6 +470,17 @@
 
 /**************************************************************************
   Returns TRUE iff the specified distance between actor and target is
+  sm,aller or equal to the max range accepted by the specified action.
+**************************************************************************/
+bool action_distance_inside_max(const struct action *action,
+                                const int distance)
+{
+  return (distance <= action->max_distance
+          || action->max_distance == ACTION_DISTANCE_UNLIMITED);
+}
+
+/**************************************************************************
+  Returns TRUE iff the specified distance between actor and target is
   within the range acceptable to the specified action.
 **************************************************************************/
 bool action_distance_accepted(const struct action *action,
@@ -478,8 +489,7 @@
   fc_assert_ret_val(action, FALSE);
 
   return (distance >= action->min_distance
-          && (distance <= action->max_distance
-              || action->max_distance == ACTION_DISTANCE_UNLIMITED));
+          && action_distance_inside_max(action, distance));
 }
 
 /**************************************************************************

Modified: trunk/common/actions.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.h?rev=33811&r1=33810&r2=33811&view=diff
==============================================================================
--- trunk/common/actions.h      (original)
+++ trunk/common/actions.h      Fri Sep 16 04:01:41 2016
@@ -309,6 +309,11 @@
 #define action_id_distance_accepted(action_id, distance)                  \
   action_distance_accepted(action_by_number(action_id), distance)
 
+bool action_distance_inside_max(const struct action *action,
+                                const int distance);
+#define action_id_distance_inside_max(action_id, distance)                  \
+  action_distance_inside_max(action_by_number(action_id), distance)
+
 bool action_would_be_blocked_by(const struct action *blocked,
                                 const struct action *blocker);
 #define action_id_would_be_blocked_by(blocked_id, blocker_id)             \

Modified: trunk/server/rssanity.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/rssanity.c?rev=33811&r1=33810&r2=33811&view=diff
==============================================================================
--- trunk/server/rssanity.c     (original)
+++ trunk/server/rssanity.c     Fri Sep 16 04:01:41 2016
@@ -915,7 +915,7 @@
       ok = FALSE;
     }
 
-    if (paction->min_distance > paction->max_distance) {
+    if (!action_distance_inside_max(paction, paction->min_distance)) {
       ruleset_error(LOG_ERROR,
                     "Action %s: min distance is %d but max distance is %d.",
                     action_get_rule_name(act),

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=33811&r1=33810&r2=33811&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Fri Sep 16 04:01:41 2016
@@ -872,16 +872,16 @@
     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)
+                  && !action_id_distance_inside_max(action_id,
+                      real_map_distance(unit_tile(punit), target_tile)))
                  || (target_city
-                     && real_map_distance(unit_tile(punit),
-                                          city_tile(target_city))
-                        > action_by_number(action_id)->max_distance)
+                     && !action_id_distance_inside_max(action_id,
+                         real_map_distance(unit_tile(punit),
+                                           city_tile(target_city))))
                  || (target_unit
-                     && real_map_distance(unit_tile(punit),
-                                          unit_tile(target_unit))
-                        > action_by_number(action_id)->max_distance))) {
+                     && !action_id_distance_inside_max(action_id,
+                         real_map_distance(unit_tile(punit),
+                                           unit_tile(target_unit)))))) {
     explnat->kind = ANEK_DISTANCE_FAR;
     explnat->distance = action_by_number(action_id)->max_distance;
   } else if (action_id == ACTION_PARADROP && punit && target_tile
@@ -4462,7 +4462,7 @@
         return;
       }
 
-      if (action_by_number(packet->action[i])->max_distance > 1) {
+      if (action_id_distance_inside_max(packet->action[i], 2)) {
         /* Long range actions aren't supported in unit orders. Clients
          * should order them performed via the unit_do_action packet.
          *
@@ -4489,7 +4489,7 @@
         return;
       }
 
-      if (action_by_number(packet->action[i])->max_distance == 0
+      if (!action_id_distance_inside_max(packet->action[i], 1)
           && map_untrusted_dir_is_valid(packet->dir[i])) {
         /* Actor must be on the target tile. */
         log_error("handle_unit_orders() can't do %s to a neighbor tile. "


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

Reply via email to