Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2003:
[Freeciv-Dev] (PR#5234) gen 2 island circumference
Home

[Freeciv-Dev] (PR#5234) gen 2 island circumference

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#5234) gen 2 island circumference
From: "andrearo@xxxxxxxxxxxx" <andrearo@xxxxxxxxxxxx>
Date: Wed, 20 Aug 2003 06:24:43 -0700
Reply-to: rt@xxxxxxxxxxxxxx

Please consider this patch which gives all islands
the same circumference with generator 2,3,4.
It does so by making sure that each island has the same
ammount of tiles that are adjacent to water.
It might be a bit cpu intensive, but I think it's worth it.

Andreas Røsdal
diff -ruN -X freeciv-cvs-Aug-14-orig/diff_ignore 
freeciv-cvs-Aug-14-orig/server/mapgen.c 
freeciv-cvs-Aug-14-changed/server/mapgen.c
--- freeciv-cvs-Aug-14-orig/server/mapgen.c     2003-07-23 15:46:04.000000000 
+0200
+++ freeciv-cvs-Aug-14-changed/server/mapgen.c  2003-08-20 14:32:36.000000000 
+0200
@@ -1573,12 +1573,39 @@
 }
 
 /**************************************************************************
+ Returns the circumference of the island within the given state.
+ This is a helper-function for create_island() which evaluates the
+ circumference if tile x,y is set temporarily to land.
+**************************************************************************/
+static int island_circumference(int land_x, int land_y, 
+                                struct gen234_state *pstate)
+{
+  int x1, y1, sum = 0;
+
+  hmap(land_x, land_y) = 1;
+  for (y1 = pstate->n - 1; y1 < pstate->s + 2; y1++) {  
+    for (x1 = pstate->w - 1; x1 < pstate->e + 2; x1++) {
+      if (hmap(x1, y1) == 1) {
+        adjc_iterate(x1, y1, x2, y2) {
+          if (hmap(x2, y2) == 0) {
+           sum++;
+           break;
+          }
+        } adjc_iterate_end;
+      }
+    }
+  }
+  hmap(land_x, land_y) = 0;
+  return sum;
+}
+
+/**************************************************************************
   finds a place and drop the island created when called with islemass != 0
 **************************************************************************/
 static bool create_island(int islemass, struct gen234_state *pstate)
 {
   int x, y, i;
-  long int tries=islemass*(2+islemass/20)+99;
+  long int tries=islemass*(2+islemass/20)*20+99;
   bool j;
 
   memset(height_map, '\0', sizeof(int) * map.xsize * map.ysize);
@@ -1592,8 +1619,10 @@
   i = islemass - 1;
   while (i > 0 && tries-->0) {
     get_random_map_position_from_state(&x, &y, pstate);
-    if (hmap(x, y) == 0 && (hmap(x + 1, y) != 0 || hmap(x - 1, y) != 0 ||
-                           hmap(x, y + 1) != 0 || hmap(x, y - 1) != 0)) {
+    if (hmap(x, y) == 0 && 
+       island_circumference(x, y, pstate) < (islemass * 0.6 + 40) &&
+       (hmap(x + 1, y) != 0 || hmap(x - 1, y) != 0 ||
+       hmap(x, y + 1) != 0 || hmap(x, y - 1) != 0)) {
       hmap(x, y) = 1;
       i--;
       if (y >= pstate->s - 1 && pstate->s < map.ysize - 2) pstate->s++;

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#5234) gen 2 island circumference, andrearo@xxxxxxxxxxxx <=