Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] (PR#10201) PATCH: generator characteristics evolution, bes
Home

[Freeciv-Dev] (PR#10201) PATCH: generator characteristics evolution, bes

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#10201) PATCH: generator characteristics evolution, best handled temperature and relief.
From: "Marcelo Burda" <mburda@xxxxxxxxx>
Date: Sun, 19 Sep 2004 15:20:24 -0700
Reply-to: rt@xxxxxxxxxxx

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

This patch depend from 10124 
 
caracteristics are handles has BV, i am near end of gen-terr of 
generator. rivers and wetness still in todo. (soon) 
diff -ruN -Xfreeciv/diff_ignore freeciv_/common/map.h freeciv/common/map.h
--- freeciv_/common/map.h       2004-09-18 18:42:18.000000000 +0200
+++ freeciv/common/map.h        2004-09-18 23:25:19.000000000 +0200
@@ -540,6 +540,30 @@
 
 #define cardinal_adjc_dir_iterate_end adjc_dirlist_iterate_end
 
+/****************************************************************************
+  This iterator behaves like adjc_iterate or cardinal_adjc_iterate depending
+  on the value of card_only.
+****************************************************************************/
+#define variable_adjc_iterate(center_x, center_y, x_itr, y_itr, card_only)  \
+{                                                                          \
+  enum direction8 *_dirlist;                                               \
+  int _total;                                                              \
+                                                                           \
+  if (card_only) {                                                         \
+    _dirlist = map.cardinal_dirs;                                          \
+    _total = map.num_cardinal_dirs;                                        \
+  } else {                                                                 \
+    _dirlist = map.valid_dirs;                                             \
+    _total = map.num_valid_dirs;                                           \
+  }                                                                        \
+                                                                           \
+  adjc_dirlist_iterate(center_x, center_y, x_itr, y_itr,                   \
+                      _dir, _dirlist, _total) {
+
+#define variable_adjc_iterate_end                                          \
+  } adjc_dirlist_iterate_end;                                              \
+}
+
 /* Iterate through all tiles adjacent to a tile using the given list of
  * directions.  dir_itr is the directional value, (center_x, center_y) is
  * the center tile (which must be normalized), and (x_itr, y_itr) is the
diff -ruN -Xfreeciv/diff_ignore freeciv_/common/terrain.c 
freeciv/common/terrain.c
--- freeciv_/common/terrain.c   2004-09-10 05:55:01.000000000 +0200
+++ freeciv/common/terrain.c    2004-09-18 23:25:16.000000000 +0200
@@ -131,31 +131,6 @@
 }
 
 /****************************************************************************
-  This iterator behaves like adjc_iterate or cardinal_adjc_iterate depending
-  on the value of card_only.
-****************************************************************************/
-#define variable_adjc_iterate(center_x, center_y, x_itr, y_itr, card_only)  \
-{                                                                          \
-  enum direction8 *_dirlist;                                               \
-  int _total;                                                              \
-                                                                           \
-  if (card_only) {                                                         \
-    _dirlist = map.cardinal_dirs;                                          \
-    _total = map.num_cardinal_dirs;                                        \
-  } else {                                                                 \
-    _dirlist = map.valid_dirs;                                             \
-    _total = map.num_valid_dirs;                                           \
-  }                                                                        \
-                                                                           \
-  adjc_dirlist_iterate(center_x, center_y, x_itr, y_itr,                   \
-                      _dir, _dirlist, _total) {
-
-#define variable_adjc_iterate_end                                          \
-  } adjc_dirlist_iterate_end;                                              \
-}
-
-
-/****************************************************************************
   Returns TRUE iff any adjacent tile contains the given terrain.
 ****************************************************************************/
 bool is_terrain_near_tile(int map_x, int map_y, Terrain_type_id t)
Les fichiers binaires freeciv_/manual/civmanual et freeciv/manual/civmanual 
sont différents.
diff -ruN -Xfreeciv/diff_ignore freeciv_/server/generator/characteristics.c 
freeciv/server/generator/characteristics.c
--- freeciv_/server/generator/characteristics.c 1970-01-01 01:00:00.000000000 
+0100
+++ freeciv/server/generator/characteristics.c  2004-09-19 23:50:06.000000000 
+0200
@@ -0,0 +1,337 @@
+/********************************************************************** 
+   Copyright (C) 2004  Marcelo Burda
+   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.
+***********************************************************************/
+#include "config.h"
+#include "map.h"
+#include "rand.h"
+
+#include "utilities.h"
+#include "characteristics.h"
+#include "height_map.h"
+#include "mapgen_topology.h"
+
+static characteristic_type *characteristic_map;
+
+characteristic_type RT_FLAT, RT_HILLY, RT_ABRUPT, RT_NFLAT;
+characteristic_type TT_FROZEN, TT_COLD, TT_TEMPERATE, TT_TROPICAL,
+                    TT_NFROZEN,  TT_ALL, TT_NHOT, TT_HOT;
+
+/* necessary condition of swamp placement */
+static int hmap_low_level = 0;
+#define ini_hmap_low_level() \
+{ \
+hmap_low_level = (2 * map.swampsize  * \
+     (hmap_max_level - hmap_shore_level)) / 100 + hmap_shore_level; \
+}
+
+/**************************************************************************
+ return TRUE if initialized
+*************************************************************************/ 
+bool characteristics_are_initialized(void)
+{
+  return characteristic_map != NULL;
+}
+
+/****************************************************************************
+****************************************************************************/
+void create_characteristics(void)                               
+{   
+  int i;                                                       
+  assert( !characteristics_are_initialized());                              
+  characteristic_map = fc_malloc (sizeof(characteristic_type) * MAX_MAP_INDEX);
+  for( i = 0; i < MAX_MAP_INDEX; i++) {
+      BV_CLR_ALL(characteristic_map[i]);
+  }
+  /* initialize constant values of relief */
+  BV_CLR_ALL(RT_FLAT);
+  BV_SET(RT_FLAT, CB_FLAT);
+  BV_CLR_ALL(RT_HILLY);
+  BV_SET(RT_HILLY, CB_HILLY);
+  BV_CLR_ALL(RT_ABRUPT);
+  BV_SET(RT_ABRUPT, CB_ABRUPT);
+  BV_CLR_ALL(RT_NFLAT);
+  BV_SET(RT_NFLAT, CB_HILLY);
+  BV_SET(RT_NFLAT, CB_ABRUPT);
+
+  /* inizialize constant value of temperature */
+  BV_CLR_ALL(TT_FROZEN);
+  BV_SET(TT_FROZEN, CB_FROZEN);
+  BV_CLR_ALL(TT_COLD);
+  BV_SET(TT_COLD, CB_COLD);
+  BV_CLR_ALL(TT_TEMPERATE);
+  BV_SET(TT_TEMPERATE, CB_TEMPERATE);
+  BV_CLR_ALL(TT_TROPICAL);
+  BV_SET(TT_TROPICAL, CB_TROPICAL);
+
+  BV_CLR_ALL(TT_NFROZEN);
+  BV_SET(TT_NFROZEN, CB_COLD);
+  BV_SET(TT_NFROZEN, CB_TEMPERATE);
+  BV_SET(TT_NFROZEN, CB_TROPICAL);
+
+  BV_CLR_ALL(TT_ALL);
+  BV_SET(TT_ALL, CB_FROZEN);
+  BV_SET(TT_ALL, CB_COLD);
+  BV_SET(TT_ALL, CB_TEMPERATE);
+  BV_SET(TT_ALL, CB_TROPICAL);
+
+  BV_CLR_ALL(TT_NHOT);
+  BV_SET(TT_NHOT, CB_FROZEN);
+  BV_SET(TT_NHOT, CB_COLD);
+ 
+  BV_CLR_ALL(TT_HOT);
+  BV_SET(TT_HOT, CB_TEMPERATE);
+  BV_SET(TT_HOT, CB_TROPICAL);
+
+}
+
+/**************************************************************************** 
+  Free the map
+****************************************************************************/
+void destroy_characteristics(void)   
+{                              
+  assert(characteristics_are_initialized()); 
+  free(characteristic_map);            
+  characteristic_map = NULL;           
+}
+
+#define cmap(x, y) (characteristic_map[map_pos_to_index(x, y)])
+
+
+bool characteristic_is_bit(int x, int y, characteristic_bits bit)
+{
+  return BV_ISSET(cmap(x, y), bit);
+}
+
+void characteristic_set_bit(int x, int y, characteristic_bits bit)
+{
+  BV_SET(cmap(x, y), bit);
+}
+
+void characteristic_clr_bit(int x, int y, characteristic_bits bit)
+{
+  BV_CLR(cmap(x, y), bit);
+}
+
+bool characteristic_is_mask(int x, int y,characteristic_type mask )
+{
+  return BV_CHECK_MASK(cmap(x, y), mask);
+}
+
+/******************************************************************
+ Return the number of oceanic tiles adjacent to the given place.
+ (c): copy of count_terrain_flag_near_tile
+ ******************************************************************/
+int characteristic_count_ocean_near_tile(int x, int y,
+                                bool cardinal_only, bool percentage)
+{
+  int count = 0, total = 0;
+
+  variable_adjc_iterate(x, y, x1, y1, cardinal_only) {
+    if (characteristic_is_oceanic(x1, y1)) {
+      count++;
+    }
+    total++;
+  } variable_adjc_iterate_end;
+
+  if (percentage) {
+    count = count * 100 / total;
+  }
+  return count;
+}
+
+/*************************************************************************
+ ************************************************************************/
+void characteristics_initialize_shores(void)
+{
+  if (HAS_POLES) {
+    normalize_hmap_poles();
+  }
+  hmap_shore_level = (hmap_max_level * (100 - map.landpercent)) / 100;
+  ini_hmap_low_level();
+  whole_map_iterate(x, y) {
+    if (hmap(x, y) < hmap_shore_level) {
+      characteristic_set_oceanic(x, y);
+    }
+  } whole_map_iterate_end;
+  if (HAS_POLES) {
+    renormalize_hmap_poles();
+  } 
+}
+
+/*************************************************************************
+ if separatepoles is set, return false if this tile has to keep ocean
+************************************************************************/
+static bool ok_for_separate_poles(int x, int y) 
+{
+  if (!map.separatepoles) {
+    return TRUE;
+  }
+  adjc_iterate(x, y, x1, y1) {
+    if(!characteristic_is_oceanic(x1, y1) &&
+       (map_colatitude(x1, y1) > 2 * ICE_BASE_LEVEL)) {
+      return FALSE;
+    }
+  } adjc_iterate_end;
+  return TRUE;
+}
+
+/****************************************************************************
+  Place untextured land at the poles.  This is used by generators 1 and 5
+  on tiles-sets with not forzen oceans
+****************************************************************************/
+void characteristics_initialize_extra_polar_land(void)
+{
+  whole_map_iterate(x, y) {
+    if (  (map_colatitude(x, y) <=  2 * ICE_BASE_LEVEL) &&
+       ok_for_separate_poles(x, y)) {
+       characteristic_unset_oceanic(x, y);
+    } 
+  } whole_map_iterate_end;
+}
+
+/**************************************************************************
+  we don't want huge flat areas, 
+  so we put in a hill here and there, where it gets too flat 
+
+  Return TRUE if the terrain at the given map position is too flat.  This
+  means that all the terrain for 2 squares around it are only flat.
+****************************************************************************/
+static bool terrain_is_too_flat(int map_x, int map_y,int thill, int my_height)
+{
+  int higher_than_me = 0;
+  square_iterate(map_x, map_y, 2, x1, y1) {
+    if (hmap(x1, y1) > thill) {
+      return FALSE;
+    }
+    if (hmap(x1, y1) > my_height) {
+      if (map_distance(map_x, map_y, x1, y1) == 1) {
+       return FALSE;
+      }
+      if (++higher_than_me > 2) {
+       return FALSE;
+      }
+    }
+  } square_iterate_end;
+
+  if ((thill - hmap_shore_level) * higher_than_me  > 
+      (my_height - hmap_shore_level) * 4) {
+    return FALSE;
+  }
+  return TRUE;
+}
+
+/**************************************************************************
+  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 too heigh.
+****************************************************************************/
+static bool terrain_is_too_high(int map_x, int map_y,int thill, int my_height)
+{
+  square_iterate(map_x, map_y, 1, x1, y1) {
+    if (hmap(x1, y1) + (hmap_max_level - hmap_mountain_level) / 5 < thill) {
+      return FALSE;
+    }
+  } square_iterate_end;
+  return TRUE;
+}
+
+/**************************************************************************
+  make_relief() will convert all squares that are higher than thill to
+  mountains and hills. Note that thill will be adjusted according to
+  the map.mountains value, so increasing map.mountains will result in
+  more hills and mountains.
+**************************************************************************/
+void characteristics_initialize_relief(void)
+{
+  /* Calculate the mountain level.  map.mountains specifies the percentage
+   * of land that is turned into hills and mountains. */
+  hmap_mountain_level = ((hmap_max_level - hmap_shore_level)
+                        * (100 - map.mountains)) / 100 + hmap_shore_level;
+
+  whole_map_iterate(x, y) {
+    if (!characteristic_is_oceanic(x, y) &&
+       ((hmap_mountain_level < hmap(x, y) && 
+         (myrand(10) > 5 
+          || !terrain_is_too_high(x, y, hmap_mountain_level, hmap(x, y))))
+        || terrain_is_too_flat(x, y, hmap_mountain_level, hmap(x, y)))) {
+      /* Randomly place hills and mountains on "high" tiles. */
+      if (myrand(100) > 70) {
+       characteristic_set_bit(x, y, CB_ABRUPT);
+      } else {
+       characteristic_set_bit(x, y, CB_HILLY);
+      }
+    } else {
+       characteristic_set_bit(x, y, CB_FLAT);
+    }
+   /* should be used after having hmap_low_level initialized */
+    if (hmap(x, y) < hmap_low_level) {
+       characteristic_set_bit(x, y, CB_LOW);
+    }
+  } whole_map_iterate_end;
+}
+
+/***************************************************************************
+ * 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 characteristics_initialize_temperature(bool real)
+{
+  int temperature[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) {
+      temperature[map_pos_to_index(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_COLATITUDE) * 
+         2 * MIN (50 ,
+                  characteristic_count_ocean_near_tile(x, y, FALSE, TRUE)) /
+         100;
+      
+      temperature[map_pos_to_index(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, MAX_COLATITUDE);
+  /* now simplify to 4 base values */ 
+  whole_map_iterate(x, y) {
+    int t = temperature[map_pos_to_index(x, y)];
+
+    /* first if is a hack to avoid some ugly effect,
+       TODO: think if there is a best way, veriffy off by one in colatitude */ 
+    if (map_colatitude(x, y) < 2 * ICE_BASE_LEVEL) {
+      characteristic_set_bit(x, y, CB_FROZEN);
+    } 
+
+    else if (t >= TROPICAL_LEVEL ) {
+      characteristic_set_bit(x, y, CB_TROPICAL);
+    } else if (t >= COLD_LEVEL) {
+      characteristic_set_bit(x, y, CB_TEMPERATE);
+    } else if (t >= 2 * ICE_BASE_LEVEL) {
+      characteristic_set_bit(x, y, CB_COLD);
+    } else {
+      characteristic_set_bit(x, y, CB_FROZEN);
+    }
+  }  whole_map_iterate_end;
+}
diff -ruN -Xfreeciv/diff_ignore freeciv_/server/generator/characteristics.h 
freeciv/server/generator/characteristics.h
--- freeciv_/server/generator/characteristics.h 1970-01-01 01:00:00.000000000 
+0100
+++ freeciv/server/generator/characteristics.h  2004-09-20 00:02:11.000000000 
+0200
@@ -0,0 +1,57 @@
+/********************************************************************** 
+   Copyright (C) 2004 - Marcelo J. Burda,
+   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__CHARACTERISTICS_H
+#define FC__CHARACTERISTICS_H
+
+BV_DEFINE(characteristic_type, 13);
+typedef enum  {CB_OCEANIC = 0, CB_RIVER = 1,
+              CB_FROZEN = 2, CB_COLD = 3, CB_TEMPERATE = 4, CB_TROPICAL = 5,
+               CB_WET = 6, CB_MEDIUM = 7, CB_DRY = 8,
+               CB_FLAT = 9, CB_HILLY = 10, CB_ABRUPT = 11,
+               CB_LOW = 12} characteristic_bits;
+
+extern characteristic_type RT_FLAT, RT_HILLY, RT_ABRUPT, RT_NFLAT;
+extern characteristic_type TT_FROZEN, TT_COLD, TT_TEMPERATE, TT_TROPICAL,
+/*
+ TT_NFROZEN == (TT_COLD | TT_TEMPERATE | TT_TROPICAL)
+ TT_ALL     == (TT_FROZEN | TT_NFROZEN)
+ TT_NHOT    == (TT_FROZEN | TT_COLD)
+ TT_HOT     == (TT_TEMPERATE, TT_TROPICAL)
+ */
+    TT_NFROZEN,  TT_ALL, TT_NHOT, TT_HOT;
+
+bool characteristics_are_initialized(void);
+void create_characteristics(void);
+void destroy_characteristics(void);  
+bool characteristic_is_mask(int x, int y,characteristic_type mask );
+bool characteristic_is_bit(int x, int y, characteristic_bits bit);
+void characteristic_set_bit(int x, int y, characteristic_bits bit);
+void characteristic_clr_bit(int x, int y, characteristic_bits bit);
+/*bool is_characteristic_mask_near(int x, int y,characteristic_type mask );*/
+
+void characteristics_initialize_shores(void);
+void characteristics_initialize_extra_polar_land(void);
+#define characteristic_is_oceanic(x, y) \
+        characteristic_is_bit((x), (y), CB_OCEANIC)
+#define characteristic_set_oceanic(x, y) \
+        characteristic_set_bit((x), (y), CB_OCEANIC)
+#define characteristic_unset_oceanic(x, y) \
+        characteristic_clr_bit((x), (y), CB_OCEANIC)
+int characteristic_count_ocean_near_tile(int x, int y,
+                                bool cardinal_only, bool percentage);
+
+
+void characteristics_initialize_relief(void);
+void characteristics_initialize_temperature(bool real);
+
+#endif  /* FC__CHARACTERISTICS_H */
diff -ruN -Xfreeciv/diff_ignore freeciv_/server/generator/Makefile.am 
freeciv/server/generator/Makefile.am
--- freeciv_/server/generator/Makefile.am       2004-09-18 13:39:14.000000000 
+0200
+++ freeciv/server/generator/Makefile.am        2004-09-19 23:39:01.000000000 
+0200
@@ -14,5 +14,5 @@
        height_map.h \
        startpos.c \
        startpos.h \
-       temperature_map.c \
-       temperature_map.h
+       characteristics.h \
+       characteristics.c
diff -ruN -Xfreeciv/diff_ignore freeciv_/server/generator/mapgen.c 
freeciv/server/generator/mapgen.c
--- freeciv_/server/generator/mapgen.c  2004-09-20 00:13:06.000000000 +0200
+++ freeciv/server/generator/mapgen.c   2004-09-19 23:56:57.000000000 +0200
@@ -36,9 +36,8 @@
 #include "height_map.h"
 #include "mapgen_topology.h"
 #include "startpos.h"
-#include "temperature_map.h"
 #include "utilities.h"
-
+#include "characteristics.h"
 
 /* Old-style terrain enumeration: deprecated. */
 enum {
@@ -54,7 +53,6 @@
 static void mapgenerator2(void);
 static void mapgenerator3(void);
 static void mapgenerator4(void);
-static void adjust_terrain_param(void);
 
 #define RIVERS_MAXTRIES 32767
 enum river_map_type {RS_BLOCKED = 0, RS_RIVER = 1};
@@ -65,8 +63,6 @@
    A value of 2 means river.                            -Erik Sigra */
 static int *river_map;
 
-#define HAS_POLES (map.temperature < 70 && !map.alltemperate  )
-
 /****************************************************************************
  * Conditions used mainly in rand_map_pos_characteristic()
  ****************************************************************************/
@@ -76,21 +72,9 @@
 #define map_pos_is_dry(x, y)                                           \
   (map_colatitude((x), (y)) <= DRY_MAX_LEVEL                           \
    && map_colatitude((x), (y)) > DRY_MIN_LEVEL                         \
-   && count_ocean_near_tile((x), (y), FALSE, TRUE) <= 35)
+   && characteristic_count_ocean_near_tile((x), (y), FALSE, TRUE) <= 35)
 typedef enum { WC_ALL = 200, WC_DRY, WC_NDRY } wetness_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_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))
