Author: cazfi
Date: Thu Nov 26 07:43:30 2015
New Revision: 30788

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

See patch #6611

Modified:
    branches/S2_5/common/map.c
    branches/S2_5/common/map.h

Modified: branches/S2_5/common/map.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/map.c?rev=30788&r1=30787&r2=30788&view=diff
==============================================================================
--- branches/S2_5/common/map.c  (original)
+++ branches/S2_5/common/map.c  Thu Nov 26 07:43:30 2015
@@ -782,7 +782,7 @@
    * leaving ships, so UTYF_IGTER check has to be before native terrain
    * check. We want to give railroad bonus only to native units. */
   ri = restrict_infra(pplayer, t1, t2);
-  cardinal_move = is_move_cardinal(t1, t2);
+  cardinal_move = (ALL_DIRECTIONS_CARDINAL() || is_move_cardinal(t1, t2));
 
   road_type_iterate(proad) {
     if (proad->move_mode != RMM_NO_BONUS
@@ -790,16 +790,13 @@
       if ((!pclass || is_native_road_to_uclass(proad, pclass))
           && tile_has_road(t1, proad) && tile_has_road(t2, proad)) {
         if (cost > proad->move_cost) {
-          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)) {
@@ -811,14 +808,14 @@
                   }
                 } cardinal_between_iterate_end;
               }
+              break;
+            case RMM_FAST_ALWAYS:
+              cost = proad->move_cost;
+              break;
+            case RMM_NO_BONUS:
+              fc_assert(proad->move_mode != RMM_NO_BONUS);
+              break;
             }
-            break;
-          case RMM_FAST_ALWAYS:
-            cost = proad->move_cost;
-            break;
-          case RMM_NO_BONUS:
-            fc_assert(proad->move_mode != RMM_NO_BONUS);
-            break;
           }
         }
       }

Modified: branches/S2_5/common/map.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/map.h?rev=30788&r1=30787&r2=30788&view=diff
==============================================================================
--- branches/S2_5/common/map.h  (original)
+++ branches/S2_5/common/map.h  Thu Nov 26 07:43:30 2015
@@ -134,6 +134,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);


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

Reply via email to