Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Technical investigation: How does plant selection work on embarks?  (Read 854 times)

PatrikLundell

  • Bay Watcher
    • View Profile

I've been trying to find out how plant selection for an embark works, and believe I've found parts of it, but there are pieces missing.

What I think I know:
1. World tiles refer to biome regions that list plants (and animals) available in that region.
2. World tiles control areas of the embark in terms of biome, etc., and an embark can contain multiple biomes, each controlled by a world region that's either the one of the embark or one of the 8 surrounding ones.
3. At embark, a 7*7 world region grid centered on the embark's world tile is drawn from to populate the df.global.world.populations list. This list contains entries from the surface as well as each underground level, organized per world tile. I don't know how complete this list is, i.e. whether it contains everything in the biome regions, only things legal to the world tile, or possibly contains an RNG selection of entries.
4. For the surface, only plants/animals legal to an actual biome show up, i.e. temperate/tropical/good/evil/savage restrictions are upheld for the embark, even when the region biome contains things that are not legal (since a region biome can span multiple biomes of the same broad type. In addition to that, it's possible to add inappropriate things through hacking).
5. The underground biomes do not seem to perform a legality check: hacking water dependent plants into Underground Chasm regions prior to embark cause those to show up on embark, so it seems DF relies on the population of the underground regions perform the check. Hacking surface plants into underground biomes prior to embark has resulted in surface plants being present in the caverns at embark. I don't know if new surface plants would sprout there after embark, but suspect the light check would prevent it.
6. For some reason, grasses seem to have been given a special treatment. The df.global.world.unk_59dc4 structure seems to contain "grasses" organized into world tiles and levels, with each level containing a list of "grasses". Adding a grass here causes the grass to start appearing on the embark, even if not legal (eyeball on a good embark, for instance). Hacking the df.global.world.populations structure has not given any effect at all regarding grasses: it seems unk_59dc4 has taken over completely.
7. Underground Chasm regions do not follow the normal pattern of providing "grasses" to unk_59dc4 from their population list (which does not contain any "grasses" [or other plants except possibly blood thorn] at all). Despite that unk_59dc4 gets both cavern moss and floor fungi for these regions, and removing the mud and pre existing ground cover with magma shows the grasses do regrow. Removing "grasses" from Underground Water regions (the normal caverns, i.e. not mud covered) prior to embark causes those caverns to be covered by generic grass, although I haven't verified that the corresponding unk_59dc4 list is empty.
8. Hacking df.global.world.populations to replace the plant reference in an entry to refer to a different plant of the same (Bush/Tree) type causes the embark to start providing the new type instead of the old one, even if the reference to the biome region's population still refers to an entry for the original type. I speculate that this back link is only used for animals for which there is a need to keep track of their numbers.
9. Hacking df.global.world.populations to insert new non grass plant entries seems to have no effect, even if properly linked up to hacked new entries in the region biome's population, even when the new entry has been inserted in between existing ones.
10. River creature populations are available in the feature_map's river feature entries on an embark tile level. Where that population is drawn from is currently unknown (educated guesses can be made, but I've made no investigations).

Things I know I don't know:
1. How does DF select which bush/tree to place when it's time to generate one? Presumably an RNG number is used to select from some kind of list, but where is that list located, and can it be manipulated? 8 & 9 above leads me to guess there is a list of pointers to the actual entries in the df.global.populations list (rather than a list of indices for the entries) somewhere.
2. Is the bush/tree "list" DF uses complete, i.e. does it contain every legal entry from the region biome's population list, or is there a further RNG based selection (on top of the one that led to the generation of the region biome population list contents)? Put a different way: does presence in the region biome's population list guarantee that you have a chance to get that plant on your embark (assuming it fulfills the local legality criteria regarding actual biome, etc.)? Experience indicates you may miss out on some, but it may just be bad luck.

So, do others have additional insights or knowledge proving/indicating things above are incorrect?

Edit: Added point 10 above.
« Last Edit: July 06, 2017, 07:32:05 am by PatrikLundell »
Logged

FantasticDorf

  • Bay Watcher
    • View Profile
Re: Technical investigation: How does plant selection work on embarks?
« Reply #1 on: July 04, 2017, 06:44:35 am »

Forgive me for such a simplistic speculation, but if you travel to said area for a embark as a adventurer the terrain is the same, so its literally all handled in worldgen rather than generated afterwards it would seem for plants that are prefixed there, the only new instances would be to determine which new biome specific saplings and harvestables/flowers grow. Animals also come in via the edges of the embark which can be broadly confirmed by captive breeding yeti's and releasing them into the wild to affect local populations.

That grasses thing is interesting but its probably for handling the spread of fungus grass into the dirt layer by creating new instances, also the cavern acts as one enormous region that simultaneously caters to the normal underground 1st layer & its water biome so your observation about hacky water plants is pretty valid.

Im still trying to process that wall of text, but reading between the lines you're trying to find out how those saplings/bushes & grasses are spontaneously (rather than induced) placed, correct?
« Last Edit: July 04, 2017, 06:47:51 am by FantasticDorf »
Logged

PatrikLundell

  • Bay Watcher
    • View Profile
Re: Technical investigation: How does plant selection work on embarks?
« Reply #2 on: July 04, 2017, 08:02:34 am »

