Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2004:
[Freeciv-Dev] (PR#7204) completing iso-map support
Home

[Freeciv-Dev] (PR#7204) completing iso-map support

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#7204) completing iso-map support
From: "Jason Short" <jshort@xxxxxxxxxxxxxx>
Date: Mon, 5 Jan 2004 22:32:49 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=7204 >

Attached is the most recent version of the gen-topologies patch.  This 
enables support for iso-maps (topologies 4-7).  There may be a few bugs 
(it is hard to test all parameters) but it is generally quite stable.

Unfortunately most of the remaining changes are either very ugly 
(mapgen) or not agreed on (climisc).  So I'm not quite sure where to go 
from here.

jason

Index: client/climisc.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v
retrieving revision 1.124
diff -u -r1.124 climisc.c
--- client/climisc.c    2003/11/28 17:37:19     1.124
+++ client/climisc.c    2004/01/06 06:28:21
@@ -362,20 +362,27 @@
     assert(punit != NULL);
     center_tile_mapcanvas(punit->x, punit->y);
   } else {
-    /* Just any known tile will do; search near the middle first. */
-    iterate_outward(map.xsize / 2, map.ysize / 2,
-                   MAX(map.xsize / 2, map.ysize / 2), x, y) {
+    int map_x, map_y, center_map_x, center_map_y, dist = -1;
+
+    native_to_map_pos(&map_x, &map_y, map.xsize / 2, map.ysize / 2);
+    center_map_x = map_x;
+    center_map_y = map_y;
+
+    /* Look for any known tile - preferably close to the map center.  The
+     * default is the map center. */
+    whole_map_iterate(x, y) {
       if (tile_get_known(x, y) != TILE_UNKNOWN) {
-       center_tile_mapcanvas(x, y);
-       goto OUT;
+       int mydist = sq_map_distance(x, y, center_map_x, center_map_y);
+
+       if (dist == -1 || mydist < dist) {
+         dist = mydist;
+         map_x = x;
+         map_y = y;
+       }
       }
-    }
-    iterate_outward_end;
-    /* If we get here we didn't find a known tile.
-       Refresh a random place to clear the intro gfx. */
-    center_tile_mapcanvas(map.xsize / 2, map.ysize / 2);
-  OUT:
-    ;                          /* do nothing */
+    } whole_map_iterate_end;
+
+    center_tile_mapcanvas(map_x, map_y);
   }
 }
 
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.150
diff -u -r1.150 capstr.c
--- common/capstr.c     2003/12/06 20:37:59     1.150
+++ common/capstr.c     2004/01/06 06:28:21
@@ -74,13 +74,16 @@
  * are not directly related to the capability strings discussed here.)
  */
 
-#define CAPABILITY "+1.14.delta +last_turns_shield_surplus"
+#define CAPABILITY "+1.14.delta +last_turns_shield_surplus +iso_maps"
 
 /* "+1.14.delta" is the new delta protocol for 1.14.0-dev.
  *
  * "last_turns_shield_surplus" means the surplus from the previous turn is
  * tracked by the server and sent to the client.  This information is used
  * in determining penalties when switching production.
+ *
+ * "iso_maps" means there is support for isometric maps (topology values
+ * 4-7).
  */
 
 void init_our_capability(void)
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.165
diff -u -r1.165 map.h
--- common/map.h        2003/11/28 17:37:21     1.165
+++ common/map.h        2004/01/06 06:28:21
@@ -634,7 +634,7 @@
 #define MAP_ORIGINAL_TOPO        TF_WRAPX
 #define MAP_DEFAULT_TOPO         TF_WRAPX
 #define MAP_MIN_TOPO             0
-#define MAP_MAX_TOPO             3
+#define MAP_MAX_TOPO             7
 
 #define MAP_DEFAULT_SEED         0
 #define MAP_MIN_SEED             0