-
 typedef enum { MC_NONE, MC_LOW, MC_NLOW } miscellaneous_c;
 
 /***************************************************************************
@@ -122,9 +106,9 @@
        case MC_NONE:
            return TRUE;
        case MC_LOW:
-           return map_pos_is_low(x, y);
+           return characteristic_is_bit(x, y, CB_LOW);
        case MC_NLOW:
-           return !map_pos_is_low(x, y);
+           return !characteristic_is_bit(x, y, CB_LOW);
        default:
            assert(0);
     }
@@ -135,7 +119,7 @@
 ***************************************************************************/
 struct DataFilter {
   wetness_c        wc;
-  temperature_type tc;
+  characteristic_type tc;
   miscellaneous_c  mc;
 };
 
@@ -148,7 +132,7 @@
   struct DataFilter *filter = data;
 
   return  not_placed(map_x, map_y) 
-      &&  tmap_is(map_x, map_y, filter->tc) 
+      &&  characteristic_is_mask(map_x, map_y, filter->tc) 
       &&  test_wetness(map_x, map_y, filter->wc) 
       &&  test_miscellaneous(map_x, map_y, filter->mc) ;
 }
@@ -160,7 +144,7 @@
 ****************************************************************************/
 static bool rand_map_pos_characteristic(int *map_x, int *map_y,
                                   wetness_c        wc,
-                                  temperature_type tc,
+                                  characteristic_type tc,
                                   miscellaneous_c  mc )
 {
   struct DataFilter filter;
@@ -171,85 +155,6 @@
   return rand_map_pos_filtered(map_x, map_y, &filter, condition_filter);
 }
 
