presenting: random world generator (with c file)
Posted: Wed Feb 16, 2011 5:42 pm
Hi, all. Here's a fairly quick version of a random world generator. It generates a lot of neat things, and is fairly complete in itself as an interesting world.
Actually using it in an actual ToME game would require converting the text output file to tome format ([~],[~],etc), which would be very easy at the end of the program (just change the for loops). One would then manually stick it in the eyal map section. Also, I currently run this in 256x256; unless one wanted to run ToME a bit bigger, the output would need to be resized.
I'm just getting this out now because I won't be able to work on it any more for the next four or five days.
Right now, it sets topography, from deep water to mountain ranges and high peaks. Then terrain features are added to the topography. The N edge is tundra and, at the very top, impassable glaciers. The tundra and glaciers are more pronounced at high elevations. Most glaciers come down over land, but if there are any northern oceans, ice floes can come down there too. A random wetness map distinguishes broad areas that might have woods from those with deserts. Rivers run from springs and rough lakes, and increase wetness in the area. Woods are added at elevations below mountainous, and deserts, too. There can also be impassable forests and scorching deserts. The W/E edges can be cutoff by impassable forests/mtns (depending on wetness/elevation), and the S can be impassably scorching. Otherwise it's just the edge of the map.
Finally, a starting town is created near the middle of the map, and then six additional sites are made, one for plains, desert (could be sandworm lair), woods (could be old forest), hills (dwarf city), tundra (snow giants?), and river (mermen or psyrens?). More could be made, eg a glacier city, which would only be approachable with special gear, maybe.
The main code is in c (with some c++ libraries I guess), and is very basic--700 lines. Comments describe sections, but only sometimes what I'm doing. I compile it using gcc in macosx with no fancy business. It runs in about two seconds. I'm just using simple gnuplot calls to look at the results.
Needed improvements: lots. It's mostly a long main(). Needs *lots* of breaking up into subroutines. The diamond-square fractal algorithm is public, but I grabbed one licensed for free private use; it should be rewritten from scratch (currently it's actually slightly rotationally asymmetric, which makes it look a bit tectonic). Very uneven use of variables, like i,j,x,y,xx,yy,kk etc for loops, some ints, some floats. Lakes should be broader. Checks should be made to ensure that all sites are reachable from the starting town (eg a site might potentially be on an island), but I haven't seen any problems yet, especially as hills and woods are passable (but mountains and forests are not). I have basic ideas to use A* to make mountain passes and roads through woods if needed, and check to make sure a site isn't on an island. It's set for 256x256, and a few variables probably aren't set to scale well if the size is changed. There is definitely no civilization yet; just towns/sites. I also have basic ideas to use A* to find conflicts, make forts, and, once battles rage, develop uniques as leaders and artifacts they use that the player could kill/find. Current Eyal dungeons (like elvish ruins) need to be allocated. Eventually would need to be incorporated as a mod.
Ideally, this could increase replayability. I always liked angband, because each time was unique. This could do that for the wilderness, whether it adds any real new content or not.
Below are two or three images, showing glaciers, rivers, forests & deserts, etc. In addition, the worldgen C file (really C++, since it puts initializations everywhere) is at
http://pastebin.com/w4hnn0c5
The fractal routine is at
http://pastebin.com/eF6MQadN
The latter file is referred to as dmnd_square.c in worldgen.c.
Thanks. Comments, suggestions, help welcome. I'll probably return to this in under a week.
All hail DG!
ELEVATION: rivers are false-yellow. TERRAIN: glaciers are false-yellow, tundra looks speckled. TERRAIN: yellow deserts, red forests.
Actually using it in an actual ToME game would require converting the text output file to tome format ([~],[~],etc), which would be very easy at the end of the program (just change the for loops). One would then manually stick it in the eyal map section. Also, I currently run this in 256x256; unless one wanted to run ToME a bit bigger, the output would need to be resized.
I'm just getting this out now because I won't be able to work on it any more for the next four or five days.
Right now, it sets topography, from deep water to mountain ranges and high peaks. Then terrain features are added to the topography. The N edge is tundra and, at the very top, impassable glaciers. The tundra and glaciers are more pronounced at high elevations. Most glaciers come down over land, but if there are any northern oceans, ice floes can come down there too. A random wetness map distinguishes broad areas that might have woods from those with deserts. Rivers run from springs and rough lakes, and increase wetness in the area. Woods are added at elevations below mountainous, and deserts, too. There can also be impassable forests and scorching deserts. The W/E edges can be cutoff by impassable forests/mtns (depending on wetness/elevation), and the S can be impassably scorching. Otherwise it's just the edge of the map.
Finally, a starting town is created near the middle of the map, and then six additional sites are made, one for plains, desert (could be sandworm lair), woods (could be old forest), hills (dwarf city), tundra (snow giants?), and river (mermen or psyrens?). More could be made, eg a glacier city, which would only be approachable with special gear, maybe.
The main code is in c (with some c++ libraries I guess), and is very basic--700 lines. Comments describe sections, but only sometimes what I'm doing. I compile it using gcc in macosx with no fancy business. It runs in about two seconds. I'm just using simple gnuplot calls to look at the results.
Needed improvements: lots. It's mostly a long main(). Needs *lots* of breaking up into subroutines. The diamond-square fractal algorithm is public, but I grabbed one licensed for free private use; it should be rewritten from scratch (currently it's actually slightly rotationally asymmetric, which makes it look a bit tectonic). Very uneven use of variables, like i,j,x,y,xx,yy,kk etc for loops, some ints, some floats. Lakes should be broader. Checks should be made to ensure that all sites are reachable from the starting town (eg a site might potentially be on an island), but I haven't seen any problems yet, especially as hills and woods are passable (but mountains and forests are not). I have basic ideas to use A* to make mountain passes and roads through woods if needed, and check to make sure a site isn't on an island. It's set for 256x256, and a few variables probably aren't set to scale well if the size is changed. There is definitely no civilization yet; just towns/sites. I also have basic ideas to use A* to find conflicts, make forts, and, once battles rage, develop uniques as leaders and artifacts they use that the player could kill/find. Current Eyal dungeons (like elvish ruins) need to be allocated. Eventually would need to be incorporated as a mod.
Ideally, this could increase replayability. I always liked angband, because each time was unique. This could do that for the wilderness, whether it adds any real new content or not.
Below are two or three images, showing glaciers, rivers, forests & deserts, etc. In addition, the worldgen C file (really C++, since it puts initializations everywhere) is at
http://pastebin.com/w4hnn0c5
The fractal routine is at
http://pastebin.com/eF6MQadN
The latter file is referred to as dmnd_square.c in worldgen.c.
Thanks. Comments, suggestions, help welcome. I'll probably return to this in under a week.
All hail DG!
ELEVATION: rivers are false-yellow. TERRAIN: glaciers are false-yellow, tundra looks speckled. TERRAIN: yellow deserts, red forests.