Index: common/packets.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.c,v
retrieving revision 1.264
diff -u -r1.264 packets.c
--- common/packets.c    2004/01/05 00:18:31     1.264
+++ common/packets.c    2004/01/06 06:28:21
@@ -602,7 +602,7 @@
 {
   if (packet->x == -1 && packet->y == -1) {
     /* since we can currently only send unsigned ints... */
-    assert(MAP_MAX_WIDTH <= 255 && MAP_MAX_HEIGHT <= 255);
+    assert(!is_normal_map_pos(255, 255));
     packet->x = 255;
     packet->y = 255;
   }
Index: server/mapgen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/mapgen.c,v
retrieving revision 1.122
diff -u -r1.122 mapgen.c
--- server/mapgen.c     2003/11/18 23:11:14     1.122
+++ server/mapgen.c     2004/01/06 06:28:22
@@ -36,6 +36,8 @@
 #define hmap(x, y) (height_map[map_pos_to_index(x, y)])
 #define rmap(x, y) (river_map[map_pos_to_index(x, y)])
 
+#define HAS_POLES() (!topo_has_flag(TF_WRAPY))
+
 static void make_huts(int number);
 static void add_specials(int prob);
 static void mapgenerator1(void);
@@ -109,28 +111,36 @@
 **************************************************************************/
 static void make_polar(void)
 {
-  int y,x;
+  int y, x, map_x, map_y;
+
+  if (!HAS_POLES()) {
+    return;
+  }
 
   for (y=0;y<map.ysize/10;y++) {
     for (x=0;x<map.xsize;x++) {
-      if ((hmap(x, y)+(map.ysize/10-y*25)>myrand(maxval) &&
-          map_get_terrain(x,y)==T_GRASSLAND) || y==0) { 
+      native_to_map_pos(&map_x, &map_y, x, y);
+      if ((hmap(map_x, map_y) + (map.ysize / 10 - y * 25) > myrand(maxval)
+          && map_get_terrain(map_x, map_y) == T_GRASSLAND) || y == 0) { 
        if (y<2)
-         map_set_terrain(x, y, T_ARCTIC);
+         map_set_terrain(map_x, map_y, T_ARCTIC);
        else
-         map_set_terrain(x, y, T_TUNDRA);
+         map_set_terrain(map_x, map_y, T_TUNDRA);
          
       } 
     }
   }
   for (y=map.ysize*9/10;y<map.ysize;y++) {
     for (x=0;x<map.xsize;x++) {
-      if ((hmap(x, y)+(map.ysize/10-(map.ysize-y)*25)>myrand(maxval) &&
-          map_get_terrain(x, y)==T_GRASSLAND) || y==map.ysize-1) {
+      native_to_map_pos(&map_x, &map_y, x, y);
+      if (((hmap(map_x, map_y) + (map.ysize / 10 - (map.ysize - y) * 25)
+           > myrand(maxval))
+          && map_get_terrain(map_x, map_y) == T_GRASSLAND)
+         || y == map.ysize - 1) {
        if (y>map.ysize-3)
-         map_set_terrain(x, y, T_ARCTIC);
+         map_set_terrain(map_x, map_y, T_ARCTIC);
        else
-         map_set_terrain(x, y, T_TUNDRA);
+         map_set_terrain(map_x, map_y, T_TUNDRA);
       }
     }
   }
@@ -140,12 +150,14 @@
      turn every land tile on the second lines that is not arctic into tundra,
      since the first lines has already been set to all arctic above. */
   for (x=0;x<map.xsize;x++) {
-    if (map_get_terrain(x, 1)!=T_ARCTIC &&
-       !is_ocean(map_get_terrain(x, 1)))
-      map_set_terrain(x, 1, T_TUNDRA);
-    if (map_get_terrain(x, map.ysize-2)!=T_ARCTIC && 
-       !is_ocean(map_get_terrain(x, map.ysize-2)))
-      map_set_terrain(x, map.ysize-2, T_TUNDRA);
+    native_to_map_pos(&map_x, &map_y, x, 1);
+    if (map_get_terrain(map_x, map_y)!=T_ARCTIC &&
+       !is_ocean(map_get_terrain(map_x, map_y)))
+      map_set_terrain(map_x, map_y, T_TUNDRA);
+    native_to_map_pos(&map_x, &map_y, x, map.ysize - 2);
+    if (map_get_terrain(map_x, map_y)!=T_ARCTIC && 
+       !is_ocean(map_get_terrain(map_x, map_y)))
+      map_set_terrain(map_x, map_y, T_TUNDRA);
   }
 }
 
@@ -199,7 +211,7 @@
 **************************************************************************/
 static void make_forests(void)
 {
-  int x,y;
+  int x, y, map_x, map_y;
   int forestsize = (map_num_tiles() * map.forestsize) / 1000;
 
   forests = 0;
@@ -212,8 +224,9 @@
     if (myrand(100)>75) {
       y=(myrand(map.ysize*2/10))+map.ysize*4/10;
       x=myrand(map.xsize);
-      if (map_get_terrain(x, y)==T_GRASSLAND) {
-       make_forest(x,y, hmap(x, y), 25);
+      native_to_map_pos(&map_x, &map_y, x, y);
+      if (map_get_terrain(map_x, map_y) == T_GRASSLAND) {
+       make_forest(map_x, map_y, hmap(map_x, map_y), 25);
       }
     }
   } while (forests<forestsize);
@@ -256,7 +269,8 @@
 **************************************************************************/
 static void make_deserts(void)
 {
-  int x,y,i,j;
+  int x, y, i, j, map_x, map_y;
+
   i=map.deserts;
   j=0;
   while (i > 0 && j < 500) {
@@ -264,14 +278,16 @@
 
     y=myrand(map.ysize*10/180)+map.ysize*110/180;
     x=myrand(map.xsize);
-    if (map_get_terrain(x, y)==T_GRASSLAND) {
-      make_desert(x,y, hmap(x, y), 50);
+    native_to_map_pos(&map_x, &map_y, x, y);
+    if (map_get_terrain(map_x, map_y) == T_GRASSLAND) {
+      make_desert(map_x, map_y, hmap(map_x, map_y), 50);
       i--;
     }
     y=myrand(map.ysize*10/180)+map.ysize*60/180;
     x=myrand(map.xsize);
-    if (map_get_terrain(x, y)==T_GRASSLAND) {
-      make_desert(x,y, hmap(x, y), 50);
+    native_to_map_pos(&map_x, &map_y, x, y);
+    if (map_get_terrain(map_x, map_y) == T_GRASSLAND) {
+      make_desert(map_x, map_y, hmap(map_x, map_y), 50);
       i--;
     }
   }
@@ -786,15 +802,33 @@
 **************************************************************************/
 static void make_passable(void)
 {
-  int x;
+  int x, map_x, map_y;
   
   for (x=0;x<map.xsize;x++) {
-    map_set_terrain(x, 2, T_OCEAN);
-    if (myrand(100)>50) map_set_terrain(x,1,T_OCEAN);
-    if (myrand(100)>50) map_set_terrain(x,3,T_OCEAN);
-    map_set_terrain(x, map.ysize-3, T_OCEAN);
-    if (myrand(100)>50) map_set_terrain(x,map.ysize-2,T_OCEAN);
-    if (myrand(100)>50) map_set_terrain(x,map.ysize-4,T_OCEAN);
+    native_to_map_pos(&map_x, &map_y, x, 2);
+    map_set_terrain(map_x, map_y, T_OCEAN);
+
+    if (myrand(100) > 50) {
+      native_to_map_pos(&map_x, &map_y, x, 1);
+      map_set_terrain(map_x, map_y, T_OCEAN);
+    }
+
+    if (myrand(100) > 50) {
+      native_to_map_pos(&map_x, &map_y, x, 3);
+      map_set_terrain(map_x, map_y, T_OCEAN);
+    }
+
+    native_to_map_pos(&map_x, &map_y, x, map.ysize - 3);
+    map_set_terrain(map_x, map_y, T_OCEAN);
+
+    if (myrand(100) > 50) {
+       native_to_map_pos(&map_x, &map_y, x, map.ysize - 2);
+       map_set_terrain(map_x, map_y, T_OCEAN);
+    }
+    if (myrand(100) > 50) {
+       native_to_map_pos(&map_x, &map_y, x, map.ysize - 4);
+       map_set_terrain(map_x, map_y, T_OCEAN);
+    }
   } 
   
 }
@@ -805,15 +839,17 @@
 **************************************************************************/
 static void make_fair(void)
 {
-  int x,y;
+  int x, y, map_x, map_y;
+
   for (y=2;y<map.ysize-2;y++) {
     for (x=0;x<map.xsize;x++) {
-      if (terrain_is_clean(x,y)) {
-       if (map_get_terrain(x, y) != T_RIVER &&
-           !map_has_special(x, y, S_RIVER)) {
-         map_set_terrain(x, y, T_HILLS);
+      native_to_map_pos(&map_x, &map_y, x, y);
+      if (terrain_is_clean(map_x, map_y)) {
+       if (map_get_terrain(map_x, map_y) != T_RIVER &&
+           !map_has_special(map_x, map_y, S_RIVER)) {
+         map_set_terrain(map_x, map_y, T_HILLS);
        }
-       cartesian_adjacent_iterate(x, y, x1, y1) {
+       cartesian_adjacent_iterate(map_x, map_y, x1, y1) {
          if (myrand(100) > 66 &&
              !is_ocean(map_get_terrain(x1, y1))
              && map_get_terrain(x1, y1) != T_RIVER
@@ -879,11 +915,11 @@
     return FALSE;
   }
 
-  cartesian_adjacent_iterate(x, y, x1, y1) {
+  adjc_iterate(x, y, x1, y1) {
     if (!is_ocean(map_get_terrain(x1, y1))) {
       return FALSE;
     }
-  } cartesian_adjacent_iterate_end;
+  } adjc_iterate_end;
 
   return TRUE;
 }
@@ -941,8 +977,13 @@
   } whole_map_iterate_end;
 
   if (map.generator != 0 && has_poles) {
-    assign_continent_flood(0, 0, 1);
-    assign_continent_flood(0, map.ysize-1, 2);
+    int map_x, map_y;
+
+    native_to_map_pos(&map_x, &map_y, 0, 0);
+    assign_continent_flood(map_x, map_y, 1);
+
+    native_to_map_pos(&map_x, &map_y, 0, map.ysize - 1);
+    assign_continent_flood(map_x, map_y, 2);
     isle = 3;
   }
       
@@ -1158,6 +1199,18 @@
 
   mysrand(map.seed);
 
+  if (topo_has_flag(TF_ISO) && topo_has_flag(TF_WRAPY)
+      && (map.ysize % 2 == 1)) {
+    /* To wrap north-south an iso-map must have even Y dimension. */
+    /* FIXME: where should this go?  Not here, certainly... */
+    map.ysize++;
+  }
+
+  if (topo_has_flag(TF_ISO) && map.generator != 1) {
+    freelog(LOG_NORMAL, _("Only map generator 1 supports iso-maps."));
+    map.generator = 1;
+  }
+
   /* FIXME: currently the lack of poles is hard-coded for maps that wrap
    * north-south.  In the future this could be a server option.  It also
    * needs to control the temperature gradient between "poles" and
@@ -1347,10 +1400,12 @@
 
 static void add_specials(int prob)
 {
-  int x,y;
+  int xn,yn;
   enum tile_terrain_type ttype;
-  for (y=1;y<map.ysize-1;y++) {
-    for (x=0;x<map.xsize; x++) {
+  for (yn=1;yn<map.ysize-1;yn++) {
+    for (xn=0;xn<map.xsize; xn++) {
+      int x,y;
+      native_to_map_pos(&x, &y, xn, yn);
       ttype = map_get_terrain(x, y);
       if ((is_ocean(ttype) && is_coastline(x,y)) || !is_ocean(ttype)) {
        if (myrand(1000)<prob) {
@@ -1769,33 +1824,36 @@
 **************************************************************************/
 static void initworld(struct gen234_state *pstate)
 {
-  int x, y;
+  int xn, yn, x, y;
   
   height_map = fc_malloc(sizeof(int) * map.ysize * map.xsize);
   islands = fc_malloc((MAP_NCONT+1)*sizeof(struct isledata));
   
-  for (y = 0 ; y < map.ysize ; y++) 
-    for (x = 0 ; x < map.xsize ; x++) {
+  for (yn = 0 ; yn < map.ysize ; yn++) 
+    for (xn = 0 ; xn < map.xsize ; xn++) {
+      native_to_map_pos(&x, &y, xn, yn);
       map_set_terrain(x, y, T_OCEAN);
       map_set_continent(x, y, 0);
       map_clear_all_specials(x, y);
       map_set_owner(x, y, NULL);
     }
   if (has_poles) {
-    for (x = 0; x < map.xsize; x++) {
-      map_set_terrain(x, 0, myrand(9) > 0 ? T_ARCTIC : T_TUNDRA);
-      map_set_continent(x, 0, 1);
+    for (xn = 0; xn < map.xsize; xn++) {
+      native_to_map_pos(&x, &y, xn, 0);
+      map_set_terrain(x, y, myrand(9) > 0 ? T_ARCTIC : T_TUNDRA);
+      map_set_continent(x, y, 1);
       if (myrand(9) == 0) {
-       map_set_terrain(x, 1, myrand(9) > 0 ? T_TUNDRA : T_ARCTIC);
-       map_set_continent(x, 1, 1);
-      }
-      map_set_terrain(x, map.ysize - 1,
-                     myrand(9) > 0 ? T_ARCTIC : T_TUNDRA);
-      map_set_continent(x, map.ysize - 1, 2);
+       native_to_map_pos(&x, &y, xn, 1);
+       map_set_terrain(x, y, myrand(9) > 0 ? T_TUNDRA : T_ARCTIC);
+       map_set_continent(x, y, 1);
+      }
+      native_to_map_pos(&x, &y, xn, map.ysize - 1);
+      map_set_terrain(x, y, myrand(9) > 0 ? T_ARCTIC : T_TUNDRA);
+      map_set_continent(x, y, 2);
       if (myrand(9) == 0) {
-       map_set_terrain(x, map.ysize - 2,
-                       myrand(9) > 0 ? T_TUNDRA : T_ARCTIC);
-       map_set_continent(x, map.ysize - 2, 2);
+       native_to_map_pos(&x, &y, xn, map.ysize - 2);
+       map_set_terrain(x, y, myrand(9) > 0 ? T_TUNDRA : T_ARCTIC);
+       map_set_continent(x, y, 2);
       }
     }
     map.num_continents = 2;

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