Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2003:
[Freeciv-Dev] (PR#6721) A Quincuncial topology
Home

[Freeciv-Dev] (PR#6721) A Quincuncial topology

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: rt-guest@xxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#6721) A Quincuncial topology
From: "Marcelo Burda" <mburda@xxxxxxxxx>
Date: Wed, 10 Dec 2003 14:40:14 -0800
Reply-to: rt@xxxxxxxxxxx

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

 
> The biggest problems are with tile updates.  Often when updating a 
unit 
> the client can't figure out where to do the update.  And client-side 
> goto doesn't work at all. 
>  
> jason 
 
This problem is no more.  
                Marcelo 
diff -ru -Xfreeciv/diff_ignore freeciv-cvs-Dec-08/client/gui-gtk/mapview.c 
freeciv/client/gui-gtk/mapview.c
--- freeciv-cvs-Dec-08/client/gui-gtk/mapview.c 2003-11-20 07:02:21.000000000 
+0100
+++ freeciv/client/gui-gtk/mapview.c    2003-12-09 16:24:36.000000000 +0100
@@ -1483,14 +1483,18 @@
   struct unit *punit, *pfocus;
   enum tile_special_type special;
   int count, i = 0;
-  bool solid_bg, fog, tile_hilited;
+  bool solid_bg, fog, tile_hilited, is_reversed;
   struct canvas_store canvas_store = {pm};
 
   if (!width || !(height || height_unit))
     return;
-
-  count = fill_tile_sprite_array_iso(tile_sprs, coasts, dither,
-                                    x, y, citymode, &solid_bg);
+  
+  if(normalize_map_pos_revdes(&x, &y,&is_reversed))
+  {
+      count = fill_tile_sprite_array_iso(tile_sprs, coasts, dither,
+                                    x, y, citymode, &solid_bg, is_reversed);
+  }
+  else { count = -1;}
 
   if (count == -1) { /* tile is unknown */
     pixmap_put_black_tile_iso(pm, canvas_x, canvas_y,
@@ -1498,9 +1502,7 @@
     return;
   }
 
-  /* Replace with check for is_normal_tile later */
-  assert(is_real_map_pos(x, y));
-  normalize_map_pos(&x, &y);
+  
 
   fog = tile_get_known(x, y) == TILE_KNOWN_FOGGED && draw_fog_of_war;
   pcity = map_get_city(x, y);
@@ -1656,7 +1658,7 @@
   }
 
   /* National borders */
-  tile_draw_borders_iso(&canvas_store, x, y, canvas_x, canvas_y, draw);
+  tile_draw_borders_iso(&canvas_store, x, y, canvas_x, canvas_y, draw, 
is_reversed);
 
   if (draw_coastline && !draw_terrain) {
     enum tile_terrain_type t1 = map_get_terrain(x, y), t2;
diff -ru -Xfreeciv/diff_ignore freeciv-cvs-Dec-08/client/gui-sdl/mapview.c 
freeciv/client/gui-sdl/mapview.c
--- freeciv-cvs-Dec-08/client/gui-sdl/mapview.c 2003-11-15 07:00:28.000000000 
+0100
+++ freeciv/client/gui-sdl/mapview.c    2003-12-09 16:24:36.000000000 +0100
@@ -2135,7 +2135,7 @@
 
   count =
        fill_tile_sprite_array_iso(pTile_sprs, pCoasts, NULL, map_col,
-                                map_row, citymode, &solid_bg);
+                                map_row, citymode, &solid_bg,FALSE);
 
   if (count == -1) { /* tile is unknown */
     des.x = map_x;
diff -ru -Xfreeciv/diff_ignore freeciv-cvs-Dec-08/client/mapview_common.c 
freeciv/client/mapview_common.c
--- freeciv-cvs-Dec-08/client/mapview_common.c  2003-11-18 07:02:24.000000000 
+0100
+++ freeciv/client/mapview_common.c     2003-12-10 22:14:08.000000000 +0100
@@ -45,11 +45,17 @@
 **************************************************************************/
 void refresh_tile_mapcanvas(int x, int y, bool write_to_screen)
 {
+    int xvec[9], yvec[9], i=0, ni;
   assert(is_real_map_pos(x, y));
-  if (!normalize_map_pos(&x, &y)) {
-    return;
-  }
 
+  ni=map_near_orbit(x, y, xvec, yvec); /* 0 if not able to be normalize */
+
+  while( i< ni)
+  {
+      x=xvec[i];
+      y=yvec[i];
+      i++;
+    
   if (tile_visible_mapcanvas(x, y)) {
     update_map_canvas(x, y, 1, 1, FALSE);
 
@@ -101,7 +107,7 @@
        } rectangle_iterate_end;
       }
     }
-
+  }
     if (write_to_screen) {
       flush_dirty();
     }
@@ -175,7 +181,7 @@
 **************************************************************************/
 bool map_to_canvas_pos(int *canvas_x, int *canvas_y, int map_x, int map_y)
 {
-  int center_map_x, center_map_y, dx, dy;
+  int center_map_x, center_map_y;
 
   /*
    * First we wrap the coordinates to hopefully be within the the mapview
@@ -186,9 +192,6 @@
   base_canvas_to_map_pos(&center_map_x, &center_map_y,
                         mapview_canvas.width / 2,
                         mapview_canvas.height / 2);
-  map_distance_vector(&dx, &dy, center_map_x, center_map_y, map_x, map_y);
-  map_x = center_map_x + dx;
-  map_y = center_map_y + dy;
 
   if (is_isometric) {
     /* For a simpler example of this math, see city_to_canvas_pos(). */
@@ -292,6 +295,7 @@
   TRUE if the position is real; in this case it will be normalized. Returns
   FALSE if the tile is unreal - caller may use nearest_real_pos() if
   required.
+  no more, in reversed wrapping we need to preserve non normal pos ![mburda]
 **************************************************************************/
 bool canvas_to_map_pos(int *map_x, int *map_y, int canvas_x, int canvas_y)
 {
@@ -311,13 +315,13 @@
   map_to_native_pos(&nat_x0, &nat_y0, map_x0, map_y0);
   get_mapview_scroll_window(&xmin, &ymin, &xmax, &ymax, &xsize, &ysize);
 
-  if (topo_has_flag(TF_WRAPX)) {
+  if (XWRAP_TYPE_IS(WT_SIMPLEST)) {
     nat_x0 = FC_WRAP(nat_x0, map.xsize);
   } else {
     nat_x0 = CLIP(xmin, nat_x0, xmax - xsize);
   }
 
-  if (topo_has_flag(TF_WRAPY)) {
+  if (YWRAP_TYPE_IS(WT_SIMPLEST)) {
     nat_y0 = FC_WRAP(nat_y0, map.ysize);
   } else {
     nat_y0 = CLIP(ymin, nat_y0, ymax - ysize);
@@ -464,14 +468,22 @@
   /* Now override the above to satisfy wrapping constraints.  We allow the
    * scrolling to cover the full range of the map, plus one unit in each
    * direction (to allow scrolling with the scroll bars, for instance). */
-  if (topo_has_flag(TF_WRAPX)) {
+  if (XWRAP_TYPE_IS(WT_SIMPLEST)) {
     *xmin = -1;
     *xmax = map.xsize + *xsize;
   }
-  if (topo_has_flag(TF_WRAPY)) {
+  if (XWRAP_TYPE_IS(WT_REVERSED)) {
+    *xmin -= 5;
+    *xmax += 5;
+  }
+  if (YWRAP_TYPE_IS(WT_SIMPLEST)) {
     *ymin = -1;
     *ymax = map.ysize + *ysize;
   }
+  if (YWRAP_TYPE_IS(WT_REVERSED)) {
+    *ymin -= 5;
+    *ymax += 5;
+  }
 
   freelog(LOG_DEBUG, "x: %d<-%d->%d; y: %d<-%d->%d",
          *xmin, *xsize, *xmax, *ymin, *ymax, *ysize);
@@ -575,19 +587,19 @@
    * border, then it's a border tile.  We can only really check the
    * scrolling when the mapview window lines up with the map. */
   if (canvas_x < border_x
-      && (!same || scroll_x > xmin || topo_has_flag(TF_WRAPX))) {
+      && (!same || scroll_x > xmin || XWRAP_TYPE_IS(WT_SIMPLEST))) {
     return FALSE;
   }
   if (canvas_y < border_y
-      && (!same || scroll_y > ymin || topo_has_flag(TF_WRAPY))) {
+      && (!same || scroll_y > ymin || YWRAP_TYPE_IS(WT_SIMPLEST))) {
     return FALSE;
   }
   if (canvas_x + NORMAL_TILE_WIDTH > mapview_canvas.width - border_x
-      && (!same || scroll_x + xsize >= xmax || topo_has_flag(TF_WRAPX))) {
+      && (!same || scroll_x + xsize >= xmax || XWRAP_TYPE_IS(WT_SIMPLEST))) {
     return FALSE;
   }
   if (canvas_y + NORMAL_TILE_HEIGHT > mapview_canvas.height - border_y
-      && (!same || scroll_y + ysize >= ymax || topo_has_flag(TF_WRAPY))) {
+      && (!same || scroll_y + ysize >= ymax || YWRAP_TYPE_IS(WT_SIMPLEST))) {
     return FALSE;
   }
 
@@ -650,7 +662,7 @@
 **************************************************************************/
 static void tile_draw_borders(struct canvas_store *pcanvas_store,
                              int map_x, int map_y,
-                             int canvas_x, int canvas_y)
+                             int canvas_x, int canvas_y, bool is_reversed)
 {
   struct player *this_owner = map_get_owner(map_x, map_y), *adjc_owner;
   int x1, y1;
@@ -660,7 +672,7 @@
   }
 
   /* left side */
-  if (MAPSTEP(x1, y1, map_x, map_y, DIR8_WEST)
+  if (MAPSTEP(x1, y1, map_x, map_y, NORMALIZE_DIR(DIR8_WEST,is_reversed))
       && this_owner != (adjc_owner = map_get_owner(x1, y1))
       && tile_get_known(x1, y1)
       && this_owner) {
@@ -670,7 +682,7 @@
   }
 
   /* top side */
-  if (MAPSTEP(x1, y1, map_x, map_y, DIR8_NORTH)
+  if (MAPSTEP(x1, y1, map_x, map_y, NORMALIZE_DIR(DIR8_NORTH,is_reversed))
       && this_owner != (adjc_owner = map_get_owner(x1, y1))
       && tile_get_known(x1, y1)
       && this_owner) {
@@ -679,7 +691,7 @@
   }
 
   /* right side */
-  if (MAPSTEP(x1, y1, map_x, map_y, DIR8_EAST)
+  if (MAPSTEP(x1, y1, map_x, map_y, NORMALIZE_DIR(DIR8_EAST,is_reversed))
       && this_owner != (adjc_owner = map_get_owner(x1, y1))
       && tile_get_known(x1, y1)
       && this_owner) {
@@ -689,7 +701,7 @@
   }
 
   /* bottom side */
-  if (MAPSTEP(x1, y1, map_x, map_y, DIR8_SOUTH)
+  if (MAPSTEP(x1, y1, map_x, map_y, NORMALIZE_DIR(DIR8_SOUTH,is_reversed))
       && this_owner != (adjc_owner = map_get_owner(x1, y1))
       && tile_get_known(x1, y1)
       && this_owner) {
@@ -709,11 +721,12 @@
   struct drawn_sprite tile_sprs[80];
   bool solid_bg;
   struct player *pplayer;
-  bool is_real = normalize_map_pos(&map_x, &map_y);
+  bool is_tile_reversed, is_real = 
+   normalize_map_pos_revdes(&map_x, &map_y, &is_tile_reversed);
 
   if (is_real && tile_get_known(map_x, map_y)) {
     int count = fill_tile_sprite_array(tile_sprs, map_x, map_y, citymode,
-                                      &solid_bg, &pplayer);
+                                      &solid_bg, &pplayer, is_tile_reversed);
     int i = 0;
 
     if (solid_bg) {
@@ -775,14 +788,14 @@
     }
 
     /* Draw national borders. */
-    tile_draw_borders(pcanvas_store, map_x, map_y, canvas_x, canvas_y);
+    tile_draw_borders(pcanvas_store, map_x, map_y, canvas_x, canvas_y, 
is_tile_reversed);
 
     if (draw_coastline && !draw_terrain) {
       enum tile_terrain_type t1 = map_get_terrain(map_x, map_y), t2;
       int x1, y1;
 
       /* left side */
-      if (MAPSTEP(x1, y1, map_x, map_y, DIR8_WEST)) {
+      if (MAPSTEP(x1, y1, map_x, map_y, 
NORMALIZE_DIR(DIR8_WEST,is_tile_reversed))) {
        t2 = map_get_terrain(x1, y1);
        if (is_ocean(t1) ^ is_ocean(t2)) {
          gui_put_line(pcanvas_store, COLOR_STD_OCEAN, LINE_NORMAL,
@@ -791,7 +804,7 @@
       }
 
       /* top side */
-      if (MAPSTEP(x1, y1, map_x, map_y, DIR8_NORTH)) {
+      if (MAPSTEP(x1, y1, map_x, map_y, 
NORMALIZE_DIR(DIR8_NORTH,is_tile_reversed))) {
        t2 = map_get_terrain(x1, y1);
        if (is_ocean(t1) ^ is_ocean(t2)) {
          gui_put_line(pcanvas_store, COLOR_STD_OCEAN, LINE_NORMAL,
@@ -812,7 +825,7 @@
       enum direction8 dir;
 
       for (dir = 0; dir < 8; dir++) {
-       if (get_drawn(map_x, map_y, dir)) {
+       if (get_drawn(map_x, map_y, NORMALIZE_DIR(dir,is_tile_reversed))) {
          draw_segment(map_x, map_y, dir);
        }
       }
@@ -854,7 +867,7 @@
 void tile_draw_borders_iso(struct canvas_store *pcanvas_store,
                           int map_x, int map_y,
                           int canvas_x, int canvas_y,
-                          enum draw_type draw)
+                          enum draw_type draw, bool is_reversed)
 {
   struct player *this_owner = map_get_owner(map_x, map_y), *adjc_owner;
   int x1, y1;
@@ -864,7 +877,7 @@
   }
 
   /* left side */
-  if ((draw & D_M_L) && MAPSTEP(x1, y1, map_x, map_y, DIR8_WEST)
+  if ((draw & D_M_L) && MAPSTEP(x1, y1, map_x, map_y, 
NORMALIZE_DIR(DIR8_WEST,is_reversed))
       && this_owner != (adjc_owner = map_get_owner(x1, y1))
       && tile_get_known(x1, y1)) {
     if (adjc_owner) {
@@ -884,7 +897,7 @@
   }
 
   /* top side */
-  if ((draw & D_M_R) && MAPSTEP(x1, y1, map_x, map_y, DIR8_NORTH)
+  if ((draw & D_M_R) && MAPSTEP(x1, y1, map_x, 
map_y,NORMALIZE_DIR(DIR8_NORTH,is_reversed))
       && this_owner != (adjc_owner = map_get_owner(x1, y1))
       && tile_get_known(x1, y1)) {
     if (adjc_owner) {
@@ -912,11 +925,10 @@
 static void put_tile_iso(int map_x, int map_y, enum draw_type draw)
 {
   int canvas_x, canvas_y;
-
   if (map_to_canvas_pos(&canvas_x, &canvas_y, map_x, map_y)) {
     int height, width, height_unit;
     int offset_x, offset_y, offset_y_unit;
-
+    bool is_reversed;
     freelog(LOG_DEBUG, "putting (%d,%d) at (%d,%d), draw %x",
            map_x, map_y, canvas_x, canvas_y, draw);
 
@@ -955,15 +967,11 @@
       offset_y_unit = NORMAL_TILE_HEIGHT;
     }
 
-    if (normalize_map_pos(&map_x, &map_y)) {
       gui_map_put_tile_iso(map_x, map_y, canvas_x, canvas_y,
                           offset_x, offset_y, offset_y_unit,
                           width, height, height_unit,
                           draw);
-    } else {
-      gui_put_sprite(mapview_canvas.store, canvas_x, canvas_y,
-                    sprites.black_tile, offset_x, offset_y, width, height);
-    }
+    
   }
 }
 
diff -ru -Xfreeciv/diff_ignore freeciv-cvs-Dec-08/client/mapview_common.h 
freeciv/client/mapview_common.h
--- freeciv-cvs-Dec-08/client/mapview_common.h  2003-10-01 06:59:02.000000000 
+0200
+++ freeciv/client/mapview_common.h     2003-12-09 16:24:36.000000000 +0100
@@ -158,7 +158,7 @@
 void tile_draw_borders_iso(struct canvas_store *pcanvas_store,
                           int map_x, int map_y,
                           int canvas_x, int canvas_y,
-                          enum draw_type draw);
+                          enum draw_type draw,bool is_reversed);
 
 void update_map_canvas(int x, int y, int width, int height,
                       bool write_to_screen);
diff -ru -Xfreeciv/diff_ignore freeciv-cvs-Dec-08/client/packhand.c 
freeciv/client/packhand.c
--- freeciv-cvs-Dec-08/client/packhand.c        2003-12-09 07:08:02.000000000 
+0100
+++ freeciv/client/packhand.c   2003-12-09 16:24:36.000000000 +0100
@@ -1241,7 +1241,7 @@
 {
   map.xsize = xsize;
   map.ysize = ysize;
-  map.topology_id = topology_id;
+  map_init_topology(topology_id);
   map.is_earth = is_earth;
 
   map_allocate();
diff -ru -Xfreeciv/diff_ignore freeciv-cvs-Dec-08/client/tilespec.c 
freeciv/client/tilespec.c
--- freeciv-cvs-Dec-08/client/tilespec.c        2003-11-30 07:05:57.000000000 
+0100
+++ freeciv/client/tilespec.c   2003-12-10 22:39:45.000000000 +0100
@@ -1369,11 +1369,14 @@
     ttype_near     : terrain types of all adjacent terrain
     tspecial_near  : specials of all adjacent terrain
 **************************************************************************/
-static void build_tile_data(int map_x, int map_y,
+#define  build_tile_data(A,B,C,D,E,F)\
+  build_tile_data_reversed((A),(B),(C),(D),(E),(F),FALSE)
+static void build_tile_data_reversed(int map_x, int map_y,
                            enum tile_terrain_type *ttype,
                            enum tile_special_type *tspecial,
                            enum tile_terrain_type *ttype_near,
-                           enum tile_special_type *tspecial_near)
+                           enum tile_special_type *tspecial_near,
+                            bool is_reversed)
 {
   enum direction8 dir;
 
@@ -1390,8 +1393,7 @@
   /* Loop over all adjacent tiles.  We should have an iterator for this. */
   for (dir = 0; dir < 8; dir++) {
     int x1, y1;
-
-    if (MAPSTEP(x1, y1, map_x, map_y, dir)
+    if (MAPSTEP(x1, y1, map_x, map_y,NORMALIZE_DIR(dir, is_reversed) )
        && tile_get_known(x1, y1) != TILE_UNKNOWN) {
       tspecial_near[dir] = map_get_special(x1, y1);
       ttype_near[dir] = map_get_terrain(x1, y1);
@@ -1859,7 +1861,7 @@
                               struct Sprite **coasts,
                               struct Sprite **dither,
                               int x, int y, bool citymode,
-                              bool *solid_bg)
+                              bool *solid_bg,bool is_reversed)
 {
   enum tile_terrain_type ttype, ttype_near[8];
   enum tile_special_type tspecial, tspecial_near[8];
@@ -1874,7 +1876,7 @@
 
   pcity = map_get_city(x, y);
 
-  build_tile_data(x, y, &ttype, &tspecial, ttype_near, tspecial_near);
+  build_tile_data_reversed(x, y, &ttype, &tspecial, ttype_near, 
tspecial_near,is_reversed);
 
   if (draw_terrain) {
     if (is_ocean(ttype)) {
@@ -2031,7 +2033,7 @@
     for (dir = 0; dir < 4; dir++) {
       int x1, y1, other;
 
-      if (MAPSTEP(x1, y1, x, y, DIR4_TO_DIR8[dir]))
+      if (MAPSTEP(x1, y1, x, y, NORMALIZE_DIR(DIR4_TO_DIR8[dir],is_reversed)))
         other = (tile_get_known(x1, y1) != TILE_UNKNOWN) ? 
ttype_near[DIR4_TO_DIR8[dir]]:T_UNKNOWN;
       else
         other = ttype_near[dir];
@@ -2061,7 +2063,7 @@
 ***********************************************************************/
 int fill_tile_sprite_array(struct drawn_sprite *sprs, int abs_x0, int abs_y0,
                           bool citymode, bool *solid_bg,
-                          struct player **pplayer)
+                          struct player **pplayer, bool is_reversed)
 {
   enum tile_terrain_type ttype, ttype_near[8];
   enum tile_special_type tspecial, tspecial_near[8];
@@ -2106,8 +2108,8 @@
     }
   }
 
-  build_tile_data(abs_x0, abs_y0, 
-                 &ttype, &tspecial, ttype_near, tspecial_near);
+  build_tile_data_reversed(abs_x0, abs_y0, 
+                 &ttype, &tspecial, ttype_near, tspecial_near,is_reversed);
 
   if(map.is_earth &&
      abs_x0>=34 && abs_x0<=36 && abs_y0>=den_y && abs_y0<=den_y+1) {
@@ -2218,7 +2220,7 @@
     for (dir = 0; dir < 4; dir++) {
       int x1, y1;
 
-      if (MAPSTEP(x1, y1, abs_x0, abs_y0, DIR4_TO_DIR8[dir]))
+      if (MAPSTEP(x1, y1, abs_x0, 
abs_y0,NORMALIZE_DIR(DIR4_TO_DIR8[dir],is_reversed)))
         known[dir] = (tile_get_known(x1, y1) != TILE_UNKNOWN);
       else
         known[dir] = TRUE;
@@ -2412,10 +2414,13 @@
 enum color_std overview_tile_color(int x, int y)
 {
   enum color_std color;
-  struct tile *ptile=map_get_tile(x, y);
+  struct tile *ptile;
   struct unit *punit;
   struct city *pcity;
 
+  normalize_map_pos(&x, &y);
+  ptile = map_get_tile(x, y);
+
   if (tile_get_known(x, y) == TILE_UNKNOWN) {
     color=COLOR_STD_BLACK;
   } else if((pcity=map_get_city(x, y))) {
diff -ru -Xfreeciv/diff_ignore freeciv-cvs-Dec-08/client/tilespec.h 
freeciv/client/tilespec.h
--- freeciv-cvs-Dec-08/client/tilespec.h        2003-10-16 06:59:07.000000000 
+0200
+++ freeciv/client/tilespec.h   2003-12-09 16:24:36.000000000 +0100
@@ -53,15 +53,14 @@
 void tilespec_free_city_tiles(int count);
 
 /* Gfx support */
-
 int fill_tile_sprite_array_iso(struct drawn_sprite *sprs,
                               struct Sprite **coasts,
                               struct Sprite **dither,
                               int x, int y, bool citymode,
-                              bool *solid_bg);
-int fill_tile_sprite_array(struct drawn_sprite *sprs, int abs_x0, int abs_y0,
-                          bool citymode, bool *solid_bg,
-                          struct player **pplayer);
+                              bool *solid_bg,bool is_reversed);
+int fill_tile_sprite_array (struct drawn_sprite *sprs, int abs_x0,
+                           int abs_y0,  bool citymode, bool *solid_bg,
+                          struct player **pplayer, bool is_reversed);
 int fill_unit_sprite_array(struct drawn_sprite *sprs,
                           struct unit *punit, bool *solid_bg);
 int fill_city_sprite_array_iso(struct drawn_sprite *sprs,
diff -ru -Xfreeciv/diff_ignore freeciv-cvs-Dec-08/common/aicore/path_finding.c 
freeciv/common/aicore/path_finding.c
--- freeciv-cvs-Dec-08/common/aicore/path_finding.c     2003-11-23 
07:07:50.000000000 +0100
+++ freeciv/common/aicore/path_finding.c        2003-12-09 16:24:36.000000000 
+0100
@@ -265,7 +265,7 @@
     /* Processing Stage */
     /* The previous position is contained in {x,y} fields of map */
 
-    adjc_dir_iterate(pf_map->x, pf_map->y, x1, y1, dir) {
+    adjc_dir_iterate_full(pf_map->x, pf_map->y, x1, y1, dir, dir1, rev_des) {
       mapindex_t index1 = map_pos_to_index(x1, y1);
       struct pf_node *node1 = &pf_map->lattice[index1];
       utiny_t *status = &pf_map->status[index1];
@@ -324,13 +324,13 @@
          *status = NS_NEW;
          node1->extra_cost = extra;
          node1->cost = cost;
-         node1->dir_to_here = dir;
+         node1->dir_to_here = dir1;
          pq_insert(pf_map->queue, index1, -cost_of_path);
        }
       }
 
     }
-    adjc_dir_iterate_end;
+    adjc_dir_iterate_full_end;
   }
 
   /* Get the next nearest node */
@@ -707,7 +707,7 @@
 /***********************************************************************
   Creating path segment going back from d_node1 to a safe tile.
 ***********************************************************************/
-static void create_danger_segment(struct pf_map *pf_map, enum direction8 dir,
+static void create_danger_segment(struct pf_map *pf_map,
                                   struct danger_node *d_node1, int length)
 {
   int i;
@@ -817,7 +817,7 @@
            : d_node->step + 1);
 
     /* The previous position is contained in {x,y} fields of map */
-    adjc_dir_iterate(pf_map->x, pf_map->y, x1, y1, dir) {
+    adjc_dir_iterate_full(pf_map->x, pf_map->y, x1, y1, dir, dir1, rev_des) {
       mapindex_t index1 = map_pos_to_index(x1, y1);
       struct pf_node *node1 = &pf_map->lattice[index1];
       struct danger_node *d_node1 = &pf_map->d_lattice[index1];
@@ -880,11 +880,11 @@
                < get_total_CC(pf_map, node1->cost, node1->extra_cost))) {
          node1->extra_cost = extra;
          node1->cost = cost;
-         node1->dir_to_here = dir;
+         node1->dir_to_here = dir1;
           d_node1->step = loc_step + 1;
          if (d_node->is_dangerous) {
            /* Transition from red to blue, need to record the path back */
-           create_danger_segment(pf_map, dir, d_node1, 
+           create_danger_segment(pf_map, d_node1, 
                                   d_node->segment_length);
          } else {
            /* Clear the path back */
@@ -917,7 +917,7 @@
                && pf_map->status[index1] == NS_PROCESSED)) {
          node1->extra_cost = extra;
          node1->cost = cost;
-         node1->dir_to_here = dir;
+         node1->dir_to_here = dir1;
           d_node1->step = loc_step + 1;
           if (d_node->is_dangerous) {
             /* Increment the number of steps we are making across danger */
diff -ru -Xfreeciv/diff_ignore freeciv-cvs-Dec-08/common/map.c 
freeciv/common/map.c
--- freeciv-cvs-Dec-08/common/map.c     2003-12-09 07:08:06.000000000 +0100
+++ freeciv/common/map.c        2003-12-10 22:53:21.000000000 +0100
@@ -69,6 +69,9 @@
 
 #define MAP_TILE(x,y)  (map.tiles + map_pos_to_index(x, y))
 
+
+
+
 /***************************************************************
 ...
 ***************************************************************/
@@ -170,14 +173,96 @@
 {
   return !map.tiles;
 }
+/********************************************************************
+ choice of legal xsize and ysize near the selected ratio,
+ priority to preserve xsize*ysize over ratio 
+ this is a crude code but generaly is ok (mburda)
+*********************************************************************/ 
+void setmapratio(int Xratio, int Yratio)
+{
+    int size= map.xsize*map.ysize;
+    map.xsize=sqrt(size * Xratio/ Yratio);
+    if(map.xsize< MAP_MIN_WIDTHandHEIGHT) map.xsize=MAP_MIN_WIDTHandHEIGHT;
+    if(map.xsize> MAP_MAX_WIDTHandHEIGHT) map.xsize=MAP_MAX_WIDTHandHEIGHT;
+    map.ysize=size/map.xsize;
+    if(map.ysize< MAP_MIN_WIDTHandHEIGHT) map.ysize=MAP_MIN_WIDTHandHEIGHT;
+    if(map.ysize> MAP_MAX_WIDTHandHEIGHT) map.ysize=MAP_MAX_WIDTHandHEIGHT;
+    /* this is not a error, priority to map size */
+    map.xsize=size/map.ysize;
+    if(map.xsize< MAP_MIN_WIDTHandHEIGHT) map.xsize=MAP_MIN_WIDTHandHEIGHT;
+    if(map.xsize> MAP_MAX_WIDTHandHEIGHT) map.xsize=MAP_MAX_WIDTHandHEIGHT;
+}
+/*************************************************************************** 
+   WARNING: set topology_id this way or at last call it:
+       map_init_topology(map.topology_id) 
+
+   only set topology_id if a god one, be carrefuly to set oters flags 
+   and select the best ratio for this topology if topo as changed 
+   Alow set xsize or ysize freely after the choice of topology (mburda)
+
+   After WRAPX and WRAPY flags disapear we can symplify it a litle.
+*************************************************************************/
+
+void map_init_topology(int topology_id)
+{
+    map.topology_id = topology_id;
+    switch(topology_id & TF_MASK)
+ {
+   case TF_FLAT: 
+       if(( XWRAP_TYPE_IS(WT_NONE) &&  YWRAP_TYPE_IS(WT_NONE))) break;
+       setmapratio(1, 1) ;
+       map.xwrap_type=WT_NONE; map.ywrap_type=WT_NONE;
+       map.separatepoles=0;
+       break;
+   case TF_CLASSIC:
+       if(( XWRAP_TYPE_IS(WT_SIMPLEST) &&  YWRAP_TYPE_IS(WT_NONE))) break;
+       setmapratio(8, 5) ;
+       map.xwrap_type=WT_SIMPLEST; map.ywrap_type=WT_NONE;
+       break;
+   case TF_MOBIUS:
+       if(( XWRAP_TYPE_IS(WT_SIMPLEST) &&  YWRAP_TYPE_IS(WT_OFFSET))) break;
+       setmapratio(2, 1) ;
+       map.separatepoles=0;
+       map.xwrap_type=WT_SIMPLEST; map.ywrap_type=WT_OFFSET;
+       break;
+   case TF_TORUS:
+       if(( XWRAP_TYPE_IS(WT_SIMPLEST) &&  YWRAP_TYPE_IS(WT_SIMPLEST))) break;
+       setmapratio(1, 1) ;
+       map.xwrap_type=WT_SIMPLEST; map.ywrap_type=WT_SIMPLEST;
+       map.separatepoles=0;
+       break;
+   case TF_QUINCUNCIAL_SQ:
+       if(( XWRAP_TYPE_IS(WT_REVERSED) &&  YWRAP_TYPE_IS(WT_REVERSED))) break;
+       setmapratio(1, 1) ;
+       map.xwrap_type=WT_REVERSED; map.ywrap_type=WT_REVERSED;
+       map.separatepoles=0;
+       break;
+   case TF_QUINCUNCIAL:
+       if(( XWRAP_TYPE_IS(WT_SIMPLEST) &&  YWRAP_TYPE_IS(WT_REVERSED))) break;
+       setmapratio(2, 1) ;
+       map.xwrap_type=WT_SIMPLEST; map.ywrap_type=WT_REVERSED;
+       map.separatepoles=0;
+       break;
+   case TF_SPIN: 
+       if(( XWRAP_TYPE_IS(WT_REVERSED) &&  YWRAP_TYPE_IS(WT_NONE))) break;
+       setmapratio(2, 3) ;
+       map.xwrap_type=WT_REVERSED; map.ywrap_type=WT_NONE;
+       map.separatepoles=0;
+       break;
+ 
+ };
+    /* reversed topologies test sizes */ 
+    if(YWRAP_TYPE_IS(WT_REVERSED) | YWRAP_TYPE_IS(WT_OFFSET))
+       map.xsize =  map.xsize- map.xsize%2;
+    if(XWRAP_TYPE_IS(WT_REVERSED))  map.ysize =  map.ysize- map.ysize%2;      
+}
 
 /***************************************************************
  put some sensible values into the map structure
 ***************************************************************/
 void map_init(void)
 {
-  map.topology_id = MAP_DEFAULT_TOPO;
-  map.xsize                 = MAP_DEFAULT_WIDTH;
+  map.xsize                 = MAP_DEFAULT_WIDTH; 
   map.ysize                 = MAP_DEFAULT_HEIGHT;
   map.seed                  = MAP_DEFAULT_SEED;
   map.riches                = MAP_DEFAULT_RICHES;
@@ -200,8 +285,11 @@
   map.have_specials         = FALSE;
   map.have_rivers_overlay   = FALSE;
   map.have_huts             = FALSE;
+  map_init_topology(MAP_DEFAULT_TOPO); /*at last*/
 }
 
+ 
+
 /***************************************************************
 ...
 ***************************************************************/
@@ -480,12 +568,13 @@
 
 /***************************************************************
 ...
+ ice are not real coast, not safe [mburda]
 ***************************************************************/
 bool is_coastline(int x, int y)
 {
   adjc_iterate(x, y, x1, y1) {
     enum tile_terrain_type ter = map_get_terrain(x1, y1);
-    if (!is_ocean(ter) && ter != T_UNKNOWN) {
+    if (!(is_ocean(ter)|| is_ice(ter)) && ter != T_UNKNOWN) {
       return TRUE;
     }
   } adjc_iterate_end;
@@ -1145,14 +1234,14 @@
   /* trying to move off the screen is the default */
   memset(tile0->move_cost, maxcost, sizeof(tile0->move_cost));
 
-  adjc_dir_iterate(x, y, x1, y1, dir) {
+  adjc_dir_iterate_full(x, y, x1, y1, dir, dir1, revdes) {
     tile1 = map_get_tile(x1, y1);
     tile0->move_cost[dir] = tile_move_cost_ai(tile0, tile1, x, y,
                                              x1, y1, maxcost);
     /* reverse: not at all obfuscated now --dwp */
-    tile1->move_cost[DIR_REVERSE(dir)] =
+    tile1->move_cost[DIR_REVERSE(dir1)] =
        tile_move_cost_ai(tile1, tile0, x1, y1, x, y, maxcost);
-  } adjc_dir_iterate_end;
+  } adjc_dir_iterate_full_end;
   debug_log_move_costs("Reset move costs for", x, y, tile0);
 }
 
@@ -1202,9 +1291,9 @@
 /***************************************************************
 ...
 ***************************************************************/
-struct tile *map_get_tile(int x, int y)
+struct tile *map_get_tile(int map_x, int map_y)
 {
-  return MAP_TILE(x, y);
+    return MAP_TILE(map_x, map_y);
 }
 
 /***************************************************************
@@ -1367,56 +1456,219 @@
 
   Note, we need to leave x and y with sane values even in the unreal case.
   Some callers may for instance call nearest_real_pos on these values.
-**************************************************************************/
+ *************************************************************************
+ *alow the 9 topology xwrap_type-ywrap_type (mburda)
+ *************************************************************************/
 bool normalize_map_pos(int *x, int *y)
 {
-  int nat_x, nat_y;
+    bool tmp_descriptor;
+    return normalize_map_pos_revdes_city(x, y , &tmp_descriptor, NULL);
+}
+/**************************************************************************
+ * Some of normalize_map_pos and return a is_reversed flag if the tiles is
+ * turned 180° in the original x,y map pos  (mburda)
+ * if unreal is_reversed not well defined!
+ **************************************************************************/
+bool normalize_map_pos_revdes(int *x, int *y,bool *pdescriptor)
+{
+    return normalize_map_pos_revdes_city(x, y , pdescriptor, NULL);
+}
+
+/*****************************************************************************
+ * Some of normalize_map_pos_isreversed 
+ * the tiles are real only in one pos in the city map
+ * if there are a 2 image for this one  normalize_map_pos_isreversed_in_a_city
+ * return FALSE  (mburda)
+ *****************************************************************************/
 
+bool normalize_map_pos_revdes_city(int *px, int *py,bool *prevdes, struct city 
*pcity )
+{
+  int nat_x, nat_y, xfactor, yfactor ;
+ 
   /* Normalization is best done in native coordinatees. */
-  map_to_native_pos(&nat_x, &nat_y, *x, *y);
-
+  map_to_native_pos(&nat_x, &nat_y, *px, *py);
+  
   /* If the position is out of range in a non-wrapping direction, it is
    * unreal. */
-  if (!((topo_has_flag(TF_WRAPX) || (nat_x >= 0 && nat_x < map.xsize))
-       && (topo_has_flag(TF_WRAPY) || (nat_y >= 0 && nat_y < map.ysize)))) {
+  if (!(
+      ( !XWRAP_TYPE_IS(WT_NONE) || (nat_x >= 0 && nat_x < map.xsize) ) &&
+      ( !YWRAP_TYPE_IS(WT_NONE) || (nat_y >= 0 && nat_y < map.ysize) ) 
+     )) {
     return FALSE;
   }
-
-  /* Wrap in X and Y directions, as needed. */
-  if (topo_has_flag(TF_WRAPX)) {
-    nat_x = FC_WRAP(nat_x, map.xsize);
-  }
-  if (topo_has_flag(TF_WRAPY)) {
-    nat_y = FC_WRAP(nat_y, map.ysize);
+  xfactor=XWRAP_TYPE_IS(WT_REVERSED)?2:1;
+  yfactor=YWRAP_TYPE_IS(WT_REVERSED)?2:1;
+  *prevdes=
+      ( 
+      (MODULO(nat_x,xfactor*map.xsize) <  map.xsize)
+     !=
+      (MODULO(nat_y,yfactor*map.ysize) < map.ysize)
+      );
+
+  /* Wrap in X and Y directions and rotate, as needed. */
+  if(!YWRAP_TYPE_IS(WT_OFFSET))
+  {   /* not Movius strip */
+      if( *prevdes )
+      {
+         nat_x=MODULO(-nat_x-1, map.xsize);
+         nat_y=MODULO(-nat_y-1, map.ysize);
+      }
+      else 
+      { 
+         nat_x=MODULO(nat_x, map.xsize);
+         nat_y=MODULO(nat_y, map.ysize);
+      }
+  } else if (!XWRAP_TYPE_IS(WT_SIMPLEST))
+  { assert ( FALSE ); /* not a valid topologie */ }
+  else
+  {   /* Mobius */ /* not the best all the time */
+      while( nat_y < 0)
+      {
+         nat_y+= map.ysize;
+         nat_x+= map.xsize/2;
+      }
+      while( nat_y >= map.ysize)
+      {
+         nat_y-= map.ysize;
+         nat_x-= map.xsize/2;
+      }
+      nat_x=MODULO(nat_x, map.xsize);
+  }
+
+  /* if in a city and there are singularities*/
+  if(*prevdes && (pcity != NULL) )
+  {
+      int DX,DY, city_x,city_y;
+      map_to_native_pos(&city_x, &city_y, pcity->x, pcity->y);
+      DX=abs(nat_x-city_x);
+      DY=abs(nat_y-city_y);
+      if((DX<=2 && DY<=1) || (DX<=1 && DY<=2)) return FALSE;
   }
 
   /* Now transform things back to map coordinates. */
-  native_to_map_pos(x, y, nat_x, nat_y);
+  native_to_map_pos(px, py, nat_x, nat_y);
   return TRUE;
 }
 
 /**************************************************************************
 Twiddle *x and *y to point the the nearest real tile, and ensure that the
-position is normalized.
+position is normalized. 
+alow the 9 topology xwrap_type-ywrap_type
 **************************************************************************/
 void nearest_real_pos(int *x, int *y)
 {
-  int nat_x, nat_y;
+  int nat_x, nat_y,xfactor, yfactor;
+  bool revdes;
+
+  if(!XWRAP_TYPE_IS(WT_NONE) && !YWRAP_TYPE_IS(WT_NONE))
+      {normalize_map_pos(x, y);
+      return;}
+
+  assert( !XWRAP_TYPE_IS(WT_OFFSET) && !YWRAP_TYPE_IS(WT_OFFSET)); 
 
   map_to_native_pos(&nat_x, &nat_y, *x, *y);
-  if (!topo_has_flag(TF_WRAPX)) {
-    nat_x = CLIP(0, nat_x, map.xsize - 1);
-  }
-  if (!topo_has_flag(TF_WRAPY)) {
-    nat_y = CLIP(0, nat_y, map.ysize - 1);
+ 
+  xfactor=XWRAP_TYPE_IS(WT_REVERSED)?2:1;
+  yfactor=YWRAP_TYPE_IS(WT_REVERSED)?2:1;
+  revdes=
+      ( 
+      (MODULO(nat_x,xfactor*map.xsize) <  map.xsize)
+     !=
+      (MODULO(nat_y,yfactor*map.ysize) < map.ysize)
+      );
+  if( revdes)
+  {
+   nat_x=XWRAP_TYPE_IS(WT_NONE)
+       ?CLIP(0, map.xsize-nat_x-1, map.xsize - 1)
+       :MODULO(-nat_x-1, map.xsize);
+         
+   nat_y=YWRAP_TYPE_IS(WT_NONE)
+       ?CLIP(0, map.ysize-nat_y-1, map.ysize - 1)
+       :MODULO(-nat_y-1, map.ysize);
+         
+  }
+  else 
+  { 
+   nat_x=XWRAP_TYPE_IS(WT_NONE)
+       ?CLIP(0, nat_x, map.xsize - 1)
+       :MODULO(nat_x, map.xsize);
+   nat_y=YWRAP_TYPE_IS(WT_NONE)
+         ?CLIP(0, nat_y, map.ysize - 1)
+         :MODULO(nat_y, map.ysize);
   }
+  
   native_to_map_pos(x, y, nat_x, nat_y);
 
   if (!normalize_map_pos(x, y)) {
     assert(FALSE);
   }
 }
-
+/* **********************************************************************
+ return 0 for the coolest map_x,map_y tile of the map
+ and 100 for the hotest one, this is proportional to area climatic zones
+*************************************************************************/ 
+int map_clima(int map_x, int map_y)
+{
+    int nat_x, nat_y,x_2,y_2;
+    double x,y,m;
+    normalize_map_pos( &map_x, &map_y );
+    map_to_native_pos(&nat_x, &nat_y, map_x, map_y);
+    /* is a partial map */
+    if(XWRAP_TYPE_IS(WT_NONE) && YWRAP_TYPE_IS(WT_NONE))
+    {
+        return 100*nat_y/(map.ysize-1);        
+    } 
+    /* is a global map, get symeties */
+    x_2=map.xsize/2 -1+ map.xsize%2;
+    y_2=map.ysize/2 -1+ map.ysize%2;
+    if (nat_x >= x_2) nat_x = map.xsize-1- nat_x;
+    if (nat_y >= y_2) nat_y = map.ysize-1- nat_y;
+    x=(double )nat_x / (double)x_2;
+    y=(double)nat_y / (double)y_2;
+    if((XWRAP_TYPE_IS(WT_SIMPLEST) && YWRAP_TYPE_IS(WT_NONE)))
+    {
+       return 100*y;
+    }
+    if((XWRAP_TYPE_IS(WT_REVERSED) && YWRAP_TYPE_IS(WT_NONE)))
+    {
+       return 100-100*y;
+    }
+    if(XWRAP_TYPE_IS(WT_NONE) && YWRAP_TYPE_IS(WT_SIMPLEST))
+    {
+       return 100*x;
+    }
+    if(XWRAP_TYPE_IS(WT_NONE) && YWRAP_TYPE_IS(WT_REVERSED))
+    {
+       return 100-100*x;
+    }
+
+   
+    if((XWRAP_TYPE_IS(WT_SIMPLEST) && YWRAP_TYPE_IS(WT_SIMPLEST))
+    || (XWRAP_TYPE_IS(WT_REVERSED) && YWRAP_TYPE_IS(WT_REVERSED)))
+    {
+
+       if(x+y > 1) 
+       {
+           x = 1-x;
+           y = 1-y;
+       }
+       return 150*(x*x*y+x*y*y)-50*(x*x*x+y*y*y)+150*(x*x+y*y);
+
+    }
+    if((XWRAP_TYPE_IS(WT_SIMPLEST) && YWRAP_TYPE_IS(WT_REVERSED))||
+      (XWRAP_TYPE_IS(WT_SIMPLEST) && YWRAP_TYPE_IS(WT_OFFSET)))
+    {
+       x = x>.5
+            ? 2*x-1
+           : 1-2*x;
+    } else {
+       y = y > .5
+            ? 2*y-1
+           : 1-2*y;
+    }
+    m=MAX(x,y);
+    return  75*(x*x+y*y)*(1-m)+100*m*m*m;
+}
 /**************************************************************************
 Returns the total number of (real) positions (or tiles) on the map.
 **************************************************************************/
@@ -1437,41 +1689,224 @@
 
   (See also: real_map_distance, map_distance, and sq_map_distance.)
 
-  With the standard topology the ranges of the return value are:
-    -map.xsize/2 <= dx <= map.xsize/2
+  With all 9 topology the ranges of the return value are:
+    -map.xsize   <  dx < map.xsize
     -map.ysize   <  dy <  map.ysize
 ****************************************************************************/
 void map_distance_vector(int *dx, int *dy, int x0, int y0, int x1, int y1)
 {
-  if (topo_has_flag(TF_WRAPX) || topo_has_flag(TF_WRAPY)) {
-    /* Wrapping is done in native coordinates. */
+    int Dist,_Dist,Dx,Dy,_dx,_dy;
+    /* Work is done in native coordinates. */
     map_to_native_pos(&x0, &y0, x0, y0);
     map_to_native_pos(&x1, &y1, x1, y1);
-
-    /* Find the "native" distance vector. This corresponds closely to the
-     * map distance vector but is easier to wrap. */
     *dx = x1 - x0;
     *dy = y1 - y0;
-    if (topo_has_flag(TF_WRAPX)) {
-      /* Wrap dx to be in [-map.xsize/2, map.xsize/2). */
-      *dx = FC_WRAP(*dx + map.xsize / 2, map.xsize) - map.xsize / 2;
-    }
-    if (topo_has_flag(TF_WRAPY)) {
-      /* Wrap dy to be in [-map.ysize/2, map.ysize/2). */
-      *dy = FC_WRAP(*dy + map.ysize / 2, map.ysize) - map.ysize / 2;
-    }
+    /* offset wrap */
+    if(YWRAP_TYPE_IS(WT_OFFSET))
+    {
+       while (*dy > map.ysize / 2) 
+       { *dy -= map.ysize;
+       *dx -= map.xsize/2;} 
+       while (*dy <= -map.ysize / 2)
+           {*dy += map.ysize;
+           *dx += map.xsize/2;} 
+    } 
+    assert(!XWRAP_TYPE_IS(WT_OFFSET));
+    /* simplest wraps */
+    if(XWRAP_TYPE_IS(WT_SIMPLEST))
+    {
+       while (*dx > map.xsize / 2) *dx -= map.xsize;
+       while (*dx <= -map.xsize / 2) *dx += map.xsize;
+    } 
+    if(YWRAP_TYPE_IS(WT_SIMPLEST))
+    {
+       while (*dy > map.ysize / 2) *dy -= map.ysize; 
+       while (*dy <= -map.ysize / 2) *dy += map.ysize;
+    } 
+    Dist=MAX(abs( *dx ),abs( *dy ));
 
+    /* reversed toologies : */    
+  
+    if(XWRAP_TYPE_IS(WT_REVERSED) && YWRAP_TYPE_IS(WT_REVERSED))
+    {
+        /* Selection of best vector to a unmirrored destination */
+               _dx = *dx-map.xsize;
+       _dy = *dy-map.ysize;
+       while (_dx > map.xsize  ) _dx -= 2*map.xsize;
+       while (_dx <= -map.xsize ) _dx += 2*map.xsize;
+       while (_dy > map.ysize ) _dy -= 2*map.ysize;
+       while (_dy <= -map.ysize ) _dy += 2*map.ysize;
+       _Dist=MAX(abs( _dx ),abs( _dy ));
+        /* best way a this point of code */
+       if (Dist > _Dist)
+       {
+           *dx = _dx ; 
+           *dy = _dy ;
+           Dist = _Dist ;
+       } 
+
+       /* Selection of best vector to a mirrored verticaly destination */
+       _dx = (map.xsize - 1 - x1) - x0 ;
+       _dy = (-1 - y1) - y0;
+       while (_dx > map.xsize  ) _dx -= 2*map.xsize;
+       while (_dx <= -map.xsize ) _dx += 2*map.xsize;
+       while (_dy > map.ysize ) _dy -= 2*map.ysize;
+       while (_dy <= -map.ysize ) _dy += 2*map.ysize;
+       _Dist=MAX(abs( _dx ),abs( _dy ));
+       /* best way a this point of code */
+       if (Dist > _Dist)
+       {
+           *dx = _dx ; 
+           *dy = _dy ;
+           Dist = _Dist ;
+       } 
+
+       /* Selection of best vector to a mirrored horizontaly destination */
+
+       _dx =( - 1 - x1) - x0 ;
+       _dy = (map.ysize-1 - y1) - y0;
+       while (_dx > map.xsize  ) _dx -= 2*map.xsize;
+       while (_dx <= -map.xsize ) _dx += 2*map.xsize;
+       while (_dy > map.ysize ) _dy -= 2*map.ysize;
+       while (_dy <= -map.ysize ) _dy += 2*map.ysize;
+       _Dist=MAX(abs( _dx ),abs( _dy ));
+
+
+       /* best way is...*/
+       if (Dist > _Dist)
+       {
+           *dx = _dx ; 
+           *dy = _dy ;
+           Dist = _Dist ;
+       } 
+
+    }
+    else if(YWRAP_TYPE_IS(WT_REVERSED))
+    {
+        // central symetry 
+       Dy=(-1-y1) - y0; 
+       Dx=(map.xsize-x1-1) - x0;
+
+        /* periodicity in y over 2 maps */ 
+        while (Dy > map.ysize ) Dy -= 2*map.ysize; 
+       while (Dy <= -map.ysize ) Dy += 2*map.ysize;
+       
+       _Dist=MAX(abs(Dx),abs(Dy)); 
+        // get the best way 
+       if(_Dist<Dist) 
+       { 
+           Dist=_Dist; 
+           *dx=Dx; 
+           *dy=Dy; 
+       } 
+    }
+    else if( XWRAP_TYPE_IS(WT_REVERSED) )
+    {
+        // central symetry 
+       Dx=(-1-x1) - x0; 
+       Dy=(map.ysize-y1-1) - y0;
+
+        /* periodicity in y over 2 maps */ 
+        while (Dx > map.xsize ) Dx -= 2*map.xsize; 
+       while (Dx <= -map.xsize ) Dx += 2*map.xsize;
+       
+       _Dist=MAX(abs(Dx),abs(Dy)); 
+        // get the best way 
+       if(_Dist<Dist) 
+       { 
+           Dist=_Dist; 
+           *dx=Dx; 
+           *dy=Dy; 
+       } 
+    }
+    
     /* Convert the native delta vector back to a pair of map positions. */
     x1 = x0 + *dx;
     y1 = y0 + *dy;
     native_to_map_pos(&x0, &y0, x0, y0);
     native_to_map_pos(&x1, &y1, x1, y1);
-  }
+  
 
   /* Find the final (map) vector. */
   *dx = x1 - x0;
   *dy = y1 - y0;
 }
+/*************************************************************************
+Return begin in px, py, all the cordiantes of one tile, 
+normalized and near non normalized ones
+the return value are the number of this (0 to 9)
+the first one is the normalized if exist
+*************************************************************************/
+int map_near_orbit( int x, int y, int *px, int *py) 
+{
+    int n=1;
+    if(!normalize_map_pos( &x, &y)) return 0;
+    
+    *(px)=x;
+    *(py)=y;
+    if( XWRAP_TYPE_IS(WT_REVERSED) )
+    {
+        // central symetry 
+       *(px+n)=-1-x; 
+       *(py+n)=map.ysize-y-1;
+       n++;
+       *(px+n)=2*map.xsize-1-x; 
+       *(py+n)=map.ysize-y-1;
+       n++;
+    } else  if(XWRAP_TYPE_IS(WT_SIMPLEST))
+    {
+       int i, ni=n;
+       for(i=0; i<ni; i++)
+       {
+           *(py+n)=*(py+i); 
+           *(px+n)=*(px+i)+map.xsize;
+           n++;
+           *(py+n)=*(py+i); 
+           *(px+n)=*(px+i)-map.xsize;
+           n++;
+       }
+    };
+
+    if(YWRAP_TYPE_IS(WT_REVERSED))
+    {
+       int i, ni=n;
+       for(i=0; i<ni; i++ )
+       {
+           *(py+n)=-1-*(py+i); 
+           *(px+n)=map.xsize-*(px+i)-1;
+           n++;
+           *(py+n)=2*map.ysize-1-*(py+i); 
+           *(px+n)=map.xsize-*(px+i)-1;
+           n++;
+       }
+    }  else if(YWRAP_TYPE_IS(WT_SIMPLEST))
+    {
+       int i, ni=n;
+       for(i=0; i<ni; i++)
+       {
+           *(py+n)=*(py+i)+map.ysize; 
+           *(px+n)=*(px+i);
+           n++;
+           *(py+n)=*(py+i)-map.ysize; 
+           *(px+n)=*(px+i);
+           n++;
+       }
+    } else if(YWRAP_TYPE_IS(WT_OFFSET))
+    {
+       int i, ni=n;
+       for(i=0; i<ni; i++)
+       {
+           *(py+n)=*(py+i)+map.ysize; 
+           *(px+n)=*(px+i)+map.xsize/2;
+           n++;
+           *(py+n)=*(py+i)-map.ysize; 
+           *(px+n)=*(px+i)-map.xsize/2;
+           n++;
+       }
+    }
+    return n;
+}
+
 
 /**************************************************************************
 Random neighbouring square.
@@ -1667,10 +2102,11 @@
 {
   int diff_x, diff_y;
 
-  assert(is_tiles_adjacent(start_x, start_y, end_x, end_y));
+  assert(is_tiles_adjacent(start_x, start_y, end_x, end_y) ||
+(start_x == end_x && start_y == end_y ));
 
   map_distance_vector(&diff_x, &diff_y, start_x, start_y, end_x, end_y);
-  return (diff_x == 0) || (diff_y == 0);
+  return (diff_x == 0) != (diff_y == 0);
 }
 
 /**************************************************************************
diff -ru -Xfreeciv/diff_ignore freeciv-cvs-Dec-08/common/map.h 
freeciv/common/map.h
--- freeciv-cvs-Dec-08/common/map.h     2003-11-29 07:05:26.000000000 +0100
+++ freeciv/common/map.h        2003-12-09 21:27:08.000000000 +0100
@@ -137,6 +137,8 @@
 
 struct civ_map { 
   int topology_id;
+  int xwrap_type;
+  int ywrap_type;
   int xsize, ysize; /* native dimensions */
   int seed;
   int riches;
@@ -165,18 +167,71 @@
 };
 
 enum topo_flag {
-  /* Bit-values. */
-  TF_WRAPX = 1,
-  TF_WRAPY = 2,
-  TF_ISO = 4
+  /* Bit-values(deprecated). and topos index */
+  TF_FLAT=0,    /* xwrap_type = 0 , ywrap_type = 0 */
+  TF_CLASSIC,   /* xwrap_type = 1 , ywrap_type = 0 */
+  TF_QUINCUNCIAL,      /* xwrap_type = 1 , ywrap_type = 2 */
+  TF_QUINCUNCIAL_SQ,   /* xwrap_type = 2 , ywrap_type = 2 */
+  TF_TORUS,     /* xwrap_type = 1 , ywrap_type = 1 */ 
+  TF_MOBIUS,    /* xwrap_type = 1 , ywrap_type = 3 */
+  TF_SPIN,             /* xwrap_type = 2 , ywrap_type = 0 */
+
+  /* index_mask */
+  TF_MASK=7,
+  /* Bit-value, non deprecated flag */
+  TF_ISO = 8,
+  /* Bit-values(deprecated) */
+  TF_WRAPX = 16,  
+  TF_WRAPY = 32,  
 };
 
+enum topo_wrap_type {
+    WT_NONE=0,
+    WT_SIMPLEST=1, 
+    WT_REVERSED=2,
+    WT_OFFSET         /* this simple wrap only good combine with SIMPLEST */
+};
+
+/*
+
+ TF_WRAPX and TF_WRAPY are deprecated. i precerve its fontionality for 
+ the simplest topologies 
+ new code can use XWRAP_TYPE_IS() and YWRAP_TYPE_IS()
+
+ xwrap_type = WT_NONE : no wrap
+ xwrap_type = WT_SIMPLEST : simple wrap
+ xwrap_type = WT_REVERSED : wrap and reverse
+ xwrap_type = WT_OFFSET :   wrap and size/2 offset
+                                                                  (mburda)
+*/
+
+
 #define CURRENT_TOPOLOGY (map.topology_id)
 
-#define topo_has_flag(flag) ((CURRENT_TOPOLOGY & (flag)) != 0)
+/* when deprecated bit diapear we can simplify this                   */
+
+#define topo_has_flag(flag) ((((flag) & (TF_WRAPX | TF_WRAPY)) == 0)       \
+                 ? ((CURRENT_TOPOLOGY & (flag)) != 0)                      \
+                 : ((flag) == TF_WRAPX                                     \
+                 ? XWRAP_TYPE_IS(WT_SIMPLEST)                              \
+                   : YWRAP_TYPE_IS(WT_SIMPLEST)))
+
+
+#define XWRAP_TYPE_IS(WTYPE) (map.xwrap_type==(WTYPE))
+
+#define YWRAP_TYPE_IS(WTYPE) (map.ywrap_type==(WTYPE))
+ 
+#define NORMALIZE_DIR(DIR, REVERSE_FLAG) \
+      ((REVERSE_FLAG)?DIR_REVERSE(DIR):(DIR))
+
+/* return TRUE IF (X,Y) is in the P% coolest part of the map */
+#define IS_COOLEST_PERCENT(X,Y,P) (map_cliam((X),(Y))<=(P))
+
+int map_clima(int map_x, int map_y);
 
 bool map_is_empty(void);
 void map_init(void);
+void map_init_topology(int);
 void map_allocate(void);
 void map_free(void);
 
@@ -258,11 +313,26 @@
  *    MAPSTEP(x, y, x, y, dir)
  * we bend this rule here.
  */
+
+
+
 #define MAPSTEP(dest_x, dest_y, src_x, src_y, dir)     \
 (    (dest_x) = (src_x) + DIR_DX[(dir)],               \
      (dest_y) = (src_y) + DIR_DY[(dir)],               \
      normalize_map_pos(&(dest_x), &(dest_y)))
 
+#define MAPSTEP_REVDES(dest_x, dest_y, src_x, src_y, dir, rev_des)\
+(    (dest_x) = (src_x) + DIR_DX[(dir)],               \
+     (dest_y) = (src_y) + DIR_DY[(dir)],               \
+     normalize_map_pos_revdes(&(dest_x), &(dest_y),&(revdes)))
+
+#define MAPSTEP_FULL(dest_x, dest_y, src_x, src_y, dir, ndir, rev_des)\
+(    (dest_x) = (src_x) + DIR_DX[(dir)],                                  \
+     (dest_y) = (src_y) + DIR_DY[(dir)],                                  \
+     normalize_map_pos_revdes(&(dest_x), &(dest_y),&(revdes)))             \
+     (ndir)=NORMALIZE_DIR(dir,rev_des)
+
+
 struct player *map_get_owner(int x, int y);
 void map_set_owner(int x, int y, struct player *pplayer);
 struct city *map_get_city(int x, int y);
@@ -298,7 +368,11 @@
    || (x) < (dist) || (x) >= map.xsize - (dist)               \
    || (y) < (dist) || (y) >= map.ysize - (dist))
 
+int map_near_orbit( int x, int y, int *px, int *py);
+void setmapratio(int Xratio, int Yratio);
 bool normalize_map_pos(int *x, int *y);
+bool normalize_map_pos_revdes(int *x, int *y,bool *descriptor);
+bool normalize_map_pos_revdes_city(int *x, int *y,bool *descriptor, struct 
city *pcity );
 void nearest_real_pos(int *x, int *y);
 void map_distance_vector(int *dx, int *dy, int x0, int y0, int x1, int y1);
 int map_num_tiles(void);
@@ -379,6 +453,7 @@
    As a special case positive is initialized as 0 (ie we start in step 2) ),
    as the center tile would else be returned by both step 1) and 2).
 */
+/* Only one time in reversed-wrapping (mburda) (TODO verify cycles !)*/
 #define iterate_outward(ARG_start_x, ARG_start_y, ARG_max_dist, ARG_x_itr, 
ARG_y_itr) \
 {                                                                             \
   int ARG_x_itr, ARG_y_itr;                                                   \
@@ -388,6 +463,7 @@
   bool MACRO_positive = FALSE;                                                \
   bool MACRO_is_border = IS_BORDER_MAP_POS(ARG_start_x, ARG_start_y,          \
                                            ARG_max_dist);                     \
+  bool MACRO_revdes_out=0;                                                 \
   int MACRO_dxy = 0, MACRO_do_xy;                                             \
   CHECK_MAP_POS(ARG_start_x, ARG_start_y);                                    \
   while(MACRO_dxy <= (ARG_max_dist)) {                                        \
@@ -412,9 +488,18 @@
        if (MACRO_dx > MACRO_max_dx || MACRO_dx < MACRO_min_dx)               \
          continue;                                                           \
       }                                                                       \
-      if (MACRO_is_border && !normalize_map_pos(&ARG_x_itr, &ARG_y_itr)) {    \
+      if (MACRO_is_border && !normalize_map_pos_revdes(&ARG_x_itr,            \
+          &ARG_y_itr,&MACRO_revdes_out)) {                                    \
        continue;                                                             \
-      }
+      }                                                                       \
+      ONETIME((ARG_start_x),(ARG_start_y),(ARG_x_itr),(ARG_y_itr),            \
+                                   (ARG_max_dist),(MACRO_revdes_out))
+
+/* end iterate if more than one time in reversed topologies */
+#define ONETIME(XC,YC,X,Y,D,rev_des)                                          \
+      if( (rev_des) && (MAX(abs((XC)-(X)),abs((YC)-(Y)))<=(D))) {             \
+         continue;                                                            \
+       }
 
 #define iterate_outward_end                                                   \
     }                                                                         \
@@ -450,18 +535,26 @@
  * position. Note that when the square is larger than the map the
  * distance vector may not be the minimum distance vector.
  */
+/*
+ * only one time if reversed wrapping [mburda]
+ */
+
 #define square_dxy_iterate(center_x, center_y, radius, x_itr, y_itr,          \
                            dx_itr, dy_itr)                                    \
 {                                                                             \
   int dx_itr, dy_itr;                                                         \
+  bool macro_revdes=FALSE;                                                    \
   bool _is_border = IS_BORDER_MAP_POS((center_x), (center_y), (radius));      \
   CHECK_MAP_POS((center_x), (center_y));                                      \
   for (dy_itr = -(radius); dy_itr <= (radius); dy_itr++) {                    \
     for (dx_itr = -(radius); dx_itr <= (radius); dx_itr++) {                  \
       int x_itr = dx_itr + (center_x), y_itr = dy_itr + (center_y);           \
-      if (_is_border && !normalize_map_pos(&x_itr, &y_itr)) {                 \
+      if (_is_border &&                                                       \
+       !normalize_map_pos_revdes(&(x_itr), &(y_itr),&macro_revdes)) {    \
         continue;                                                             \
-      }
+      }                                                                       \
+      ONETIME((center_x), (center_y),(x_itr), (y_itr), (radius),macro_revdes)
+ 
 
 #define square_dxy_iterate_end                                                \
     }                                                                         \
@@ -476,7 +569,7 @@
 #define square_iterate(center_x, center_y, radius, x_itr, y_itr)              \
 {                                                                             \
   square_dxy_iterate(center_x, center_y, radius, x_itr, y_itr,                \
-                     _dummy_x, _dummy_y);
+                     _dummy_x, _dummy_y)
 
 #define square_iterate_end  square_dxy_iterate_end                            \
 }
@@ -513,6 +606,7 @@
 /* Iterate through all tiles adjacent to a tile.  dir_itr is the
    directional value (see DIR_D[XY]).  This assumes that center_x and
    center_y are normalized. --JDS */
+
 #define adjc_dir_iterate(center_x, center_y, x_itr, y_itr, dir_itr)           \
 {                                                                             \
   int x_itr, y_itr, dir_itr;                                                  \
@@ -526,12 +620,56 @@
     y_itr += MACRO_center_y;                                                  \
     if (MACRO_border && !normalize_map_pos(&x_itr, &y_itr)) {                 \
        continue;                                                             \
+    } 
+   
+#define adjc_dir_iterate_revdes(center_x, center_y, x_itr, y_itr, dir_itr, 
revdes ) \
+{                                                                             \
+  int x_itr, y_itr, dir_itr;                                                  \
+  bool revdes=FALSE;                                               \
+  bool MACRO_border = IS_BORDER_MAP_POS((center_x), (center_y), 1);           \
+  int MACRO_center_x = (center_x);                                            \
+  int MACRO_center_y = (center_y);                                            \
+  CHECK_MAP_POS(MACRO_center_x, MACRO_center_y);                              \
+  for (dir_itr = 0; dir_itr < 8; dir_itr++) {                                 \
+    DIRSTEP(x_itr, y_itr, dir_itr);                                           \
+    x_itr += MACRO_center_x;                                                  \
+    y_itr += MACRO_center_y;                                                  \
+    if (MACRO_border && !normalize_map_pos_isreversed(&x_itr, &y_itr,         \
+        &revdes)) {                                                           \
+       continue;                                                             \
     }
 
+#define adjc_dir_iterate_full(center_x, center_y, x_itr, y_itr,          \
+                                    dir_itr,ndir_itr, revdes )                \
+{                                                                             \
+  int x_itr, y_itr, dir_itr,ndir_itr;                                         \
+  bool revdes=FALSE;                                                          \
+  bool MACRO_border = IS_BORDER_MAP_POS((center_x), (center_y), 1);           \
+  int MACRO_center_x = (center_x);                                            \
+  int MACRO_center_y = (center_y);                                            \
+  CHECK_MAP_POS(MACRO_center_x, MACRO_center_y);                              \
+  for (dir_itr = 0; dir_itr < 8; dir_itr++) {                                 \
+    DIRSTEP(x_itr, y_itr, dir_itr);                                           \
+    x_itr += MACRO_center_x;                                                  \
+    y_itr += MACRO_center_y;                                                  \
+    if (MACRO_border && !normalize_map_pos_revdes(&x_itr, &y_itr,         \
+        &revdes)) {                                                           \
+       continue;                                                             \
+    }                                                                         \
+    ndir_itr=NORMALIZE_DIR(dir_itr,revdes);
+    
 #define adjc_dir_iterate_end                                                  \
   }                                                                           \
 }
 
+#define adjc_dir_iterate_revdes_end                                       \
+  }                                                                           \
+}
+
+#define adjc_dir_iterate_full_end                                       \
+  }                                                                           \
+}
+
 /* Iterate over all positions on the globe. */
 #define whole_map_iterate(map_x, map_y)                                     \
 {                                                                           \
@@ -602,15 +740,18 @@
 {                                                                             \
   int IAC_i;                                                                  \
   int IAC_x, IAC_y;                                                           \
-  bool _is_border = IS_BORDER_MAP_POS(x, y, 1);                               \
+  bool car_revdes=FALSE, _is_border = IS_BORDER_MAP_POS(x, y, 1);             \
   CHECK_MAP_POS(x, y);                                                        \
   for (IAC_i = 0; IAC_i < 4; IAC_i++) {                                       \
     IAC_x = x + CAR_DIR_DX[IAC_i];                                            \
     IAC_y = y + CAR_DIR_DY[IAC_i];                                            \
                                                                               \
-    if (_is_border && !normalize_map_pos(&IAC_x, &IAC_y)) {                   \
+    if (_is_border &&                                                         \
+    !normalize_map_pos_revdes(&IAC_x, &IAC_y, &car_revdes)) {                 \
       continue;                                                               \
-    }
+    }                                                                         \
+   ONETIME((x),( y), IAC_x, IAC_y,1 ,car_revdes);
+
 
 #define cartesian_adjacent_iterate_end                                        \
   }                                                                           \
@@ -623,18 +764,25 @@
 #define MAP_MIN_HUTS             0
 #define MAP_MAX_HUTS             500
 
-#define MAP_DEFAULT_WIDTH        80
-#define MAP_MIN_WIDTH            40
-#define MAP_MAX_WIDTH            200
 
+/* map_init_topology() modifiy it by the x-y ratios */
+#define MAP_DEFAULT_WIDTH        80
 #define MAP_DEFAULT_HEIGHT       50
-#define MAP_MIN_HEIGHT           25
-#define MAP_MAX_HEIGHT           100
 
-#define MAP_ORIGINAL_TOPO        TF_WRAPX
-#define MAP_DEFAULT_TOPO         TF_WRAPX
+#define MAP_MIN_WIDTHandHEIGHT   20
+#define MAP_MAX_WIDTHandHEIGHT   200
+
+
+#define MAP_MIN_WIDTH           MAP_MIN_WIDTHandHEIGHT   
+#define MAP_MAX_WIDTH           MAP_MAX_WIDTHandHEIGHT
+
+#define MAP_MIN_HEIGHT           MAP_MIN_WIDTHandHEIGHT   
+#define MAP_MAX_HEIGHT           MAP_MAX_WIDTHandHEIGHT
+
+#define MAP_ORIGINAL_TOPO        TF_CLASSIC
+#define MAP_DEFAULT_TOPO         TF_CLASSIC
 #define MAP_MIN_TOPO             0
-#define MAP_MAX_TOPO             3
+#define MAP_MAX_TOPO             6
 
 #define MAP_DEFAULT_SEED         0
 #define MAP_MIN_SEED             0
diff -ru -Xfreeciv/diff_ignore freeciv-cvs-Dec-08/common/shared.h 
freeciv/common/shared.h
--- freeciv-cvs-Dec-08/common/shared.h  2003-11-29 07:05:27.000000000 +0100
+++ freeciv/common/shared.h     2003-12-09 16:24:36.000000000 +0100
@@ -99,6 +99,9 @@
 #define DIVIDE(n, d) \
     ( (n) / (d) - (( (n) < 0 && (n) % (d) < 0 ) ? 1 : 0) )
 
+/* Good version of % operator : */
+#define MODULO(X,M) ((X)%(M)+((X)%(M)>=0?0:(M)))
+
 /* Deletes bit no in val,
    moves all bits larger than no one down,
    and inserts a zero at the top. */
diff -ru -Xfreeciv/diff_ignore freeciv-cvs-Dec-08/common/terrain.h 
freeciv/common/terrain.h
--- freeciv-cvs-Dec-08/common/terrain.h 2003-11-20 07:02:21.000000000 +0100
+++ freeciv/common/terrain.h    2003-12-09 16:24:36.000000000 +0100
@@ -86,6 +86,7 @@
 /* These gets used very commonly, but we might change the definition of
  * ocean at a later date, and then we'll need to change only these
  * defines. */
+#define is_ice(x) ((x) == T_ARCTIC)
 #define is_ocean(x) ((x) == T_OCEAN)
 #define is_ocean_near_tile(x, y) is_terrain_near_tile(x, y, T_OCEAN)
 #define adjacent_ocean_tiles4(x, y) adjacent_terrain_tiles4(x, y, T_OCEAN)
diff -ru -Xfreeciv/diff_ignore freeciv-cvs-Dec-08/common/unit.c 
freeciv/common/unit.c
--- freeciv-cvs-Dec-08/common/unit.c    2003-11-29 07:05:27.000000000 +0100
+++ freeciv/common/unit.c       2003-12-09 16:24:37.000000000 +0100
@@ -1366,13 +1366,15 @@
    * we'd need to confirm that we can exist/move at the (x, y)
    * location we are given.
    */
-  if (map_get_terrain(x, y) != T_OCEAN || is_coastline(x, y)) {
+  if (!is_ocean(map_get_terrain(x, y)) || is_coastline(x, y)) {
     return 0;
   } else {
     return base_trireme_loss_pct(pplayer);
   }
 }
 
+
+
 /**************************************************************************
  Triremes have a varying loss percentage. based on tech. Seafaring
  reduces this to 25%, Navigation to 12.5%. The Lighthouse wonder
@@ -1392,6 +1394,23 @@
 }
 
 /**************************************************************************
+  
+**************************************************************************/
+int groundunit_onice_loss_pct(struct player *pplayer, int x, int y)
+{
+  /*
+   * If we are next to land, we have no chance of losing
+   * the unit.  To make this really useful for ai planning purposes,
+   * we'd need to confirm that we can exist/move at the (x, y)
+   * location we are given.
+   */
+  if (!is_ice(map_get_terrain(x, y)) || is_coastline(x, y)) {
+    return 0;
+  } else {
+    return 20;
+  }
+}
+/**************************************************************************
 An "aggressive" unit is a unit which may cause unhappiness
 under a Republic or Democracy.
 A unit is *not* aggressive if one or more of following is true:
diff -ru -Xfreeciv/diff_ignore freeciv-cvs-Dec-08/common/unit.h 
freeciv/common/unit.h
--- freeciv-cvs-Dec-08/common/unit.h    2003-12-02 07:12:22.000000000 +0100
+++ freeciv/common/unit.h       2003-12-09 16:24:37.000000000 +0100
@@ -270,7 +270,7 @@
 
 int trireme_loss_pct(struct player *pplayer, int x, int y);
 int base_trireme_loss_pct(struct player *pplayer);
-
+int groundunit_onice_loss_pct(struct player *pplayer, int x, int y);
 bool is_my_zoc(struct player *unit_owner, int x0, int y0);
 bool unit_being_aggressive(struct unit *punit);
 bool can_step_taken_wrt_to_zoc(Unit_Type_id type, struct player *unit_owner,
Seulement dans freeciv/server: civservertest.c
diff -ru -Xfreeciv/diff_ignore freeciv-cvs-Dec-08/server/gotohand.c 
freeciv/server/gotohand.c
--- freeciv-cvs-Dec-08/server/gotohand.c        2003-10-22 06:59:52.000000000 
+0200
+++ freeciv/server/gotohand.c   2003-12-09 16:24:37.000000000 +0100
@@ -299,7 +299,7 @@
                          ? WARMAP_SEACOST(x, y) : WARMAP_COST(x, y));
 
     ptile = map_get_tile(x, y);
-    adjc_dir_iterate(x, y, x1, y1, dir) {
+    adjc_dir_iterate_full(x, y, x1, y1, dir, dir1, rev_des) {
       switch (move_type) {
       case LAND_MOVING:
        if (WARMAP_COST(x1, y1) <= cost)
@@ -321,7 +321,7 @@
        /* else c = ptile->move_cost[k]; 
           This led to a bad bug where a unit in a swamp was considered too far 
away */
         else { /* we have a city */
-         int tmp = map_get_tile(x1, y1)->move_cost[DIR_REVERSE(dir)];
+         int tmp = map_get_tile(x1, y1)->move_cost[DIR_REVERSE(dir1)]; 
           move_cost = (ptile->move_cost[dir] + tmp +
                       (ptile->move_cost[dir] > tmp ? 1 : 0))/2;
         }
@@ -333,7 +333,6 @@
         }
        break;
 
-
       case SEA_MOVING:
         move_cost = SINGLE_MOVE;
         move_cost += cost;
@@ -351,7 +350,7 @@
        move_cost = 0; /* silence compiler warning */
        die("Bad/unimplemented move_type in really_generate_warmap().");
       }
-    } adjc_dir_iterate_end;
+    } adjc_dir_iterate_full_end;
   }
 
   freelog(LOG_DEBUG, "Generated warmap for (%d,%d).",
@@ -485,7 +484,7 @@
 
     adjc_dir_iterate(src_x, src_y, x, y, dir) {
       /* if we didn't come from there */
-      if (!BV_ISSET(came_from, dir)
+      if (!BV_ISSET(came_from, dir) /* no normalize dir */
          && !is_ocean(map_get_terrain(x, y))
          /* and there is an enemy there */
          && is_enemy_unit_tile(map_get_tile(x, y), owner)) {
@@ -629,7 +628,7 @@
 
     /* Try to move to all tiles adjacent to x,y. The coordinats of the tile we
        try to move to are x1,y1 */
-    adjc_dir_iterate(x, y, x1, y1, dir) {
+    adjc_dir_iterate_full(x, y, x1, y1, dir, dir1, rev_des) {
       if ((restriction == GOTO_MOVE_CARDINAL_ONLY)
          && !DIR_IS_CARDINAL(dir)) continue;
 
@@ -690,7 +689,7 @@
              /* Allow players to target anything */
              continue;
            } else {
-             move_cost = SINGLE_MOVE;
+             move_cost = 
SINGLE_MOVE+(SINGLE_MOVE+1)*groundunit_onice_loss_pct(unit_owner(punit),x1,y1)/20;
            }
          }
        } else if (!goto_zoc_ok(punit, x, y, x1, y1, LOCAL_VECTOR(x, y))) {
@@ -712,9 +711,9 @@
            && !same_pos(x1, y1, dest_x, dest_y)) {
          continue;
        }
-       else if (unit_flag(punit, F_TRIREME)
-                && trireme_loss_pct(unit_owner(punit), x1, y1) > 0) {
-         move_cost = 2*SINGLE_MOVE+1;
+       else if (unit_flag(punit, F_TRIREME)) {
+         move_cost = SINGLE_MOVE+
+         (SINGLE_MOVE+1)*trireme_loss_pct(unit_owner(punit), x1, y1)/50;
        } else {
          move_cost = SINGLE_MOVE;
        }
@@ -788,12 +787,13 @@
          warmap_cost[map_pos_to_index(x1, y1)] = total_cost;
          add_to_mapqueue(total_cost, x1, y1);
          BV_CLR_ALL(LOCAL_VECTOR(x1, y1));
-         BV_SET(LOCAL_VECTOR(x1, y1), DIR_REVERSE(dir));
+         BV_SET(LOCAL_VECTOR(x1, y1),DIR_REVERSE(dir1));
+                                            
          freelog(LOG_DEBUG,
                  "Candidate: %s from (%d, %d) to (%d, %d), cost %d",
                  dir_get_name(dir), x, y, x1, y1, total_cost);
        } else if (warmap_cost[map_pos_to_index(x1, y1)] == total_cost) {
-         BV_SET(LOCAL_VECTOR(x1, y1), DIR_REVERSE(dir));
+         BV_SET(LOCAL_VECTOR(x1, y1), DIR_REVERSE(dir1));
          freelog(LOG_DEBUG,
                  "Co-Candidate: %s from (%d, %d) to (%d, %d), cost %d",
                  dir_get_name(dir), x, y, x1, y1, total_cost);
@@ -805,7 +805,7 @@
        /* Make sure we stop searching when we have no hope of finding a 
shorter path */
         maxcost = total_cost + 1;
       }
-    } adjc_dir_iterate_end;
+    } adjc_dir_iterate_full_end;
   }
 
   freelog(LOG_DEBUG, "GOTO: (%d, %d) -> (%d, %d), cost = %d", 
@@ -826,7 +826,7 @@
     if (!get_from_mapqueue(&x, &y))
       break;
 
-    adjc_dir_iterate(x, y, x1, y1, dir) {
+    adjc_dir_iterate_full(x, y, x1, y1, dir, dir1 ,rev_des) {
       if ((restriction == GOTO_MOVE_CARDINAL_ONLY)
          && !DIR_IS_CARDINAL(dir)) continue;
 
@@ -837,12 +837,13 @@
 
         add_to_mapqueue(MAXCOST-1 - move_cost, x1, y1);
        /* Mark it on the warmap */
-       WARMAP_VECTOR(x1, y1) |= 1 << DIR_REVERSE(dir); 
+       WARMAP_VECTOR(x1, y1) |= 1 << DIR_REVERSE(dir1) ;
+                                       
        BV_CLR(LOCAL_VECTOR(x, y), dir); /* avoid repetition */
        freelog(LOG_DEBUG, "PATH-SEGMENT: %s from (%d, %d) to (%d, %d)",
-               dir_get_name(DIR_REVERSE(dir)), x1, y1, x, y);
+               dir_get_name( DIR_REVERSE(dir1)), x1, y1, x, y);
       }
-    } adjc_dir_iterate_end;
+    } adjc_dir_iterate_full_end;
   }
 
   return TRUE;
diff -ru -Xfreeciv/diff_ignore freeciv-cvs-Dec-08/server/mapgen.c 
freeciv/server/mapgen.c
--- freeciv-cvs-Dec-08/server/mapgen.c  2003-11-19 07:04:30.000000000 +0100
+++ freeciv/server/mapgen.c     2003-12-10 23:04:49.000000000 +0100
@@ -105,48 +105,34 @@
 
 /**************************************************************************
  add arctic and tundra squares in the arctic zone. 
- (that is the top 10%, and low 10% of the map)
+ (that is the coolest 10% of the map)
 **************************************************************************/
 static void make_polar(void)
 {
-  int y,x;
-
-  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) { 
-       if (y<2)
-         map_set_terrain(x, y, T_ARCTIC);
-       else
-         map_set_terrain(x, 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) {
-       if (y>map.ysize-3)
-         map_set_terrain(x, y, T_ARCTIC);
-       else
-         map_set_terrain(x, y, T_TUNDRA);
-      }
-    }
-  }
-
-  /* only arctic and tundra allowed at the poles (first and last two lines,
-     as defined in make_passable() ), to be consistent with generator>1. 
-     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);
-  }
+    int T;
+    struct tile *ptile;
+    
+    whole_map_iterate(map_x, map_y) {
+       T=map_clima(map_x, map_y); /* temperature parameter */
+       ptile = map_get_tile(map_x,map_y);
+       if(T <= 10 ) /* get the 10% coolest part of the map */
+       {
+           if(!is_ocean(ptile->terrain)) 
+           {
+               bool ocean=FALSE;
+               cartesian_adjacent_iterate(map_x, map_y, x1, y1){
+                   if(is_ocean( map_get_tile(x1,y1)->terrain))
+                       ocean=TRUE;
+               }cartesian_adjacent_iterate_end;
+               
+               if(ocean || (T < (5+myrand(5)))) /* 5% arctic + 5% arctic and 
tundra */
+                   ptile->terrain = T_ARCTIC;
+               else
+                   ptile->terrain = T_TUNDRA;
+           } else if(T < (5+myrand(5))) /* 5% arctic  */
+                   ptile->terrain = T_ARCTIC;
+       }
+    } whole_map_iterate_end;
 }
 
 /**************************************************************************
@@ -855,9 +841,7 @@
       tres*=9;
     tres/=10;
   } while (abs(total-count)> maxval/40);
-  if (map.separatepoles && has_poles) {
-    make_passable();
-  }
+  
   make_mountains(maxval*8/10);
   make_forests();
   make_swamps();
@@ -866,6 +850,9 @@
   if (has_poles) {
     make_polar();
   }
+  if (map.separatepoles && has_poles) {
+      make_passable();
+  }
   make_fair();
   make_rivers();
 }
@@ -2115,8 +2102,8 @@
 **************************************************************************/
 static void mapgenerator5(void)
 {
-  const bool xnowrap = !topo_has_flag(TF_WRAPX);
-  const bool ynowrap = !topo_has_flag(TF_WRAPY);
+  const bool xnowrap = XWRAP_TYPE_IS(WT_NONE) | XWRAP_TYPE_IS(WT_REVERSED);
+  const bool ynowrap = YWRAP_TYPE_IS(WT_NONE) | YWRAP_TYPE_IS(WT_REVERSED) ;
 
   /* 
    * How many blocks should the x and y directions be divided into
@@ -2165,7 +2152,7 @@
     }
   }
 
-  if (ynowrap) {
+  if (ynowrap ) {
     for (x = 0; x < xdiv2; x++) {
       hmap(x * xmax / xdiv, 0) -= avoidedge;
       hmap(x * xmax / xdiv, ymax) -= avoidedge;
@@ -2178,6 +2165,7 @@
     }
   }
 
+ 
   /* calculate recursively on each block */
   for (x = 0; x < xdiv; x++) {
     for (y = 0; y < ydiv; y++) {
diff -ru -Xfreeciv/diff_ignore freeciv-cvs-Dec-08/server/savegame.c 
freeciv/server/savegame.c
--- freeciv-cvs-Dec-08/server/savegame.c        2003-12-07 07:08:48.000000000 
+0100
+++ freeciv/server/savegame.c   2003-12-09 16:24:37.000000000 +0100
@@ -322,8 +322,8 @@
 ***************************************************************/
 static void map_tiles_load(struct section_file *file)
 {
-  map.topology_id = secfile_lookup_int_default(file, MAP_ORIGINAL_TOPO,
-                                              "map.topology_id");
+  map_init_topology(secfile_lookup_int_default(file, MAP_ORIGINAL_TOPO,
+                                              "map.topology_id"));
 
   map.is_earth=secfile_lookup_bool(file, "map.is_earth");
 
@@ -1531,7 +1531,7 @@
       assert(len > 0);
       secfile_insert_int(file, len, "player%d.u%d.goto_length", plrno, i);
       /* assumption about the chars per map position */
-      assert(MAP_MAX_HEIGHT < 1000 && MAP_MAX_WIDTH < 1000);
+      assert(MAP_MAX_WIDTHandHEIGHT < 1000);
       {
        char *goto_buf = fc_malloc(4 * len + 1);
        char *goto_buf_ptr = goto_buf;
diff -ru -Xfreeciv/diff_ignore freeciv-cvs-Dec-08/server/stdinhand.c 
freeciv/server/stdinhand.c
--- freeciv-cvs-Dec-08/server/stdinhand.c       2003-11-29 07:05:37.000000000 
+0100
+++ freeciv/server/stdinhand.c  2003-12-09 16:53:59.000000000 +0100
@@ -224,25 +224,56 @@
   
 /* Map size parameters: adjustable if we don't yet have a map */  
   GEN_INT("xsize", map.xsize, SSET_MAP_SIZE, SSET_TO_CLIENT,
-         N_("Map width in squares"), "", NULL,
-         MAP_MIN_WIDTH, MAP_MAX_WIDTH, MAP_DEFAULT_WIDTH)
+         N_("Map width in squares"),
+         N_("This value is modified when setting topology_id"), NULL,
+         MAP_MIN_WIDTHandHEIGHT,MAP_MAX_WIDTHandHEIGHT , MAP_DEFAULT_WIDTH)
     
   GEN_INT("ysize", map.ysize, SSET_MAP_SIZE, SSET_TO_CLIENT,
-         N_("Map height in squares"), "", NULL,
-         MAP_MIN_HEIGHT, MAP_MAX_HEIGHT, MAP_DEFAULT_HEIGHT)
-
+         N_("Map height in squares"),
+         N_("This value is modified when setting topology_id"), NULL,
+         MAP_MIN_WIDTHandHEIGHT, MAP_MAX_WIDTHandHEIGHT, MAP_DEFAULT_HEIGHT)
+
+/* map.topology_id determine map.xwrap_type and map.ywrap_type
+   the best way to set it is a call to map_init_topology(id) or
+   a call  map_init_topology(map.topology_id) to actualize xwrap_type
+   and ywrap_type */
   GEN_INT("topology", map.topology_id, SSET_MAP_SIZE, SSET_TO_CLIENT,
          N_("The map topology index"),
          N_("Two-dimensional maps can wrap at the north-south or \n"
-            "east-west edges, and use a cartesian or isometric \n"
-            "rectangular grid.  See the manual for further explanation.\n"
-             "  0 Flat Earth (unwrapped)          4 Flat Earth (isometric)\n"
-             "  1 Earth (wraps E-W)               5 Earth (isometric)\n"
-             "  2 Uranus (wraps N-S)              6 Uranus (isometric)\n"
-             "  3 Donut World (wraps N-S, E-W)    7 Donut World (isometric)"
+            "east-west edges or can use a nice quincuncial topology\n"
+             " and use a cartesian or isometric rectangular grid.  \n"
+            "See the manual for further explanation.\n"
+            "  Index  (+8=Isometric map) : Name ( Wraps )        Notes \n"
+            "  Cartographic topologies:\n"
+            "  0 (8 ) : Flat            (unwrapped)\n"
+            "  1 (9 ) : Cylindrical Earth(wraps E-W)             Classic Civ2 
style \n"
+            "  2 (10) : Spherical Planet (wraps E-W N-N S-S)     best for 
generated map    \n"
+            "  3 (11) : Spherical Earth  (wraps E-E N-N W-W S-S) best for real 
Earth map  \n"
+            "  ScFi topologies:\n"
+            "  4 (12) : Donut World      (wraps N-S, E-W)\n"
+            "  5 (13) : Mobius Strip     (wrap E-W, offset wrap N-S)\n"
+            "  6 (14) : Cyl. electron    (wraps E-E W-W)\n" 
           ), NULL, 
          MAP_MIN_TOPO, MAP_MAX_TOPO, MAP_DEFAULT_TOPO)
-
+ GEN_INT("xwrap_type", map.xwrap_type, SSET_MAP_SIZE, SSET_TO_CLIENT,
+         N_("The map xwrap type"),
+         N_("This index determine the wrapx mode \n"
+            "determined by topology index \n"
+             "  0 Flat on x  (unwrapped) \n"
+             "  1 Wrap on x  (E-W)        \n"
+             "  2 Wrap on x and reversed  (E-E W-W) "
+          ), NULL, 
+         0, 2, 1)
+ GEN_INT("ywrap_type", map.ywrap_type, SSET_MAP_SIZE, SSET_TO_CLIENT,
+         N_("The map ywrap type"),
+         N_("This index determine the wrapy mode \n"
+            "determined by topology index \n"
+             "  0 Flat on y  (unwrapped) \n"
+             "  1 Wrap on y  (N-S)  \n"
+             "  2 Wrap on y and reversed (N-N S-S) \n"
+             "  3 Wrap on y and offset   (offset N-S)\n"
+          ), NULL, 
+         0, 3, 0)
 /* Map generation parameters: once we have a map these are of historical
  * interest only, and cannot be changed.
  */
@@ -3167,6 +3198,9 @@
   }
 
   if (do_update) {
+        /* if map.topology_id as modified we need to call map_init_topology */
+        /* there is not the best place for it, you can FIX IT       (mburda)*/
+        map_init_topology(map.topology_id);
     /* 
      * send any modified game parameters to the clients -- if sent
      * before RUN_GAME_STATE, triggers a popdown_races_dialog() call
diff -ru -Xfreeciv/diff_ignore freeciv-cvs-Dec-08/server/unittools.c 
freeciv/server/unittools.c
--- freeciv-cvs-Dec-08/server/unittools.c       2003-12-05 07:07:46.000000000 
+0100
+++ freeciv/server/unittools.c  2003-12-09 16:24:37.000000000 +0100
@@ -447,7 +447,16 @@
       wipe_unit(punit);
       continue; /* Continue iterating... */
     }
-
+   if (is_ground_unit(punit)
+       && myrand(100) < groundunit_onice_loss_pct(pplayer, punit->x, 
punit->y)) {
+      notify_player_ex(pplayer, punit->x, punit->y, E_UNIT_LOST, 
+                      _("Game: Your %s has been lost on hight ice."),
+                      unit_name(punit->type));
+      gamelog(GAMELOG_UNITTRI, _("%s unit lost on ice"),
+             get_nation_name_plural(pplayer->nation));
+      wipe_unit(punit);
+      continue; /* Continue iterating... */
+    }
     /* 5) Resque planes if needed */
     if (is_air_unit(punit)) {
       /* Shall we emergency return home on the last vapors? */

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