-/**************************************************************************
-  we don't want huge areas of grass/plains, 
-  so we put in a hill here and there, where it gets too 'clean' 
-
-  Return TRUE if the terrain at the given map position is "clean".  This
-  means that all the terrain for 2 squares around it is not mountain or hill.
-****************************************************************************/
-static bool terrain_is_too_flat(int map_x, int map_y,int thill, int my_height)
-{
-  int higher_than_me = 0;
-  square_iterate(map_x, map_y, 2, x1, y1) {
-    if (hmap(x1, y1) > thill) {
-      return FALSE;
-    }
-    if (hmap(x1, y1) > my_height) {
-      if (map_distance(map_x, map_y, x1, y1) == 1) {
-       return FALSE;
-      }
-      if (++higher_than_me > 2) {
-       return FALSE;
-      }
-    }
-  } square_iterate_end;
-
-  if ((thill - hmap_shore_level) * higher_than_me  > 
-      (my_height - hmap_shore_level) * 4) {
-    return FALSE;
-  }
-  return TRUE;
-}
-
-/**************************************************************************
-  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 too heigh.
-****************************************************************************/
-static bool terrain_is_too_high(int map_x, int map_y,int thill, int my_height)
-{
-  square_iterate(map_x, map_y, 1, x1, y1) {
-    if (hmap(x1, y1) + (hmap_max_level - hmap_mountain_level) / 5 < thill) {
-      return FALSE;
-    }
-  } square_iterate_end;
-  return TRUE;
-}
-
-/**************************************************************************
-  make_relief() will convert all squares that are higher than thill to
-  mountains and hills. Note that thill will be adjusted according to
-  the map.mountains value, so increasing map.mountains will result in
-  more hills and mountains.
-**************************************************************************/
-static void make_relief(void)
-{
-  /* Calculate the mountain level.  map.mountains specifies the percentage
-   * of land that is turned into hills and mountains. */
-  hmap_mountain_level = ((hmap_max_level - hmap_shore_level)
-                        * (100 - map.mountains)) / 100 + hmap_shore_level;
-
-  whole_map_iterate(x, y) {
-    if (not_placed(x,y) &&
-       ((hmap_mountain_level < hmap(x, y) && 
-         (myrand(10) > 5 
-          || !terrain_is_too_high(x, y, hmap_mountain_level, hmap(x, y))))
-        || 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 || tmap_is(x, y, TT_NHOT)) {
-       map_set_terrain(x, y, T_MOUNTAINS);
-       map_set_placed(x, y);
-      } else {
-       map_set_terrain(x, y, T_HILLS);
-       map_set_placed(x, y);
-      }
-    }
-  } whole_map_iterate_end;
-}
-
 /****************************************************************************
   Add arctic and tundra squares in the arctic zone (that is, the coolest
   10% of the map).  We also texture the pole (adding arctic, tundra, and
@@ -258,52 +163,12 @@
 static void make_polar(void)
 {
   whole_map_iterate(map_x, map_y) {  
-    if (tmap_is(map_x, map_y, TT_FROZEN )
-       ||
-       (tmap_is(map_x, map_y, TT_COLD ) &&
-        (myrand(10) > 7) &&
-        is_temperature_type_near(map_x, map_y, TT_FROZEN))) { 
+    if (characteristic_is_mask(map_x, map_y, TT_FROZEN )) { 
       map_set_terrain(map_x, map_y, T_ARCTIC);
     }
   } whole_map_iterate_end;
 }
 
-/*************************************************************************
- if separatepoles is set, return false if this tile has to keep ocean
-************************************************************************/
-static bool ok_for_separate_poles(int x, int y) 
-{
-  if (!map.separatepoles) {
-    return TRUE;
-  }
-  adjc_iterate(x, y, x1, y1) {
-    if(!is_ocean(map_get_terrain(x1, y1))
-       && map_get_continent(x1, y1 ) != 0) {
-      return FALSE;
-    }
-  } adjc_iterate_end;
-  return TRUE;
-}
-
-/****************************************************************************
-  Place untextured land at the poles.  This is used by generators 1 and 5.
-****************************************************************************/
-static void make_polar_land(void)
-{
-  assign_continent_numbers();
-  whole_map_iterate(map_x, map_y) {
-    if ((tmap_is(map_x, map_y, TT_FROZEN ) &&
-       ok_for_separate_poles(map_x, map_y))
-       ||
-       (tmap_is(map_x, map_y, TT_COLD ) &&
-        (myrand(10) > 7) &&
-        is_temperature_type_near(map_x, map_y, TT_FROZEN) &&
-        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;
-}
 
 /**************************************************************************
   Recursively generate terrains.
@@ -311,7 +176,7 @@
 static void place_terrain(int x, int y, int diff, 
                            Terrain_type_id ter, int *to_be_placed,
                           wetness_c        wc,
-                          temperature_type tc,
+                          characteristic_type tc,
                           miscellaneous_c  mc)
 {
   if (*to_be_placed <= 0) {
@@ -326,7 +191,7 @@
     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) 
+       && characteristic_is_mask(x1, y1, tc) 
        && test_wetness(x1, y1, wc)
        && test_miscellaneous(x1, y1, mc)
        && Delta < diff 
@@ -343,9 +208,9 @@
 static void make_plain(int x, int y, int *to_be_placed )
 {
   /* in cold place we get tundra instead */
-  if (tmap_is(x, y, TT_FROZEN)) {
+  if (characteristic_is_mask(x, y, TT_FROZEN)) {
     map_set_terrain(x, y, T_ARCTIC); 
-  } else if (tmap_is(x, y, TT_COLD)) {
+  } else if (characteristic_is_mask(x, y, TT_COLD)) {
     map_set_terrain(x, y, T_TUNDRA); 
   } else {
     if (myrand(100) > 50) {
@@ -372,6 +237,7 @@
     }
   } whole_map_iterate_end;
 }
+
 /**************************************************************************
  This place randomly a cluster of terrains with some characteristics
  **************************************************************************/
@@ -406,6 +272,25 @@
   int plains_count = 0;
   int swamps_count = 0;
 
+  create_placed_map();
+
+  whole_map_iterate(x, y) {
+    if (characteristic_is_oceanic(x, y)) {
+      map_set_placed(x, y);
+      map_set_terrain(x, y, T_OCEAN);
+    } else if (characteristic_is_mask(x,  y, RT_HILLY)) {
+      map_set_placed(x, y);
+      map_set_terrain(x, y, T_HILLS);
+      /* hack for terrains-set, where hills are too green */
+      if (characteristic_is_mask(x, y, TT_FROZEN)) {
+       map_set_terrain(x, y, T_MOUNTAINS);
+      }
+    } else  if (characteristic_is_mask(x,  y, RT_ABRUPT)) {
+      map_set_placed(x, y);
+      map_set_terrain(x, y, T_MOUNTAINS);
+    }
+  } whole_map_iterate_end;
+
   whole_map_iterate(x, y) {
     if(not_placed(x,y)) {
      total++;
@@ -457,6 +342,8 @@
   } while (forests_count > 0 || jungles_count > 0 
           || deserts_count > 0 || alt_deserts_count > 0 
           || plains_count > 0 || swamps_count > 0 );
+
+  destroy_placed_map();
 }
 
 /*********************************************************************
@@ -910,46 +797,6 @@
 }
 
 /**************************************************************************
-  make land simply does it all based on a generated heightmap
-  1) with map.landpercent it generates a ocean/grassland map 
-  2) it then calls the above functions to generate the different terrains
-**************************************************************************/
-static void make_land(void)
-{
-  
-  if (HAS_POLES) {
-    normalize_hmap_poles();
-  }
-  hmap_shore_level = (hmap_max_level * (100 - map.landpercent)) / 100;
-  ini_hmap_low_level();
-  whole_map_iterate(x, y) {
-    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);
-    }
-  } whole_map_iterate_end;
-  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_all_ocean_tiles_placed();
-  make_relief(); /* base relief on map */
-  make_terrains(); /* place all exept mountains and hill */
-  destroy_placed_map();
-
-  make_rivers(); /* use a new placed_map. destroy older before call */
-
-  assign_continent_numbers();
-}
-
-/**************************************************************************
   Returns if this is a 1x1 island
 **************************************************************************/
 static bool is_tiny_island(int x, int y) 
@@ -986,6 +833,26 @@
 }
 
 /**************************************************************************
+ Convert terrain parameters from the server into percents for the generators
+**************************************************************************/
+static void adjust_terrain_param(void)
+{
+  int total;
+  int polar = ICE_BASE_LEVEL * 100 / MAX_COLATITUDE;
+
+  total = map.mountains + map.deserts + map.forestsize + map.swampsize
+    + map.grasssize;
+
+  if (total != 100 - polar) {
+    map.forestsize = map.forestsize * (100 - polar) / total;
+    map.swampsize = map.swampsize * (100 - polar) / total;
+    map.mountains = map.mountains * (100 - polar) / total;
+    map.deserts = map.deserts * (100 - polar) / total;
+    map.grasssize = 100 - map.forestsize - map.swampsize - map.mountains 
+      - polar - map.deserts;
+  }
+}
+/**************************************************************************
   See stdinhand.c for information on map generation methods.
 
 FIXME: Some continent numbers are unused at the end of this function, fx
@@ -1029,23 +896,61 @@
       make_random_hmap(1 + SQSIZE);
     }
 
-    /* if hmap only generator make anything else */
+    /*
+     * if hmap only generator make anything else
+     *
+     * TO DO: height map scenario
+     */ 
     if (map.generator == 1 || map.generator == 5) {
-      make_land();
+      create_characteristics();
+      /*
+       * Second step, Initialize generalized terrains characteristics
+       */
+      characteristics_initialize_shores();
+      /* this is a hack to terrains-set with not frozen oceans*/
+      if (HAS_POLES) { 
+       characteristics_initialize_extra_polar_land();
+      }
+      characteristics_initialize_temperature(TRUE);
+      characteristics_initialize_relief();
+
+      /*
+       * 3 step, place terrians
+       */
+      make_terrains();
+ 
+      /* old style river code, not set terrains characteristics
+       *   TODO in 2 step 
+       */
+      make_rivers();
+      
+      assign_continent_numbers();
+
       free(height_map);
       height_map = NULL;
-    }
+    } 
 
