Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2001:
[Freeciv-Dev] Re: example patch: [xy]_map_iterate
Home

[Freeciv-Dev] Re: example patch: [xy]_map_iterate

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: example patch: [xy]_map_iterate
From: Jason Dorje Short <vze2zq63@xxxxxxxxxxx>
Date: Thu, 04 Oct 2001 07:58:22 -0400
Reply-to: jdorje@xxxxxxxxxxxx

Raimar Falke wrote:
> 
> On Thu, Oct 04, 2001 at 07:00:01AM -0400, Jason Dorje Short wrote:
> > Raimar Falke wrote:
> > >
> > > On Thu, Oct 04, 2001 at 05:57:09AM -0400, Jason Dorje Short wrote:
> > > > There's a lot of code that can't use whole_map_iterate because the
> > > > iteration has to happen in a certain order.
> > >
> > > What code? I don't have a good feeling with code that has such
> > > dependencies. Printing the map?
> >
> > Printing the map (to some random text file, I presume) is part of it.
> > Also saving the game and sending tiles across the network.  These depend
> > strictly upon the ordering, so are easy to fix using [xy]_map_iterate.
> 
> So what code would be used (after preprocessor expansion) instead of
> 
>   for(y=0; y<map.ysize; y++) {
>     char *terline=secfile_lookup_str(file, "map.l%03d", y);
> 
>     for(x=0; x<map.xsize; x++) {
>       char ch=terline[x];
> 
> with an isometric map? Will there be map.xsize and map.ysize in an
> isometric map?

There may be map.xsize and map.ysize; this depends on the
implementation.  You could also do a single array using map_pos_to_index
and the inverse.  In any case though there will be some single value
that represents the maximum X and Y width; call them map_[xy]_size().

  for(y=0; y<map_y_size(); y++) {
    char *terline=...

    for(y=0; y<map_x_size(); x++) {
      char ch=terline[x];
      if(!is_normal_map_pos(x, y)) continue;
      ...

But, some special handling may be necessary in the case of off-the-map
coordinate positions.  Everything will have to be fixed up case-by-case.

> > Other examples don't iterate over the whole map...for instance some
> > iterate over just the poles while others skip border positions.  These
> > can be done with whole_map_iterate by skipping invalid positions; the
> > problem here is that the current definition of "valid" is
> > topology-dependent (it assumes the current wrapping system).  These will
> > take a little time to figure out.
> 
> For the poles I can imagine a rectangle_iterare.

No...the problem is "polar" may vary from topology to topology.  In an
isometric map polar regions will run diagonally along two sides, so a
rectangular iteration will not work.  In the more general case, it may
be desirable to have polar regions defined by the ruleset or server
options - in a taurus topology, what regions are polar?  Or, perhaps the
ruleset should just define "north" and "south" and let the game figure
it out (this would fail for a topology that was not well-oriented).

static void make_fair(void)
{
  whole_map_iterate(x, y) {
    if (!IS_POLAR(x, y)) {
      ...
    }
  } whole_map_iterate_end;

Add to this complication: in make_fair() I'm not sure if the correct
restriction is IS_POLAR (which is true of the northernmost and
southernmost 2 tiles) or IS_NEAR_BORDER (also true of the northernmost
and southernmost 2 tiles).  Ross's patch has a cleverly incomprehensible
algorithm for this that wouldn't work under isometric topologies - I
can't tell from it one way or the other.

jason


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