Map Generation

From Star Ruler

Jump to: navigation, search

Map Generation

uint sysCount = getGameSetting("SYSTEM_COUNT",150);
- Determines the number of stars to generate

float rad, theta;
- variable holders

float maxRad = sqrt(sysCount) * getGameSetting("MAP_SYSTEM_SPACING", 3000.f) * orbitRadiusFactor / 70.f; //Magic number = old base setting
- This is the maximum orbit of stars from the center object (Quasar)

float maxHgt = maxRad / 4.f;
- Set galaxy depth (from top to bottom, presume 0 is mid plane)

if(getGameSetting("MAP_FLATTEN", 0) == 1)
maxHgt = 0;
- Over rides map depth if player has clicked flatten map option.

makeOddities = getGameSetting("MAP_ODDITIES", 1.f) != 0.f;
- Generates Comets/Asteroids for map.

uint noticePctInc;
if(sysCount < 50)
noticePctInc = 50;
else if(sysCount < 1000)
noticePctInc = 25;
else if(sysCount < 5000)
noticePctInc = 10;
noticePctInc = 5;
- Controls the Percentage loading update while generating the galaxy.

float minRad = 250.f;
- Minimal distance between stars(?).

uint sysIndex = 0;
if(sysCount >= 10) {
minRad = makeQuasar(Glx, vector(0,0,0), sqrt(float(sysCount) / 50.f)) + (12.f * orbitRadiusFactor);
- If Galaxy has at least 10 stars create a Quasar star in the center of the system, this counts as the first star (so if play selected 10 stars only 9 would be actual stars).

for(; sysIndex < sysCount; ++sysIndex) {
Error on the line above? (Semi colon)

- This is the distribution algorithm... -
theta = randomf(twoPi);
rad = range(minRad, maxRad, pow(randomf(1.f),0.85f));

vector position(rad * cos(theta), pow(1.f - (rad/maxRad), 2.f) * maxHgt * (randomf(1.f) - 0.5f), rad * sin(theta));

- End of distribution algrathm -

float sysType = randomf(100.f);
- Setup what type of star to generate on a random percentage system.

if(sysType < 96)
makeStandardSystem(Glx, position);
- 96% chance of using the standard system method to create a star and planets.

else if(sysType >= 96 && sysType <= 98)
makeBrownDwarf(Glx, position);
- 3% chance of creating a Brown Dwarf star system (code not in by standard!).

makeSupernova(Glx, position);
- Everything else is a Star waiting to go nova! (1% chance)

- Everything below this line simply informs the user of current creation process.

if(float(sysIndex + 1) / float(sysCount) > float(nextNoticePct) / 100.f) {
updateLoadScreen(" Generating map... " + nextNoticePct + "%");
nextNoticePct += noticePctInc;

System Generation

Apologies for formatting not used to Wiki editing!

Array options:

.Temperature - int value that controls star colour (low value red, mid value yellow, high value white/blue)
.Radius - int value that controls the stars radius (how large it is)
.Brightness - int value that controls luminosity (how bright it is)

A little help in getting going with map mods, first a break down of what things do from what I can work out.

void makeStandardSystem(Galaxy@ glx, vector pos) {

This line simple acts like a method, it is called "makeStandardSystem" and will use "Galaxy", glx I've not established but "vector pos" are the co-ordinates of the star system that will be generated.

System@ sys;
System_Desc desc;
desc.Position = pos;
desc.AutoStar = false;

@sys = @glx.createSystem(desc);

... and now broken down...

System_Desc desc;
- This is an array which holds all the system details in an array.
desc.Position = pos;
- The actual position of the star in the galaxy.
desc.AutoStar = false;
- I think if set to true then it generate a star using random settings.
@sys = @glx.createSystem(desc);
- Places the holder and generates the star if above is true otherwise it will use the next bit below to create the star properties.

Star_Desc desc;
desc.Temperature = randomf(2000,21000);
desc.Radius = randomf(30.f + (desc.Temperature / 1000.f),60.f + (desc.Temperature / 600.f)) * starSizeFactor;
desc.Brightness = 1;


Star_Dec desc;
- This is an array to hold all the star details.
desc.Temperature = randomf(2000, 21000);
- this sets the star colour, I haven't established when the generator uses different colours but lower values generate red, then yellow to white/blue at the higher end. It is not possible to generate anything other than red (so no black holes!) The values can be set from 0-infinite but there is a point where the value becomes pointless.
desc.Radius = randomf(30.f + (desc.Temperature / 1000.f),60.f + (desc.Temperature / 600.f)) * starSizeFactor;
- In this example it uses the star temprature to generate a min/max size to randomly choose from then times it by "starSizeFactor" (default 2.5) this helps keep things in prespective, but can be set to any valid integer, large numbers make it hard for planet spawns to occur.
desc.Brightness = 1;
- Specifies how bright the star is, supports float values (eg. 0.5) anything much above 8 is very bright and tends to be reserved for lifeless systems! 1 is default.
- generates the star based on the array information

Planet Formation

Array options:

.PlanetRadius - Planet size.
.OrbitRadius - Planet's orbit location.
.OrbitEccentricity - needs more testing!
.setPlanetType - Set the type of planet e.g. Rock, Gas, Lava, etc. The type must be in the XML document "PlanetTypes"

Planet formation is done during the same method as star creation (above), this means that you can be very specific with how many and what types of planets will spawn if you decide to generate specific stars with many claimable planets to none.

float oRad = orbitRadiusFactor;
Planet_Desc plDesc;
int pCount = rand(1, 3) + rand(1, 3);

float oRad = orbitRadiusFactor;
- This creates an orbit variable to hold the orbit distance later on.

Planet_Desc plDesc;
- This is an array to hold all the planet details

int pCount = rand(1,3)+rand(1,3);

- This creates the number of planets to generate in this system, can be replaced with integers and the upper limit will be forced by maximum orbit radius (a static variable)

float pRad = randomf(minPlanetRadius, maxPlanetRadius), pVol = pRad * pRad * pRad * 4.189f;
plDesc.PlanetRadius = pRad;
oRad += randomf(1.f, 2.5f) * orbitRadiusFactor;
plDesc.OrbitRadius = oRad;
plDesc.OrbitEccentricity = randomf(0.5f, 1.5f);

This is the bit of code that generates the planet, it is in a for loop to ensure that every planet (pCount) is created.

float pRad = randomf(minPlanetRadius, maxPlanetRadius), pVol = pRad * pRad * pRad * 4.189f;
- This sizes the planet in the star system we just generated, using static variables minPlanetRadius and maxPlanetRadius the planet will be a random size, again this can be changed to any integer. pVol gives the volume of the sphere (our planet) used later for ore values.
plDesc.PlanetRadius = pRad;
- Set the planets radius to the planet array
oRad += randomf(1.f, 2.5f) * orbitRadiusFactor;
- This places the planet in orbit around our star, orbit RadiusFactor is a static variable, if you have intend to generate a lot of planets adjust the upper value here too.
plDesc.OrbitRadius = oRad;
- Sets the planet orbit details in the array.
plDesc.OrbitEccentricity = randomf(0.5f, 1.5f);
-Not 100% sure, but would appear to affect the orbit path, more testing needed...
plDesc.setPlanetType( getPlanetTypeID( "rock2" ));
This is an extra line not normally needed that lets you specify the exact planet type that is being generated, in this example a rocky planet using texture 2 (from the default game setup, see the array note for where planet types are created).

Planet@ pl = sys.makePlanet(plDesc);
pl.setStructureSpace((pctBetween(pRad, minPlanetRadius, maxPlanetRadius) * 0.5f + 0.5f) * maxStructSpace);

The first line generates the actual planet, the second line tells the planet how many structures are allowed to be placed upon it. This takes in to account the actual planets size, its potential min/max size and the maximum allowed structure space.

Finally the script generates some ore, the planets maximum damage or hit points and any moons, this is all done below and isn't any more complicated than above so I won't break this down.

Object@ planet = pl.toObject();

State@ ore = planet.getState(strOre);
ore.max = pVol * 6000.f;
ore.val = ore.max * (0.5f + randomf(0.5f));

planet.getState(strDmg).max = pVol * 1000000.f;

uint moons = 0;

while(randomf(1.f) < 0.35f && moons < 6) {

if(moons == 0 && randomf(1.f) < 0.10f) {

Personal tools