Author: cazfi
Date: Fri Apr 22 22:00:53 2016
New Revision: 32462

URL: http://svn.gna.org/viewcvs/freeciv?rev=32462&view=rev
Log:
Call is_move_cardinal() only when really needed.

See patch #7126

Modified:
    trunk/common/map.c

Modified: trunk/common/map.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/map.c?rev=32462&r1=32461&r2=32462&view=diff
==============================================================================
--- trunk/common/map.c  (original)
+++ trunk/common/map.c  Fri Apr 22 22:00:53 2016
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/***********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -766,6 +766,7 @@
 {
   const struct unit_class *pclass = utype_class(punittype);
   int cost;
+  bool cardinality_checked = FALSE;
   bool cardinal_move;
   bool ri;
 
@@ -805,7 +806,6 @@
 
   cost = tile_terrain(t2)->movement_cost * SINGLE_MOVE;
   ri = restrict_infra(pplayer, t1, t2);
-  cardinal_move = (ALL_DIRECTIONS_CARDINAL() || is_move_cardinal(t1, t2));
 
   extra_type_by_cause_iterate(EC_ROAD, pextra) {
     struct road_type *proad = extra_road_get(pextra);
@@ -827,31 +827,40 @@
         if (tile_has_extra(t1, iextra)
             && (!pclass
                 || is_native_extra_to_uclass(iextra, pclass))) {
-          if (cardinal_move) {
+          if (proad->move_mode == RMM_FAST_ALWAYS) {
             cost = proad->move_cost;
           } else {
-            switch (proad->move_mode) {
-            case RMM_CARDINAL:
-              break;
-            case RMM_RELAXED:
-              if (cost > proad->move_cost * 2) {
-                cardinal_between_iterate(t1, t2, between) {
-                  if (tile_has_extra(between, pextra)
-                      || (pextra != iextra && tile_has_extra(between, 
iextra))) {
-                    /* 'pextra != iextra' is there just to avoid 
tile_has_extra()
-                     * in by far more common case that 'pextra == iextra' */
-                    /* TODO: Should we restrict this more?
-                     * Should we check against enemy cities on between tile?
-                     * Should we check against non-native terrain on between 
tile?
-                     */
-                    cost = proad->move_cost * 2;
-                  }
-                } cardinal_between_iterate_end;
+            if (!cardinality_checked) {
+              cardinal_move = (ALL_DIRECTIONS_CARDINAL() || 
is_move_cardinal(t1, t2));
+              cardinality_checked = TRUE;
+            }
+            if (cardinal_move) {
+              cost = proad->move_cost;
+            } else {
+              switch (proad->move_mode) {
+              case RMM_CARDINAL:
+                break;
+              case RMM_RELAXED:
+                if (cost > proad->move_cost * 2) {
+                  cardinal_between_iterate(t1, t2, between) {
+                    if (tile_has_extra(between, pextra)
+                        || (pextra != iextra && tile_has_extra(between, 
iextra))) {
+                      /* 'pextra != iextra' is there just to avoid 
tile_has_extra()
+                       * in by far more common case that 'pextra == iextra' */
+                      /* TODO: Should we restrict this more?
+                       * Should we check against enemy cities on between tile?
+                       * Should we check against non-native terrain on between 
tile?
+                       */
+                      cost = proad->move_cost * 2;
+                    }
+                  } cardinal_between_iterate_end;
+                }
+                break;
+              case RMM_FAST_ALWAYS:
+                fc_assert(proad->move_mode != RMM_FAST_ALWAYS); /* Already 
handled above */
+                cost = proad->move_cost;
+                break;
               }
-              break;
-            case RMM_FAST_ALWAYS:
-              cost = proad->move_cost;
-              break;
             }
           }
         }
@@ -864,12 +873,16 @@
     cost = MOVE_COST_IGTER;
   }
 
-  if (!cardinal_move
-      && terrain_control.pythagorean_diagonal) {
-    return (int) (cost * 1.41421356f);
-  } else {
-    return cost;
-  }
+  if (terrain_control.pythagorean_diagonal) {
+    if (!cardinality_checked) {
+      cardinal_move = (ALL_DIRECTIONS_CARDINAL() || is_move_cardinal(t1, t2));
+    }
+    if (!cardinal_move) {
+      return (int) (cost * 1.41421356f);
+    }
+  }
+
+  return cost;
 }
 
 /****************************************************************************


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

Reply via email to