Files
Bubberstation/code/datums/mapgen
SkyratBot 23095a406a [MIRROR] Adds Biomes to the Cave Generator, for all of your procedurally-placed cave biome needs! (#27996)
* Adds Biomes to the Cave Generator, for all of your procedurally-placed cave biome needs! (#83138)

## About The Pull Request
Implements biomes into the Cave Generator, using some adapted code from
the biomes feature of the Jungle Generator. It's there as a tool for
whomever would want to implement it on /tg/, I simply don't have the
sprites, mobs and motivation to add biomes to anything at this current
point in time, even though I'm fully open to helping anyone that would
be interested in doing so.

Here's how it works:
You supply a 2D list of biomes based on the two arbitrary criteria
'heat' and 'humidity', you can treat these as simply two independent
variables that would affect your biome distribution. There's three
levels of each, `LOW`, `MEDIUM` and `HIGH`, take a look at
`possible_biomes` for a good example of it. Here's what it looks like by
default (yes, that's the default on the jungle generator as well, except
here we use 3x3 instead of 4x4):

![image](https://github.com/tgstation/tgstation/assets/58045821/2c53b46b-f4f9-497f-9647-efc2cc118805)

On the `/datum/biome`, you have three important stats, split into two
each: flora, features and fauna. They are evaluated in this order, so if
a flora spawns, no feature nor fauna will spawn. If a feature spawns, no
fauna will spawn, and if fauna spawns, then that's cool. Each of these
stats have a corresponding `density` (i.e. `flora_density`), which is
simply the probability for that thing to be spawned if it's eligible,
and a `types` list (i.e. `flora_types`), which is a weighted list that
then gets expanded at runtime in order to make the `pick()` operation
faster.

The areas you want to have the biomes in also need to have their
`area_flags` set up to include `FLORA_ALLOWED` for both flora and
features, and `MOB_SPAWN_ALLOWED` for fauna to spawn.

The fauna currently does just about every check that is done in
`cave_generator`'s `populate_terrain()`, except for handling megafauna
differently, or taking megafauna into account. If that's desired, it can
be added easily, I simply chose not to add it because it felt like
wasted processor time over something that would probably not be
pertinent in the majority of cases.

I've run a few tests, and keeping in mind that I've got a high-specs
computer, generating the caves with biomes takes about 1 second for an
entire z-level covered in biomes. For comparison, I compile the repo in
about 36 seconds. ~~It may increase the amount of time spent
initializing the atoms subsystem, however, I'll need to compare that,
I'd really appreciate some help optimizing that if anyone knows how
to.~~ It didn't seem to have an effect, I just had seen things a bit
weird. I optimized things by moving rust-g calls outside of the for
loop, and we gained about 0.3-0.4 seconds, which is pretty nice.

## Why It's Good For The Game
Biomes are cool, and since we use mainly cave generators for z-level
generation, I decided to add biomes to that, so that the biome code
added by floyd lives on.

Here's an example of ice box with jungle caves, just as a proof of
concept, to prove that it works:

![image](https://github.com/tgstation/tgstation/assets/58045821/33b348db-513b-4a2e-b11f-907e80b65177)

## Changelog

🆑 GoldenAlpharex
add: Added Biomes capabilities to the Cave Generator, to allow for
procedurally-placed biomes to be introduced in cave generation. This
feature is not currently used on any map, but the tools are all there
for anyone with the motivation to add biomes to any cave-generating
area, like Lavaland and Ice Box.
code: Biomes can now affect features (which are usually structures), on
top of flora and fauna.
/🆑

* Adds Biomes to the Cave Generator, for all of your procedurally-placed cave biome needs!

---------

Co-authored-by: GoldenAlpharex <58045821+GoldenAlpharex@users.noreply.github.com>
2024-06-06 18:19:22 +05:30
..