+  
+    /* old style tune
+     * TODO rm
+     */
     if (!map.tinyisles) {
       remove_tiny_islands();
     }
+
   } else {
       assign_continent_numbers();
   }
 
-  if(!temperature_is_initialized()) {
-    create_tmap(FALSE);
-  }
+  /*
+   * 4 Place specials and huts
+   */
+
+  /* initialize needed characteristics if not yet done, */
+  if (!characteristics_are_initialized()) {
+      create_characteristics();
+      characteristics_initialize_temperature(FALSE);
+    } 
 
   if(!map.have_specials) /* some scenarios already provide specials */
     add_specials(map.riches); /* hvor mange promiller specials oensker vi*/
@@ -1054,30 +959,9 @@
     make_huts(map.huts); /* Vi vil have store promiller; man kan aldrig faa
                            for meget oel! */
 
-  /* restore previous random state: */
+  destroy_characteristics();
+ /* restore previous random state: */
   set_myrand_state(rstate);
-  destroy_tmap();
-}
-
-/**************************************************************************
- Convert terrain parameters from the server into percents for the generators
-**************************************************************************/
-static void adjust_terrain_param(void)
-{
-  int total;
-  int polar = ICE_BASE_LEVEL * 100 / MAX_COLATITUDE;
-
-  total = map.mountains + map.deserts + map.forestsize + map.swampsize
-    + map.grasssize;
-
-  if (total != 100 - polar) {
-    map.forestsize = map.forestsize * (100 - polar) / total;
-    map.swampsize = map.swampsize * (100 - polar) / total;
-    map.mountains = map.mountains * (100 - polar) / total;
-    map.deserts = map.deserts * (100 - polar) / total;
-    map.grasssize = 100 - map.forestsize - map.swampsize - map.mountains 
-      - polar - map.deserts;
-  }
 }
 
 /****************************************************************************
@@ -1622,7 +1506,8 @@
   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);
+  create_characteristics();
+  characteristics_initialize_temperature(FALSE);
   whole_map_iterate(x, y) {
     map_set_terrain(x, y, T_OCEAN);
     map_set_continent(x, y, 0);
diff -ruN -Xfreeciv/diff_ignore freeciv_/server/generator/mapgen_topology.c 
freeciv/server/generator/mapgen_topology.c
--- freeciv_/server/generator/mapgen_topology.c 2004-09-18 13:39:14.000000000 
+0200
+++ freeciv/server/generator/mapgen_topology.c  2004-09-19 19:15:32.000000000 
+0200
@@ -29,6 +29,14 @@
   functions instead (x,y) coordinate to place terrains
   colatitude is 0 at poles and MAX_COLATITUDE at equator
 ****************************************************************************/
+int colatitude (int index)
+{
+    int x, y;
+ 
+    index_to_map_pos( &x, &y, index);
+    return map_colatitude(x, y);
+}
+
 int map_colatitude(int map_x, int map_y)
 {
   double x, y;
diff -ruN -Xfreeciv/diff_ignore freeciv_/server/generator/mapgen_topology.h 
freeciv/server/generator/mapgen_topology.h
--- freeciv_/server/generator/mapgen_topology.h 2004-09-18 13:39:14.000000000 
+0200
+++ freeciv/server/generator/mapgen_topology.h  2004-09-19 19:15:28.000000000 
+0200
@@ -45,6 +45,9 @@
 extern int ice_base_colatitude;
 #define ICE_BASE_LEVEL ice_base_colatitude
 
+#define HAS_POLES (map.temperature < 70 && !map.alltemperate)
+
+int colatitude (int index);
 int map_colatitude(int map_x, int map_y);
 bool near_singularity(int map_x, int map_y);
 void generator_init_topology(bool autosize);

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