Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] (PR#9876) PATCH temperature parameters for Earth like gene
Home

[Freeciv-Dev] (PR#9876) PATCH temperature parameters for Earth like gene

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9876) PATCH temperature parameters for Earth like generators 1,5
From: "Marcelo Burda via RT" <mburda@xxxxxxxxx>
Date: Sun, 12 Sep 2004 04:45:08 -0700
Reply-to: RT_CorrespondAddressNotSet@xxxxxxxxxxxxxx

<URL: http://RT::WebBaseURL.not.configured:80/Ticket/Display.html?id=9876 >

> [mburda - Ven. Sep. 10 19:04:57 2004]: 
>  
> > [mburda - Ven. Sep. 10 07:29:03 2004]:  
> >   
> > Update   
> >   
> Finally i simplify the TT_FRIZZED, now i am happy  
>    
>  
in this alternante version, i new directory server/generator is 
created and the code touched by temperature is move there.  
placed and temperature are best encapsulated 
 
 
we can commit any of the 2 last version, normally created this 
directory is a well asked feature of any team members. then best if 
commit this one. 
 
no other changes has in temperature-7 to temperature-8. 
 
if your commit 7 i will simply open a new ticket. 
 
Marcelo 
diff -ruN -Xfreeciv/diff_ignore freeciv/common/map.c freeciv_/common/map.c
--- freeciv/common/map.c        2004-09-12 07:15:16.979120776 +0200
+++ freeciv_/common/map.c       2004-09-12 09:22:08.834942800 +0200
@@ -207,6 +207,7 @@
   map.tinyisles             = MAP_DEFAULT_TINYISLES;
   map.separatepoles         = MAP_DEFAULT_SEPARATE_POLES;
   map.alltemperate          = MAP_DEFAULT_ALLTEMPERATE;
+  map.temperature           = MAP_DEFAULT_TEMPERATURE;
   map.tiles                 = NULL;
   map.num_continents        = 0;
   map.num_oceans            = 0;
diff -ruN -Xfreeciv/diff_ignore freeciv/common/map.h freeciv_/common/map.h
--- freeciv/common/map.h        2004-09-03 17:12:25.000000000 +0200
+++ freeciv_/common/map.h       2004-09-12 09:22:08.836942496 +0200
@@ -173,6 +173,7 @@
   bool tinyisles;
   bool separatepoles;
   bool alltemperate;
+  int temperature;
   int num_start_positions;
   bool have_specials;
   bool have_huts;
@@ -675,6 +676,9 @@
 #define MAP_MIN_ALLTEMPERATE       FALSE
 #define MAP_MAX_ALLTEMPERATE       TRUE
 
+#define MAP_DEFAULT_TEMPERATURE   50
+#define MAP_MIN_TEMPERATURE       0
+#define MAP_MAX_TEMPERATURE       100
 
 /*
  * Inline function definitions.  These are at the bottom because they may use
diff -ruN -Xfreeciv/diff_ignore freeciv/configure.ac freeciv_/configure.ac
--- freeciv/configure.ac        2004-09-06 19:13:06.000000000 +0200
+++ freeciv_/configure.ac       2004-09-11 18:17:21.000000000 +0200
@@ -648,7 +648,8 @@
          client/gui-win32/Makefile 
          client/gui-ftwl/Makefile
          client/gui-stub/Makefile 
-         server/Makefile 
+         server/Makefile
+         server/generator/Makefile
          server/userdb/Makefile
          manual/Makefile
          intl/Makefile
Les fichiers freeciv/manual/civmanual et freeciv_/manual/civmanual sont 
différents.
diff -ruN -Xfreeciv/diff_ignore freeciv/manual/Makefile.am 
freeciv_/manual/Makefile.am
--- freeciv/manual/Makefile.am  2004-09-07 16:51:42.000000000 +0200
+++ freeciv_/manual/Makefile.am 2004-09-12 09:09:45.002022592 +0200
@@ -19,6 +19,6 @@
       @INTLLIBS@ ../client/helpdata.o \
       ../utility/libcivutility.a ../common/libcivcommon.a ../ai/libcivai.a \
       ../utility/libcivutility.a ../server/libcivserver.a \
-      ../server/userdb/libuserdb.a \
+      ../server/userdb/libuserdb.a ../server/generator/libgenerator.a  \
       ../utility/libcivutility.a \
       ../common/aicore/libaicore.a $(SERVER_LIBS)
diff -ruN -Xfreeciv/diff_ignore freeciv/server/generator/height.c 
freeciv_/server/generator/height.c
--- freeciv/server/generator/height.c   1970-01-01 01:00:00.000000000 +0100
+++ freeciv_/server/generator/height.c  2004-09-11 22:36:38.000000000 +0200
@@ -0,0 +1,16 @@
+/********************************************************************** 
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+
+int *height_map;
+const int hmap_max_level = 1000;
+int hmap_shore_level, hmap_mountain_level;
diff -ruN -Xfreeciv/diff_ignore freeciv/server/generator/height.h 
freeciv_/server/generator/height.h
--- freeciv/server/generator/height.h   1970-01-01 01:00:00.000000000 +0100
+++ freeciv_/server/generator/height.h  2004-09-11 22:38:29.000000000 +0200
@@ -0,0 +1,38 @@
+/********************************************************************** 
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+#ifndef FC__HEIGHT_H
+#define FC__HEIGHT_H
+
+/* Wrappers for easy access.  They are a macros so they can be a lvalues.*/
+#define hmap(x, y) (height_map[map_pos_to_index(x, y)])
+#define hnat(x, y) (height_map[native_pos_to_index((x), (y))])
+
+/* shore_level safe unit of height */
+#define H_UNIT MIN(1, (hmap_max_level - hmap_shore_level) / 100)
+
+/*
+ * Height map information
+ *
+ *   height_map[] stores the height of each tile
+ *   hmap_max_level is the maximum height (heights will range from
+ *     [0,hmap_max_level).
+ *   hmap_shore_level is the level of ocean.  Any tile at this height or
+ *     above is land; anything below is ocean.
+ *   hmap_mount_level is the level of mountains and hills.  Any tile above
+ *     this height will usually be a mountain or hill.
+ */
+extern int *height_map;
+extern const int hmap_max_level;
+extern int hmap_shore_level, hmap_mountain_level;
+
+#endif  /* FC__HEIGHT_H */
diff -ruN -Xfreeciv/diff_ignore freeciv/server/generator/Makefile.am 
freeciv_/server/generator/Makefile.am
--- freeciv/server/generator/Makefile.am        1970-01-01 01:00:00.000000000 
+0100
+++ freeciv_/server/generator/Makefile.am       2004-09-12 08:09:35.517747608 
+0200
@@ -0,0 +1,15 @@
+## Process this file with automake to produce Makefile.in
+
+noinst_LIBRARIES = libgenerator.a
+
+AM_CPPFLAGS = -I$(top_srcdir)/utility -I$(top_srcdir)/common
+
+libgenerator_a_SOURCES = \
+       topology.c      \
+       topology.h      \
+        temperature.c   \
+        temperature.h   \
+        height.c        \
+        height.h        \
+        utilities.c     \
+        utilities.h
diff -ruN -Xfreeciv/diff_ignore freeciv/server/generator/temperature.c 
freeciv_/server/generator/temperature.c
--- freeciv/server/generator/temperature.c      1970-01-01 01:00:00.000000000 
+0100
+++ freeciv_/server/generator/temperature.c     2004-09-12 09:16:59.122026320 
+0200
@@ -0,0 +1,120 @@
+/********************************************************************** 
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "map.h"
+
+#include "height.h"
+#include "temperature.h"
+#include "topology.h"
+#include "utilities.h" 
+
+static int *temperature_map;
+
+#define tmap(x, y) (temperature_map[map_pos_to_index(x, y)])
+
+/**************************************************************
+ **************************************************************/
+bool temperature_is_inizialized(void)
+{
+  return temperature_map != NULL;
+}
+/*********************************************************
+ return true if the tile has tt temperature type
+**********************************************************/
+bool tmap_is(int x, int y, temperature_type tt)
+{
+  return BOOL_VAL(tmap((x), (y)) & (tt));
+}
+
+/*****************************************************************
+ return true if at last one tile has tt temperature type
+****************************************************************/
+bool  ajdc_tmap_has(int x, int y, temperature_type tt) 
+{
+  adjc_iterate(x, y, x1, y1) {
+    if(BOOL_VAL(tmap((x1), (y1)) & (tt))) {
+      return TRUE;
+    };
+  } adjc_iterate_end;
+  return FALSE;
+}
+
+/**************************************************************************** 
+   Free the tmap
+ ****************************************************************************/
+void destroy_tmap(void)
+{
+  assert( temperature_map != NULL);
+  free( temperature_map);
+  temperature_map = NULL;
+}
+
+/***************************************************************************
+ * create_tmap initialize the temperature_map
+ * if arg is FALSE, create a dumy tmap == map_colattitude
+ * to be used if hmap or oceans are not placed gen 2-4
+ ***************************************************************************/
+void create_tmap(bool real)
+{
+  int i;
+
+  /* if map is defined this is not changed */
+  /* TO DO load if from scenario game with tmap */
+  assert( temperature_map == NULL ); /* to debug, never load a this time */
+  if( temperature_map != NULL ) {
+    return;
+  }
+
+  temperature_map = fc_malloc (sizeof(int) * MAX_MAP_INDEX);
+  whole_map_iterate(x, y) {
+  
+     /* the base temperature is equal to base map_colatitude */
+    int t = map_colatitude(x, y) ;
+    if (!real) {
+      tmap(x, y) =  t;
+    } else {
+      /* height land can be 30% collest */
+      float height = - 0.3 * MAX(0, hmap(x,y) - hmap_shore_level) 
+         / (hmap_max_level - hmap_shore_level); 
+      /* near ocean temperature can be 15 % more "temperate" */
+      float temperate = 0.15 * (map.temperature / 100 - t / MAX_COLA) * 
+         2 * MIN (50 ,count_ocean_near_tile(x, y, FALSE, TRUE)) /
+         100;
+      
+      tmap(x, y) =  t * (1.0 + temperate) * (1.0 + height) ;
+    }
+  } whole_map_iterate_end;
+  /* adjust to get well sizes frequencies */
+  /* Notice: if colatitude is load from a scenario never call adjust has
+             scenario maybe has a odd colatitude ditribution and adjust will
+            brack it */
+  adjust_int_map(temperature_map, MAX_COLA);
+  /* now simplify to 4 base values */ 
+  for (i = 0; i < MAX_MAP_INDEX; i++) {
+    int t = temperature_map[i];
+
+    if( t >= TROPICAL_LEVEL ) {
+      temperature_map[i] = TT_TROPICAL;
+    } else if ( t >= COLD_LEVEL) {
+      temperature_map[i] = TT_TEMPERATE;
+    } else if ( t >= 2 * ICE_BASE_LEVEL) {
+      temperature_map[i] = TT_COLD;
+    } else {
+      temperature_map[i] = TT_FRIZZED;
+    }
+  } 
+}
diff -ruN -Xfreeciv/diff_ignore freeciv/server/generator/temperature.h 
freeciv_/server/generator/temperature.h
--- freeciv/server/generator/temperature.h      1970-01-01 01:00:00.000000000 
+0100
+++ freeciv_/server/generator/temperature.h     2004-09-12 09:17:28.859505536 
+0200
@@ -0,0 +1,37 @@
+/********************************************************************** 
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+#ifndef FC__TEMPERATURE_H
+#define FC__TEMPERATURE_H
+
+
+/*
+ *  temperature_map[] stores the temperature of each tile
+ *  values on tmap can get one of these 4 values
+ *  there is 4 extra values as macros combining the 4 basics ones
+ */
+typedef enum {
+    TT_FRIZZED = 1, TT_COLD = 2, TT_TEMPERATE = 4, TT_TROPICAL = 8
+} temperature_type;
+
+#define TT_NFRIZZED (TT_COLD | TT_TEMPERATE | TT_TROPICAL)
+#define TT_ALL (TT_FRIZZED | TT_NFRIZZED)
+#define TT_NHOT (TT_FRIZZED | TT_COLD)
+#define TT_HOT (TT_TEMPERATE, TT_TROPICAL)
+
+bool temperature_is_inizialized(void);
+bool tmap_is(int x, int y, temperature_type tt);
+bool ajdc_tmap_has(int x, int y, temperature_type tt);
+void destroy_tmap(void);
+void create_tmap(bool real);
+
+#endif  /* FC__TEMPERATURE_H */
diff -ruN -Xfreeciv/diff_ignore freeciv/server/generator/topology.c 
freeciv_/server/generator/topology.c
--- freeciv/server/generator/topology.c 1970-01-01 01:00:00.000000000 +0100
+++ freeciv_/server/generator/topology.c        2004-09-12 09:03:36.276077456 
+0200
@@ -0,0 +1,150 @@
+#include "config.h"
+#include "map.h"
+
+#include "topology.h"
+
+
+/****************************************************************************
+  Returns the temperature of this map position.  This is a value in the
+  range of 0 to MAX_COLA (inclusive).
+  This function is wanted to concentrate the topology information
+  all generator code has to use  colatitude and other topology safe 
+  functions instead (x,y) coordinate to place terrains
+  colatitud is 0 at poles and MAX_COLA at equator
+****************************************************************************/
+int map_colatitude(int map_x, int map_y)
+{
+  double x, y;
+  
+  if (map.alltemperate) {
+    /* An all-temperate map has "average" temperature everywhere.
+     *
+     * TODO: perhaps there should be a random temperature variation. */
+    return MAX_COLA / 2;
+  }
+
+  do_in_natural_pos(ntl_x, ntl_y, map_x, map_y) {
+    if (!topo_has_flag(TF_WRAPX) && !topo_has_flag(TF_WRAPY)) {
+      /* A FLAT (unwrapped) map 
+       *
+       * We assume this is a partial planetary map.  A polar zone is placed
+       * at the top and the equator is at the bottom.  The user can specify
+       * all-temperate to avoid this. */
+      return MAX_COLA * ntl_y / (NATURAL_HEIGHT - 1);
+    }
+
+    /* Otherwise a wrapping map is assumed to be a global planetary map. */
+
+    /* we fold the map to get the base symetries
+     *
+     * ...... 
+     * :c__c:
+     * :____:
+     * :____:
+     * :c__c:
+     * ......
+     *
+     * C are the corners.  In all cases the 4 corners have equal temperature.
+     * So we fold the map over in both directions and determine
+     * x and y vars in the range [0.0, 1.0].
+     *
+     * ...>x 
+     * :C_
+     * :__
+     * V
+     * y
+     *
+     * And now this is what we have - just one-quarter of the map.
+     */
+    x = ((ntl_x > (NATURAL_WIDTH / 2 - 1)
+        ? NATURAL_WIDTH - 1.0 - (double)ntl_x
+        : (double)ntl_x)
+        / (NATURAL_WIDTH / 2 - 1));
+    y = ((ntl_y > (NATURAL_HEIGHT / 2 - 1)
+         ? NATURAL_HEIGHT - 1.0 - (double)ntl_y
+         : (double)ntl_y)
+        / (NATURAL_HEIGHT / 2 - 1));
+  } do_in_natural_pos_end;
+
+  if (topo_has_flag(TF_WRAPX) && !topo_has_flag(TF_WRAPY)) {
+    /* In an Earth-like topology the polar zones are at north and south.
+     * This is equivalent to a Mercator projection. */
+    return MAX_COLA * y;
+  }
+  
+  if (!topo_has_flag(TF_WRAPX) && topo_has_flag(TF_WRAPY)) {
+    /* In a Uranus-like topology the polar zones are at east and west.
+     * This isn't really the way Uranus is; it's the way Earth would look
+     * if you tilted your head sideways.  It's still a Mercator
+     * projection. */
+    return MAX_COLA * x;
+  }
+
+  /* Otherwise we have a torus topology.  We set it up as an approximation
+   * of a sphere with two circular polar zones and a square equatorial
+   * zone.  In this case north and south are not constant directions on the
+   * map because we have to use a more complicated (custom) projection.
+   *
+   * Generators 2 and 5 work best if the center of the map is free.  So
+   * we want to set up the map with the poles (N,S) along the sides and the
+   * equator (/,\) in between.
+   *
+   * ........
+   * :\ NN /:
+   * : \  / :
+   * :S \/ S:
+   * :S /\ S:
+   * : /  \ :
+   * :/ NN \:
+   * ''''''''
+   */
+
+  /* Remember that we've already folded the map into fourths:
+   *
+   * ....
+   * :\ N
+   * : \ 
+   * :S \
+   *
+   * Now flip it along the X direction to get this:
+   *
+   * ....
+   * :N /
+   * : / 
+   * :/ S
+   */
+  x = 1.0 - x;
+
+  /* Since the north and south poles are equivalent, we can fold along the
+   * diagonal.  This leaves us with 1/8 of the map
+   *
+   * .....
+   * :P /
+   * : / 
+   * :/
+   *
+   * where P is the polar regions and / is the equator. */
+  if (x + y > 1.0) {
+    x = 1.0 - x;
+    y = 1.0 - y;
+  }
+
+  /* This projection makes poles with a shape of a quarter-circle along
+   * "P" and the equator as a straight line along "/".
+   *
+   * This is explained more fully at
+   * http://rt.freeciv.org/Ticket/Display.html?id=8624. */
+  return MAX_COLA * (1.5 * (x * x * y + x * y * y) 
+                    - 0.5 * (x * x * x + y * y * y) 
+                    + 1.5 * (x * x + y * y));
+}
+
+/****************************************************************************
+  Return TRUE if the map in a city radius is SINGULAR.  This is used to
+  avoid putting (non-polar) land near the edge of the map.
+****************************************************************************/
+bool near_singularity(int map_x, int map_y)
+{
+  return is_singular_map_pos(map_x, map_y, CITY_MAP_RADIUS);
+}
+
diff -ruN -Xfreeciv/diff_ignore freeciv/server/generator/topology.h 
freeciv_/server/generator/topology.h
--- freeciv/server/generator/topology.h 1970-01-01 01:00:00.000000000 +0100
+++ freeciv_/server/generator/topology.h        2004-09-12 07:54:04.129340168 
+0200
@@ -0,0 +1,60 @@
+/********************************************************************** 
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+#ifndef FC__TOPOLOGY_H
+#define FC__TOPOLOGY_H
+
+/* this is the maximal colatitude at equators returned by 
+   map_colatitude */
+
+#define MAX_COLA 1000
+
+/* An estimate of the linear (1-dimensional) size of the map. */
+#define SQSIZE MAX(1, sqrt(map.xsize * map.ysize / 1000))
+
+/* size safe Unit of colatitude */ 
+#define L_UNIT (MAX_COLA / (30 * SQSIZE) )
+
+/* define the 5 region of a Earth like map 
+   =========================================================
+    0-COLD_LV                cold region: 
+    COLD_LV-TREOPICAL_LV     temperate wet region: 
+    TROPICAL_LV-MAX_COLA     tropical wet region:
+
+   and a dry region, this last one can ovelap others 
+   DRY_MIN_LEVEL- DRY_MAX_LEVEL
+ */
+#define COLD_LEVEL \
+ (MAX(0,        MAX_COLA * (60*7 - map.temperature * 6 ) / 700))
+#define TROPICAL_LEVEL\
+ (MIN(MAX_COLA, MAX_COLA * (143*7 - map.temperature * 10) / 700))
+#define DRY_MIN_LEVEL (MAX_COLA * (7300 - map.temperature * 18 ) / 10000)
+#define DRY_MAX_LEVEL (MAX_COLA * (7300 + map.temperature * 17 ) / 10000)
+
+/* used to create the poles and for separating them.  In a
+ * mercator projection map we don't want the poles to be too big. */
+#define ICE_BASE_LEVEL                                         \
+  ((!topo_has_flag(TF_WRAPX) || !topo_has_flag(TF_WRAPY))      \
+   /* 5% for little maps; 2% for big ones, if map.temperature == 50 */\
+   ? (MAX(0, 100 * COLD_LEVEL / 3 - 2 *  MAX_COLA) + 2 *  MAX_COLA * SQSIZE)\
+      / (100 * SQSIZE)                                               \
+   : COLD_LEVEL / 3  /* for all maps */)
+/*
+ * at some map.temperature there is no more poles at all
+ * COLD_LEVEL > 0 if HAS_POLES
+ */
+
+
+int map_colatitude(int map_x, int map_y);
+bool near_singularity(int map_x, int map_y);
+
+#endif  /* FC__TOPOLOGY_H */
diff -ruN -Xfreeciv/diff_ignore freeciv/server/generator/utilities.c 
freeciv_/server/generator/utilities.c
--- freeciv/server/generator/utilities.c        1970-01-01 01:00:00.000000000 
+0100
+++ freeciv_/server/generator/utilities.c       2004-09-12 08:20:47.856536576 
+0200
@@ -0,0 +1,114 @@
+#include "config.h"
+#include "map.h"
+
+#include "utilities.h"
+
+/****************************************************************************
+ Map that contains, according to circumstances, information on whether
+ we have already placed terrain (special, hut) here.
+****************************************************************************/
+static bool *placed_map;
+
+/**************************************************************************
+ return TRUE if initialized
+*************************************************************************/ 
+bool placed_map_is_initialized(void)
+{
+  return placed_map != NULL;
+}
+
+/****************************************************************************
+  Create a clean pmap
+****************************************************************************/
+void create_placed_map(void)                               
+{                                                          
+  assert( !placed_map_is_initialized());                              
+  placed_map = fc_malloc (sizeof(bool) * MAX_MAP_INDEX);   
+  INITIALIZE_ARRAY(placed_map, MAX_MAP_INDEX, FALSE );     
+}
+
+/**************************************************************************** 
+  Free the pmap
+****************************************************************************/
+void destroy_placed_map(void)   
+{                              
+  assert(placed_map_is_initialized()); 
+  free(placed_map);            
+  placed_map = NULL;           
+}
+
+
+
+#define pmap(x, y) (placed_map[map_pos_to_index(x, y)])
+
+/* Checks if land has not yet been placed on pmap at (x, y) */
+bool not_placed(int x, int y)
+{
+  return !pmap((x), (y));
+}
+
+/* set has placed or not placed position in the pmap */
+void map_set_placed(int x, int y)
+{
+  pmap((x), (y)) = TRUE;
+}
+
+void map_unset_placed(int x, int y)
+{
+  pmap((x), (y)) = FALSE;
+}
+
+/**************************************************************************** 
+  set all oceanics tiles in placed_map
+****************************************************************************/
+void set_placed_all_oceans(void) 
+{                               
+  whole_map_iterate(x, y) {     
+    if (is_ocean(map_get_terrain(x,y))) { 
+      map_set_placed(x, y);     
+    }                           
+  } whole_map_iterate_end;      
+}
+
+/**************************************************************************
+  Change the values of the integer map, so that they contain ranking of each 
+  tile scaled to [0 .. int_map_max].
+  The lowest 20% of tiles will have values lower than 0.2 * int_map_max.
+
+**************************************************************************/
+void adjust_int_map(int *int_map, int int_map_max)
+{
+  int i, minval = *int_map, maxval = minval;
+
+  /* Determine minimum and maximum value. */
+  for (i = 0; i < MAX_MAP_INDEX; i++) {
+    maxval = MAX(maxval, int_map[i]);
+    minval = MIN(minval, int_map[i]);
+  }
+
+  {
+    int const size = 1 + maxval - minval;
+    int i, count = 0, frequencies[size];
+
+    INITIALIZE_ARRAY(frequencies, size, 0);
+
+    /* Translate value so the minimum value is 0
+       and count the number of occurencies of all values to initialize the 
+       frequencies[] */
+    for (i = 0; i < MAX_MAP_INDEX; i++) {
+      int_map[i] = (int_map[i] - minval);
+      frequencies[int_map[i]]++;
+    }
+
+    /* create the linearize function as "incremental" frequencies */
+    for(i =  0; i < size; i++) {
+      count += frequencies[i]; 
+      frequencies[i] = (count * int_map_max) / MAX_MAP_INDEX;
+    }
+
+    /* apply the linearize function */
+    for (i = 0; i < MAX_MAP_INDEX; i++) {
+      int_map[i] = frequencies[int_map[i]];
+    }; 
+  }
+}
diff -ruN -Xfreeciv/diff_ignore freeciv/server/generator/utilities.h 
freeciv_/server/generator/utilities.h
--- freeciv/server/generator/utilities.h        1970-01-01 01:00:00.000000000 
+0100
+++ freeciv_/server/generator/utilities.h       2004-09-12 08:33:20.929052152 
+0200
@@ -0,0 +1,40 @@
+/********************************************************************** 
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+#ifndef FC__UTILITIES_H
+#define FC__UTILITIES_H
+
+bool placed_map_is_initialized(void);
+void set_placed_all_oceans(void);
+void create_placed_map(void);
+void destroy_placed_map(void);
+bool not_placed(int x, int y);
+void map_set_placed(int x, int y);
+void map_unset_placed(int x, int y);
+void set_placed_all_oceans(void) ;
+
+/****************************************************************************
+  Used to initialize an array 'a' of size 'size' with value 'val' in each
+  element.
+****************************************************************************/
+#define INITIALIZE_ARRAY(array, size, value)                               \
+  {                                                                        \
+    int _ini_index;                                                        \
+                                                                           \
+    for (_ini_index = 0; _ini_index < (size); _ini_index++) {              \
+      (array)[_ini_index] = (value);                                       \
+    }                                                                      \
+  }
+
+void adjust_int_map(int *int_map, int int_map_max);
+
+#endif  /* FC__UTILITIES_H */
diff -ruN -Xfreeciv/diff_ignore freeciv/server/Makefile.am 
freeciv_/server/Makefile.am
--- freeciv/server/Makefile.am  2004-09-04 20:28:43.000000000 +0200
+++ freeciv_/server/Makefile.am 2004-09-11 21:35:33.000000000 +0200
@@ -1,10 +1,10 @@
 ## Process this file with automake to produce Makefile.in
 
-SUBDIRS=       userdb
+SUBDIRS=       generator userdb
 
 bin_PROGRAMS = civserver
 noinst_LIBRARIES = libcivserver.a
-AM_CPPFLAGS = -I$(top_srcdir)/utility -I$(srcdir)/../common -I$(srcdir)/../ai 
-I../intl -I$(top_srcdir)/common/aicore -I$(srcdir)/userdb
+AM_CPPFLAGS = -I$(top_srcdir)/utility -I$(srcdir)/../common -I$(srcdir)/../ai 
-I../intl -I$(top_srcdir)/common/aicore -I$(srcdir)/userdb -I$(srcdir)/generator
 
 ## Above, note -I../intl instead of -I$(top_srdir/intl) is deliberate.
 
@@ -83,10 +83,11 @@
 
 civserver_DEPENDENCIES = ../utility/libcivutility.a ../common/libcivcommon.a \
       ../ai/libcivai.a ../utility/libcivutility.a ./libcivserver.a \
-      ../utility/libcivutility.a ../common/aicore/libaicore.a $(USER_DB_DEP)
+      ../utility/libcivutility.a ../common/aicore/libaicore.a \
+      ./generator/libgenerator.a $(USER_DB_DEP)
 civserver_LDADD        = ../utility/libcivutility.a ../common/libcivcommon.a \
       ../ai/libcivai.a ../utility/libcivutility.a ./libcivserver.a @INTLLIBS@ \
       ../utility/libcivutility.a ../common/libcivcommon.a ../ai/libcivai.a \
       ../utility/libcivutility.a ./libcivserver.a ../utility/libcivutility.a \
-      ../common/aicore/libaicore.a $(USER_DB_LIB) $(SERVER_LIBS)
-
+      ../common/aicore/libaicore.a ./generator/libgenerator.a \
+      $(USER_DB_LIB) $(SERVER_LIBS)
\ Pas de fin de ligne à la fin du fichier.
diff -ruN -Xfreeciv/diff_ignore freeciv/server/mapgen.c freeciv_/server/mapgen.c
--- freeciv/server/mapgen.c     2004-09-10 05:55:02.000000000 +0200
+++ freeciv_/server/mapgen.c    2004-09-12 09:29:05.715567312 +0200
@@ -33,6 +33,12 @@
 
 #include "mapgen.h"
 
+#include "height.h"
+#include "temperature.h"
+#include "topology.h"
+#include "utilities.h"
+
+
 /* Old-style terrain enumeration: deprecated. */
 enum {
   T_ARCTIC, T_DESERT, T_FOREST, T_GRASSLAND, T_HILLS, T_JUNGLE,
@@ -57,10 +63,7 @@
 }
 
 /* Wrappers for easy access.  They are a macros so they can be a lvalues.*/
-#define hmap(x, y) (height_map[map_pos_to_index(x, y)])
-#define hnat(x, y) (height_map[native_pos_to_index((x), (y))])
 #define rmap(x, y) (river_map[map_pos_to_index(x, y)])
-#define pmap(x, y) (placed_map[map_pos_to_index(x, y)])
 
 static void make_huts(int number);
 static void add_specials(int prob);
@@ -70,7 +73,6 @@
 static void mapgenerator4(void);
 static void mapgenerator5(void);
 static void smooth_map(void);
-static void adjust_hmap(void);
 static void adjust_terrain_param(void);
 
 #define RIVERS_MAXTRIES 32767
@@ -82,245 +84,13 @@
    A value of 2 means river.                            -Erik Sigra */
 static int *river_map;
 
-/*
- * Height map information
- *
- *   height_map[] stores the height of each tile
- *   hmap_max_level is the maximum height (heights will range from
- *     [0,hmap_max_level).
- *   hmap_shore_level is the level of ocean.  Any tile at this height or
- *     above is land; anything below is ocean.
- *   hmap_mount_level is the level of mountains and hills.  Any tile above
- *     this height will usually be a mountain or hill.
- */
-static int *height_map;
-static const int hmap_max_level = 1000;
-static int hmap_shore_level, hmap_mountain_level;
-
 struct isledata {
   int goodies;
   int starters;
 };
 static struct isledata *islands;
 
-/* this is the maximal temperature at equators returned by map_temperature */
-#define MAX_TEMP 1000
-
-/* An estimate of the linear (1-dimensional) size of the map. */
-#define SQSIZE MAX(1, sqrt(map.xsize * map.ysize / 1000))
-/*
- * these are base units to define distances 
- */
-#define H_UNIT MIN(1, (hmap_max_level - hmap_shore_level) / 100)
-#define T_UNIT (MAX_TEMP / (30 * SQSIZE) )
-
-/* define the 5 region of a Earth like map
-   =========================================================
-    0-COLD_LV                cold region: 
-    COLD_LV-TREOPICAL_LV     temperate wet region: 
-    TROPICAL_LV-MAX_TEMP     tropical wet region:
-
-   and a dry region, this last one can ovelap others 
-   DRY_MIN_LEVEL- DRY_MAX_LEVEL
- */
-#define COLD_LEVEL (10 * MAX_TEMP / 100)
-#define TROPICAL_LEVEL (70 * MAX_TEMP / 100)
-#define DRY_MIN_LEVEL (65 * MAX_TEMP / 100)
-#define DRY_MAX_LEVEL (80 * MAX_TEMP / 100)
-
-/* used to create the poles and for separating them.  In a
- * mercator projection map we don't want the poles to be too big. */
-#define ICE_BASE_LEVEL                                         \
-  ((!topo_has_flag(TF_WRAPX) || !topo_has_flag(TF_WRAPY))      \
-   /* 5% for little maps; 2% for big ones */                   \
-   ? MAX_TEMP * (3 + 2 * SQSIZE) / (100 * SQSIZE)              \
-   : COLD_LEVEL / 2  /* for all maps */)
-
-/****************************************************************************
-  Used to initialize an array 'a' of size 'size' with value 'val' in each
-  element.
-****************************************************************************/
-#define INITIALIZE_ARRAY(array, size, value)                               \
-  {                                                                        \
-    int _ini_index;                                                        \
-                                                                           \
-    for (_ini_index = 0; _ini_index < (size); _ini_index++) {              \
-      (array)[_ini_index] = (value);                                       \
-    }                                                                      \
-  }
-
-/****************************************************************************
- Map that contains, according to circumstances, information on whether
- we have already placed terrain (special, hut) here.
-****************************************************************************/
-static bool *placed_map;
-
-/****************************************************************************
-  Create a clean pmap
-****************************************************************************/
-static void create_placed_map(void)
-{
-  assert(placed_map == NULL); 
-  placed_map = fc_malloc (sizeof(bool) * MAX_MAP_INDEX);
-  INITIALIZE_ARRAY(placed_map, MAX_MAP_INDEX, FALSE );
-}
-
-/**************************************************************************** 
-  Free the pmap
-****************************************************************************/
-static void destroy_placed_map(void)
-{
-  free(placed_map);
-  placed_map = NULL;
-}
-
-/* Checks if land has not yet been placed on pmap at (x, y) */
-#define not_placed(x, y) (!pmap((x), (y)))
-
-/* set has placed or not placed position in the pmap */
-#define map_set_placed(x, y) (pmap((x), (y)) = TRUE)
-#define map_unset_placed(x, y) (pmap((x), (y)) = FALSE)
-/**************************************************************************** 
-  Unset all oceanics tiles in placed_map
-****************************************************************************/
-static void unset_placed_all_oceans(void)
-{
-  whole_map_iterate(x, y) {
-    if (is_ocean(map_get_terrain(x,y))) {
-      map_unset_placed(x, y);
-    }
-  } whole_map_iterate_end;
-}
-/****************************************************************************
-  Returns the temperature of this map position.  This is a value in the
-  range of 0 to MAX_TEMP (inclusive).
-****************************************************************************/
-static int map_temperature(int map_x, int map_y)
-{
-  double x, y;
-  
-  if (map.alltemperate) {
-    /* An all-temperate map has "average" temperature everywhere.
-     *
-     * TODO: perhaps there should be a random temperature variation. */
-    return MAX_TEMP / 2;
-  }
-
-  do_in_natural_pos(ntl_x, ntl_y, map_x, map_y) {
-    if (!topo_has_flag(TF_WRAPX) && !topo_has_flag(TF_WRAPY)) {
-      /* A FLAT (unwrapped) map 
-       *
-       * We assume this is a partial planetary map.  A polar zone is placed
-       * at the top and the equator is at the bottom.  The user can specify
-       * all-temperate to avoid this. */
-      return MAX_TEMP * ntl_y / (NATURAL_HEIGHT - 1);
-    }
-
-    /* Otherwise a wrapping map is assumed to be a global planetary map. */
-
-    /* we fold the map to get the base symetries
-     *
-     * ...... 
-     * :c__c:
-     * :____:
-     * :____:
-     * :c__c:
-     * ......
-     *
-     * C are the corners.  In all cases the 4 corners have equal temperature.
-     * So we fold the map over in both directions and determine
-     * x and y vars in the range [0.0, 1.0].
-     *
-     * ...>x 
-     * :C_
-     * :__
-     * V
-     * y
-     *
-     * And now this is what we have - just one-quarter of the map.
-     */
-    x = ((ntl_x > (NATURAL_WIDTH / 2 - 1)
-        ? NATURAL_WIDTH - 1.0 - (double)ntl_x
-        : (double)ntl_x)
-        / (NATURAL_WIDTH / 2 - 1));
-    y = ((ntl_y > (NATURAL_HEIGHT / 2 - 1)
-         ? NATURAL_HEIGHT - 1.0 - (double)ntl_y
-         : (double)ntl_y)
-        / (NATURAL_HEIGHT / 2 - 1));
-  } do_in_natural_pos_end;
-
-  if (topo_has_flag(TF_WRAPX) && !topo_has_flag(TF_WRAPY)) {
-    /* In an Earth-like topology the polar zones are at north and south.
-     * This is equivalent to a Mercator projection. */
-    return MAX_TEMP * y;
-  }
-  
-  if (!topo_has_flag(TF_WRAPX) && topo_has_flag(TF_WRAPY)) {
-    /* In a Uranus-like topology the polar zones are at east and west.
-     * This isn't really the way Uranus is; it's the way Earth would look
-     * if you tilted your head sideways.  It's still a Mercator
-     * projection. */
-    return MAX_TEMP * x;
-  }
-
-  /* Otherwise we have a torus topology.  We set it up as an approximation
-   * of a sphere with two circular polar zones and a square equatorial
-   * zone.  In this case north and south are not constant directions on the
-   * map because we have to use a more complicated (custom) projection.
-   *
-   * Generators 2 and 5 work best if the center of the map is free.  So
-   * we want to set up the map with the poles (N,S) along the sides and the
-   * equator (/,\) in between.
-   *
-   * ........
-   * :\ NN /:
-   * : \  / :
-   * :S \/ S:
-   * :S /\ S:
-   * : /  \ :
-   * :/ NN \:
-   * ''''''''
-   */
-
-  /* Remember that we've already folded the map into fourths:
-   *
-   * ....
-   * :\ N
-   * : \ 
-   * :S \
-   *
-   * Now flip it along the X direction to get this:
-   *
-   * ....
-   * :N /
-   * : / 
-   * :/ S
-   */
-  x = 1.0 - x;
-
-  /* Since the north and south poles are equivalent, we can fold along the
-   * diagonal.  This leaves us with 1/8 of the map
-   *
-   * .....
-   * :P /
-   * : / 
-   * :/
-   *
-   * where P is the polar regions and / is the equator. */
-  if (x + y > 1.0) {
-    x = 1.0 - x;
-    y = 1.0 - y;
-  }
-
-  /* This projection makes poles with a shape of a quarter-circle along
-   * "P" and the equator as a straight line along "/".
-   *
-   * This is explained more fully at
-   * http://rt.freeciv.org/Ticket/Display.html?id=8624. */
-  return MAX_TEMP * (1.5 * (x * x * y + x * y * y) 
-                    - 0.5 * (x * x * x + y * y * y) 
-                    + 1.5 * (x * x + y * y));
-}
+#define HAS_POLES (map.temperature < 70 && !map.alltemperate  )
 
 /****************************************************************************
  * Conditions used mainly in rand_map_pos_characteristic()
@@ -329,42 +99,23 @@
 
 /* necessary condition of deserts placement */
 #define map_pos_is_dry(x, y)                                           \
-  (map_temperature((x), (y)) <= DRY_MAX_LEVEL                          \
-   && map_temperature((x), (y)) > DRY_MIN_LEVEL                                
\
-   && count_ocean_near_tile((x), (y), FALSE, TRUE) <= 50)
+  (map_colatitude((x), (y)) <= DRY_MAX_LEVEL                           \
+   && map_colatitude((x), (y)) > DRY_MIN_LEVEL                         \
+   && count_ocean_near_tile((x), (y), FALSE, TRUE) <= 35)
 typedef enum { WC_ALL = 200, WC_DRY, WC_NDRY } wetness_c;
 
-/* TEMPERATURE */
-
-/* necessary condition of jungle placement */
-#define map_pos_is_tropical(x, y) (map_temperature((x), (y)) > TROPICAL_LEVEL)
-
-
-/* necessary condition of arctic placement */
-#define map_pos_is_frizzed(x, y) \
-             (map_temperature((x), (y)) <= 2 * ICE_BASE_LEVEL)
-
-/* necessary condition of tundra placement */
-#define map_pos_is_cold(x, y) (map_temperature((x), (y)) <= COLD_LEVEL && \
-                               !map_pos_is_frizzed((x), (y)))
-/* used by generator 2-4 */
-#define map_pos_is_cold_or_frizzed(x, y) \
-                              (map_temperature((x), (y)) <= COLD_LEVEL)
-
-typedef enum { TC_ALL = 100, TC_FRIZZED, TC_NFRIZZED, TC_COLD, 
-                  TC_TROPICAL, TC_NTROPICAL} temperature_c;
-
 /* MISCELANEOUS (OTHER CONDITIONS) */
 
 /* necessary condition of swamp placement */
 static int hmap_low_level = 0;
 #define ini_hmap_low_level() \
 { \
-hmap_low_level = (2 * map.swampsize * \
+hmap_low_level = (2 * map.swampsize  * \
      (hmap_max_level - hmap_shore_level)) / 100 + hmap_shore_level; \
 }
 /* should be used after having hmap_low_level initialized */
-#define map_pos_is_low(x, y) ( hmap((x), (y)) < hmap_low_level )
+#define map_pos_is_low(x, y) ((hmap((x), (y)) < hmap_low_level) || \
+                              is_ocean_near_tile((x), (y)))
 
 typedef enum { MC_NONE, MC_LOW, MC_NLOW } miscellaneous_c;
 
