[Freeciv-Dev] (PR#8632) Easy way to set map size with auto ratios (setea
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients: ; |
Subject: |
[Freeciv-Dev] (PR#8632) Easy way to set map size with auto ratios (seteables if desired) |
From: |
"Marcelo Burda" <mburda@xxxxxxxxx> |
Date: |
Wed, 5 May 2004 00:33:42 -0700 |
Reply-to: |
rt@xxxxxxxxxxx |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=8632 >
> [mburda - Mer. Mai. 05 00:08:48 2004]:
>
i make some clean ups (comment, style code and help info for user)
ratio keep in geology, but i think we can move it to internal!
i make a text for ratio to explain user to not change it, but you known
my english ;-)
i test the game with this patch + overview tuning patch. nice!!
Marcelo
diff -ruN -Xdiff_ignore freeciv-cvs-Apr-29/client/packhand.c
freeciv-cvs-Apr-29_/client/packhand.c
--- freeciv-cvs-Apr-29/client/packhand.c 2004-04-28 07:11:35.000000000
+0200
+++ freeciv-cvs-Apr-29_/client/packhand.c 2004-05-05 11:20:06.000000000
+0200
@@ -1303,9 +1303,13 @@
****************************************************************************/
void handle_map_info(int xsize, int ysize, int topology_id)
{
+ map.size = 0; /* use server sended sizes */
+ map.ratio = 100;
+ map.topology_id = topology_id;
+ map_init_topology();
+
map.xsize = xsize;
map.ysize = ysize;
- map.topology_id = topology_id;
map_allocate();
init_client_goto();
diff -ruN -Xdiff_ignore freeciv-cvs-Apr-29/common/map.c
freeciv-cvs-Apr-29_/common/map.c
--- freeciv-cvs-Apr-29/common/map.c 2004-04-21 07:11:39.000000000 +0200
+++ freeciv-cvs-Apr-29_/common/map.c 2004-05-05 11:01:09.000000000 +0200
@@ -176,7 +176,9 @@
***************************************************************/
void map_init(void)
{
- map.topology_id = MAP_DEFAULT_TOPO;
+ map.topology_id = MAP_DEFAULT_TOPO;
+ map.size = MAP_DEFAULT_SIZE;
+ map.ratio = MAP_DEFAULT_RATIO;
map.xsize = MAP_DEFAULT_WIDTH;
map.ysize = MAP_DEFAULT_HEIGHT;
map.seed = MAP_DEFAULT_SEED;
@@ -199,6 +201,109 @@
map.have_specials = FALSE;
map.have_rivers_overlay = FALSE;
map.have_huts = FALSE;
+ map_init_topology(); /* correct xsize/ysize values if needed */
+}
+
+/*
+ * This is the core of calculate size of the maps
+ * final value are calculate to get defined ratios size in natural
+ * coordinated
+ * xsize and ysize are even numbers
+ * if iso-map ysize%4 == 0 to avoid any type of problems in
+ * extended topologies and iso-maps
+ */
+static void setmapratio2(double base_size, int Xratio, int Yratio)
+{
+ /* if map.xsize and map.ysize are set from server do nothing*/
+ if (base_size == 0)
+ return;
+ /*
+ * Simplify the prime common divisor in ratios
+ * ratios as 9:9 8:8 7:7 are converted to 1:1
+ */
+ if ((Xratio % 2) == 0 && (Yratio % 2) == 0) {
+ setmapratio2(base_size, Xratio / 2, Yratio / 2);
+ return;
+ }
+ if ((Xratio % 3) == 0 && (Yratio % 3) == 0) {
+ setmapratio2(base_size, Xratio / 3, Yratio / 3);
+ return;
+ }
+ if ((Xratio % 5) == 0 && (Yratio % 5) == 0) {
+ setmapratio2(base_size, Xratio / 5, Yratio / 5);
+ return;
+ }
+ if ((Xratio % 7) == 0 && (Yratio % 7) == 0) {
+ setmapratio2(base_size, Xratio / 7, Yratio / 7);
+ return;
+ }
+ {
+ /* in TF_ISO we need double map.ysize/map.ysize factor */
+ int iso = topo_has_flag(TF_ISO)? 2 : 1;
+ /* get a integer for the size var,this alow to make easy even numbers */
+ int size = floor(0.49 + sqrt(250.0 * base_size / (Xratio * Yratio * iso)));
+ /* verify if map.xsize and map.ysize are ok and correct its*/
+ int size_max = MAP_MAX_LINEAR_SIZE / MAX(Xratio, Yratio * iso) / 2;
+ int size_min = MAP_MIN_LINEAR_SIZE / MIN(Xratio, Yratio * iso) / 2;
+ if (size < size_min) { size = size_min; };
+ if (size > size_max) { size = size_max; };
+ /* sanity check for extreme map.ratio
+ (as 9:1 or 1:9 (1:18 IN ISO!) and extreme map.size as (2 or 20)*/
+ assert(size_min <= size_max);
+
+ /* set map.[xy]size as even numbers (and ysize %4 == 0 for TF_ISO)*/
+ map.xsize = 2 * Xratio * size;
+ map.ysize = iso * 2 * Yratio * size;
+ }
+
+ /* sanity chek for iso map coordinates */
+ if (topo_has_flag(TF_ISO) &&
+ (MAX(map.xsize + map.ysize / 2, map.xsize / 2 + map.ysize) + 1
+ > MAP_MAX_LINEAR_SIZE)) { /* make a more litle map if possible */
+ assert(base_size > 0.1);
+ setmapratio2(base_size - 0.1, Xratio, Yratio);
+ return;
+ }
+}
+/* auto-ratios can't change map.ratio */
+static void auto_ratio(int ratio)
+{
+ assert(ratio >= 11 && ratio < 100);
+ setmapratio2(map.size, ratio / 10,(ratio % 10));
+}
+
+static void user_ratio(void)
+{
+ assert(map.ratio >= 11 && map.ratio <= 100);
+ if (map.ratio != 100)
+ setmapratio2(map.size, map.ratio / 10,
+ (map.ratio % 10));
+}
+
+#define INIT_TOPOLOGIE_CASE(TOPO,DEFAULTRATIO) \
+ case TOPO: \
+ if( map.ratio == 100){ \
+ auto_ratio(DEFAULTRATIO); \
+ } else { user_ratio(); } \
+ break;
+
+/***************************************************************************
+ map_init_topology() need to be called after changes on
+ map.topology_id, map.size and map.ratio was donned.
+ this calculate map.xsize and map.ysize
+
+ in client or when loading savegames map.size can be set to zero to
+ alow code to set direcly xsize and ysize
+ [mburda]
+*************************************************************************/
+void map_init_topology( void)
+{
+ switch (map.topology_id & (TF_WRAPX |TF_WRAPY)) {
+ INIT_TOPOLOGIE_CASE(0, AUTO_RATIO_FLAT);
+ INIT_TOPOLOGIE_CASE((TF_WRAPX |TF_WRAPY), AUTO_RATIO_TORUS);
+ INIT_TOPOLOGIE_CASE(TF_WRAPY, AUTO_RATIO_URANUS);
+ INIT_TOPOLOGIE_CASE(TF_WRAPX, AUTO_RATIO_CLASSIC);
+ };
}
/***************************************************************
@@ -251,6 +356,9 @@
/**************************************************************************
Allocate space for map, and initialise the tiles.
+ Call UPDATE_TOPOLOGY_PARAMETERS to verify and correct befor call it in
+ new games at server.
+ loaded games and client can't change this values
Uses current map.xsize and map.ysize.
**************************************************************************/
void map_allocate(void)
diff -ruN -Xdiff_ignore freeciv-cvs-Apr-29/common/map.h
freeciv-cvs-Apr-29_/common/map.h
--- freeciv-cvs-Apr-29/common/map.h 2004-04-30 07:11:50.000000000 +0200
+++ freeciv-cvs-Apr-29_/common/map.h 2004-05-05 10:50:12.000000000 +0200
@@ -117,6 +117,7 @@
struct civ_map {
int topology_id;
+ int size, ratio; /* used to calculate [xy]size */
int xsize, ysize; /* native dimensions */
int seed;
int riches;
@@ -154,6 +155,8 @@
#define topo_has_flag(flag) ((CURRENT_TOPOLOGY & (flag)) != 0)
+void map_init_topology(void );
+
bool map_is_empty(void);
void map_init(void);
void map_allocate(void);
@@ -589,13 +592,49 @@
#define MAP_MIN_HUTS 0
#define MAP_MAX_HUTS 500
+/* size of the map in thusand of tiles */
+#define MAP_DEFAULT_SIZE 4
+#define MAP_MIN_SIZE 2
+#define MAP_MAX_SIZE 20
+
+/*
+ * This define the max linear size in map or native coordinates
+ * this must be liter than 255, this value is reserved for net usage
+ */
+#define MAP_MAX_LINEAR_SIZE 254
+#define MAP_MIN_LINEAR_SIZE 8
+
+/*
+ * This value determine the x:y ration of the map in NATURAL coordinated
+ * This ratio need to be corrected for NATIVE coordinated in
+ * iso-map by a factor sqrt(2) as (x / sqrt(2)) : (y * sqrt (2))
+ * the spetial values 100 is the AUTO RATIO (this is the prefered value)
+ */
+#define MAP_DEFAULT_RATIO 100
+#define MAP_MIN_RATIO 11
+#define MAP_MAX_RATIO 100
+
+/*
+ * The auto ratios for knowns topologies
+ * best if (but not needed)
+ * get RATIO factor = Xratio*Yratio as litle as posible
+ * this is best for litles map sizes
+ * get DEFAULT RATIO <= 2:1 or 1:2
+ */
+#define AUTO_RATIO_FLAT 11
+#define AUTO_RATIO_CLASSIC 85
+#define AUTO_RATIO_URANUS 74
+#define AUTO_RATIO_TORUS 11
+
+
+/* this default values (WIDTH, HEIGHT) are overwrited by calculated ones*/
#define MAP_DEFAULT_WIDTH 80
-#define MAP_MIN_WIDTH 40
-#define MAP_MAX_WIDTH 200
+#define MAP_MIN_WIDTH MAP_MIN_LINEAR_SIZE
+#define MAP_MAX_WIDTH MAP_MAX_LINEAR_SIZE
#define MAP_DEFAULT_HEIGHT 50
-#define MAP_MIN_HEIGHT 25
-#define MAP_MAX_HEIGHT 100
+#define MAP_MIN_HEIGHT MAP_MIN_LINEAR_SIZE
+#define MAP_MAX_HEIGHT MAP_MAX_LINEAR_SIZE
#define MAP_ORIGINAL_TOPO TF_WRAPX
#define MAP_DEFAULT_TOPO TF_WRAPX
diff -ruN -Xdiff_ignore freeciv-cvs-Apr-29/server/savegame.c
freeciv-cvs-Apr-29_/server/savegame.c
--- freeciv-cvs-Apr-29/server/savegame.c 2004-04-05 21:04:24.000000000
+0200
+++ freeciv-cvs-Apr-29_/server/savegame.c 2004-05-05 11:03:44.000000000
+0200
@@ -323,8 +323,11 @@
***************************************************************/
static void map_tiles_load(struct section_file *file)
{
+ map.size = 0; /* use xize/ysize from load */
+ map.ratio= 100;
map.topology_id = secfile_lookup_int_default(file, MAP_ORIGINAL_TOPO,
"map.topology_id");
+ map_init_topology(); /* this call never change [xy]size */
/* In some cases we read these before, but not always, and
* its safe to read them again:
diff -ruN -Xdiff_ignore freeciv-cvs-Apr-29/server/stdinhand.c
freeciv-cvs-Apr-29_/server/stdinhand.c
--- freeciv-cvs-Apr-29/server/stdinhand.c 2004-04-25 07:11:33.000000000
+0200
+++ freeciv-cvs-Apr-29_/server/stdinhand.c 2004-05-05 11:15:42.000000000
+0200
@@ -253,14 +253,24 @@
/* These should be grouped by sclass */
/* Map size parameters: adjustable if we don't yet have a map */
- GEN_INT("xsize", map.xsize, SSET_MAP_SIZE, SSET_GEOLOGY, SSET_TO_CLIENT,
- N_("Map width in squares"), "", NULL,
- MAP_MIN_WIDTH, MAP_MAX_WIDTH, MAP_DEFAULT_WIDTH)
-
- GEN_INT("ysize", map.ysize, SSET_MAP_SIZE, SSET_GEOLOGY, SSET_TO_CLIENT,
- N_("Map height in squares"), "", NULL,
- MAP_MIN_HEIGHT, MAP_MAX_HEIGHT, MAP_DEFAULT_HEIGHT)
-
+ GEN_INT("size", map.size, SSET_MAP_SIZE, SSET_GEOLOGY, SSET_TO_CLIENT,
+ N_("Map size in 1,000 tiles units"),
+ N_("This value is used to determine xsize and ysize\n"
+ " size = 4 is a litle map of 4,000 tiles (default)\n"
+ " size = 20 is a Huge map of 20,000 tiles"), NULL,
+ MAP_MIN_SIZE,MAP_MAX_SIZE , MAP_DEFAULT_SIZE)
+
+ GEN_INT("ratio", map.ratio, SSET_MAP_SIZE, SSET_GEOLOGY, SSET_TO_CLIENT,
+ N_("Map ratio, keep it default value of 100 (auto)\n"),
+ N_("This value is used to determine xsize and ysize \n"
+ " 100 is the default ratio determined by the topology_id\n"
+ "Otherwise first digit is the x factor \n"
+ "and second digit the y factor of the x:y ratio \n"
+ " 11 is 1:1 ratio, 23 is a 2:3 ratio. \n"
+ "Extreme ratio (more than 3:1 or 1:3) are bad idea \n"
+ "Change it at your own risk!"
+ ), NULL,
+ MAP_MIN_RATIO, MAP_MAX_RATIO , MAP_DEFAULT_RATIO)
GEN_INT("topology", map.topology_id, SSET_MAP_SIZE, SSET_GEOLOGY,
SSET_TO_CLIENT,
N_("The map topology index"),
@@ -3569,6 +3579,7 @@
}
if (!check && do_update) {
+ map_init_topology(); /* update map.[xy]size from last changes */
/*
* send any modified game parameters to the clients -- if sent
* before RUN_GAME_STATE, triggers a popdown_races_dialog() call
- [Freeciv-Dev] Re: (PR#8632) Easy way to set map size with auto ratios (seteables if desired), Jason Short, 2004/05/02
- [Freeciv-Dev] (PR#8632) Easy way to set map size with auto ratios (seteables if desired), Marcelo Burda, 2004/05/04
- [Freeciv-Dev] Re: (PR#8632) Easy way to set map size with auto ratios (seteables if desired), Jason Short, 2004/05/04
- [Freeciv-Dev] Re: (PR#8632) Easy way to set map size with auto ratios (seteables if desired), Marcelo Burda, 2004/05/05
- [Freeciv-Dev] (PR#8632) Easy way to set map size with auto ratios (seteables if desired),
Marcelo Burda <=
- [Freeciv-Dev] Re: (PR#8632) Easy way to set map size with auto ratios (seteables if desired), Jason Short, 2004/05/05
- [Freeciv-Dev] Re: (PR#8632) Easy way to set map size with auto ratios (seteables if desired), Marcelo Burda, 2004/05/05
- [Freeciv-Dev] Re: (PR#8632) Easy way to set map size with auto ratios (seteables if desired), Marcelo Burda, 2004/05/05
- [Freeciv-Dev] Re: (PR#8632) Easy way to set map size with auto ratios (seteables if desired), Jason Short, 2004/05/05
- [Freeciv-Dev] Re: (PR#8632) Easy way to set map size with auto ratios (seteables if desired), Marcelo Burda, 2004/05/05
- [Freeciv-Dev] Re: (PR#8632) Easy way to set map size with auto ratios (seteables if desired), Jason Short, 2004/05/05
- [Freeciv-Dev] Re: (PR#8632) Easy way to set map size with auto ratios (seteables if desired), Marcelo Burda, 2004/05/05
- [Freeciv-Dev] Re: (PR#8632) Easy way to set map size with auto ratios (seteables if desired), Jason Short, 2004/05/05
- [Freeciv-Dev] Re: (PR#8632) Easy way to set map size with auto ratios (seteables if desired), Marcelo Burda, 2004/05/05
- [Freeciv-Dev] (PR#8632) Easy way to set map size with auto ratios (seteables if desired), Marcelo Burda, 2004/05/05
|
|