### Author Topic: Cavern generation code  (Read 19754 times)

#### miki151

• Rogueliker
• Posts: 264
• Karma: +0/-0
##### Re: Cavern generation code
« Reply #15 on: July 08, 2013, 04:51:01 PM »
Does anyone know a simple algorithm to create irregular semi-round shapes? Something like a pond or lake.
KeeperRL, Dungeon Keeper in roguelike style:
http://keeperrl.com

#### Anvilfolk

• Rogueliker
• Posts: 374
• Karma: +0/-0
##### Re: Cavern generation code
« Reply #16 on: July 08, 2013, 04:57:33 PM »
A quick idea would be to generate several intersecting circles of different diameters, and then adding and removing some of the outlying water tiles so it's not obviously just circles. Alternatively, start with circles of large diameters, then add circles of smaller diameters. This might give you something like lake shapes
"Get it hot! Hit it harder!!!"
- The tutor warcry

One of They Who Are Too Busy

#### miki151

• Rogueliker
• Posts: 264
• Karma: +0/-0
##### Re: Cavern generation code
« Reply #17 on: July 08, 2013, 05:35:58 PM »
I've already tried combining circles and it looks pretty bad  . Maybe making the edges smooth would help, but here I can't think of anything simple.
KeeperRL, Dungeon Keeper in roguelike style:
http://keeperrl.com

#### dscreamer

• Rogueliker
• Posts: 65
• Karma: +0/-0
##### Re: Cavern generation code
« Reply #18 on: July 08, 2013, 07:13:41 PM »
Does anyone know a simple algorithm to create irregular semi-round shapes? Something like a pond or lake.

