World Generator - RyanBabij/WorldSim GitHub Wiki
Before playing, you must generate a world. The world generator primarily deals with creating landmasses, biomes, and also spawning starting tribes. There are currently several options to customise the world you create:
World Size
Currently world size is restricted to powers of 2 (+ 1) in order to work nicely with the fractal algorithms. I could modify it to work with non-powers of 2, but that is not a priority. A single tile represents about 25km^2, that is, a square of 5kmx5km.
Using this scale, here's a quick reference for comparison:
- 129 - Germany
- 257 - Mongolia
- 513 - Australia
- 1025 - Europe + North Africa
- 2049 - 20% of earth's surface area.
- 4097 - 80% of earth's surface area.
I doubt most games will benefit from going beyond 1025. Even though it would technically be possible to simulate at 1:1, it would probably make the game boring. Therefore some scaling will likely be used to move points of interest closer together.
Fragmentation
Increases the likelihood of the land being broken up into more islands and continents. Generally a value of 0 is good for normal gameplay.
Island Mode
Ensures that all border tiles of the map will be ocean. Can be useful if you don't want to deal with wrapping in your game.
Wrap-X
The world will match up along the left and right edge of the map.
Wrap-Y
The world will match up along the top and bottom edge of the map. This is probably not a useful feature if you are assuming your world is on a sphere, because Y-wrapping does not work as simply as X-wrapping. Normally you should just have impassable terrain on the top and bottom of the map to eliminate the need to deal with this issue.
Land Percent
The percentage of the map that is land. For Earth this value would be 29%. For games it's probably worthwhile setting it higher for more interesting gameplay. Oh and it might be backwards, I can't remember.
Civs
Civs are tribes that have evolved to become sedentary. They have villages, cities, armies, etc.1
Tribes
Tribes are nomadic groups of people. They wander the map as units until certain circumstances cause them to become sedentary civilisations. This parameter will be changed to "Human Tribes". Humans will be good at technology.
Dwarven Tribes
The game will have 3 races. The Dwarves will mostly live in mountains and will be experts at metalworking and mining.
Human Tribes
Humans live in Towns and Cities. They are good at warfare and agriculture.
Elven Tribes
The Elves will generally not be sedentary, and will generally live in forest and jungle biomes. They will be good at magic and being aesthetic.
Generate
Generate a new world with the given parameters.
Simulate World
Progresses to to simulation phase of the game.
Export World Data (todo)
Save the world data to a file.
Load World (todo)
Will load a world file for you to use.
Planned additional features
Map editing
Ability to paint terrain to create your own maps.
Biomes
Better control over biome generation.
Presentation
It's all programmer art right now. In the future I would like to tighten up the graphics but first I will work on the game mechanics.
Local Maps
Ability to zoom into global tiles to see the local maps. You can do that now by right-clicking on a tile but it is very lame and boring.
Other issues
Realism (tectonics, weather, ocean currents, etc)
No u.
3D
Technically it is possible to create a 3D interface over the game, but I won't be doing this because I don't have time/skills for 3D modelling, animations, etc. The only thing I would be interested in is a 3D projection of the map onto a sphere, because this would resolve wrapping issues. But it would be very difficult to implement.
Algorithm
The core algorithm is diamond-square. This is a variant of midpoint displacement which reduces some (but not all) artifacts. Diamond-square is not perfect, but I am quite happy with how it looks, so I'm planning to stick with it.
To generate landmasses, a diamond-square fractal is created. A table of height values is created, then "sea-level" is calculated based on how much land the player wants on the map. This alone does not create a particularly nice map, as the edges of coastlines are much too rough. Therefore a smoothing/erosion algorithm is applied. This is not only done for landmasses, but also some biomes. Each overlay may have its own configuration of smoothing, variance, free steps, and percentage of the map. I'm also working on latitude biases (you can see that the jungles are near the equator, and snow is near the poles), and ability for two biomes to be "opposites", meaning one extreme of a fractal will be one biome, and the other extreme will be another biome (mostly just used for "good/evil" biome creation). I have done some basic work on tectonics but I don't think I'll be implementing it.
Note that biomes are currently overlaid in an order depending on when their thread terminates. This will be fixed later.
Note that we don't use diamond-square to generate an actual heightmap. We use it only to create a definition of land/sea. Using the algorithm to generate both landmass and heightmap would be unrealistic, because landmasses don't necessarily slope upward based on how far inland they are. If you want a heightmap you should overlay a second diamond-square map in the same way that biomes are generated. This is another important aspect of writing a map generator: Overlay multiple fractals instead of just using a single one for everything.
The good thing about fractals is that you can use them to generate things on a large scale, such as landmasses, and also things on a small scale, like forests, caves, dungeons, etc. And of course the size of the fractal is limited only by memory size and CPU speed. For example, here's a 33x33 and 2049x2049 version of the previous map:
Heightmaps
Currently I'm not using actual heightmaps. Instead I am defining certain tiles as either "hilly" or "mountainous". This system is much easier for both the human and AI to understand.