Post new topic    
Page 1, 2  »
Metal King Slime
Send private message
Random terrain 
 PostMon Nov 12, 2012 2:58 am
Send private message Reply with quote
So I've been dabbling with generating random terrain. I can successfully generate a map of pretty much any size with some code I pounded out when I should have been sleeping last night. Here are a few screenies of generated terrain:




What I can't figure out though, is how to save that map for the next play through. I suppose I could save the tile values in a whole bunch of globals, but that would get rather messy. I thought of saving everything to a string using number to string but said string doesn't persist over different playthroughs.

Any ideas? Thanks in advance!
Being from the third world, I reserve the right to speak in the third person.

Using Editor version wip 20170527 gfx_sdl+fb music_sdl
Metal King Slime
Send private message
 
 PostMon Nov 12, 2012 3:57 am
Send private message Reply with quote
Wow. From this distance, those rivers look really nice!

I recommend regenerating the map on the next playthrough. The only other option is to use global variables. If 16384 isn't enough, then you could store it in multiple save files using "export globals". But that's really messy.

In the not-to-distant future we want to let you save maps, strings, slices, and other things not currently saved in save games.

Anyway, to regenerate the map, use the "reseed random" command, like so:

Code:
#Before generating a map:
map seed := random(-2147483648, 2147483647)
reseed random(map seed)
#generate map randomly....

#To regenerate:
reseed random(map seed)
#generate map randomly....
Metal King Slime
Send private message
 
 PostMon Nov 12, 2012 4:03 am
Send private message Reply with quote
Ah, I see, that makes it a lot easier then. So the map seed is stored in a global, and then I just reuse that map seed for later playthroughs? Makes sense, thanks!


Regarding the rivers, they're not yet exactly how I want them to work yet though. Currently, the script picks a random point on the edge of the map, and works its way to the opposite side. The direction and the flow is influenced by underlying terrain. e.g. The river tries to avoid grass tiles if possible, most visible in the first screenie. If it can't avoid the grass tiles, it'll just go straight through randomly.

I've been tinkering around with the idea of using zones and multiple maps and teleport to map to simulate Z-levels, but that might be a bit much for what I'm trying to accomplish. I'll definitely experiment with it in the future though.

Thanks again for the solution!


EDIT: Just tested it, works perfectly, thanks!
Being from the third world, I reserve the right to speak in the third person.

Using Editor version wip 20170527 gfx_sdl+fb music_sdl
Metal King Slime
Send private message
 
 PostMon Nov 12, 2012 6:50 am
Send private message Reply with quote
Multiple Z levels? What do you mean? Do you want to generate Dwarf Fortress-style 3D maps?
Metal King Slime
Send private message
 
 PostMon Nov 12, 2012 6:52 am
Send private message Reply with quote
Playing around with the code a bit more. Added lakes, cliffs, and tweaked the rivers to flow a bit more the way I want them to.

Screenies!





Pretty much all of the settings are adjustable in the code, so it's possible to make more archipelago-y or more continent-y lands.

I originally intended to use this code in Legacy for certain areas, but it's a bit too resource-intensive and clunky to use it multiple times. The generating takes long enough (around 12 seconds for a 128 × 128 map) that Game warns me I might be in an infinite loop. I'll probably put this on the back burner for a bit though, and recycle it for an OHR survival roguelike or something similar.

There are still quite a few things that need adding, like trees, caves, more shrubs ni!, elevation, ravines, etc... Right now, the only things implemented are basic terrain, rivers, lakes, the surrounding water, cliffs, and a few basic plants. I'd also like to work an elevation map so I can do some more realistic flow for the rivers. That would allow me to do drainage for the lakes as well. So much I want to do! But I must focus instead on Legacy for HotOHR, hehe.

Still, if anyone wants the code or anything, just tell me, I'm more than willing to share.

Cheers!
Being from the third world, I reserve the right to speak in the third person.

Using Editor version wip 20170527 gfx_sdl+fb music_sdl
Metal King Slime
Send private message
 
 PostMon Nov 12, 2012 6:57 am
Send private message Reply with quote
TMC wrote:
Multiple Z levels? What do you mean? Do you want to generate Dwarf Fortress-style 3D maps?


Something like that. I couldn't sleep last night, and was thinking about how it would be possible to implement. I don't have a clear idea yet, but I was thinking Z-level boundaries could be done with zones. So Z-level 1 on Map 01 could be marked as Zone 1. On map 1, areas that are a higher Z-Level could be marked as Zone 2. Lower areas would be Zone 3 It wouldn't be too difficult to write a script that detects a change in Zone on each step. If a change from Zone 1 to Zone 2 is detected, teleport map could move the player to Map 2 while keeping X and Y coordinates. On Map 2, areas that were marked as Zone 1 on Map 1 would instead be Zone 3 (lower area) on Map 2.

I probably explained that rather poorly, hehe. That's what I get for late night/early morning brainstorming sessions. I haven't tried to implement the code yet, but I think it would be doable without being overly complicated. But I could be wrong.
Being from the third world, I reserve the right to speak in the third person.