@@ -389,29 +140,6 @@
 }
 
 /***************************************************************************
-  Checks if the given location satisfy some temperature condition
-***************************************************************************/
-static bool test_temperature(int x, int y, temperature_c c)
-{
-    switch(c) {
-       case TC_ALL:
-           return TRUE;
-       case TC_FRIZZED:
-           return map_pos_is_frizzed(x, y);
-       case TC_NFRIZZED:
-           return !map_pos_is_frizzed(x, y);
-       case TC_COLD:
-           return map_pos_is_cold(x, y);
-       case TC_TROPICAL:
-           return map_pos_is_tropical(x, y);
-       case TC_NTROPICAL:
-           return !map_pos_is_tropical(x, y);
-       default:
-           assert(0);
-    }
-}
-
-/***************************************************************************
   Checks if the given location satisfy some miscellaneous condition
 ***************************************************************************/
 static bool test_miscellaneous(int x, int y, miscellaneous_c c)
@@ -433,7 +161,7 @@
 ***************************************************************************/
 struct DataFilter {
   wetness_c        wc;
-  temperature_c    tc;
+  temperature_type tc;
   miscellaneous_c  mc;
 };
 
@@ -446,7 +174,7 @@
   struct DataFilter *filter = data;
 
   return  not_placed(map_x, map_y) 
