Free and Open Source real time strategy game with a new take on micro-management

Resource Algorithm

From Globulation2

Jump to: navigation, search

Every tick, the function Map::growRessources() is called, which iterates over the board growing resources. The algorithm is:

Along the X axis of the map, examine every 4th row, starting at a random row between 0 and 3. For each examined row, start at a random square between 0 and 15, then move right by a random number between 0 and 31 squares until you reach the end of the row.

If there is no resource there, do nothing.

Else, look at a square rand(15) - rand(15) squares to the right, and rand(15) - rand(15) down. In other words, binomially distributed around the current square. We'll refer to that as point 1. Also, look at the square twice as far away in the same direction (point 2). Also, look at the square the same distance in the other direction (point -1).

  • If there is alga on the current tile, do nothing unless there is water at point 1 and sand at point 2.
  • If there is wood or wheat on the current tile, do nothing unless there is water at point 1 and NOT sand at point -1.
  • Else, carry on no matter what

If the current size of the resource is less than or equal to rand(7), the resource grows by one square. Else, if the resource is capable of extending, it attempts to extend into a random square next to the current one (and does nothing if it fails)