The terrain is actually not generated during worldgen: DF generates the region as the world map is loaded (or possibly one of the adjacent ones, since DF contains a block of 3*3 world tiles generated to region level at a time. This is presumably based on seeds which have not yet been located. Hacking the region prior to embark affects the embark, but hacking a region and then changing the focus and return will have wiped out your hacks. If you return to a hacked region where you've set up a fortress the region itself is returned to the seed based shape, but the embark is locked to what was generated at embark. The generation of the embark/local adventure mode terrain is again based on seeds (which have been mapped) together with things that are generated at world gen (Toady fixed a bug in this generation a while back. The bug caused adventure mode entry into an area to have the area look different depending on which direction the area was entered from because RNGs weren't separated properly). However, many of these things can be hacked in between world gen and embark. Evilness and savagery can be hacked, plant and creature selection for the region biomes can be hacked, the geo biome can be hacked, the region elevation, biome selection, and rivers can be hacked (the region stuff is temporary, as mentioned), etc. The hacks mentioned above affect the embark if performed pre embark.

I don't know how fungal spread works, as I haven't investigated it. The caverns are actually split up into multiple underground biomes per level, but the boundaries do not coincide with the surface biome ones. I don't know if underground biomes are "boxy", i.e. fully fill a region, or if they have boundaries inside the embark like the surface does. I've had some embark where parts of a cavern was muddy and the rest not, but that didn't come with a visible biome split in plants.

I'm not actually trying to find out where individual plants are placed, but rather how the selection of species is done and how to influence that, i.e. how to make sure the stuff you want to get enters into the selection lottery. I'm not actually interested in the grasses as their species does not make any functional difference to anything (although I don't like the movement of wormy tendrils, and bubble bulbs have sort of a nice color). The investigation there is what I happened upon as I used grasses for my experiments because they have the fastest placement rates, and then I found they weren't useful as models for the stuff I'm actually interested in.
You could say this is an offshoot of the Booze Quest challenge (get every kind of booze known to dwarf in your fortress).
Logged

Fleeting Frames

  • Bay Watcher
  • Spooky cart at distance
    • View Profile
Re: Technical investigation: How does plant selection work on embarks?
« Reply #3 on: July 04, 2017, 03:52:00 pm »

Quite a post.

Third known explains how I have kea in region-pops despite them not having a biome to their name.

Fifth and eight knowns seems to have potential in getting some plants to show up, if they wouldn't show otherwise.
(potentially barring weird cases of subterranean/Inside/Light in reclaimed worldgen forts).

Second unknown...Well, you probs already know this, but did a quick check in all booze biomes embark with biodiversity-populated plants and got 97,33% region-pops coverage - the two plants missing being two-grain wheat and sweet potato.

(also corrected several bugs in worksheet - whoops).

Interesting and unexpected; those two aren't exactly special, the first being found in tropical grasslands and savannas and the other in any tropical. .

PatrikLundell

  • Bay Watcher
    • View Profile
Re: Technical investigation: How does plant selection work on embarks?
« Reply #4 on: July 04, 2017, 05:17:50 pm »

Yup. Region-pops doesn't do any filtering to what's possible (which is also why you can have ocean creatures in that report despite not being adjacent to any ocean).

In my Booze Quest embark I did get everything except bananas (bought those from the elven caravan). Both your reports and my experience indicates there might be something beyond bad luck at play.
Logged

Fleeting Frames

  • Bay Watcher
  • Spooky cart at distance
    • View Profile
Re: Technical investigation: How does plant selection work on embarks?
« Reply #5 on: July 04, 2017, 11:11:56 pm »

Correction again: Those two plants are actually in region pops (100% coverage with biodiversity). I just forgot to use underscores in searching >_>

Though yeah, the lack of shrubs for things that should be present is definitely odd.

Sanctume

  • Bay Watcher
    • View Profile
Re: Technical investigation: How does plant selection work on embarks?
« Reply #6 on: July 05, 2017, 02:03:02 pm »

Plants do not show in "prospect all" prior to embark, and shows the details after the embark. 

Perhaps the code in prospect has provide clue .

PatrikLundell

  • Bay Watcher
    • View Profile
Re: Technical investigation: How does plant selection work on embarks?
« Reply #7 on: July 05, 2017, 03:06:31 pm »

@Sanctume: prospect checks what's on the tiles of the embark at the time the command is executed, so it's good for getting to know what's actually there at the moment, but it doesn't hold much of a predictive value (pave the complete embark and nothing will show on the list, but rip up the roads and stuff will start to grow).

Another minor tangential piece of info: The feature_map structure contains "river" features on a per region embark tile basis that in turn contain population lists of river creatures. I don't know where these lists get their populations from, but one might speculate that they draw from the region tile's biome and region. The feature_map seems to be only partially populated (with seg faults trying to read parts that ought to exist, at times) and seems to be populated only when regions are in focus. However, hacking a changed river course (rivers are also"features") kept the new entry even after I've changed focus to the other side of the world. As a tangent to the tangent, it can be mentioned that hacking a candy spire right before embark can cause it to reach the first cavern, but trying to get it to reach the surface removed it altogether.
« Last Edit: July 06, 2017, 07:28:55 am by PatrikLundell »
Logged