Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2000:
[Freeciv-Dev] Re: warmap patch and gotohand
Home

[Freeciv-Dev] Re: warmap patch and gotohand

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Thue Janus Kristensen <thue@xxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: warmap patch and gotohand
From: Nicolas BRUNEL <brunel@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 5 May 2000 05:09:55 +0000 (GMT)

> But what abouT such places in the code as (advmillitary.c)
> 
>            c = (warmap.cost[bx][by] + m - 1) / m + 1 + 
>                 warmap.seacost[x][y] / boatspeed; /* kluge */ 
> 
> Here the ai clearly have a movecostmap for both a boat and a unit at the
> same time.

You're rigth it is used. But, is it initialized ?
I changed the code a long time ago. Here the original code :

Index: gotohand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gotohand.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- gotohand.c  1999/01/28 17:26:10     1.27
+++ gotohand.c  1999/02/03 18:46:32     1.28
@@ -65,25 +65,11 @@
 
 void init_warmap(int orig_x, int orig_y, enum unit_move_type which)
 {
-  int x, y, i, j;
-  int maxcost = THRESHOLD * 6 + 2; /* should be big enough without being TOO 
big */
-  for (x = 0; x < map.xsize; x++) {
-    if (x > orig_x)
-      i = MIN(x - orig_x, orig_x + map.xsize - x);
-    else
-      i = MIN(orig_x - x, x + map.xsize - orig_x);      
-    for (y = 0; y < map.ysize; y++) {
-      if (y > orig_y)
-        j = MAX(y - orig_y, i);
-      else
-        j = MAX(orig_y - y, i);
-      j *= 3; /* can be speed up */
-      if (j < maxcost) j = maxcost;
-      if (j > 255) j = 255;
-      if (which == LAND_MOVING) warmap.cost[x][y] = j; /* one if by land */
-      else warmap.seacost[x][y] = j;
-    }
-  }
+  int x, y;
+  for (x = 0; x < map.xsize; x++) 
+    for (y = 0; y < map.ysize; y++) 
+      if (which == LAND_MOVING) warmap.cost[x][y] = 255; /* one if by land */
+      else warmap.seacost[x][y] = 255;
   if (which == LAND_MOVING) warmap.cost[orig_x][orig_y] = 0;
   else warmap.seacost[orig_x][orig_y] = 0;
 }  

   There was at the middle a square with value maxcost. Then, it was 
real_map_distance * 3. It couldn't get bigger than 255. I though it was
faster to set it to 255.

As you see for a land moving unit, the sea cost isn't initialized ! 
Well, it isn't initialized here. Between generate_warmap and
really_generate_warmap, seacost and cost is initialized. Usually, generate 
warmap is called for a unit. Then really_generate_warmap is called for a
ferryboat. It is done in find_something_to_kill and
auto_settler_findwork. Many lines are shared between gotohand.c settlers.c
and the ai code. So, yes, it's better to keep warmap.seacost
untouched. With global variables, there is alway the risk to have a side
effect.  
 
   To try to optimize the shortest path algorithm have a look at dijkstra 
shortest path algorithm.

Bye and happy coding,












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