Post new topic    
Red Slime
Send private message
Minecraft-like World Generation in OHR 
 PostSat Feb 07, 2015 4:56 am
Send private message Reply with quote
gen0011.png
One of the latest generations.
gen0008.png
Changing some more tiles. Changing more variables.
gen0006.png
Changing some tiles, adding some terrain.
gen0004.png
Playing around with variables.
gen0001.png
One of the first generations.
The code here is not very advanced, but I ended up making something I'm happy with. I'm not very experienced as a programmer so this was kind of a challenge. Also, I'm not going to lie, I was really inspired by Valigarmander and Bob the Hamster by this, especially since these two have made some really neat random generation scripts in Crypt of Baconthulhu and Downward (name apparently subject to change). It makes a randomly generated overworld with various terrains. There are islands, continents, lakes, and biomes.
The code is pretty solid in this respect, I think. The way it works is, instead of writing every single tile on the map, it places various chunks of land. It starts off with a blank map covered in water. The map is 50x50, but can easily be changed to make larger or smaller maps by changing some variables. The first thing it does is create several "continents" which are just areas where chunks of land I call "shapes" can spawn. These shapes are random terrain and shape that can overlap, so the land masses that form transition seamlessly most of the time.



Tell me what you think. Criticism is much appreciated and expected. Veteran programmers, any comments?

Code:


include, gen.hsi
include, plotscr.hsd
include, Scancode.hsi

global variable, begin
   1, mapsize
   2, currentx
   3, currenty
   4, xincriment
   5, yincriment
   6, tera
   7, terahigh
   8, teralow
end


#main runs as new game script
plotscript, main, begin
mapsize:=50
terahigh := 11
teralow := 0
#terahigh will determine what tiles will be placed
variable(cut)
cut :=12
for(cut, 1, 12, +1)
   do(cont)
# "cut" determines how many "continents" will be placed on the entire map
end



plotscript, cont, begin
xincriment := random(5, mapsize--6)
yincriment := random(5, mapsize--6)
variable(con)
con :=25
for(con, 1, 25, +1)
   do(generator)
# con determines how many "shapes" will be placed within "continents"
end

plotscript, generator, begin
#This places 1 "continent" on the map. It's an area where a shape can be placed.
currentx := random(xincriment--5, xincriment+5)
currenty := random(yincriment--5, yincriment+5)
pickshape
end

plotscript, pickshape, begin
#"shapes" are small units of land that are of a certain type of terrain
variable(shape)
shape := random(1,10)
if (shape == 1 || shape == 2 || shape== 3) then (cross)
if (shape == 4) then (square)
if  (shape == 5) then (corner1)
if  (shape ==6) then (corner2)
if  (shape ==7) then (block1)
if  (shape==8) then (block2)
if  (shape==9) then (line1)
if  (shape==10) then (line2)
end

script, cross, begin
tera := random(teralow,terahigh)
write map block (currentx + 1, currenty, tera, 1)
write map block (currentx, currenty+1, tera, 1)
write map block (currentx--1, currenty, tera, 1)
write map block (currentx, currenty--1, tera, 1)
write map block (currentx, currenty, tera, 1)
end

script, square, begin
tera := random(teralow,terahigh)
write map block (currentx--1, currenty+1, tera, 1)
write map block (currentx, currenty+1, tera, 1)
write map block (currentx+1, currenty+1, tera, 1)
write map block (currentx+1, currenty, tera, 1)
write map block (currentx+1, currenty--1, tera, 1)
write map block (currentx, currenty--1, tera, 1)
write map block (currentx--1, currenty--1, tera, 1)
write map block (currentx--1, currenty, tera, 1)
write map block (currentx, currenty, tera, 1)
set hero position (0, currentx, currenty)
end

script, corner1, begin
tera := random(teralow,terahigh)
write map block (currentx+1, currenty, tera, 1)
write map block (currentx, currenty--1, tera, 1)
write map block (currentx--1, currenty--1, tera, 1)
write map block (currentx, currenty, tera, 1)
end

script, corner2, begin
tera := random(teralow,terahigh)
write map block (currentx+1, currenty, tera, 1)
write map block (currentx, currenty+1, tera, 1)
write map block (currentx+1, currenty--1, tera, 1) 
write map block (currentx, currenty, tera, 1)
end

script, block1, begin
tera := random(teralow,terahigh)
write map block (currentx+1, currenty, tera, 1)
write map block (currentx, currenty+1, tera, 1)
write map block (currentx, currenty--1, tera, 1)
write map block (currentx+1, currenty--1, tera, 1)
write map block (currentx, currenty--1, tera, 1)
end

script, block2, begin
tera := random(teralow,terahigh)
write map block (currentx--1, currenty, tera, 1)
write map block (currentx--1, currenty--1, tera, 1)
write map block (currentx, currenty--1, tera, 1)
write map block (currentx+1, currenty--1, tera, 1)
write map block (currentx+1, currenty, tera, 1)   
write map block (currentx, currenty, tera, 1)
end