-      &&  test_temperature(map_x, map_y, filter->tc) 
+      &&  tmap_is(map_x, map_y, filter->tc) 
       &&  test_wetness(map_x, map_y, filter->wc) 
       &&  test_miscellaneous(map_x, map_y, filter->mc) ;
 }
@@ -458,7 +186,7 @@
 ****************************************************************************/
 static bool rand_map_pos_characteristic(int *map_x, int *map_y,
                                   wetness_c        wc,
-                                  temperature_c    tc,
+                                  temperature_type tc,
                                   miscellaneous_c  mc )
 {
   struct DataFilter filter;
@@ -469,15 +197,6 @@
   return rand_map_pos_filtered(map_x, map_y, &filter, condition_filter);
 }
 
-/****************************************************************************
-  Return TRUE if the map in a city radius is SINGULAR.  This is used to
-  avoid putting (non-polar) land near the edge of the map.
-****************************************************************************/
-static bool near_singularity(int map_x, int map_y)
-{
-  return is_singular_map_pos(map_x, map_y, CITY_MAP_RADIUS);
-}
-
 /**************************************************************************
   we don't want huge areas of grass/plains, 
   so we put in a hill here and there, where it gets too 'clean' 
@@ -513,7 +232,7 @@
   we don't want huge areas of hill/mountains, 
   so we put in a plains here and there, where it gets too 'heigh' 
 
-  Return TRUE if the terrain at the given map position is to heigh.
+  Return TRUE if the terrain at the given map position is too heigh.
 ****************************************************************************/
 static bool terrain_is_too_high(int map_x, int map_y,int thill, int my_height)
 {
@@ -546,8 +265,7 @@
         || terrain_is_too_flat(x, y, hmap_mountain_level, hmap(x, y)))) {
       /* Randomly place hills and mountains on "high" tiles.  But don't
        * put hills near the poles (they're too green). */
-      if (myrand(100) > 70 
-         || map_temperature(x, y) <= COLD_LEVEL) {
+      if (myrand(100) > 70 || tmap_is(x, y, TT_NHOT)) {
        map_set_terrain(x, y, T_MOUNTAINS);
        map_set_placed(x, y);
       } else {
@@ -565,34 +283,13 @@
 ****************************************************************************/
 static void make_polar(void)
 {
-  struct tile *ptile;
-  int T;
-
-  whole_map_iterate(map_x, map_y) {
-    T = map_temperature(map_x, map_y); /* temperature parameter */
-    ptile = map_get_tile(map_x, map_y);
-    if (T < ICE_BASE_LEVEL) { /* get the coldest part of the map */
-      if (ptile->terrain != T_MOUNTAINS) {
-       ptile->terrain = T_ARCTIC;
-       map_set_placed(map_x, map_y);
-      }
-    } else if ((T <= 1.5 * ICE_BASE_LEVEL) 
-              && (ptile->terrain == T_OCEAN) ) {  
-      ptile->terrain = T_ARCTIC;
-      map_set_placed(map_x, map_y);
-    } else if (T <= 2 * ICE_BASE_LEVEL) {
-      if (ptile->terrain == T_OCEAN) {
-       if (myrand(10) > 5) {
-         ptile->terrain = T_ARCTIC;
-         map_set_placed(map_x, map_y);
-       } else if (myrand(10) > 6) {
-         ptile->terrain = T_TUNDRA;
-         map_set_placed(map_x, map_y);
-       }
-      } else if (myrand(10) > 0 && ptile->terrain != T_MOUNTAINS) {
-       ptile->terrain = T_TUNDRA; 
-       map_set_placed(map_x, map_y);
-      }
+  whole_map_iterate(map_x, map_y) {  
+    if (tmap_is(map_x, map_y, TT_FRIZZED )
+       ||
+       (tmap_is(map_x, map_y, TT_COLD ) &&
+        (myrand(10) > 7) &&
+        ajdc_tmap_has(map_x, map_y, TT_FRIZZED))) { 
+      map_set_terrain(map_x, map_y, T_ARCTIC);
     }
   } whole_map_iterate_end;
 }
@@ -616,44 +313,21 @@
 
 /****************************************************************************
   Place untextured land at the poles.  This is used by generators 1 and 5.
-  The land is textured by make_tundra, make_arctic, and make_mountains.
 ****************************************************************************/
 static void make_polar_land(void)
 {
-  struct tile *ptile;
-  int T;
-
   assign_continent_numbers();
   whole_map_iterate(map_x, map_y) {
-    T = map_temperature(map_x, map_y); /* temperature parameter */
-    ptile = map_get_tile(map_x, map_y);
-    if (T < 1.5 * ICE_BASE_LEVEL && ok_for_separate_poles(map_x, map_y)) {
-      ptile->terrain = T_UNKNOWN;
-      map_unset_placed(map_x, map_y);
-      map_set_continent(map_x, map_y, 0);
-    } else if ((T <= 2 * ICE_BASE_LEVEL) 
-              && myrand(10) > 4 && ok_for_separate_poles(map_x, map_y)) { 
-      ptile->terrain = T_UNKNOWN;
-      map_unset_placed(map_x, map_y);
-      map_set_continent(map_x, map_y, 0);
-    }
-  } whole_map_iterate_end;
-}
-
-/****************************************************************************
-  Create arctic in cold zones.  Used by generators 1 and 5.
-****************************************************************************/
-static void make_arctic(void)
-{
-  whole_map_iterate(x, y) {
-    int T = map_temperature(x, y);
-
-    if (not_placed(x, y)
-       && myrand(1.5 * COLD_LEVEL) > T -  ICE_BASE_LEVEL 
-       && T <= 3 * ICE_BASE_LEVEL) {
-      map_set_terrain(x, y, T_ARCTIC);
-      map_set_placed(x, y);
-    }
+    if ((tmap_is(map_x, map_y, TT_FRIZZED ) &&
+       ok_for_separate_poles(map_x, map_y))
+       ||
+       (tmap_is(map_x, map_y, TT_COLD ) &&
+        (myrand(10) > 7) &&
+        ajdc_tmap_has(map_x, map_y, TT_FRIZZED) &&
+        ok_for_separate_poles(map_x, map_y))) {
+       map_set_terrain(map_x, map_y, T_UNKNOWN);
+       map_set_continent(map_x, map_y, 0);
+    } 
   } whole_map_iterate_end;
 }
 
@@ -663,7 +337,7 @@
 static void place_terrain(int x, int y, int diff, 
                            Terrain_type_id ter, int *to_be_placed,
                           wetness_c        wc,
-                          temperature_c    tc,
+                          temperature_type tc,
                           miscellaneous_c  mc)
 {
   if (*to_be_placed <= 0) {
@@ -675,11 +349,11 @@
   (*to_be_placed)--;
   
   cardinal_adjc_iterate(x, y, x1, y1) {
-    int Delta = abs(map_temperature(x1, y1) - map_temperature(x, y)) / T_UNIT
+    int Delta = abs(map_colatitude(x1, y1) - map_colatitude(x, y)) / L_UNIT
        + abs(hmap(x1, y1) - (hmap(x, y))) /  H_UNIT;
     if (not_placed(x1, y1) 
+       && tmap_is(x1, y1, tc) 
        && test_wetness(x1, y1, wc)
-       && test_temperature(x1, y1, tc) 
        && test_miscellaneous(x1, y1, mc)
        && Delta < diff 
        && myrand(10) > 4) {
@@ -694,9 +368,10 @@
 **************************************************************************/
 static void make_plain(int x, int y, int *to_be_placed )
 {
-  int T = map_temperature(x, y);
   /* in cold place we get tundra instead */
-  if ((COLD_LEVEL > T)) {
+  if (tmap_is(x, y, TT_FRIZZED)) {
+    map_set_terrain(x, y, T_ARCTIC); 
+  } else if (tmap_is(x, y, TT_COLD)) {
     map_set_terrain(x, y, T_TUNDRA); 
   } else {
     if (myrand(100) > 50) {
@@ -730,7 +405,7 @@
   if((count) > 0) {                                       \
     int x, y; \
     /* Place some terrains */                             \
-    if (rand_map_pos_characteristic(&x, &y, (wc), (tc), (mc))) { \
+    if (rand_map_pos_characteristic(&x, &y, (wc), (tc), (mc))) {  \
       place_terrain(x, y, (weight), (ter), &(count), (wc),(tc), (mc));   \
     } else {                                                             \
       /* If rand_map_pos_temperature returns FALSE we may as well stop*/ \
@@ -765,8 +440,8 @@
 
   forests_count = total * map.forestsize
        / ( map.forestsize + map.deserts + map.grasssize +  map.swampsize );
-  jungles_count = (MAX_TEMP - TROPICAL_LEVEL) * forests_count 
-      /  (MAX_TEMP * 2);
+  jungles_count = (MAX_COLA - TROPICAL_LEVEL) * forests_count 
+      /  (MAX_COLA * 2);
   forests_count -= jungles_count;
 
   deserts_count = total * map.deserts
@@ -782,22 +457,22 @@
   do {
     
     PLACE_ONE_TYPE(forests_count , plains_count, T_FOREST,
-                  WC_ALL, TC_NFRIZZED, MC_NONE, 60);
+                  WC_ALL, TT_NFRIZZED, MC_NONE, 60);
     PLACE_ONE_TYPE(jungles_count, forests_count , T_JUNGLE,
-                  WC_ALL, TC_TROPICAL, MC_NONE, 50);
+                  WC_ALL, TT_TROPICAL, MC_NONE, 50);
     PLACE_ONE_TYPE(swamps_count, forests_count , T_SWAMP,
-                  WC_NDRY, TC_NFRIZZED, MC_LOW, 50);
+                  WC_NDRY, TT_NFRIZZED, MC_LOW, 50);
     PLACE_ONE_TYPE(deserts_count, alt_deserts_count , T_DESERT,
-                  WC_DRY, TC_NFRIZZED, MC_NLOW, 80);
+                  WC_DRY, TT_NFRIZZED, MC_NLOW, 80);
     PLACE_ONE_TYPE(alt_deserts_count, plains_count , T_DESERT,
-                  WC_ALL, TC_NFRIZZED, MC_NLOW, 40);
+                  WC_ALL, TT_NFRIZZED, MC_NLOW, 40);
  
   /* make the plains and tundras */
     if (plains_count > 0) {
       int x, y;
 
       /* Don't use any restriction here ! */
-      if (rand_map_pos_characteristic(&x, &y,  WC_ALL, TC_ALL, MC_NONE)){
+      if (rand_map_pos_characteristic(&x, &y,  WC_ALL, TT_ALL, MC_NONE)){
        make_plain(x,y, &plains_count);
       } else {
        /* If rand_map_pos_temperature returns FALSE we may as well stop
@@ -1039,7 +714,7 @@
     if (count_special_near_tile(x, y, TRUE, TRUE, S_RIVER) > 0
        || count_ocean_near_tile(x, y, TRUE, TRUE) > 0
         || (map_get_terrain(x, y) == T_ARCTIC 
-           && map_temperature(x, y) < 0.8 * COLD_LEVEL)) { 
+           && map_colatitude(x, y) < 0.8 * COLD_LEVEL)) { 
 
       freelog(LOG_DEBUG,
              "The river ended at (%d, %d).\n", x, y);
@@ -1144,7 +819,7 @@
     10 *
     /* The size of the map (poles don't count). */
     map_num_tiles() 
-      * (map.alltemperate ? 1.0 : 1.0 - 2.0 * ICE_BASE_LEVEL / MAX_TEMP) *
+      * (map.alltemperate ? 1.0 : 1.0 - 2.0 * ICE_BASE_LEVEL / MAX_COLA) *
     /* Rivers need to be on land only. */
     map.landpercent /
     /* Adjustment value. Tested by me. Gives no rivers with 'set
@@ -1163,7 +838,7 @@
   int iteration_counter = 0;
 
   create_placed_map(); /* needed bu rand_map_characteristic */
-  unset_placed_all_oceans();
+  set_placed_all_oceans();
 
   river_map = fc_malloc(sizeof(int) * MAX_MAP_INDEX);
 
@@ -1172,7 +847,7 @@
         && iteration_counter < RIVERS_MAXTRIES) {
 
     if (!rand_map_pos_characteristic(&x, &y, 
-                                     WC_NDRY, TC_NFRIZZED, MC_NLOW)) {
+                                     WC_ALL, TT_NFRIZZED, MC_NLOW)) {
        break; /* mo more spring places */
     }
 
@@ -1270,13 +945,13 @@
   whole_map_iterate(x, y) {
     if (near_singularity(x, y)) {
       hmap(x, y) = 0;
-    } else if (map_temperature(x, y) < 2 * ICE_BASE_LEVEL) {
-      hmap(x, y) *= map_temperature(x, y) / (2.5 * ICE_BASE_LEVEL);
+    } else if (map_colatitude(x, y) < 2 * ICE_BASE_LEVEL) {
+      hmap(x, y) *= map_colatitude(x, y) / (2.5 * ICE_BASE_LEVEL);
     } else if (map.separatepoles 
-              && map_temperature(x, y) <= 2.5 * ICE_BASE_LEVEL) {
+              && map_colatitude(x, y) <= 2.5 * ICE_BASE_LEVEL) {
       hmap(x, y) *= 0.1;
-    } else if (map_temperature(x, y) <= 2.5 * ICE_BASE_LEVEL) {
-      hmap(x, y) *= map_temperature(x, y) / (2.5 * ICE_BASE_LEVEL);
+    } else if (map_colatitude(x, y) <= 2.5 * ICE_BASE_LEVEL) {
+      hmap(x, y) *= map_colatitude(x, y) / (2.5 * ICE_BASE_LEVEL);
     }
   } whole_map_iterate_end;
 }
@@ -1288,15 +963,15 @@
 static void renormalize_hmap_poles(void)
 {
   whole_map_iterate(x, y) {
-    if (hmap(x, y) == 0 || map_temperature(x, y) == 0) {
+    if (hmap(x, y) == 0 || map_colatitude(x, y) == 0) {
       /* Nothing. */
-    } else if (map_temperature(x, y) < 2 * ICE_BASE_LEVEL) {
-      hmap(x, y) *= (2.5 * ICE_BASE_LEVEL) / map_temperature(x, y);
+    } else if (map_colatitude(x, y) < 2 * ICE_BASE_LEVEL) {
+      hmap(x, y) *= (2.5 * ICE_BASE_LEVEL) / map_colatitude(x, y);
     } else if (map.separatepoles 
-              && map_temperature(x, y) <= 2.5 * ICE_BASE_LEVEL) {
+              && map_colatitude(x, y) <= 2.5 * ICE_BASE_LEVEL) {
       hmap(x, y) *= 10;
-    } else if (map_temperature(x, y) <= 2.5 * ICE_BASE_LEVEL) {
-      hmap(x, y) *= (2.5 * ICE_BASE_LEVEL) /  map_temperature(x, y);
+    } else if (map_colatitude(x, y) <= 2.5 * ICE_BASE_LEVEL) {
+      hmap(x, y) *= (2.5 * ICE_BASE_LEVEL) /  map_colatitude(x, y);
     }
   } whole_map_iterate_end;
 }
@@ -1308,9 +983,8 @@
 **************************************************************************/
 static void make_land(void)
 {
-  create_placed_map(); /* here it means land terrains to be placed */
-  adjust_hmap();
-  if (!map.alltemperate) {
+  adjust_int_map(height_map, hmap_max_level);
+  if (HAS_POLES) {
     normalize_hmap_poles();
   }
   hmap_shore_level = (hmap_max_level * (100 - map.landpercent)) / 100;
@@ -1319,18 +993,26 @@
     map_set_terrain(x, y, T_UNKNOWN); /* set as oceans count is used */
     if (hmap(x, y) < hmap_shore_level) {
       map_set_terrain(x, y, T_OCEAN);
-      map_set_placed(x, y); /* placed, not a land target */
     }
   } whole_map_iterate_end;
-  if(!map.alltemperate) {
-    renormalize_hmap_poles(); 
+  if (HAS_POLES) {
+    renormalize_hmap_poles();
+  } 
+
+  create_tmap(TRUE); /* base temperature map, need hmap and oceans */
+  
+  if (HAS_POLES) { /* this is a hack to terrains set with not frizzed oceans*/
     make_polar_land(); /* make extra land at poles*/
   }
+
+  create_placed_map(); /* here it means land terrains to be placed */
+  set_placed_all_oceans();
   make_relief(); /* base relief on map */
-  make_arctic(); 
-  make_terrains(); /* place forest/desert/swamp/grass/tundra and plains */
+  make_terrains(); /* place all exept mountains and hill */
   destroy_placed_map();
-  make_rivers();
+
+  make_rivers(); /* use a new placed_map. destroy older before call */
+
   assign_continent_numbers();
 }
 
@@ -1439,7 +1121,7 @@
       /* (x1,y1) is possible location of a future city which will
        * be able to get benefit of the tile (x,y) */
       if (is_ocean(map_get_terrain(x1, y1)) 
-         || map_temperature(x1, y1) <= 2 * ICE_BASE_LEVEL) { 
+         || map_colatitude(x1, y1) <= 2 * ICE_BASE_LEVEL) { 
        /* Not land, or too cold. */
         continue;
       }
@@ -1774,6 +1456,10 @@
       assign_continent_numbers();
   }
 
+  if(!temperature_is_inizialized()) {
+    create_tmap(FALSE);
+  }
+
   if(!map.have_specials) /* some scenarios already provide specials */
     add_specials(map.riches); /* hvor mange promiller specials oensker vi*/
 
@@ -1783,6 +1469,7 @@
 
   /* restore previous random state: */
   set_myrand_state(rstate);
+  destroy_tmap();
 }
 
 /**************************************************************************
@@ -1791,7 +1478,7 @@
 static void adjust_terrain_param(void)
 {
   int total;
-  int polar = ICE_BASE_LEVEL * 100 / MAX_TEMP;
+  int polar = ICE_BASE_LEVEL * 100 / MAX_COLA;
 
   total = map.mountains + map.deserts + map.forestsize + map.swampsize
     + map.grasssize;
@@ -1807,51 +1494,6 @@
 }
 
 /**************************************************************************
-  Change the values of the height map, so that they contain ranking of each 
-  tile scaled to [0 .. hmap_max_level].
-  The lowest 20% of tiles will have values lower than 0.2 * hmap_max_level.
-
-  slope can globally be estimated as
-        hmap_max_level * sqrt(number_of_islands) / linear_size_of_map
-**************************************************************************/
-static void adjust_hmap(void)
-{
-  int minval = hnat(0, 0), maxval = minval;
-
-  /* Determine minimum and maximum heights. */
-  whole_map_iterate(x, y) {
-    maxval = MAX(maxval, hmap(x, y));
-    minval = MIN(minval, hmap(x, y));
-  } whole_map_iterate_end;
-
-  {
-    int const size = 1 + maxval - minval;
-    int i, count = 0, frequencies[size];
-
-    INITIALIZE_ARRAY(frequencies, size, 0);
-
-    /* Translate heights so the minimum height is 0
-       and count the number of occurencies of all values to initialize the 
-       frequencies[] */
-    whole_map_iterate(x, y) {
-      hmap(x, y) = (hmap(x, y) - minval);
-      frequencies[hmap(x, y)]++;
-    } whole_map_iterate_end;
-
-    /* create the linearize function as "incremental" frequencies */
-    for(i =  0; i < size; i++) {
-      count += frequencies[i]; 
-      frequencies[i] = (count * hmap_max_level) / MAX_MAP_INDEX;
-    }
-
-    /* apply the linearize function */
-    whole_map_iterate(x, y) {
-      hmap(x, y) = frequencies[hmap(x, y)];
-    } whole_map_iterate_end; 
-  }
-}
-
-/**************************************************************************
   mapgenerator1, highlevel function, that calls all the previous functions
 **************************************************************************/
 static void mapgenerator1(void)
@@ -1867,7 +1509,7 @@
     rand_map_pos(&x, &y);
 
     if (near_singularity(x, y)
-       || map_temperature(x, y) <= ICE_BASE_LEVEL / 2) { 
+       || map_colatitude(x, y) <= ICE_BASE_LEVEL / 2) { 
       /* Avoid land near singularities or at the poles. */
       hmap(x, y) -= myrand(5000);
     } else { 
@@ -1966,7 +1608,7 @@
 
     /* Add a hut.  But not on a polar area, on an ocean, or too close to
      * another hut. */
-    if (rand_map_pos_characteristic(&x, &y, WC_ALL, TC_NFRIZZED, MC_NONE)) {
+    if (rand_map_pos_characteristic(&x, &y, WC_ALL, TT_NFRIZZED, MC_NONE)) {
       if (is_ocean(map_get_terrain(x, y))) {
        map_set_placed(x, y); /* not good for a hut */
       } else {
@@ -2107,7 +1749,7 @@
             || is_terrain_near_tile(x,y,cold1) 
             )
           &&( !is_cardinally_adj_to_ocean(x, y) || myrand(100) < coast )) {
-       if (map_pos_is_cold_or_frizzed(x, y)) {
+       if (map_colatitude(x, y) < COLD_LEVEL) {
          map_set_terrain(x, y, (myrand(cold0_weight
                                        + cold1_weight) < cold0_weight) 
                          ? cold0 : cold1);
@@ -2479,6 +2121,7 @@
   height_map = fc_malloc(sizeof(int) * map.ysize * map.xsize);
   islands = fc_malloc((MAP_NCONT+1)*sizeof(struct isledata));
   create_placed_map(); /* land tiles which aren't placed yet */
+  create_tmap(FALSE);
   whole_map_iterate(x, y) {
     map_set_terrain(x, y, T_OCEAN);
     map_set_continent(x, y, 0);
@@ -2486,7 +2129,7 @@
     map_clear_all_specials(x, y);
     map_set_owner(x, y, NULL);
   } whole_map_iterate_end;
-  if (!map.alltemperate) {
+  if (HAS_POLES) {
     make_polar();
   }
   
@@ -2534,11 +2177,15 @@
                        * (map.xsize - spares)) / 100;
   totalweight = 100 * game.nplayers;
 
-  assert(placed_map == NULL);
+  assert(!placed_map_is_initialized());
 
   while (!done && bigfrac > midfrac) {
     done = TRUE;
-    if ( placed_map != NULL ) { destroy_placed_map(); }
+
+    if (placed_map_is_initialized()) {
+      destroy_placed_map();
+    }
+
     initworld(pstate);
     
     /* Create one big island for each player. */
@@ -2786,7 +2433,7 @@
 #define set_midpoints(X, Y, V)                                         \
   do_in_map_pos(map_x, map_y, (X), (Y)) {                               \
     if (!near_singularity(map_x, map_y)                                        
\
-       && map_temperature(map_x, map_y) >  ICE_BASE_LEVEL/2            \
+       && map_colatitude(map_x, map_y) >  ICE_BASE_LEVEL/2             \
        && hnat((X), (Y)) == 0) {                                       \
       hnat((X), (Y)) = (V);                                            \
     }                                                                  \
@@ -2866,7 +2513,7 @@
          hmap(x, y) -= avoidedge;
        }
 
-       if (map_temperature(x, y) <= ICE_BASE_LEVEL / 2 ) {
+       if (map_colatitude(x, y) <= ICE_BASE_LEVEL / 2 ) {
          /* separate poles and avoid too much land at poles */
          hmap(x, y) -= myrand(avoidedge);
        }
diff -ruN -Xfreeciv/diff_ignore freeciv/server/savegame.c 
freeciv_/server/savegame.c
--- freeciv/server/savegame.c   2004-09-04 23:25:57.000000000 +0200
+++ freeciv_/server/savegame.c  2004-09-12 09:22:08.910931248 +0200
@@ -3104,6 +3104,9 @@
       map.forestsize = secfile_lookup_int(file, "map.forestsize");
       map.have_huts = secfile_lookup_bool_default(file, TRUE,
                                                  "map.have_huts");
+      map.temperature =
+       secfile_lookup_int_default(file,
+                                  MAP_DEFAULT_TEMPERATURE, "map.temperature");
       map.alltemperate
        = secfile_lookup_bool_default(file, MAP_DEFAULT_ALLTEMPERATE,
                                      "map.alltemperate");
@@ -3483,6 +3486,7 @@
     secfile_insert_int(file, map.huts, "map.huts");
     secfile_insert_int(file, map.generator, "map.generator");
     secfile_insert_bool(file, map.have_huts, "map.have_huts");
+    secfile_insert_int(file, map.temperature, "map.temperature");
     secfile_insert_bool(file, map.alltemperate, "map.alltemperate");
     secfile_insert_bool(file, map.tinyisles, "map.tinyisles");
     secfile_insert_bool(file, map.separatepoles, "map.separatepoles");
diff -ruN -Xfreeciv/diff_ignore freeciv/server/settings.c 
freeciv_/server/settings.c
--- freeciv/server/settings.c   2004-09-04 22:36:10.000000000 +0200
+++ freeciv_/server/settings.c  2004-09-12 09:22:08.913930792 +0200
@@ -293,6 +293,17 @@
           N_("0 = normal Earth-like planet; 1 = all-temperate planet "),
           NULL, MAP_DEFAULT_ALLTEMPERATE)
 
+  GEN_INT("temperature", map.temperature,
+         SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
+         N_("medium temperature of planet"),
+         N_("100 a very dry and hot planet: no poles, all tropical or dry \n"
+            "70 hot planet, frized poles disapear near this point \n"
+          "50 a temperate planet: poles, cold, temperate and tropical\n"
+          "   zone with a dessert zone overlaping bot tropical and temperate\n"
+            "30 cold planet, tropical disapear near this point \n"
+     "0 very cold planet, big poles, and any else cold and temperate"), NULL,
+         MAP_MIN_TEMPERATURE, MAP_MAX_TEMPERATURE, MAP_DEFAULT_TEMPERATURE)
+ 
   GEN_INT("landmass", map.landpercent,
          SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
          N_("Amount of land vs ocean"), "", NULL,

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