[Freeciv-Dev] Re: (PR#6285) rand_map_pos using native coordinates
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Jason Short wrote:
> This simple patch rewrites rand_map_pos to use native coordinates. This
> allows it to work with iso-maps.
> + native_to_map_pos(x, y, myrand(map.xsize), myrand(map.ysize));
Except, with a macro form of native_to_map_pos, that will not work. At
all. This new patch is better.
FYI, in gen-topologies (which is pretty well tested) the function looks like
+ int nat_x, nat_y;
+
+ nat_x = myrand(map.xsize);
+ nat_y = myrand(map.ysize);
+ native_to_map_pos(x, y, nat_x, nat_y);
+ assert(is_normal_map_pos(*x, *y));
which is close to the attached version. Just a matter of taste, I suppose.
jason
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.145
diff -u -r1.145 map.c
--- common/map.c 2003/09/25 20:55:01 1.145
+++ common/map.c 2003/09/25 21:10:09
@@ -1489,10 +1489,11 @@
**************************************************************************/
void rand_map_pos(int *x, int *y)
{
- do {
- *x = myrand(map.xsize);
- *y = myrand(map.ysize);
- } while (!is_normal_map_pos(*x, *y));
+ int nat_x = myrand(map.xsize), nat_y = myrand(map.ysize);
+
+ /* Don't pass non-deterministic expressions to native_to_map_pos! */
+ native_to_map_pos(x, y, nat_x, nat_y);
+ CHECK_MAP_POS(*x, *y);
}
/**************************************************************************
|
|