script, line1, begin
tera := random(teralow,terahigh)
write map block (currentx+1, currenty, tera, 1)
write map block (currentx--1, currenty, tera, 1)
write map block (currentx, currenty, tera, 1)
end
script, line2, begin
tera := random(teralow,terahigh)
write map block (currentx, currenty--1, tera, 1)
write map block (currentx, currenty+1, tera, 1)
write map block (currentx, currenty, tera, 1)
end

Slime Knight
Send private message
 
 PostSat Feb 07, 2015 12:18 pm
Send private message Reply with quote
Very neat. Surprised
I know that TMC has made something like this with valleys and rivers. It should be around somewhere.
"I can't buy food with glory"
Metal King Slime
Send private message
 
 PostSat Feb 07, 2015 3:09 pm
Send private message Reply with quote
Cool! I like this trend :) Thinking of making more extensions to it?

Very simple scripts, but creates interesting jagged continents. (The simplest way to make them smoother I suppose being just to use larger shapes.)

One thing you could try to is place several shapes for a single biome together (not necessarily all the shapes making up a continent). That would lead to fewer single isolated tiles. But whether that's bad or good depends... a single ice tile in a desert looks bad, while a single forest tile in a plane is fine. One possibility would be to have more complicated rules, like above y = 12 place ice with probability 50% and sand with probability 0%, and so on. Or disallow ice next to desert.

Watch out, the following line:
Code:
for(con, 1, 25, +1)

does not do what you think! You've actually hit an edge case of the HSpeak parser here, as it will be interpreted as "for(con, 1, (25,+,1))", looping from 1 to 26 with the default step size of 1. The reason is that there is no unary + operator in HS (which does nothing in most languages anyway), and it's rather blind to commas (there's absolutely no difference between "+1" and "+,1").

Quote:
I know that TMC has made something like this with valleys and rivers. It should be around somewhere.

It wasn't me. You're probably thinking of BMR's map generator, though there have been a couple other (simpler) overland map generators.

Actually, Pepsi Ranger has also written a parkland map generator (streams, lakes, hills, trees) that gives similar results. Instead of placing things randomly in clumps, he performs random walks over the map (that is, have a 'cursor' that move up/dow/left/right randomly). It's for an unreleased game, and I can't remember whether there are public screenshots anywhere.
Metal King Slime
Send private message
 
 PostSat Feb 07, 2015 3:45 pm
Send private message Reply with quote
This is some really spiffy stuff Smile It's looking really promising thus far, and I'm excited to see where you go with it.


TMC wrote:
It wasn't me. You're probably thinking of BMR's map generator, though there have been a couple other (simpler) overland map generators.


If it is mind that you're thinking about, then here's the old thread that I posted about it.

I did process things differently though. Rather than placing different biomes and stuff everywhere, I used a diamond-square algorithm to generate a height map of sorts. Then I used pathfinding to "flow" rivers from random points on the map down to the coast, lowering the height map appropriately to simulate erosion. After that, I randomly threw lakes around here and there, and then smoothed the entire height map.

Once the height map was done, I would figure out what sort of stuff (grass, trees, mud, etc...) would go where depending on the height map. e.g. water for really low heights, grass in areas with relatively uniform heights, snow and rocks at high heights, etc...
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
 
 PostSat Feb 07, 2015 4:08 pm
Send private message Reply with quote
Oh, I forgot that you were doing erosion! Are you using that map generation for anything?

It's always interesting how you can get quite similar (but typically worse and 'illogical') results from doing something a (semi-)'proper' way, like erosion simulation, or through some simpler but completely non-physical algorithm like automata or random walks. And then there's the option of just trying to imitate the empirical result using lots of detailed rules for placement.
Metal King Slime
Send private message
 
 PostSat Feb 07, 2015 4:11 pm
Send private message Reply with quote
Right now? Nah, haven't really touched that generation thing in a long time, though I keep meaning to go back to it.

I tried doing the rules for placement with the rivers and stuff, but found that simulating erosion was actually (surprisingly) easier and gave nicer looking results. The screenies on my old thread aren't the latest ones that have the nice canyons and stuff though, nor is the script I've got up somewhere here.

I'd be willing to place it on the wiki once I've cleaned it up and properly documented it.
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
 
 PostSat Feb 07, 2015 4:25 pm
Send private message Reply with quote
Well, you should post screenshots of the latest version, at least! So the pictures with rivers that you posted previously were just ones placed with pathfinding to the edges (plus a heightmap smoothing step I suppose)? And the erosion produces larger canyons instead? That previous thread got pretty long/technical; I don't have the patience to read through my own replies :)
Red Slime
Send private message
 
 PostSat Feb 07, 2015 11:32 pm
Send private message Reply with quote
gen0028.png
gen0027.png
gen0026.png
gen0024.png
gen0025.png
Made "biomes". Snow biomes only spawn above or below a certain Y position.
Metal King Slime
Send private message
 
 PostSun Feb 08, 2015 2:18 am
Send private message Reply with quote
Heh, with the biomes it looks a lot like Minecraft now. Minecraft has pretty simplicist map generation at a large scale. So did you add large square shapes? I now notice large blobs on the maps.
Red Slime
Send private message
 
 PostSun Feb 08, 2015 3:10 am
Send private message Reply with quote
lol That block thing is kind of silly looking. That's just an unfortunate result of having too many shapes spawn in too small of an area.
Display posts from previous: