Author: cazfi
Date: Thu Nov 26 07:43:14 2015
New Revision: 30786

URL: http://svn.gna.org/viewcvs/freeciv?rev=30786&view=rev
Log:
Avoid unnecessary is_move_cardinal() calls on hex topologies

See patch #6611

Modified:
    trunk/common/map.c
    trunk/common/map.h
    trunk/common/movement.c

Modified: trunk/common/map.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/map.c?rev=30786&r1=30785&r2=30786&view=diff
==============================================================================
--- trunk/common/map.c  (original)
+++ trunk/common/map.c  Thu Nov 26 07:43:14 2015
@@ -738,7 +738,7 @@
 
   cost = tile_terrain(t2)->movement_cost * SINGLE_MOVE;
   ri = restrict_infra(pplayer, t1, t2);
-  cardinal_move = is_move_cardinal(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);
@@ -760,16 +760,13 @@
         if (tile_has_extra(t1, iextra)
             && (!pclass
                 || is_native_extra_to_uclass(iextra, pclass))) {
-          switch (proad->move_mode) {
-          case RMM_CARDINAL:
-            if (cardinal_move) {
-              cost = proad->move_cost;
-            }
-            break;
-          case RMM_RELAXED:
-            if (cardinal_move) {
-              cost = proad->move_cost;
-            } else {
+          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_road(between, proad)) {
@@ -781,11 +778,11 @@
                   }
                 } cardinal_between_iterate_end;
               }
+              break;
+            case RMM_FAST_ALWAYS:
+              cost = proad->move_cost;
+              break;
             }
-            break;
-          case RMM_FAST_ALWAYS:
-            cost = proad->move_cost;
-            break;
           }
         }
       } extra_type_list_iterate_end;
@@ -798,8 +795,7 @@
   }
 
   if (!cardinal_move
-      && terrain_control.pythagorean_diagonal
-      && !current_topo_has_flag(TF_HEX)) {
+      && terrain_control.pythagorean_diagonal) {
     return (int) (cost * 1.41421356f);
   } else {
     return cost;

Modified: trunk/common/map.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/map.h?rev=30786&r1=30785&r2=30786&view=diff
==============================================================================
--- trunk/common/map.h  (original)
+++ trunk/common/map.h  Thu Nov 26 07:43:14 2015
@@ -43,6 +43,8 @@
 
 #define topo_has_flag(topo, flag) (((topo) & (flag)) != 0)
 #define current_topo_has_flag(flag) topo_has_flag((CURRENT_TOPOLOGY), (flag))
+
+#define ALL_DIRECTIONS_CARDINAL() topo_has_flag((CURRENT_TOPOLOGY), TF_HEX)
 
 bool map_is_empty(void);
 void map_init(void);

Modified: trunk/common/movement.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/movement.c?rev=30786&r1=30785&r2=30786&view=diff
==============================================================================
--- trunk/common/movement.c     (original)
+++ trunk/common/movement.c     Thu Nov 26 07:43:14 2015
@@ -357,6 +357,10 @@
     extra_type_list_iterate(proad->integrators, iextra) {
       if (!tile_has_extra(src_tile, iextra)) {
         continue;
+      }
+      if (ALL_DIRECTIONS_CARDINAL()) {
+        /* move_mode does not matter as all of them accept cardinal move */
+        return TRUE;
       }
       switch (extra_road_get(iextra)->move_mode) {
       case RMM_FAST_ALWAYS:


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

Reply via email to