Friday, October 30, 2015

c# - A simple map, four biomes, and how to distribute them


Here's the basic idea: I've got a Rogue-ish, perhaps Dwarf Fortress-ish game, with a randomly generated overworld and several dungeon entrances scattered around it. I already have the dungeons basically covered, but I'm stuck on an aspect of the overworld.


Said overworld, considered as a 2D map of screens, should have a perhaps blob-like distribution of four different themes or biomes -- grasslands, desert, snow and swamp, each with their own total amount of screens. Let's say the map is 8x8, which gives 64 unique screens. Half of those could be grasslands, a quarter desert, and swamp and snow get a quarter each:


mockup of a possible world map with towns and starting location, but no dungeon entrances


It seems palette reduction has made snow the same color as swamp. Originally, there were eight snow screens in the bottom corner, and a slightly staggered eight-screen swamp area in the middle. Sorry 'bout that, and please ignore the location markers.


The best I could get was some snaking shapes, and often enough with nonsensical combinations like desert snaking through snow (or vice versa). I can't for the life of me figure out how to get it nice and blobby, let alone having it make climatical (?) sense. So how do I generate a biome map like in the mockup?


Okay, by request: the world really isn't much bigger than that example, and what I need is just a way to spread some blobs that determine thematic appearances, with the extra limitation that snow can't touch desert. Screens don't scroll, and if a screen is set to "desert", there'll be no grass anywhere on it.




Answer



There are many ways to skin this cat, however one of the more interesting is using cellular automata. Begin with your empty grid and add a few seed starting cells in random locations. These should be of some basic non-mixed types of biomes. Say: Grass, Desert, Snow, Ocean.


Based on growth rules of your own design, which could feature some randomness (I don't care that it technically breaks the idea of CA, do you?) have them grown each step into the map. Additional rules can be such that if you are ocean and are next to grass or swamp, you might turn into swamp. If you are next to snow, you may become ice, if you are near desert, you may dry up and become desert too.


The same might be true for other mixes, and in theory even sub-mixes like frozen swamp, or tundra, or jungle sprouting from large expanses of forests that grew from large expanses of grassland.


The possibilities are endless, and can also be continual. As these rules are all simple, you can implement environments that shift over time. Combined with height information, and rules that take it into account, you can grow lakes and rivers, block the growth of forests over mountains and other fancy things.


That height map can be the result of perlin noise, or diamond square, or even whole other CA models. In fact, you could modify that map as time goes on as well by modelling plate tectonics, pushing up mountains, sinking in trenches, and even let rivers lower the landscape creating canyons.


This rabbit hole extends forever.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...