Something like this? (http://i.imgur.com/4QGluRG.png  http://i.imgur.com/CFSk8bl.png )

If those are the sorts of shapes you want, here's the algorithm:

1. Choose a maximum radius for the shape, so you have a clear stopping point. (You could also experiment with other termination criteria, like the total number of cells, etc.)

2. Start with a single cell of "water" surrounded by plenty of empty space.

3. Choose a cell at random.

4. If the chosen cell is empty space AND is next to water, continue to 5. Otherwise, go back to step 3.

5. Randomly decide whether the chosen cell will become water. The probability should be based on distance from the center (the original water cell). For example, I used (100 - (euclidean_distance * 10))%, for a maximum radius of 10.

6. If you just changed the chosen cell to water AND the chosen cell was at the desired maximum radius, go to 7. Otherwise, the shape isn't finished yet - go back to 3.

7. Finally, smooth it out just once using the "4-5 rule" mentioned here: http://roguebasin.com/index.php?title=Cellular_Automata_Method_for_Generating_Random_Cave-Like_Levels .

Hope this helps.

#### miki151

• Rogueliker
• Posts: 264
• Karma: +0/-0
##### Re: Cavern generation code
« Reply #19 on: July 08, 2013, 09:18:16 PM »
Thanks!
KeeperRL, Dungeon Keeper in roguelike style:
http://keeperrl.com

#### languard

• Newcomer
• Posts: 41
• Karma: +0/-0
##### Re: Cavern generation code
« Reply #20 on: July 11, 2013, 02:20:44 AM »
Hmm, I think I'll try running the end result through the cellular process, see if that helps with the diags without destroying how the dungeon looks.

#### Endorya

• Rogueliker
• Posts: 513
• Karma: +0/-0
• The non-purist roguelike lover
##### Re: Cavern generation code
« Reply #21 on: July 11, 2013, 11:24:03 AM »
Though I like your cavern system, I'm planning to implement an another type of cave model as seen bellow:

The reason for this is that I think it adds more sense of depth and tension as the player ventures himself deeper into the cave system, because dangers and rewards will increase with it. I really don't know if this is more realistic or not, but at least for my game it will be better.
« Last Edit: July 11, 2013, 01:57:37 PM by Endorya »
"You are never alone. Death is always near watching you."

#### guest509

• Guest
##### Re: Cavern generation code
« Reply #22 on: July 12, 2013, 05:02:17 AM »
Can I just say that your Atari/Intellivision/Colecovision presentation is top notch?

#### Endorya

• Rogueliker
• Posts: 513
• Karma: +0/-0
• The non-purist roguelike lover
##### Re: Cavern generation code
« Reply #23 on: July 12, 2013, 08:07:17 AM »
Can I just say that your Atari/Intellivision/Colecovision presentation is top notch?
Well thanks. Not entirely sure thought if anyone else would find this model appealing. Though my project will be closed source I would gladly share parts of it, like the source code for generating something like this.
« Last Edit: July 12, 2013, 10:58:31 AM by Endorya »
"You are never alone. Death is always near watching you."

#### guest509

• Guest
##### Re: Cavern generation code
« Reply #24 on: July 13, 2013, 12:03:08 AM »
Did you see my drunken walk algorithm? Using diggers and roomies?

http://forums.roguetemple.com/index.php?topic=2830.0

Krice also got some interesting results with that method, he links in that thread. Dungeon building is fun.

#### Krice

• (Banned)
• Rogueliker
• Posts: 2316
• Karma: +0/-2
##### Re: Cavern generation code
« Reply #25 on: July 13, 2013, 10:06:42 AM »
Krice also got some interesting results with that method, he links in that thread. Dungeon building is fun.

I think maze generation is a different topic, but in that routine I was able to solve the room problem as well and results can be seen in the next version of Teemu.

In cavern generation I've tried something similar dscreamer described, but I call it a random flood fill routine. Perfect flood fill in void generates a diamond shape, but with random variations it's more or less like a cavern. I think there are better ways to do caverns, but one advantage in flood fill is that you can store the seed distance from the center, making it easy to create ponds or other similar formations simply by filling the required number of seeds with water tile.

#### Endorya

• Rogueliker
• Posts: 513
• Karma: +0/-0
• The non-purist roguelike lover
##### Re: Cavern generation code
« Reply #26 on: July 13, 2013, 10:12:18 AM »
Did you see my drunken walk algorithm? Using diggers and roomies?

http://forums.roguetemple.com/index.php?topic=2830.0

Krice also got some interesting results with that method, he links in that thread. Dungeon building is fun.

That's impressive! I think I will have sites of exploration base as those. I will call it: Mazed Catacombs. I just need to add a few rooms (which in fact will be the chambers) where the bodies of the deceased remain. Thanks for sharing it!
« Last Edit: July 13, 2013, 10:40:00 AM by Endorya »
"You are never alone. Death is always near watching you."

#### languard

• Newcomer
• Posts: 41
• Karma: +0/-0
##### Re: Cavern generation code
« Reply #27 on: July 14, 2013, 11:49:59 PM »
The diggers/roomies approach does look interesting, but as Krice noted maze generation is different from cave generation.  Still looks like an interesting approach, and it's been added to my list of generation techniques I want to implement in C#.

Still tweaking data values/experimenting with cleanup code to refine my algorithm.

#### guest509

• Guest
##### Re: Cavern generation code
« Reply #28 on: July 15, 2013, 05:45:04 AM »
With the diggers you just set them to turn more often and they'll dig you caverns. If you want long corridors, turn them less often. Have them die if they aren't adjacent to a diggable block and they'll build you rooms.

But what is IN the caverns is more important than the layout I think.

#### Nekoninja

• Newcomer
• Posts: 34
• Karma: +0/-0
##### Re: Cavern generation code
« Reply #29 on: July 18, 2013, 08:05:32 AM »
The link to the source code is broken: http://languard.koding.com/cave/CaveGenDropMethod.zip

Can you fix it so we can learn from your source code?

Thanks
Bow to me, your evil programmer or I will destroy the internet with my 'delete' button!