Putting the 'role' back in role-playing games since 2002.
Donate to Codex
Good Old Games
  • Welcome to rpgcodex.net, a site dedicated to discussing computer based role-playing games in a free and open fashion. We're less strict than other forums, but please refer to the rules.

    "This message is awaiting moderator approval": All new users must pass through our moderation queue before they will be able to post normally. Until your account has "passed" your posts will only be visible to yourself (and moderators) until they are approved. Give us a week to get around to approving / deleting / ignoring your mundane opinion on crap before hassling us about it. Once you have passed the moderation period (think of it as a test), you will be able to post normally, just like all the other retards.

World generator for 4x games

baturinsky

Arcane
Joined
Apr 21, 2013
Messages
5,526
Location
Russia
qzupvvl41j451.png


The goal was to write a worldgen that does not overcomplicate things, is easy to understand and works fast (about 1.5 sec to generate and another 1 sec to draw).

Written in JS. You can check the source and read about the algorithm of it at https://github.com/baturinsky/worldgen and try the live version at https://batgen.netlify.app/

Emulates tectonics, erosion, humidity, rivers etc. It works with a high-res a rectangular grid (such as 640x640) and generates humidity, elevation, biomes and "satellite view", among other things.

Then builds a hexagonal map of lower resolution, and generates rivers, cities and towns on it.
 

urmom

Learned
Joined
May 28, 2020
Messages
308
It's nice that you even have rivers! I started creating a spherical world generator but stopped at implementing precipitation because I am not smart enough.
 
Last edited:

baturinsky

Arcane
Joined
Apr 21, 2013
Messages
5,526
Location
Russia
It's nice that you even have rivers! I started creating a spherical world generator but stopped at implementing precipitation because I am not smart enough.

This one is nice to look at:

https://experilous.com/1/blog/post/procedural-planet-generation

Catch with the rivers is that if you model them "naive" way, they will stuck into some local minimum, instead of reaching the sea.
To solve this, you have to emulate erosion and sedimentation. It's very simple: launch tons of rivers, but reduce elevation a bit when river can flow, add elevation a bit when it is stuck in some local minimum that is not a deep sea.

Here is a timelapse of the effect of few thousands of such cycles:
ErosionBigGif.gif
 

Catacombs

Arcane
Patron
Joined
Aug 10, 2017
Messages
5,927
Nice job. This is really cool. And thanks for sharing the code. Interesting you wrote this entirely in vanilla.
 

baturinsky

Arcane
Joined
Apr 21, 2013
Messages
5,526
Location
Russia
Nice job. This is really cool. And thanks for sharing the code. Interesting you wrote this entirely in vanilla.
I usually write in typescript, but tried vanilla this time. Turns out, modern JS is nearly equivalent to TS, especially is you use JSDoc to specify the types.
 

Catacombs

Arcane
Patron
Joined
Aug 10, 2017
Messages
5,927
Nice job. This is really cool. And thanks for sharing the code. Interesting you wrote this entirely in vanilla.
I usually write in typescript, but tried vanilla this time. Turns out, modern JS is nearly equivalent to TS, especially is you use JSDoc to specify the types.
I've never used JSDoc. I thought it was only for commenting purposes.
 

baturinsky

Arcane
Joined
Apr 21, 2013
Messages
5,526
Location
Russia
I've never used JSDoc. I thought it was only for commenting purposes.
Mostly it is, but VSCode can do intellisense stuff based on it, and some type inference. It's still not as good as TS, though, it does not explicitly shows type errors and such, but it's close. And removes the need for compiling.
 

vlzvl

Arcane
Developer
Joined
Aug 7, 2017
Messages
191
Location
Athens
Do you need rectangular grid? It's very easy to convert map generation part for it. It's just I don't have visualisation module that can properly draw it.

If you can support rectangular grid, then it would be preferable. Hexagonal, i can't use them.
Do you support exporting to files? i don't mean PNGs or such, but data files i.e. XML, describing the tiles in some way than could be post-processed by another app
 

Stormcrowfleet

Aeon & Star Interactive
Developer
Joined
Sep 23, 2009
Messages
1,020
This is really awesome. Thanks for sharing the code I'll take a look at it. It can still be very useful for TTRPGs world building, I'll share it on my blog. Do you have a blog outside Twitter I can link it to ?
 

baturinsky

Arcane
Joined
Apr 21, 2013
Messages
5,526
Location
Russia
Do you need rectangular grid? It's very easy to convert map generation part for it. It's just I don't have visualisation module that can properly draw it.

If you can support rectangular grid, then it would be preferable. Hexagonal, i can't use them.
Do you support exporting to files? i don't mean PNGs or such, but data files i.e. XML, describing the tiles in some way than could be post-processed by another app

Not yet, but will add JSON export soon.
 

Catacombs

Arcane
Patron
Joined
Aug 10, 2017
Messages
5,927
I've never used JSDoc. I thought it was only for commenting purposes.
Mostly it is, but VSCode can do intellisense stuff based on it, and some type inference. It's still not as good as TS, though, it does not explicitly shows type errors and such, but it's close. And removes the need for compiling.
Interesting. I'm open to using it. I use Emacs, and I'm sure there is a JSDoc minor mode hidden somewhere.
 

vlzvl

Arcane
Developer
Joined
Aug 7, 2017
Messages
191
Location
Athens
It can now generate square grid maps. Though, rendering is not nearly as neat as for hex map yet.

Hey, nice update!
About rendering, it wont be a thing as long as one gets access to the high-res version of the map, in tile mode.
Since i already use my own tiles, rendering is not a problem; interpretation of data is.
It could certainly be done by processing pixels from the high-res version but i would prefer an organized JSON/XML data export to this solution,
as you know more about the terrain types.
Most services on Internet simply provide the graphics etc. Donjon (hex as well, @$#) & its pain in the arse to convert that to data.
Thanx!
 

Mastermind

Cognito Elite Material
Patron
Bethestard
Joined
Apr 15, 2010
Messages
21,144
Steve gets a Kidney but I don't even get a tag.
hex >>>>>>>>>>> squares for world maps, anyone who disagrees is a faggot
 

urmom

Learned
Joined
May 28, 2020
Messages
308
I have been messing around in World Machine. I want to produce something usable in a tile based game but am not sure how to proceed.
 

As an Amazon Associate, rpgcodex.net earns from qualifying purchases.
Back
Top Bottom