Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2001:
[Freeciv-Dev] PATCH: fix for smooth_map (PR#991)
Home

[Freeciv-Dev] PATCH: fix for smooth_map (PR#991)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Cc: bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] PATCH: fix for smooth_map (PR#991)
From: jdorje@xxxxxxxxxxxxxxxxxxxxx
Date: Fri, 5 Oct 2001 12:15:26 -0700 (PDT)

The following simple patch cleans up the smooth_map() function as
discussed of freeciv-dev.

jason
? rc
? profile.sh
Index: server/mapgen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/mapgen.c,v
retrieving revision 1.72
diff -u -r1.72 mapgen.c
--- server/mapgen.c     2001/09/30 21:55:34     1.72
+++ server/mapgen.c     2001/10/05 19:13:23
@@ -31,7 +31,7 @@
 #include "mapgen.h"
 
 /* Wrapper for easy access.  It's a macro so it can be a lvalue. */
-#define hmap(x,y) (height_map[(y) * map.xsize + map_adjust_x(x)])
+#define hmap(x,y) (height_map[map_inx(x, y)])
 
 static void make_huts(int number);
 static void add_specials(int prob);
@@ -1333,38 +1333,40 @@
 }
 
 /**************************************************************************
-  smooth_map should be viewed  as a  corrosion function on the map, it levels
-  out the differences in the heightmap.
+  smooth_map should be viewed  as a corrosion function on the map, it
+  levels out the differences in the heightmap.
 **************************************************************************/
 static void smooth_map(void)
 {
-  int mx,my,px,py;
-  int a;
-  
+  int* new_hmap = fc_malloc(sizeof(int) * map.xsize * map.ysize);
+
+  /* We make a new height map and then copy it back over the old one.
+     Care must be taken so that the new height map uses the exact
+     same storage structure as the real one - it must be the same
+     size and use the same indexing.  --JDS */
+
   whole_map_iterate(x, y) {
-    my = map_adjust_y(y - 1);
-    py = map_adjust_y(y + 1);
-    mx = map_adjust_x(x - 1);
-    px = map_adjust_x(x + 1);
-    a = hmap(x, y) * 2;
-
-    a += hmap(px, my);
-    a += hmap(mx, my);
-    a += hmap(mx, py);
-    a += hmap(px, py);
+    int a = hmap(x, y) * 2; /* double-count this tile */
+    int dir;
 
-    a += hmap(x, my);
-    a += hmap(mx, y);
+    /* what about a new macro, adjc_nearest_iterate? */
+    for (dir=0; dir<8; dir++) {
+      int dx, dy, x2, y2;
+      DIRSTEP(dx, dy, dir); /* can't use MAPSTEP */
+      x2 = x + dx, y2 = y + dy;
+      nearest_real_pos(&x2, &y2);
 
-    a += hmap(x, py);
-    a += hmap(px, y);
+      a += hmap(x2, y2);
+    }
 
-    a += myrand(60);
-    a -= 30;
+    a += myrand(60) - 30;
     if (a < 0)
       a = 0;
-    hmap(x, y) = a / 10;
+    new_hmap[map_inx(x, y)] = a / 10;
   } whole_map_iterate_end;
+
+  memcpy(height_map, new_hmap, sizeof(int) * map.xsize * map.ysize);
+  free(new_hmap);
 }
 
 /**************************************************************************

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