presenting: random world generator (with c file)

All new ideas for the upcoming releases of ToME 4.x.x should be discussed here

Moderator: Moderator

Message
Author
asthmatic_thematic
Higher
Posts: 79
Joined: Tue Aug 19, 2008 7:15 pm

presenting: random world generator (with c file)

#1 Post by asthmatic_thematic »

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.
elevation with popped rivers.png
elevation with popped rivers.png (100.24 KiB) Viewed 6529 times
TERRAIN: glaciers are false-yellow, tundra looks speckled.
yellow glaciers, speckled tundra.png
yellow glaciers, speckled tundra.png (48.71 KiB) Viewed 6529 times
TERRAIN: yellow deserts, red forests.
yellow deserts, red forests.png
yellow deserts, red forests.png (49.67 KiB) Viewed 6529 times
Last edited by asthmatic_thematic on Thu Feb 17, 2011 1:47 am, edited 1 time in total.

asthmatic_thematic
Higher
Posts: 79
Joined: Tue Aug 19, 2008 7:15 pm

Re: random world generator

#2 Post by asthmatic_thematic »

If you have gcc and a viewing program that can read text files, you can have your own world in under one minute of start up time! Have fun playing with parameters, everyone.
Last edited by asthmatic_thematic on Thu Feb 17, 2011 2:09 am, edited 1 time in total.

Graziel
Wyrmic
Posts: 234
Joined: Wed Sep 15, 2010 10:32 am

Re: random world generator

#3 Post by Graziel »

nice!

i would really like to see random world cause "discovering" same over and over again gets borring really fast : /
You are likely to be eaten by a grue

Susramanian
Spiderkin
Posts: 454
Joined: Sat May 15, 2010 3:09 am

Re: random world generator

#4 Post by Susramanian »

I would dearly love to see random world generation in ToME. Thanks for your work, asthmatic_thematic!

asthmatic_thematic
Higher
Posts: 79
Joined: Tue Aug 19, 2008 7:15 pm

Re: presenting: random world generator (with c file)

#5 Post by asthmatic_thematic »

One last self-comment before heading off to Dublin: if you really like this, please

(i) improve it, and
(ii) make a five pound donation to DarkGod.

A random world generator isn't very much fun with nothing to do in it.

asthmatic_thematic
Higher
Posts: 79
Joined: Tue Aug 19, 2008 7:15 pm

Re: presenting: random world generator (with c file)

#6 Post by asthmatic_thematic »

Someone already pointed out a small problem which was causing the rotational asymmetry and vaguely tectonic look. My fault, not the diamond square code. (It would be nice to have some of the tectonics back, but in a better way...)

The corrected code is at http://pastebin.com/ifJX8H8d. Thanks.

Mithril
Archmage
Posts: 327
Joined: Fri Oct 01, 2010 5:43 pm

Re: presenting: random world generator (with c file)

#7 Post by Mithril »

Sounds very nice! :D I feel trudging through the same world is boring. However, DG has previously expressed sentiment against a random world. Maybe it could be implemented as an option?

Grey
Loremaster
Posts: 3517
Joined: Thu Sep 23, 2010 10:18 pm
Location: London, England
Contact:

Re: presenting: random world generator (with c file)

#8 Post by Grey »

It would certainly be handy for modules at least.
http://www.gamesofgrey.com - My own T-Engine games!
Roguelike Radio - A podcast about roguelikes

darkgod
Master of Eyal
Posts: 10750
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

Re: presenting: random world generator (with c file)

#9 Post by darkgod »

Maj'Eyal is set, but random world generation would fit well for some of the other campaigns I have in mind :)
However it would need to be in lua ;)
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

asthmatic_thematic
Higher
Posts: 79
Joined: Tue Aug 19, 2008 7:15 pm

