Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: System Generation for a sci-fi rougelike  (Read 775 times)

Vorthon

  • Bay Watcher
  • Now with 50% more pointless rambling!
    • View Profile
System Generation for a sci-fi rougelike
« on: November 05, 2010, 09:00:57 am »

I'm developing a science fiction rougelike in visual basic, for a school project, and I'm having a bit of trouble with the system generation/placement aspect of things. I've got it set up so that it generates a 'bounding box for the universe, the dimensions of which can be set by the user before generating a world. It also generates a seed number. I want to randomly place the systems, following certain rules (If system is outside the bounding box, discard cooridinates and try again; If StarA and StarB are closer than X lightyears, collapse to binary system; etc.), and then run through the generated system placements and generate th masses, age, and metallicity, then from the mass, calculate it's main sequence life-span, its luminosity, etc. (and if StarAge > Main sequence life-span, star  = Giant, Subgiant, or Supergiant). Could Anybody help me?
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: System Generation for a sci-fi rougelike
« Reply #1 on: November 05, 2010, 10:04:48 am »

Sounds very similar to a project I'm working on in Java (which will hopefully become a full-fledged 4X at some point in the future). Here's the method I use for generating the star system:


1.) Generate a number of Stars. Give them each an X and an Y coordinate within the universe's ranges (I actually skew the random number generator a bit so the star system clumps together). You might want to iterate over all stars and check if there is another star within a set distance to collapse to a binary system. I didn't bother with collapsing to binaries yet, but I'll probably add code for generating binary systems later. Each star will also get an age and a spectral type once I get to that. Initially they'll get a random value, maybe I'll look into getting clusters of stars later, but that would require a partial rewrite.
2.) Upon generating, each star system generates a number of planets for itself, starting with a low random distance and then widening the random interval for each new planet and making sure it's at least 20% more then the previous planet's distance.
3.) (not yet implemented from here onward) When a planet is created, it's temperature is determined based upon the distance from the star and the star's spectral type. Then the greenhouse gas pressure is determined and the new temperature is calculated. Using these values we know what gases are possible and a sensible combination will be chosen (No methane and oxygen atmosphere for example). Greenhouse gas concentration is adjusted for the relative power of different greenhouse gases.
4.) The concentration of minerals is determined for each planet.
5.) Planets that fall into the correct temperature range get fluids (water, methane, ammonia, some other possibilities I haven't thought of yet)
6.) Radiation density is determined for each planet, based upon the type of star, distance from the star and any protective gases.
7.) Races are placed on appropriate planets (I've still got to figure out exactly how that'll work)
Logged

Sowelu

  • Bay Watcher
  • I am offishially a penguin.
    • View Profile
Re: System Generation for a sci-fi rougelike
« Reply #2 on: November 05, 2010, 03:23:36 pm »

When I generated a procedural galaxy, I wanted to make sure no two stars were too close to each other but that the grid was non-obvious.  This algorithm lets you have trillions of stars if you want, and a basically infinitely sized galaxy, since it only generates stuff near the player but always generates the same stuff each time--way better on your memory use, especially since you can go ahead and make each system take up megs of RAM if you want.  There's basically no setup time either...it's all free.  I arranged the stars like this:

1) Define the absolute minimum distance apart you want stars to be and halve that number.  If this is 2 light years, then make the galaxy up of 1ly x 1ly x 1ly sectors.  (I use 3 dimensions, you can use 2.)  Define a viewing area M; the player can see anything within the M x M x M sectors that they are centered in.  Define an interference zone I; some calculations will be performed for stars within M+I of the player's location, because it impacts stars that are within distance I from each other.  Maybe you'll call M 500ly and I 50ly.
2) Define a function that takes x,y,z in the range -(M+I)..(M+I) and returns the chance for a potential star in that sector, independent of other nearby stars.  (Modify that function for distance from the galactic core, position along arms, etc.)  For each sector near the player, run that function once, in a specific order--left to right, top to bottom, forward to back.  If it returns true, then position the potential star randomly in that sector using a uniform distribution.
3) Define a function that takes a distance R from other stars within a maximum distance I, and returns the % chance that it will interfere with star generation.  Take your potential star within M, and test it only against the upper-left-forward quadrant within distance I of that star, rolling that function for the distance R to each potential star in that area.  If any of these interference rolls fail, then your potential star is not an actual star.  Do not display it to the player.  If none of them fail, then your potential star is promoted to an actual star.

These steps allow you to only calculate stars in a small range around the player, while letting them roam freely around the galaxy.  Importantly, stars will appear to be distributed in a completely analogue fashion; your 1ly x 1ly x 1ly grid will be completely invisible.  And of course, they can leave an area, come back, and see the exact same stuff that was there when they left.  (Anything they change will need to be written to disk of course.)  It's also very fast.  You can calculate characteristics for each star after step 3.


If you want larger-scale features--dust clouds, regions with a lot of young stars, etc--run this algorithm on two passes.  First generate the big features on a massive scale, then when you generate the stars, have them search for them in all directions instead of just one quadrant.  And yeah, all this stuff is really useful for showing a map to the player--a small map for nearby stars, and a big one for large scale phenomena.

Remember to consider star populations!  You should consider a probability function that takes star location as input, and returns what population it's in (I or II).  Yes, you'll end up with regions of really awful crummy densely packed dead pop II stars.  And yes that's kind of cool.

Supposedly, binary stars outnumber non-binaries.  But I'd recommend calculating their 'type' after step 3, instead of doing any collapsing tricks.  MUCH easier to change later, and this algorithm is totally awesome if I do say so myself and depends on it.  And of course when you get closer to the system, close enough to scan it, just use the star's location as the random number seed to generate its contents.
« Last Edit: November 05, 2010, 03:29:57 pm by Sowelu »
Logged
Some things were made for one thing, for me / that one thing is the sea~
His servers are going to be powered by goat blood and moonlight.
Oh, a biomass/24 hour solar facility. How green!