Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2004:
[Freeciv-Dev] (PR#7350) Map radius change with city size
Home

[Freeciv-Dev] (PR#7350) Map radius change with city size

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: remi.bonnet@xxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#7350) Map radius change with city size
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 31 Mar 2004 13:41:47 -0800
Reply-to: rt@xxxxxxxxxxx

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

I think the generation of the indices is more complicated than it needs
to be.

I think this implementation should work:

  int dist, count = 0;

  for (dist = 0; dist <= CITY_MAP_RADIUS * CITY_MAP_RADIUS + 2; dist++) {
    for (x = 0; x < CITY_MAP_SIZE; x++) {
      for (y = 0; y < CITY_MAP_SIZE; y++) {
        int dx = (x - CITY_MAP_RADIUS);
        int dy = (y - CITY_MAP_RADIUS);

        if (dx * dx + dy * dy == dist) {
          indices[count].x = x;
          indices[count].y = y;
          count++;
        }
      }
    }
  }

This is O(R^4), where R = CITY_MAP_RADIUS (or max city radius).  This is
quite acceptable as a one-time cost.

jason



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