Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2004:
[Freeciv-Dev] Re: (PR#9871) autosize parameter for mapgen
Home

[Freeciv-Dev] Re: (PR#9871) autosize parameter for mapgen

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#9871) autosize parameter for mapgen
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 29 Aug 2004 22:21:13 -0700
Reply-to: rt@xxxxxxxxxxx

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

Jason Short wrote:
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=9871 >
> 
> Mapgen creates xsize and ysize from the server's "size" variable.
> 
> But civworld uses mapgen, and should be able to let the user set the 
> sizes directly.  Adding a paramter to mapgen makes this easy.
> 
> Note to Mike: letting the user set xsize/ysize directly is dangerous. 
> xsize and ysize don't do what you'd expect them to do in hex and iso 
> topologies.  You might be better off letting the user set an integer (or 
> floating-point) width and height, then dividing the width by sqrt(2) and 
> multiplying the height by sqrt(2) (TF_HEX or TF_ISO).  Then they'll 
> probably get about what they expect.

Same patch, with documentation.

jason

Index: server/mapgen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/mapgen.c,v
retrieving revision 1.149
diff -u -r1.149 mapgen.c
--- server/mapgen.c     28 Aug 2004 16:50:49 -0000      1.149
+++ server/mapgen.c     30 Aug 2004 05:20:38 -0000
@@ -1549,18 +1549,22 @@
   This function sets sizes in a topology-specific way then calls
   map_init_topology.
 ***************************************************************************/
-static void generator_init_topology(void)
+static void generator_init_topology(bool autosize)
 {
-  /* Changing or reordering the topo_flag enum will break this code. */
-  const int default_ratios[4][2] =
+  /* The default server behavior is to generate xsize/ysize from the
+   * "size" server option.  Others may want to set xsize/ysize directly. */
+  if (autosize) {
+    /* Changing or reordering the topo_flag enum will break this code. */
+    const int default_ratios[4][2] =
       {AUTO_RATIO_FLAT, AUTO_RATIO_CLASSIC,
        AUTO_RATIO_URANUS, AUTO_RATIO_TORUS};
-  const int id = 0x3 & map.topology_id;
-  
-  assert(TF_WRAPX == 0x1 && TF_WRAPY == 0x2);
+    const int id = 0x3 & map.topology_id;
+
+    assert(TF_WRAPX == 0x1 && TF_WRAPY == 0x2);
 
-  /* Set map.xsize and map.ysize based on map.size. */
-  set_sizes(map.size, default_ratios[id][0], default_ratios[id][1]);
+    /* Set map.xsize and map.ysize based on map.size. */
+    set_sizes(map.size, default_ratios[id][0], default_ratios[id][1]);
+  }
 
   /* Then initialise all topoloicals parameters */
   map_init_topology(TRUE);
@@ -1574,8 +1578,12 @@
        When this function is finished various data is written to "islands",
        indexed by continent numbers, so a simple renumbering would not
        work...
+
+  If "autosize" is specified then mapgen will automatically size the map
+  based on the map.size server parameter and the specified topology.  If
+  not map.xsize and map.ysize will be used.
 **************************************************************************/
-void map_fractal_generate(void)
+void map_fractal_generate(bool autosize)
 {
   /* save the current random state: */
   RANDOM_STATE rstate = get_myrand_state();
@@ -1588,7 +1596,7 @@
   /* don't generate tiles with mapgen==0 as we've loaded them from file */
   /* also, don't delete (the handcrafted!) tiny islands in a scenario */
   if (map.generator != 0) {
-    generator_init_topology();  /* initialize map.xsize and map.ysize, etc */
+    generator_init_topology(autosize);
     map_allocate();
     adjust_terrain_param();
     /* if one mapgenerator fails, it will choose another mapgenerator */
Index: server/mapgen.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/mapgen.h,v
retrieving revision 1.14
diff -u -r1.14 mapgen.h
--- server/mapgen.h     24 Aug 2004 20:27:11 -0000      1.14
+++ server/mapgen.h     30 Aug 2004 05:20:38 -0000
@@ -13,7 +13,7 @@
 #ifndef FC__MAPGEN_H
 #define FC__MAPGEN_H
 
-void map_fractal_generate(void);
+void map_fractal_generate(bool autosize);
 void create_start_positions(void);
 
 #endif  /* FC__MAPGEN_H */
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.184
diff -u -r1.184 srv_main.c
--- server/srv_main.c   29 Aug 2004 19:03:32 -0000      1.184
+++ server/srv_main.c   30 Aug 2004 05:20:39 -0000
@@ -1705,7 +1705,7 @@
   /* if we have a tile map, and map.generator==0, call map_fractal_generate
      anyway, to make the specials and huts */
   if (map_is_empty() || (map.generator == 0 && game.is_new_game)) {
-    map_fractal_generate();
+    map_fractal_generate(TRUE);
   }
 
   /*

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: (PR#9871) autosize parameter for mapgen, Jason Short <=