Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2006:
[Freeciv-Dev] Re: (PR#18441) [Patch] Better warmap caching
Home

[Freeciv-Dev] Re: (PR#18441) [Patch] Better warmap caching

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#18441) [Patch] Better warmap caching
From: "Marko Lindqvist" <cazfi74@xxxxxxxxx>
Date: Mon, 10 Jul 2006 12:47:57 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=18441 >

Marko Lindqvist wrote:
> 
>   There is a problem with ferries. What is free ferry when warmap is 
> first generated, might be full ferry after one unit has moved.

  Taken care of. Also fixed situation where first unit occupies city and 
city automatically builds railroads.

  Autogames still differ.


  - ML

diff -Nurd -X.diff_ignore freeciv/server/citytools.c freeciv/server/citytools.c
--- freeciv/server/citytools.c  2006-07-10 20:47:18.421875000 +0300
+++ freeciv/server/citytools.c  2006-07-10 22:36:47.578125000 +0300
@@ -898,6 +898,7 @@
                  pcity->name);
     tile_set_special(pcity->tile, S_RAILROAD);
     update_tile_knowledge(pcity->tile);
+    invalidate_warmap();
   }
 
   /* Build a new palace for free if the player lost her capital and
diff -Nurd -X.diff_ignore freeciv/server/gotohand.c freeciv/server/gotohand.c
--- freeciv/server/gotohand.c   2006-07-10 22:22:02.343750000 +0300
+++ freeciv/server/gotohand.c   2006-07-10 22:39:38.796875000 +0300
@@ -42,6 +42,8 @@
 
 struct move_cost_map warmap;
 
+static bool force_warmap_regeneration;
+
 /* 
  * These settings should be either true or false.  They are used for
  * finding routes for airplanes - the airplane doesn't want to fly
@@ -311,10 +313,12 @@
          continue; /* No need for all the calculations */
 
         if (is_ocean(tile_get_terrain(tile1))) {
-          if (punit && ground_unit_transporter_capacity(tile1, pplayer) > 0)
+          if (punit && ground_unit_transporter_capacity(tile1, pplayer) > 0) {
+            warmap.with_ferry = punit; /* Warmap with ferry is less reusable */
            move_cost = SINGLE_MOVE;
-          else
+          } else {
            continue;
+          }
        } else if (is_ocean(ptile->terrain)) {
          int base_cost
            = tile_get_terrain(tile1)->movement_cost * SINGLE_MOVE;
@@ -390,6 +394,8 @@
          (punit ? unit_type(punit)->name : "NULL"));
 
   if (punit) {
+    int speed;
+
     /* 
      * Checking for an existing warmap. If the previous warmap was for
      * a city and our unit is in that city, use city's warmap.
@@ -399,20 +405,37 @@
     }
 
     /* 
-     * If the previous warmap was for the same unit and it's still
+     * If the previous warmap was for the same unit_type and it's still
      * correct (warmap.(sea)cost[x][y] == 0), reuse it.
      */
-    if (warmap.warunit == punit &&
-       (is_sailing_unit(punit) ? (WARMAP_SEACOST(punit->tile) == 0)
+    speed = unit_move_rate(punit);
+    if (!force_warmap_regeneration
+        && (warmap.with_ferry == punit /* Exactly same unit */
+            || (!warmap.with_ferry     /* Can be used for units of same type 
if there is no
+                                     * ferry around */
+                && warmap.warunit == unit_type(punit)
+                && warmap.warspeed == speed))
+        && (is_sailing_unit(punit) ? (WARMAP_SEACOST(punit->tile) == 0)
         : (WARMAP_COST(punit->tile) == 0))) {
       return;
     }
 
+    force_warmap_regeneration = FALSE;
+
     pcity = NULL;
+    warmap.warunit = unit_type(punit);
+    warmap.warspeed = speed;
+
+    if (punit->transported_by == -1) {
+      warmap.with_ferry = NULL;
+    } else {
+      warmap.with_ferry = punit; /* We may unload ferry */
+    }
+  } else {
+    warmap.warunit = NULL;
   }
 
   warmap.warcity = pcity;
-  warmap.warunit = punit;
 
   if (punit) {
     if (is_sailing_unit(punit)) {
@@ -1595,3 +1618,12 @@
   freelog(LOG_DEBUG, "air_can_move_between: no route found");
   return -1;
 }
+
+/**************************************************************************
+ When generate_warmap() is called next time, warmap is regenerated.
+**************************************************************************/
+void invalidate_warmap(void)
+{
+  force_warmap_regeneration = TRUE;
+}
+
diff -Nurd -X.diff_ignore freeciv/server/gotohand.h freeciv/server/gotohand.h
--- freeciv/server/gotohand.h   2006-07-10 22:22:21.500000000 +0300
+++ freeciv/server/gotohand.h   2006-07-10 22:36:03.484375000 +0300
@@ -34,6 +34,7 @@
                              enum goto_move_restriction restriction,
                              bool trigger_special_ability);
 void generate_warmap(struct city *pcity, struct unit *punit);
+void invalidate_warmap(void);
 void really_generate_warmap(struct city *pcity, struct unit *punit,
                            enum unit_move_type move_type);
 int calculate_move_cost(struct unit *punit, struct tile *dst_tile);
@@ -53,8 +54,11 @@
   unsigned char *vector;
   int size;
 
-  struct city *warcity; /* so we know what we're dealing with here */
-  struct unit *warunit; /* so we know what we're dealing with here */
+  struct city      *warcity;    /* so we know what we're dealing with here */
+  struct unit_type *warunit;    /* so we know what we're dealing with here */
+  int               warspeed;
+  struct unit      *with_ferry; /* If not NULL, warmap contains ferry and map
+                                 * generated for given unit */
   struct tile *orig_tile;
 };
 

[Prev in Thread] Current Thread [Next in Thread]