MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / produceSystem

Method produceSystem

source/game/StarCelestialDatabase.cpp:451–535  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

449}
450
451Maybe<pair<CelestialParameters, HashMap<int, CelestialPlanet>>> CelestialMasterDatabase::produceSystem(
452 RandomSource& random, Vec3I const& location) const {
453 float typeSelector = m_generationInformation.systemTypePerlin.get(location[0], location[1]);
454 String systemTypeName = binnedChoiceFromJson(m_generationInformation.systemTypeBins, typeSelector, "").toString();
455 if (systemTypeName.empty())
456 return {};
457 auto systemType = m_generationInformation.systemTypes.get(systemTypeName);
458
459 CelestialCoordinate systemCoordinate(location);
460 uint64_t systemSeed = random.randu64();
461
462 String prefix = m_generationInformation.systemPrefixNames.select(random);
463 String mid = m_generationInformation.systemNames.select(random);
464 String suffix = m_generationInformation.systemSuffixNames.select(random);
465
466 String systemName = String(strf("{} {} {}", prefix, mid, suffix)).trim();
467
468 systemName = systemName.replace("<onedigit>", strf("{:01d}", random.randu32() % 10));
469 systemName = systemName.replace("<twodigit>", strf("{:02d}", random.randu32() % 100));
470 systemName = systemName.replace("<threedigit>", strf("{:03d}", random.randu32() % 1000));
471 systemName = systemName.replace("<fourdigit>", strf("{:04d}", random.randu32() % 10000));
472
473 CelestialParameters systemParameters = CelestialParameters(systemCoordinate,
474 systemSeed,
475 systemName,
476 jsonMerge(systemType.baseParameters, random.randValueFrom(systemType.variationParameters)));
477
478 List<int> planetaryOrbits;
479 for (int i = 1; i <= m_baseInformation.planetOrbitalLevels; ++i) {
480 if (auto systemOrbitRegion = orbitRegion(systemType.orbitRegions, i)) {
481 if (random.randf() <= systemOrbitRegion->bodyProbability)
482 planetaryOrbits.append(i);
483 }
484 }
485
486 HashMap<int, CelestialPlanet> systemObjects;
487 for (auto planetPair : enumerateIterator(planetaryOrbits)) {
488 auto systemOrbitRegion = orbitRegion(systemType.orbitRegions, planetPair.first);
489
490 auto planetaryTypeName = systemOrbitRegion->planetaryTypes.select(random);
491 if (m_generationInformation.planetaryTypes.contains(planetaryTypeName)) {
492 auto planetaryType = m_generationInformation.planetaryTypes.get(planetaryTypeName);
493 auto planetaryParameters =
494 jsonMerge(planetaryType.baseParameters, random.randValueFrom(planetaryType.variationParameters));
495
496 CelestialCoordinate planetCoordinate(location, planetPair.first);
497 uint64_t planetarySeed = random.randu64();
498 String planetaryName = strf("{} {}", systemName, m_generationInformation.planetarySuffixes.at(planetPair.second));
499
500 CelestialPlanet planet;
501 planet.planetParameters =
502 CelestialParameters(planetCoordinate, planetarySeed, planetaryName, planetaryParameters);
503
504 List<int> satelliteOrbits;
505 for (int i = 1; i <= m_baseInformation.satelliteOrbitalLevels; ++i) {
506 if (satelliteOrbits.size() < planetaryType.maxSatelliteCount
507 && random.randf() < planetaryType.satelliteProbability)
508 satelliteOrbits.append(i);

Callers

nothing calls this directly

Calls 15

binnedChoiceFromJsonFunction · 0.85
StringClass · 0.85
strfFunction · 0.85
CelestialParametersClass · 0.85
enumerateIteratorFunction · 0.85
randu64Method · 0.80
randu32Method · 0.80
randValueFromMethod · 0.80
randfMethod · 0.80
toArrayMethod · 0.80
jsonMergeFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected