Map Generator

Baxnie

Excellent OT User
Joined
Oct 5, 2007
Messages
88
Best answers
0
Reaction score
33
Location
Brazil
Hello,

There's been a while since I don't post here at OTLand.
Last week I've decided to research a subject that has been my interest for years: pseudo-random map generation.

This weekend I've made the first prototype:


I've chosen Remere's Mapeditor as the base code because it already has proper map editing functions and will reduce a lot of work related to map viewing, editing, automatic borders and more. The main subject here is pseudo-random, not map editing.

The goal of this first attempt was to generate a simple island.
My research began with the Perlin Noise, which I knew it was used by other game developers to generate pseudo random levels.
This repository saved me some time because it has a single header implementation of perlin noise that could be easily integrated to Remere.
By inputing a XY coordinate value to the noise function, we get a 0 to 1 value which is random, but not completely random. Changing the seed, usually using current time in seconds, we get new values for the noise function.

The first code was really simple. A 100x100 grid which each tile was assigned a noise value from 0 to 1.
Using a simple rule, we can decide what should be the ground ID for each tile.
If we think that noise is the terrain elevation and 0.3 means the sea level, we could say:
0.0 <= noise < 0.3 means 'water'
0.3 <= noise < 0.8 means 'grass'
0.8 <= noise < 1.0 means 'mountain'

Using the Remere's borderize function I thought that the first result would show something nice.

1568082303994.png

But it was garbage.

So I've added a simple window so I could play with the noise parameters.

1568082370110.png

X and Y are the top left coordinates where the map will be generated.
Width and Height are the size of the generated map.
Scale is a factor multiplied by each tile coordinate. We could say that this is the noise frequency value.
Octaves are the number of times that the noise function is called.

Gotta study more, but here're my thoughts for now:
From what I've seen octaves gives how much detail the noise has. It reminds me of the Fourier Series.
So, the first time the noise function is called, it has a small frequency and high amplitude. This gives us the bottom of the sea and high ground terrains.
As we advance on the octaves, we get smaller amplitudes, but higher frequencies. This way we get the detail on the bottom of the sea and on the high ground terrains.

After some fine tuning on parameters, it improved quite a bit.

1568082030394.png

But it still doesnt look like an island. It's more like a clip from a big continent.
Thinking about an island:
- It's surrounded by water (low heights there)
- The middle of it has land, and maybe some mountains (high heights)

So, in addition to the noise, another math function could be added.
The map center is located at:
centerX = left + width / 2
centerY = top + height / 2

The radius of the island could fill the whole generated map area, so:
radius = width / 2.

Thinking about it, probably using a smaller percentage of the width would give better results, as we'd have a larger portion of water, making the island to be 100% surrounded by water.

So for every tile, we'd like to reduce the height value if it's far from the center and increase it near the center.
heightIncrease = 1 - distance to center / radius

Adding it to the height generated by the noise function, we start to get some nice results, which are shown in the video.

1568084461087.png

This is it for this post. I'm not sure if I'll continue researching this as it's just a hobby for now.
The goal here is not to replace the mapper, but just aid the development of new maps.
For the next post I'll probably try to generate the path of hunting caves.
 

Attachments

Last edited:

Sajgon

Active Member
Joined
Mar 10, 2017
Messages
156
Best answers
2
Reaction score
146
Impressive progress just over the weekend. Keep it up! Large parts of maps are very time consuming to build and your tool could help with development for projects that wouldnt happend. IMO a goal could be you couldnt tell whats autogenerated or not. And I like the idea about caves, hunting spawns from Tibia such as scarabs, ancient scarabs, dara rotworms could be easily generated instead.

I know about a guy, Forby, who made something similar. He also made a tool converting OTMB maps to JSON and other way around, thats how he can generate maps with JSON with some help. If you don't know about him you can find his work here and look into the code.

There is also an online version of the application you can use

You could also try to speak with curl for support and ideas, for example he made a tool to auto generate houses, with serveral floors.
 

XeekXeek

Well-Known Member
Joined
Jul 20, 2011
Messages
80
Best answers
0
Reaction score
23
This may look useless, but to me (although I am not a professional programmer), it's a lot useful if you want to make a map more dynamic and changing over the course of time (I am sure it's possible somehow).

A "Dynamic + Random" tibia server. I hope someone makes a use of this.
 

Tony32

Legendary OT User
Joined
Jun 6, 2008
Messages
1,117
Best answers
0
Reaction score
219
Nice job :)
Here is another example but with placeholder sprites. Just click play and u can adjust the sliders.
Its generating the map every frame which is incredibly slow (and dumb for that matter) but you might get some ideas.
EDIT: Its apparently broken. But the scale slider works at least. Feel free to copy and work on it however you want
 

Evil Puncker

I'd rather kiss a rattlesnake
Joined
May 30, 2009
Messages
5,561
Best answers
14
Reaction score
1,645
Location
160,54,7
here is a lua one:
 

Tony32

Legendary OT User
Joined
Jun 6, 2008
Messages
1,117
Best answers
0
Reaction score
219
Would be cool if someone made a dungeon crawler/rougelike tibia game, with levels and random items, much like Enter the gungeon. Would be pretty cool tbh!
 

kay

Advanced OT User
Joined
Apr 23, 2013
Messages
238
Best answers
0
Reaction score
166
Would be cool if someone made a dungeon crawler/rougelike tibia game, with levels and random items, much like Enter the gungeon. Would be pretty cool tbh!
Exactly my thought, when I saw this thread. Rogue-tibia to play alone, or even multi with friends, that would be insane.
 
Top