Using Editor version wip 20170527 gfx_sdl+fb music_sdl
Metal King Slime
Send private message
 
 PostMon Nov 12, 2012 8:42 am
Send private message Reply with quote
Pseudo z-levels work!

Now to combine this with the random terrain generator in order to automatically create multiple linked maps! Shouldn't be too difficult... I hope... V
Being from the third world, I reserve the right to speak in the third person.

Using Editor version wip 20170527 gfx_sdl+fb music_sdl
Liquid Metal King Slime
Send private message
 
 PostMon Nov 12, 2012 3:06 pm
Send private message Reply with quote
This is all very cool!
Liquid Metal King Slime
Send private message
 
 PostMon Nov 12, 2012 5:49 pm
Send private message Reply with quote
Indeed. I don't think I've ever seen a good outdoor rogue-like. You may be onto something there.
Slime Knight
Send private message
 
 PostTue Nov 13, 2012 11:49 am
Send private message Reply with quote
BMR, Are you a wizard?! A plotscript Wizard?!
"I can't buy food with glory"
Metal King Slime
Send private message
 
 PostTue Nov 13, 2012 12:29 pm
Send private message Reply with quote
misac wrote:
BMR, Are you a wizard?! A plotscript Wizard?!


Hardly =p If anyone is a plotscript wizard, then maybe TMC or James. Spoon is pretty great at scripting as well, look at Tim-Tim the Mighty Gnome or Tim Tim's Tower, those are pretty nifty. I have a rather long way to go before I can consider myself a plotscript wizard V
Being from the third world, I reserve the right to speak in the third person.

Using Editor version wip 20170527 gfx_sdl+fb music_sdl
Metal King Slime
Send private message
 
 PostTue Nov 13, 2012 5:20 pm
Send private message Reply with quote
Dash it all, this has really captured my mind and I can't put it down. After doing some brainstorming (another sleepless night) I believe I've figured out how to generate a pseudo-3D map ala-Dwarf Fortress.

My first step would be to generate a height map using zones. Height can range from 0 to 127, so I have 128 different height values. Each tile will have a different zone written to it, depending on what my height map generator generates. Using the method TMC provided, I'll run this same generation again over 16 different maps.

Now that each map has the same height-map (zones), I can run another script for each map to figure out what goes where. Water could fill all areas below a certain height. Grass could only grow on areas that are relatively flat over a certain area to simulate plains. Areas with very varied heights would be rocky. If there's a very drastic change over a certain range, then a script could figure out that it's a cliff.

Different maps would thus have different terrain generated on them. Using the z-level walking I made yesterday (or was it two days ago?) the player would be able to walk between different levels almost seamlessly. Going to a "low" map, the player would be more likely to see rivers and water. Going to a "mid" map, rivers wouldn't be visible, rather they would be seen on the map as empty space leading to a lower z-level. The same goes for higher z-levels.

I feel that the main hurdle here would be generating a good height map. I've done a bit (read: a lot) of reading, and I've implemented a diamond-square algorithm to create a height map. The results are still a bit rough as seen below, but a little bit more tweaking will probably allow me to make better height maps.

I'm also planning on having the code also run rivers based on the generated terrain. The script would randomly pick a point on the edge map. It would then find its way "down" the height map by checking all eight directions of that specific point for the "lowest" of heights. Alternatively, I could use A* pathfinding with a target somewhere in the center of the map with height being the pathfinding cost. It would then continue in this way until it reaches either a predefined lowest value, the target point, or the maximum river length. I also plan to make it so that as the river runs, it also erodes the land nearby by a predefined value thus allowing for the formation of canyons if multiple rivers run through an area.

Anywho, screenies of height map generation below:



Being from the third world, I reserve the right to speak in the third person.

Using Editor version wip 20170527 gfx_sdl+fb music_sdl
Liquid Metal King Slime
Send private message
 
 PostTue Nov 13, 2012 5:42 pm
Send private message Reply with quote
Yay! diamond square!

I am a fan of perlin simplex noise.

Not that the results look any different from diamond-square :)
Metal King Slime
Send private message
 
 PostTue Nov 13, 2012 5:46 pm
Send private message Reply with quote
Was actually trying to do Perlin at first, and while I can wrap my head around the theory behind it, I haven't quite figured out how to actually implement it yet V
Being from the third world, I reserve the right to speak in the third person.

Using Editor version wip 20170527 gfx_sdl+fb music_sdl
Liquid Metal King Slime
Send private message
 
 PostTue Nov 13, 2012 6:37 pm
Send private message Reply with quote
Yeah, and I can see how it would be extra difficult to implement in plotscripting due to the lack of any floating point number support.

Although I have used perlin simplex noise myself, I haven't actually ever written my own implementation. I just do

Code:

import perlin
simplex = perlin.SimplexNoise()


Python spoils me :)
Display posts from previous:
Page 1, 2  »