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: Sun, 9 Jul 2006 14:12:58 -0700
Reply-to: bugs@xxxxxxxxxxx

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

Marko Lindqvist wrote:
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=18441 >
> 
> Marko Lindqvist wrote:
>>   Warmap is identical to two units of same type. So reuse existing 
>> warmap  even if it's not exactly for this unit, but for other unit of 
>> the same type.
> 
>   Umh, sorry. Warmap may differ if unit is slowed down by damage.

  So I'll test this version instead. Reuse warmap only if it's generated 
for same unit speed.


  - ML



diff -Nurd -X.diff_ignore freeciv/server/gotohand.c freeciv/server/gotohand.c
--- freeciv/server/gotohand.c   2006-07-09 23:28:10.515625000 +0300
+++ freeciv/server/gotohand.c   2006-07-10 00:09:01.484375000 +0300
@@ -390,6 +390,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 +401,25 @@
     }
 
     /* 
-     * 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 (warmap.warunit == unit_type(punit)
+        && warmap.warspeed == speed
+        && (is_sailing_unit(punit) ? (WARMAP_SEACOST(punit->tile) == 0)
         : (WARMAP_COST(punit->tile) == 0))) {
       return;
     }
 
     pcity = NULL;
+    warmap.warunit = unit_type(punit);
+    warmap.warspeed = speed;
+  } else {
+    warmap.warunit = NULL;
   }
 
   warmap.warcity = pcity;
-  warmap.warunit = punit;
 
   if (punit) {
     if (is_sailing_unit(punit)) {
diff -Nurd -X.diff_ignore freeciv/server/gotohand.h freeciv/server/gotohand.h
--- freeciv/server/gotohand.h   2006-07-09 23:50:25.687500000 +0300
+++ freeciv/server/gotohand.h   2006-07-09 23:51:11.437500000 +0300
@@ -51,8 +51,9 @@
   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 tile *orig_tile;
 };
 

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