1
\$\begingroup\$

So, I have a procedurally generated planet. In my case it's 3D (hexagon/pentagon globe) but for simplicity let's assume it is a 2D grid.

I have distributed resources over this planet, using Simplex Noise, with a cut-off value, giving me a binary distribution.

One of the things I generate in this way, are fields of wheat, shown in yellow below.

wheat and farm distributions

After the wheat-fields are generated, I want to procedurally place farms on the planet.

If I would just randomly pick a "yellow tile" (tile with wheat on it) then I run the danger of having them poorly distributed, as shown on the left.

What I want, is a nice distribution where farms favour large wheat areas that are still unoccupied by other farms, as shown on the right.

Is there a simple algorithm that can do this placement?

NOTE: I want to use this approach for other buildings like mines, quarries, lumberjack operations, etc. So I want to avoid placing first, and then growing resources around it. I want the noise field to drive the placement, not the other way around.

NOTE: Farms will not consume the wheat. I've made wheat fields binary wheat/no-wheat but also have scaled distributions with "potency" for e.g. forests, where the number of trees per tile can vary.

\$\endgroup\$
6
  • 5
    \$\begingroup\$ First of all, I just want to say I love the aesthetic in that screenshot. Awesome work. \$\endgroup\$
    – Peethor
    May 30 '19 at 17:19
  • 1
    \$\begingroup\$ Apart from that, there are multiple possibilities. I don't think I have a well founded answer (that's why this is a comment) but what have you tried? Logically, I would say a farm requires x wheat fields. If the patch of connected fields contains y fields, you can place y / x = z farms on the patch. Or you could just keep placing farms on patches, and subtract the closest x fields from that patch. Then check if the patch is still big enough, or perhaps broken up by the older farm. \$\endgroup\$
    – Peethor
    May 30 '19 at 17:26
  • \$\begingroup\$ Come to think of it, I think wheat is planted around farms, not the other way around. Plant farms first (perhaps distribute them evenly over fertile land) and place x wheat fields around it. That could be easier. \$\endgroup\$
    – Peethor
    May 30 '19 at 17:27
  • \$\begingroup\$ How does the farm affect the field? Does it "consume" a field, does it have a range? Are all the fields created equal, or a field that has other fields around it is "more potent"? \$\endgroup\$
    – Vaillancourt
    May 30 '19 at 17:40
  • \$\begingroup\$ Do farms have a range? \$\endgroup\$
    – Vaillancourt
    May 30 '19 at 18:09
0
\$\begingroup\$

Thanks to the insight from @Peethor about computing the number of grain tiles per farm, I managed to solve it with a simple yet very effective approach:

Let G be the number of grain-tiles.

Let F be the number of farms.

  1. Compute the number of Grain tiles per Farm: G / F
  2. Find all contiguous regions of grain R₀, R₁, ... Rₙ
  3. foreach farm:
    • Find largest grain region Rᵢ.
    • Place farm on region Rᵢ.
    • Adjust the size of region Rᵢ by subtracting ( G / F )
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .