Author: cazfi
Date: Sat May 14 21:18:29 2016
New Revision: 32712

URL: http://svn.gna.org/viewcvs/freeciv?rev=32712&view=rev
Log:
Added list of roads providing movement bonus to the unit class caches.

See patch #7176

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

Modified: branches/S2_5/common/map.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/map.c?rev=32712&r1=32711&r2=32712&view=diff
==============================================================================
--- branches/S2_5/common/map.c  (original)
+++ branches/S2_5/common/map.c  Sat May 14 21:18:29 2016
@@ -793,53 +793,50 @@
    * check. We want to give railroad bonus only to native units. */
   ri = restrict_infra(pplayer, t1, t2);
 
-  road_type_iterate(proad) {
-    if (proad->move_mode != RMM_NO_BONUS
-        && (!ri || road_has_flag(proad, RF_UNRESTRICTED_INFRA))) {
-      if ((!pclass || is_native_road_to_uclass(proad, pclass))
-          && tile_has_road(t1, proad) && tile_has_road(t2, proad)) {
-        if (cost > proad->move_cost) {
-
-          if (proad->move_mode == RMM_FAST_ALWAYS) {
+  road_type_list_iterate(pclass->cache.bonus_roads, proad) {
+    if ((!ri || road_has_flag(proad, RF_UNRESTRICTED_INFRA))
+        && tile_has_road(t1, proad) && tile_has_road(t2, proad)) {
+      if (cost > proad->move_cost) {
+
+        if (proad->move_mode == RMM_FAST_ALWAYS) {
+          cost = proad->move_cost;
+        } else {
+          if (!cardinality_checked) {
+            cardinal_move = (ALL_DIRECTIONS_CARDINAL() || is_move_cardinal(t1, 
t2));
+            cardinality_checked = TRUE;
+          }
+          if (cardinal_move) {
             cost = proad->move_cost;
           } else {
-            if (!cardinality_checked) {
-              cardinal_move = (ALL_DIRECTIONS_CARDINAL() || 
is_move_cardinal(t1, t2));
-              cardinality_checked = TRUE;
-            }
-            if (cardinal_move) {
+            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)) {
+                    /* 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;
-            } 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)) {
-                      /* 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;
-              case RMM_NO_BONUS:
-                fc_assert(proad->move_mode != RMM_NO_BONUS);
-                break;
-              }
+              break;
+            case RMM_NO_BONUS:
+              fc_assert(proad->move_mode != RMM_NO_BONUS);
+              break;
             }
           }
         }
       }
     }
-  } road_type_iterate_end;
+  } road_type_list_iterate_end;
 
   if (punit && unit_has_type_flag(punit, UTYF_IGTER)) {
     return MIN(cost, MOVE_COST_IGTER);

Modified: branches/S2_5/common/unittype.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/unittype.c?rev=32712&r1=32711&r2=32712&view=diff
==============================================================================
--- branches/S2_5/common/unittype.c     (original)
+++ branches/S2_5/common/unittype.c     Sat May 14 21:18:29 2016
@@ -1149,6 +1149,7 @@
     unit_classes[i].cache.refuel_bases = NULL;
     unit_classes[i].cache.native_tile_bases = NULL;
     unit_classes[i].cache.native_tile_roads = NULL;
+    unit_classes[i].cache.bonus_roads = NULL;
   }
 }
 
@@ -1171,6 +1172,10 @@
     if (unit_classes[i].cache.native_tile_roads != NULL) {
       road_type_list_destroy(unit_classes[i].cache.native_tile_roads);
       unit_classes[i].cache.native_tile_roads = NULL;
+    }
+    if (unit_classes[i].cache.bonus_roads != NULL) {
+      road_type_list_destroy(unit_classes[i].cache.bonus_roads);
+      unit_classes[i].cache.bonus_roads = NULL;
     }
   }
 }
@@ -1344,6 +1349,7 @@
   pclass->cache.refuel_bases = base_type_list_new();
   pclass->cache.native_tile_bases = base_type_list_new();
   pclass->cache.native_tile_roads = road_type_list_new();
+  pclass->cache.bonus_roads = road_type_list_new();
 
   base_type_iterate(pbase) {
     if (is_native_base_to_uclass(pbase, pclass)) {
@@ -1355,9 +1361,13 @@
   } base_type_iterate_end;
 
   road_type_iterate(proad) {
-    if (is_native_road_to_uclass(proad, pclass)
-        && road_has_flag(proad, RF_NATIVE_TILE)) {
-      road_type_list_append(pclass->cache.native_tile_roads, proad);
+    if (is_native_road_to_uclass(proad, pclass)) {
+      if (road_has_flag(proad, RF_NATIVE_TILE)) {
+        road_type_list_append(pclass->cache.native_tile_roads, proad);
+      }
+      if (proad->move_mode != RMM_NO_BONUS) {
+        road_type_list_append(pclass->cache.bonus_roads, proad);
+      }
     }
   } road_type_iterate_end;
 }

Modified: branches/S2_5/common/unittype.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/unittype.h?rev=32712&r1=32711&r2=32712&view=diff
==============================================================================
--- branches/S2_5/common/unittype.h     (original)
+++ branches/S2_5/common/unittype.h     Sat May 14 21:18:29 2016
@@ -115,6 +115,7 @@
     struct base_type_list *refuel_bases;
     struct base_type_list *native_tile_bases;
     struct road_type_list *native_tile_roads;
+    struct road_type_list *bonus_roads;
   } cache;
 };
 


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

Reply via email to