Re: presenting: random world generator (with c file) [UPDATE

#10 Post by asthmatic_thematic »

So I've had a bit more chance to work on the random world generator, and the first phase is almost done. ToME just isn't happy with my file, and I need debugging help.

I'm only doing the West for now; the Far East is the same. I have an output file which looks like the ToME wilderness input file, eyal.lua, including randomly placing all terrain sites (derth, maze, halfling ruins, etc.), and placing all western patrols and other addspots and addzones.

Certain terrain sites are carefully placed: Derth is fairly central, Trollmire and Old Forest are near Derth, the latter near a wood or forest, etc. Angolwen is in the mountains, and the teleporter is near it but accessible; Daikara is at the edge of a large mountain chain; Sandworm lair is in a desert. Etc. I haven't gotten around to placing some sites carefully yet: the biggest lack eg is that there is no distinct island of Rel yet, and tunnels are random. Also, lumberjack village isn't necessarily near a forest yet (but that's easy), and the cursed quest isn't near it, etc. Finally, I'm converting woods and tundra to plains right now in going from the world map to the tome map; I'll add a terrain type for both.

The problem is: when I substitute in my eyal.lua for the original eyal.lua, the game starts normally, but then hangs upon stepping into the wilderness, stuck on "Generating level" or wilderness or whatever it says.

Here's a randomly generated world, with elevation map (freshwater in false yellow again), terrain map (you can see woods, forests, tundra, deserts, mountains, etc, but you kind of have to know what you're looking for). Also shown is part of an old school character plot I use for looking at maps--the first letter of the site is given for short, so derth eg is d, angolwen is a, etc. This is a zoom of the above maps; it looks a little empty because certain terrains are set to plains for now. Finally, I've given a link at the bottom to the actual eyal.lua replacement file which can be subbed in for the original wilderness/eyal.lua (if you want to hang your game:).

What is the problem with using this file? Does, eg, there have to be water on all sides? Are there necessary links between certain things that aren't working? Does trollmire have to be in a certain spot because it's the starting location? Are there too many land squares, so it overloads the processor?

In short: What are the requirements for swapping in such a file? What are the boundary conditions and location requirements for files?

The worldgen program also runs with another option, which generates civilizations, sets up basic conflicts, and if territory is lost converts the area's settlements to ruins. But I'd like to get tome content placed first.
Screen shot 2011-02-24 at 9.52.22 PM.png
Screen shot 2011-02-24 at 9.52.22 PM.png (168 KiB) Viewed 6376 times
Screen shot 2011-02-24 at 9.52.46 PM.png
Screen shot 2011-02-24 at 9.52.46 PM.png (60.6 KiB) Viewed 6376 times
Screen shot 2011-02-24 at 10.03.07 PM.png
Screen shot 2011-02-24 at 10.03.07 PM.png (56.63 KiB) Viewed 6376 times
Link to eyal-2.lua (remove the "-2" in the name and put in the wilderness folder, backing up your original file). http://pastebin.com/tuLkRCdz
Last edited by asthmatic_thematic on Fri Feb 25, 2011 2:04 am, edited 1 time in total.

asthmatic_thematic
Higher
Posts: 79
Joined: Tue Aug 19, 2008 7:15 pm

Re: presenting: random world generator (with c file)

#11 Post by asthmatic_thematic »

The old school character plot (which is actually the most relevant plot for tome, since the lua file looks like that with brackets around each character) looks a little empty, with too many plains, because woods don't show up as woods, and a few other terrains also aren't included in the quickentity definitions yet, and I'm just temporarily setting them to plains. Also, i'm just including the far east by using the easternmost 70 tome tiles, which leads to oddity if the random world generator of the West has as its eastern boundary non-water tiles. The transition from West to East then looks like random world generation terrain suddenly cut to water. That's an easy fix.

For now I'm interested in the requirements of getting T4 to run with a new map, whatever its niceness or ugliness. Thanks.

asthmatic_thematic
Higher
Posts: 79
Joined: Tue Aug 19, 2008 7:15 pm

Re: presenting: random world generator (with c file)

#12 Post by asthmatic_thematic »

Do all addSpots need to be made before all addZones? ...?

I forgot to add that the big advance in this version is that it has a pathchecker (I got A* running! such a great routine!), and so it makes sure everything relevant is available from Derth. I've seen some maps where, eg, you need to walk a long ways around a huge mountain chain, cut through a narrow gap in some forests, and then take a river path up to a small recess in a glacier where Dreadfell is.:) But the path is always there!

Also, the requirements for placing a particular site are very customizable, being set in a particular check function. One can ask for something to be near Derth, far from Derth, be in the woods or the hills, make sure the site isn't available from Derth, make sure the sites aren't near each other, or make sure certain sites *are* near each other, etc.

I've also set it up so forests, rivers, lakes, and deserts are "named", in that each gets a terrain with a separate subterrain. The subterrains can get individual names, like, eg "Spellmurk Lake." The mountains and plains aren't named yet (since they're terrain, not terrain features), but I plan to do that with a type of fat floodfill function.

I also added tectonics: that's why mountains look pretty good now. There's an underlying fractal tectonic map which guides them, and keeps them from crossing randomly like weird Xs in previous versions.:) Tectonics could also guide which mountains are volcanic, for example.

Rivers are relatively wide, right now, because in converting from the world map (I usually run at 1024x1024) to tome (100x100 for the West), I was losing them by averaging out to other terrain features. Now they completely control a tome tile--if a freshwater feature shows up in the world map, the tome tile that incorporates it is guaranteed to be freshwater of some sort (river, lake, or shallows). Some middle ground would be good.

In any event, all this, and more, can be yours, if I can just get T4 to like my eyal.lua file! :)

darkgod
Master of Eyal
Posts: 10750
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

Re: presenting: random world generator (with c file)

#13 Post by darkgod »

Neat neat!

Still, I urge you to port your algorithm to lua & TE4 code this way modules can integrate it and well I can integrate it when I do a randomly generated other planet (which is planned anyway) :)
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

asthmatic_thematic
Higher
Posts: 79
Joined: Tue Aug 19, 2008 7:15 pm

Re: presenting: random world generator (with c file)

#14 Post by asthmatic_thematic »

Thanks!

I am currently steeling myself to slowly convert to lua. I am planning to break the program more into functions, and I think I'm going to try to make them lua function calls, so that finally actually flipping the main program over into c will be a small task.

But for the moment, I can only run the worldgen program as a preprocessor routine, which generates a world and then gets manually plopped into wilderness/eyal.lua. Since I'll need to understand what the map consistency requirements for eyal.lua are, in order to avoid hanging the game on load up when generating a map using *any* language, do you have any comments about what might be causing the current problems with the posted eyal-2.lua replacement file above?

If there are any particular problems, I can address them in the c program, and then when subroutines get converted to lua they'll be manually taken care of there too.

Thanks, DG!

darkgod
Master of Eyal
Posts: 10750
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

Re: presenting: random world generator (with c file)

#15 Post by darkgod »

Hum I am not sure what you mean, the map loads fine here. (the scale could probably be reduced a tad imo)

As for generating in lua, you do not want to make a lua code taht generates the eyal.lua file, you want ot make a custom level generator (have a look at engine.generator.map)
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

Post Reply