Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2000:
[Freeciv-Dev] Re: Very small patch to start the coordinate generalizatio
Home

[Freeciv-Dev] Re: Very small patch to start the coordinate generalizatio

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Erik Sigra <freeciv@xxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: Very small patch to start the coordinate generalization
From: Thue <thue@xxxxxxx>
Date: Mon, 25 Sep 2000 00:12:37 +0200
Reply-to: thue@xxxxxxx

On Fri, 22 Sep 2000 10:45:35 Erik Sigra wrote:
> Hi,
> This 955 byte patch starts the proces of coordinate generalization. It
> should be completely harmless, not changing anything visible. Since it
> is so small, it should be easy to audit. It is an important step to
> build further on.

OK; what you change is actually very little; instead of declairing a map
position as
int x, y
you call it
struct position {x, y}

While the struct concept is nice, it is not really that important that I want
to recode half of freeciv for it. I would personally find it acceptable, 
however,
for new code to use it (as it really isn't that different, it shouldn't cause
compatability problems). Note that the admins' position should also be heard.
The very first thing to do if you really want to use it is to get the support
functions right; ie macros and functions like is_real_tile() and
normalize_map_pos(). Specifically you shouldn't manually iterate over the whole 
map, but use
whole_map_iterate in the attached patch... For the same reason a generalized map
sized struct like the one for height_map should be hidden beneth an access 
layer.
(both these are needed for my numbering scheme for isometric view, if we ever
want to implement it)
Also the definition of north could also change with numbering, and should be
isolated in a seperate function. (you used it in the attached patch)

> diff -U2 -rNXd a/common/coordinates.h 1/common/coordinates.h
> --- a/common/coordinates.h    Thu Jan  1 01:00:00 1970
> +++ 1/common/coordinates.h    Fri Sep 22 09:33:20 2000
> @@ -0,0 +1 @@
> +struct locus {int x, y;};
> diff -U2 -rNXd a/server/mapgen.c 1/server/mapgen.c
> --- a/server/mapgen.c Fri Sep 22 10:05:12 2000
> +++ 1/server/mapgen.c Fri Sep 22 10:20:19 2000
> @@ -21,4 +21,5 @@
>  #include <time.h>
>  
> +#include "coordinates.h"
>  #include "fcintl.h"
>  #include "game.h"
> @@ -56,4 +57,12 @@
>  #define MAP_NCONT 255
>  
> +/*********************************************************************
> + Just a wrapper function off the height_map, returns the height at
> + position. Should eventually replace full_map.
> +*********************************************************************/
> +static int get_height(struct locus position) {
> +  return height_map[position.y * map.xsize + position.x];
> +}
> +
>  /**************************************************************************
>   Just a wrapper function off the height_map, returns the height at x,y
> @@ -106,24 +115,27 @@
>  static void make_polar(void)
>  {
> -  int y,x;
> +  struct locus position;
>  
> -  for (y=0;y<map.ysize/10;y++) {
> -    for (x=0;x<map.xsize;x++) {
> -      if ((full_map(x, y)+(map.ysize/10-y*25)>myrand(maxval) &&
map_get_terrain(x,y)==T_GRASSLAND) || y==0) { 
> -     if (y<2)
> -       map_set_terrain(x, y, T_ARCTIC);
> -     else
> -       map_set_terrain(x, y, T_TUNDRA);
> -       
> +  for (position.y = 0; position.y < map.ysize / 10; position.y++) {
> +    for (position.x = 0; position.x < map.xsize; position.x++) {
> +      if ((get_height(position) + (map.ysize / 10 - position.y * 25) >
> +        myrand(maxval) && map_get_terrain(position.x, position.y)
> +        == T_GRASSLAND) || position.y == 0) { 
> +     if (position.y < 2)
> +       map_set_terrain(position.x, position.y, T_ARCTIC);
> +     else map_set_terrain(position.x, position.y, T_TUNDRA);
>        } 
>      }
>    }
> -  for (y=map.ysize*9/10;y<map.ysize;y++) {
> -    for (x=0;x<map.xsize;x++) {
> -      if ((full_map(x, y)+(map.ysize/10-(map.ysize-y)*25)>myrand(maxval) &&
map_get_terrain(x, y)==T_GRASSLAND) || y==map.ysize-1) {
> -     if (y>map.ysize-3)
> -       map_set_terrain(x, y, T_ARCTIC);
> -     else
> -       map_set_terrain(x, y, T_TUNDRA);
> +  for (position.y = map.ysize * 9 / 10; position.y < map.ysize;
> +       position.y++) {
> +    for (position.x = 0; position.x < map.xsize; position.x++) {
> +      if ((get_height(position) +
> +        (map.ysize / 10 - (map.ysize - position.y) * 25) >
> +        myrand(maxval) && map_get_terrain(position.x, position.y)
> +        == T_GRASSLAND) || position.y == map.ysize - 1) {
> +     if (position.y > map.ysize - 3)
> +       map_set_terrain(position.x, position.y, T_ARCTIC);
> +     else map_set_terrain(position.x, position.y, T_TUNDRA);
>        }
>      }
> 

-Thue



[Prev in Thread] Current Thread [Next in Thread]