Mythruna
April 20, 2024, 01:40:42 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome to the new forums. See "Announcements" for a note for new users.
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Scripted caves...  (Read 6321 times)
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« on: February 10, 2012, 11:07:04 AM »

Don't know if this picture/link will work but I just posted one to the facebook page:
http://www.facebook.com/photo.php?fbid=344621935560331&set=a.218418391514020.54331.204533646235828

Cave generation works in two phases:
1) random cave influencers are generated using a semi-complicated algorithm
2) when the terrain is generated, these influencers are used to roughly carve the caves/gorges out of the terrain

With the new caveSystemCreated hook, scripts can add their own caves between steps 1 and 2.

The one that made that picture looks like this:
Code:

import mythruna.db.cave.*;
        
on( [caveSystemCreated] ) {
    type, event ->
        
    event.generator.addPoint( 512, 512 ).setRadius(50).setStrength(10);  
    event.generator.addPoint( 512, 512 ).setRadius(20).setStrength(-20);  
}

Caves are only carved out of where there would have been land, so you can't plop an arbitrary blob in the middle of space... but you can do all kinds of other weird things like the above with adding/subtracting negative areas.

Here is another script that makes a small crater around the spawn point connected to a deep angled tunnel that connects to a submerged gorge:

Code:

import mythruna.db.cave.*;
        
on( [caveSystemCreated] ) {
    type, event ->
        
    // Create a relatively smooth crater centered on the surface at the spawn point.
    // Proper elevation is determined from the normal fractal terrain.
    def p = event.generator.addPoint( 512, 512 ).setRadius(10).setStrength(10);

    // This generates a cylindrical cave running from the center of that crater
    // down and to the west.  In world seed=100, this is a 60 meter deep tunnel.
    event.generator.addLine( 512, 512, p.center.z, 500, 512, 20 );    

    // From there, this generates a long, roughly 12-15 meter high, 10 meter wide (diameter)
    // unground "gorge"... basically a tunnel that is tall.
    event.generator.addWall( 500, 512, 20, 490, 400, 30 );    
}

By the time these scripts are run, all of the random caves have been generated for that area and so the scripts could technically look there and see what is already there.

And by the way, this is exactly the same way that dungeons and towns will be generated and they will allow for the same level of customization... though obviously they will be much different than simple caves are. Smiley
« Last Edit: February 10, 2012, 01:17:56 PM by pspeed » Logged
FutureB
Donators
Hero Member
***
Posts: 512


RAWR


View Profile
« Reply #1 on: February 10, 2012, 10:21:25 PM »

Wow i dont understand the codeing ness but WOW man the pictures coooooool great job paul :]
Logged


Say the opposite of these words:
1)Always.
2)Coming.
3)From.
4)Take.
5)Me.
6)Down.
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #2 on: February 10, 2012, 10:40:43 PM »

Just fun to play with.

In case you (or anyone else) are curious, the algorithm sort of works like this:
1) take already generated height map from the fractal
2) go over each cell in a block of terrain
3) if that cell is within the radius of some of the influencers (point, line, wall) then add up all of the influences
4) if that value is more than 0 then erase the cell.

So, in the above first example (and the one that generated the picture)...  Each cell that is within the 30 meter radius of the first point has strength added (in simplistic terms).  Each cell that is within the 20 meter radius of the second point has strength subtracted.  Any cells that still have positive strength are erased.

Without any points, that place is very much a landlocked hill.
With only the first point, it's a carved out "bowl" or crater, just touching the shoreline.
With the second point, some of the land is "put back" making a floating island.

There's a slightly more complicated bit where the actual strength falls off based on distance and is also used to randomize the borders, etc... but you get the gist of it.
Logged
BenKenobiWan
Friendly Moderator
Donators
Hero Member
***
Posts: 674


Jesus loves you!


View Profile
« Reply #3 on: February 11, 2012, 03:34:10 PM »

With your explanation, I think that actually makes sense.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.20 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!