bool SectorRandomSystemsGenerator::Apply(Random& rng, RefCountedPtr<Galaxy> galaxy, RefCountedPtr<Sector> sector, GalaxyGenerator::SectorConfig* config) { /* Always place random systems outside the core custom-only region */ if (config->isCustomOnly) return true; const int sx = sector->sx; const int sy = sector->sy; const int sz = sector->sz; const int customCount = static_cast<Uint32>(sector->m_systems.size()); const Sint64 dist = (1 + sx*sx + sy*sy + sz*sz); const Sint64 freq = (1 + sx * sx + sy * sy); const int numSystems = (rng.Int32(4,20) * galaxy->GetSectorDensity(sx, sy, sz)) >> 8; sector->m_systems.reserve(numSystems); for (int i=0; i<numSystems; i++) { Sector::System s(sector.Get(), sx, sy, sz, customCount + i); switch (rng.Int32(15)) { case 0: s.m_numStars = 4; break; case 1: case 2: s.m_numStars = 3; break; case 3: case 4: case 5: case 6: s.m_numStars = 2; break; default: s.m_numStars = 1; break; } s.m_pos.x = rng.Double(Sector::SIZE); s.m_pos.y = rng.Double(Sector::SIZE); s.m_pos.z = rng.Double(Sector::SIZE); /* * 0 - ~500ly from sol: explored * ~500ly - ~700ly (65-90 sectors): gradual * ~700ly+: unexplored */ if (((dist <= Square(90)) && ( dist <= Square(65) || rng.Int32(dist) <= Square(40))) || galaxy->GetFactions()->IsHomeSystem(SystemPath(sx, sy, sz, customCount + i))) s.m_explored = StarSystem::eEXPLORED_AT_START; else s.m_explored = StarSystem::eUNEXPLORED; // Frequencies are low enough that we probably don't need this anymore. if (freq > Square(10)) { const Uint32 weight = rng.Int32(1000000); if (weight < 1) { s.m_starType[0] = SystemBody::TYPE_STAR_IM_BH; // These frequencies are made up } else if (weight < 3) { s.m_starType[0] = SystemBody::TYPE_STAR_S_BH; } else if (weight < 5) { s.m_starType[0] = SystemBody::TYPE_STAR_O_WF; } else if (weight < 8) { s.m_starType[0] = SystemBody::TYPE_STAR_B_WF; } else if (weight < 12) { s.m_starType[0] = SystemBody::TYPE_STAR_M_WF; } else if (weight < 15) { s.m_starType[0] = SystemBody::TYPE_STAR_K_HYPER_GIANT; } else if (weight < 18) { s.m_starType[0] = SystemBody::TYPE_STAR_G_HYPER_GIANT; } else if (weight < 23) { s.m_starType[0] = SystemBody::TYPE_STAR_O_HYPER_GIANT; } else if (weight < 28) { s.m_starType[0] = SystemBody::TYPE_STAR_A_HYPER_GIANT; } else if (weight < 33) { s.m_starType[0] = SystemBody::TYPE_STAR_F_HYPER_GIANT; } else if (weight < 41) { s.m_starType[0] = SystemBody::TYPE_STAR_B_HYPER_GIANT; } else if (weight < 48) { s.m_starType[0] = SystemBody::TYPE_STAR_M_HYPER_GIANT; } else if (weight < 58) { s.m_starType[0] = SystemBody::TYPE_STAR_K_SUPER_GIANT; } else if (weight < 68) { s.m_starType[0] = SystemBody::TYPE_STAR_G_SUPER_GIANT; } else if (weight < 78) { s.m_starType[0] = SystemBody::TYPE_STAR_O_SUPER_GIANT; } else if (weight < 88) { s.m_starType[0] = SystemBody::TYPE_STAR_A_SUPER_GIANT; } else if (weight < 98) { s.m_starType[0] = SystemBody::TYPE_STAR_F_SUPER_GIANT; } else if (weight < 108) { s.m_starType[0] = SystemBody::TYPE_STAR_B_SUPER_GIANT; } else if (weight < 158) { s.m_starType[0] = SystemBody::TYPE_STAR_M_SUPER_GIANT; } else if (weight < 208) { s.m_starType[0] = SystemBody::TYPE_STAR_K_GIANT; } else if (weight < 250) { s.m_starType[0] = SystemBody::TYPE_STAR_G_GIANT; } else if (weight < 300) { s.m_starType[0] = SystemBody::TYPE_STAR_O_GIANT; } else if (weight < 350) { s.m_starType[0] = SystemBody::TYPE_STAR_A_GIANT; } else if (weight < 400) { s.m_starType[0] = SystemBody::TYPE_STAR_F_GIANT; } else if (weight < 500) { s.m_starType[0] = SystemBody::TYPE_STAR_B_GIANT; } else if (weight < 700) { s.m_starType[0] = SystemBody::TYPE_STAR_M_GIANT; } else if (weight < 800) { s.m_starType[0] = SystemBody::TYPE_STAR_O; // should be 1 but that is boring } else if (weight < 2000) { // weight < 1300 / 20500 s.m_starType[0] = SystemBody::TYPE_STAR_B; } else if (weight < 8000) { // weight < 7300 s.m_starType[0] = SystemBody::TYPE_STAR_A; } else if (weight < 37300) { // weight < 37300 s.m_starType[0] = SystemBody::TYPE_STAR_F; } else if (weight < 113300) { // weight < 113300 s.m_starType[0] = SystemBody::TYPE_STAR_G; } else if (weight < 234300) { // weight < 234300 s.m_starType[0] = SystemBody::TYPE_STAR_K; } else if (weight < 250000) { // weight < 250000 s.m_starType[0] = SystemBody::TYPE_WHITE_DWARF; } else if (weight < 900000) { //weight < 900000 s.m_starType[0] = SystemBody::TYPE_STAR_M; } else { s.m_starType[0] = SystemBody::TYPE_BROWN_DWARF; } } else { const Uint32 weight = rng.Int32(1000000); if (weight < 100) { // should be 1 but that is boring s.m_starType[0] = SystemBody::TYPE_STAR_O; } else if (weight < 1300) { s.m_starType[0] = SystemBody::TYPE_STAR_B; } else if (weight < 7300) { s.m_starType[0] = SystemBody::TYPE_STAR_A; } else if (weight < 37300) { s.m_starType[0] = SystemBody::TYPE_STAR_F; } else if (weight < 113300) { s.m_starType[0] = SystemBody::TYPE_STAR_G; } else if (weight < 234300) { s.m_starType[0] = SystemBody::TYPE_STAR_K; } else if (weight < 250000) { s.m_starType[0] = SystemBody::TYPE_WHITE_DWARF; } else if (weight < 900000) { s.m_starType[0] = SystemBody::TYPE_STAR_M; } else { s.m_starType[0] = SystemBody::TYPE_BROWN_DWARF; } } //Output("%d: %d%\n", sx, sy); if (s.m_numStars > 1) { s.m_starType[1] = SystemBody::BodyType(rng.Int32(SystemBody::TYPE_STAR_MIN, s.m_starType[0])); if (s.m_numStars > 2) { s.m_starType[2] = SystemBody::BodyType(rng.Int32(SystemBody::TYPE_STAR_MIN, s.m_starType[0])); s.m_starType[3] = SystemBody::BodyType(rng.Int32(SystemBody::TYPE_STAR_MIN, s.m_starType[2])); } } if ((s.m_starType[0] <= SystemBody::TYPE_STAR_A) && (rng.Int32(10)==0)) { // make primary a giant. never more than one giant in a system if (freq > Square(10)) { const Uint32 weight = rng.Int32(1000); if (weight >= 999) { s.m_starType[0] = SystemBody::TYPE_STAR_B_HYPER_GIANT; } else if (weight >= 998) { s.m_starType[0] = SystemBody::TYPE_STAR_O_HYPER_GIANT; } else if (weight >= 997) { s.m_starType[0] = SystemBody::TYPE_STAR_K_HYPER_GIANT; } else if (weight >= 995) { s.m_starType[0] = SystemBody::TYPE_STAR_B_SUPER_GIANT; } else if (weight >= 993) { s.m_starType[0] = SystemBody::TYPE_STAR_O_SUPER_GIANT; } else if (weight >= 990) { s.m_starType[0] = SystemBody::TYPE_STAR_K_SUPER_GIANT; } else if (weight >= 985) { s.m_starType[0] = SystemBody::TYPE_STAR_B_GIANT; } else if (weight >= 980) { s.m_starType[0] = SystemBody::TYPE_STAR_O_GIANT; } else if (weight >= 975) { s.m_starType[0] = SystemBody::TYPE_STAR_K_GIANT; } else if (weight >= 950) { s.m_starType[0] = SystemBody::TYPE_STAR_M_HYPER_GIANT; } else if (weight >= 875) { s.m_starType[0] = SystemBody::TYPE_STAR_M_SUPER_GIANT; } else { s.m_starType[0] = SystemBody::TYPE_STAR_M_GIANT; } } else if (freq > Square(5)) s.m_starType[0] = SystemBody::TYPE_STAR_M_GIANT; else s.m_starType[0] = SystemBody::TYPE_STAR_M; //Output("%d: %d%\n", sx, sy); } s.m_name = GenName(galaxy, *sector, s, customCount + i, rng); //Output("%s: \n", s.m_name.c_str()); sector->m_systems.push_back(s); } return true; }