Author: jtn
Date: Tue Feb  9 23:57:01 2016
New Revision: 31847

URL: http://svn.gna.org/viewcvs/freeciv?rev=31847&view=rev
Log:
In rulesets with multiple lake terrains, each generated lake uses the same
terrain rather than being a patchwork of different ones. Also honour the
NotGenerated flag when choosing lake terrains.

See gna patch #6918.

Modified:
    trunk/common/terrain.c
    trunk/common/terrain.h
    trunk/server/generator/mapgen.c
    trunk/server/generator/utilities.c
    trunk/server/generator/utilities.h

Modified: trunk/common/terrain.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/terrain.c?rev=31847&r1=31846&r2=31847&view=diff
==============================================================================
--- trunk/common/terrain.c      (original)
+++ trunk/common/terrain.c      Tue Feb  9 23:57:01 2016
@@ -215,26 +215,6 @@
   } terrain_type_iterate_end;
 
   return terr;
-}
-
-/****************************************************************************
-  Fill terrain with flag to buffer. Returns number of terrains found.
-  Return value can be greater than size of buffer.
-****************************************************************************/
-int terrains_by_flag(enum terrain_flag_id flag, struct terrain **buffer, int 
bufsize)
-{
-  int num = 0;
-
-  terrain_type_iterate(pterr) {
-    if (terrain_has_flag(pterr, flag)) {
-      if (num < bufsize) {
-        buffer[num] = pterr;
-      }
-      num++;
-    }
-  } terrain_type_iterate_end;
-
-  return num;
 }
 
 /****************************************************************************

Modified: trunk/common/terrain.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/terrain.h?rev=31847&r1=31846&r2=31847&view=diff
==============================================================================
--- trunk/common/terrain.h      (original)
+++ trunk/common/terrain.h      Tue Feb  9 23:57:01 2016
@@ -257,8 +257,6 @@
 /* Functions to operate on a terrain flag. */
 #define terrain_has_flag(terr, flag) BV_ISSET((terr)->flags, flag)
 
-int terrains_by_flag(enum terrain_flag_id flag, struct terrain **buffer, int 
bufsize);
-
 bool is_terrain_flag_card_near(const struct tile *ptile,
                               enum terrain_flag_id flag);
 bool is_terrain_flag_near_tile(const struct tile *ptile,

Modified: trunk/server/generator/mapgen.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/generator/mapgen.c?rev=31847&r1=31846&r2=31847&view=diff
==============================================================================
--- trunk/server/generator/mapgen.c     (original)
+++ trunk/server/generator/mapgen.c     Tue Feb  9 23:57:01 2016
@@ -1469,8 +1469,8 @@
     /* Continent numbers must be assigned before regenerate_lakes() */
     assign_continent_numbers();
 
-    /* Make second pass on water. */
-    regenerate_lakes(NULL);
+    /* Turn small oceans into lakes. */
+    regenerate_lakes();
   } else {
     assign_continent_numbers();
   }

Modified: trunk/server/generator/utilities.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/generator/utilities.c?rev=31847&r1=31846&r2=31847&view=diff
==============================================================================
--- trunk/server/generator/utilities.c  (original)
+++ trunk/server/generator/utilities.c  Tue Feb  9 23:57:01 2016
@@ -337,52 +337,56 @@
 }
 
 /**************************************************************************
-  Regenerate all oceanic tiles with coasts, lakes, and deeper oceans.
+  Regenerate all oceanic tiles for small water bodies as lakes.
   Assumes assign_continent_numbers() and recalculate_lake_surrounders()
   have already been done!
   FIXME: insufficiently generalized, use terrain property.
-  FIXME: Results differ from initially generated waters, but this is not
-         used at all in normal map generation.
-**************************************************************************/
-void regenerate_lakes(tile_knowledge_cb knowledge_cb)
-{
-#define MAX_ALT_TER_TYPES 5
-#define DEFAULT_NEAR_COAST (6)
-  struct terrain *lakes[MAX_ALT_TER_TYPES];
-  int num_laketypes;
-
-  num_laketypes = terrains_by_flag(TER_FRESHWATER, lakes, sizeof(lakes));
-  if (num_laketypes > MAX_ALT_TER_TYPES) {
-    log_verbose("Number of lake types in ruleset %d, considering "
-                "only %d ones.", num_laketypes, MAX_ALT_TER_TYPES);
-    num_laketypes = MAX_ALT_TER_TYPES;
+**************************************************************************/
+void regenerate_lakes(void)
+{
+  struct terrain *lake_for_ocean[game.map.num_oceans];
+
+  {
+    struct terrain *lakes[5];
+    int num_laketypes = 0, i;
+
+    terrain_type_iterate(pterr) {
+      if (terrain_has_flag(pterr, TER_FRESHWATER)
+          && !terrain_has_flag(pterr, TER_NOT_GENERATED)) {
+        if (num_laketypes < ARRAY_SIZE(lakes)) {
+          lakes[num_laketypes++] = pterr;
+        } else {
+          log_verbose("Ruleset has more than %d lake types, ignoring %s",
+                      (int) ARRAY_SIZE(lakes), terrain_rule_name(pterr));
+        }
+      }
+    } terrain_type_iterate_end;
+
+    if (num_laketypes == 0) {
+      /* No lake terrains usable by map generator, so nothing to do */
+      return;
+    }
+    for (i = 0; i < game.map.num_oceans; i++) {
+      lake_for_ocean[i] = lakes[fc_rand(num_laketypes)];
+    }
   }
 
-#undef MAX_ALT_TER_TYPES
-
-  if (num_laketypes > 0) {
-    /* Lakes */
-    whole_map_iterate(ptile) {
-      struct terrain *pterrain = tile_terrain(ptile);
-      Continent_id here = tile_continent(ptile);
-
-      if (T_UNKNOWN == pterrain) {
-        continue;
-      }
-      if (terrain_type_terrain_class(pterrain) != TC_OCEAN) {
-        continue;
-      }
-      if (0 < lake_surrounders[-here]) {
-        if (terrain_control.lake_max_size >= ocean_sizes[-here]) {
-          tile_change_terrain(ptile, lakes[fc_rand(num_laketypes)]);
-        }
-        if (knowledge_cb) {
-          knowledge_cb(ptile);
-        }
-        continue;
-      }
-    } whole_map_iterate_end;
-  }
+  whole_map_iterate(ptile) {
+    struct terrain *pterrain = tile_terrain(ptile);
+    Continent_id here = tile_continent(ptile);
+
+    if (T_UNKNOWN == pterrain) {
+      continue;
+    }
+    if (terrain_type_terrain_class(pterrain) != TC_OCEAN) {
+      continue;
+    }
+    if (0 < lake_surrounders[-here]) {
+      if (terrain_control.lake_max_size >= ocean_sizes[-here]) {
+        tile_change_terrain(ptile, lake_for_ocean[-here-1]);
+      }
+    }
+  } whole_map_iterate_end;
 }
 
 /**************************************************************************

Modified: trunk/server/generator/utilities.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/generator/utilities.h?rev=31847&r1=31846&r2=31847&view=diff
==============================================================================
--- trunk/server/generator/utilities.h  (original)
+++ trunk/server/generator/utilities.h  Tue Feb  9 23:57:01 2016
@@ -17,7 +17,7 @@
 
 void generator_free(void);
 
-void regenerate_lakes(tile_knowledge_cb knowledge_cb);
+void regenerate_lakes(void);
 void smooth_water_depth(void);
 void assign_continent_numbers(void);
 int get_lake_surrounders(Continent_id cont);


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to