//////////////////////// Sector Sector::Sector(int x, int y, int z) { unsigned long _init[4] = { Uint32(x), Uint32(y), Uint32(z), UNIVERSE_SEED }; sx = x; sy = y; sz = z; MTRand rng(_init, 4); MTRand rand(UNIVERSE_SEED); GetCustomSystems(); /* Always place random systems outside the core custom-only region */ if ((x < -CUSTOM_ONLY_RADIUS) || (x > CUSTOM_ONLY_RADIUS-1) || (y < -CUSTOM_ONLY_RADIUS) || (y > CUSTOM_ONLY_RADIUS-1) || (z < -CUSTOM_ONLY_RADIUS) || (z > CUSTOM_ONLY_RADIUS-1)) { int numSystems = (rng.Int32(4,20) * Galaxy::GetSectorDensity(x, y, z)) >> 8; for (int i=0; i<numSystems; i++) { System s; switch (rng.Int32(15)) { case 0: s.numStars = 4; break; case 1: case 2: s.numStars = 3; break; case 3: case 4: case 5: case 6: s.numStars = 2; break; default: s.numStars = 1; break; } s.p.x = rng.Double(SIZE); s.p.y = rng.Double(SIZE); s.p.z = rng.Double(SIZE); s.seed = 0; s.customSys = 0; double spec = rng.Double(1000000.0); // frequencies from wikipedia /*if (spec < 100) { // should be 1 but that is boring s.starType[0] = SystemBody::TYPE_STAR_O; } else if (spec < 1300) { s.starType[0] = SystemBody::TYPE_STAR_B; } else if (spec < 7300) { s.starType[0] = SystemBody::TYPE_STAR_A; } else if (spec < 37300) { s.starType[0] = SystemBody::TYPE_STAR_F; } else if (spec < 113300) { s.starType[0] = SystemBody::TYPE_STAR_G; } else if (spec < 234300) { s.starType[0] = SystemBody::TYPE_STAR_K; } else if (spec < 250000) { s.starType[0] = SystemBody::TYPE_WHITE_DWARF; } else if (spec < 900000) { s.starType[0] = SystemBody::TYPE_STAR_M; } else { s.starType[0] = SystemBody::TYPE_BROWN_DWARF; }*/ //if ((sx > 50) || (sx < -50) || // (sy > 50) || (sy < -50)) // Frequencies are low enough that we probably don't need this anymore. if (isqrt(1+sx*sx+sy*sy) > 10) { if (spec < 1) { s.starType[0] = SystemBody::TYPE_STAR_IM_BH; // These frequencies are made up } else if (spec < 3) { s.starType[0] = SystemBody::TYPE_STAR_S_BH; } else if (spec < 5) { s.starType[0] = SystemBody::TYPE_STAR_O_WF; } else if (spec < 8) { s.starType[0] = SystemBody::TYPE_STAR_B_WF; } else if (spec < 12) { s.starType[0] = SystemBody::TYPE_STAR_M_WF; } else if (spec < 15) { s.starType[0] = SystemBody::TYPE_STAR_K_HYPER_GIANT; } else if (spec < 18) { s.starType[0] = SystemBody::TYPE_STAR_G_HYPER_GIANT; } else if (spec < 23) { s.starType[0] = SystemBody::TYPE_STAR_O_HYPER_GIANT; } else if (spec < 28) { s.starType[0] = SystemBody::TYPE_STAR_A_HYPER_GIANT; } else if (spec < 33) { s.starType[0] = SystemBody::TYPE_STAR_F_HYPER_GIANT; } else if (spec < 41) { s.starType[0] = SystemBody::TYPE_STAR_B_HYPER_GIANT; } else if (spec < 48) { s.starType[0] = SystemBody::TYPE_STAR_M_HYPER_GIANT; } else if (spec < 58) { s.starType[0] = SystemBody::TYPE_STAR_K_SUPER_GIANT; } else if (spec < 68) { s.starType[0] = SystemBody::TYPE_STAR_G_SUPER_GIANT; } else if (spec < 78) { s.starType[0] = SystemBody::TYPE_STAR_O_SUPER_GIANT; } else if (spec < 88) { s.starType[0] = SystemBody::TYPE_STAR_A_SUPER_GIANT; } else if (spec < 98) { s.starType[0] = SystemBody::TYPE_STAR_F_SUPER_GIANT; } else if (spec < 108) { s.starType[0] = SystemBody::TYPE_STAR_B_SUPER_GIANT; } else if (spec < 158) { s.starType[0] = SystemBody::TYPE_STAR_M_SUPER_GIANT; } else if (spec < 208) { s.starType[0] = SystemBody::TYPE_STAR_K_GIANT; } else if (spec < 250) { s.starType[0] = SystemBody::TYPE_STAR_G_GIANT; } else if (spec < 300) { s.starType[0] = SystemBody::TYPE_STAR_O_GIANT; } else if (spec < 350) { s.starType[0] = SystemBody::TYPE_STAR_A_GIANT; } else if (spec < 400) { s.starType[0] = SystemBody::TYPE_STAR_F_GIANT; } else if (spec < 500) { s.starType[0] = SystemBody::TYPE_STAR_B_GIANT; } else if (spec < 700) { s.starType[0] = SystemBody::TYPE_STAR_M_GIANT; } else if (spec < 800) { s.starType[0] = SystemBody::TYPE_STAR_O; // should be 1 but that is boring } else if (spec < 2000) { // spec < 1300 / 20500 s.starType[0] = SystemBody::TYPE_STAR_B; } else if (spec < 8000) { // spec < 7300 s.starType[0] = SystemBody::TYPE_STAR_A; } else if (spec < 37300) { // spec < 37300 s.starType[0] = SystemBody::TYPE_STAR_F; } else if (spec < 113300) { // spec < 113300 s.starType[0] = SystemBody::TYPE_STAR_G; } else if (spec < 234300) { // spec < 234300 s.starType[0] = SystemBody::TYPE_STAR_K; } else if (spec < 250000) { // spec < 250000 s.starType[0] = SystemBody::TYPE_WHITE_DWARF; } else if (spec < 900000) { //spec < 900000 s.starType[0] = SystemBody::TYPE_STAR_M; } else { s.starType[0] = SystemBody::TYPE_BROWN_DWARF; } } else { if (spec < 100) { // should be 1 but that is boring s.starType[0] = SystemBody::TYPE_STAR_O; } else if (spec < 1300) { s.starType[0] = SystemBody::TYPE_STAR_B; } else if (spec < 7300) { s.starType[0] = SystemBody::TYPE_STAR_A; } else if (spec < 37300) { s.starType[0] = SystemBody::TYPE_STAR_F; } else if (spec < 113300) { s.starType[0] = SystemBody::TYPE_STAR_G; } else if (spec < 234300) { s.starType[0] = SystemBody::TYPE_STAR_K; } else if (spec < 250000) { s.starType[0] = SystemBody::TYPE_WHITE_DWARF; } else if (spec < 900000) { s.starType[0] = SystemBody::TYPE_STAR_M; } else { s.starType[0] = SystemBody::TYPE_BROWN_DWARF; } } //printf("%d: %d%\n", sx, sy); if (s.numStars > 1) { s.starType[1] = SystemBody::BodyType(rng.Int32(SystemBody::TYPE_STAR_MIN, s.starType[0])); if (s.numStars > 2) { s.starType[2] = SystemBody::BodyType(rng.Int32(SystemBody::TYPE_STAR_MIN, s.starType[0])); s.starType[3] = SystemBody::BodyType(rng.Int32(SystemBody::TYPE_STAR_MIN, s.starType[2])); } } if ((s.starType[0] <= SystemBody::TYPE_STAR_A) && (rng.Int32(10)==0)) { // make primary a giant. never more than one giant in a system // while if (isqrt(1+sx*sx+sy*sy) > 10) { if (rand.Int32(0,1000) >= 999) { s.starType[0] = SystemBody::TYPE_STAR_B_HYPER_GIANT; } else if (rand.Int32(0,1000) >= 998) { s.starType[0] = SystemBody::TYPE_STAR_O_HYPER_GIANT; } else if (rand.Int32(0,1000) >= 997) { s.starType[0] = SystemBody::TYPE_STAR_K_HYPER_GIANT; } else if (rand.Int32(0,1000) >= 995) { s.starType[0] = SystemBody::TYPE_STAR_B_SUPER_GIANT; } else if (rand.Int32(0,1000) >= 993) { s.starType[0] = SystemBody::TYPE_STAR_O_SUPER_GIANT; } else if (rand.Int32(0,1000) >= 990) { s.starType[0] = SystemBody::TYPE_STAR_K_SUPER_GIANT; } else if (rand.Int32(0,1000) >= 985) { s.starType[0] = SystemBody::TYPE_STAR_B_GIANT; } else if (rand.Int32(0,1000) >= 980) { s.starType[0] = SystemBody::TYPE_STAR_O_GIANT; } else if (rand.Int32(0,1000) >= 975) { s.starType[0] = SystemBody::TYPE_STAR_K_GIANT; } else if (rand.Int32(0,1000) >= 950) { s.starType[0] = SystemBody::TYPE_STAR_M_HYPER_GIANT; } else if (rand.Int32(0,1000) >= 875) { s.starType[0] = SystemBody::TYPE_STAR_M_SUPER_GIANT; } else { s.starType[0] = SystemBody::TYPE_STAR_M_GIANT; } } else if (isqrt(1+sx*sx+sy*sy) > 5) s.starType[0] = SystemBody::TYPE_STAR_M_GIANT; else s.starType[0] = SystemBody::TYPE_STAR_M; //printf("%d: %d%\n", sx, sy); } s.name = GenName(s, rng); //printf("%s: \n", s.name.c_str()); m_systems.push_back(s); } }
//////////////////////// Sector Sector::Sector(const SystemPath& path) : m_factionsAssigned(false) { PROFILE_SCOPED() Uint32 _init[4] = { Uint32(path.sectorX), Uint32(path.sectorY), Uint32(path.sectorZ), UNIVERSE_SEED }; Random rng(_init, 4); sx = path.sectorX; sy = path.sectorY; sz = path.sectorZ; GetCustomSystems(rng); int customCount = m_systems.size(); /* Always place random systems outside the core custom-only region */ if ((path.sectorX < -CUSTOM_ONLY_RADIUS) || (path.sectorX > CUSTOM_ONLY_RADIUS-1) || (path.sectorY < -CUSTOM_ONLY_RADIUS) || (path.sectorY > CUSTOM_ONLY_RADIUS-1) || (path.sectorZ < -CUSTOM_ONLY_RADIUS) || (path.sectorZ > CUSTOM_ONLY_RADIUS-1)) { int numSystems = (rng.Int32(4,20) * Galaxy::GetSectorDensity(path.sectorX, path.sectorY, path.sectorZ)) >> 8; for (int i=0; i<numSystems; i++) { System s(sx, sy, sz, customCount + i); switch (rng.Int32(15)) { case 0: s.numStars = 4; break; case 1: case 2: s.numStars = 3; break; case 3: case 4: case 5: case 6: s.numStars = 2; break; default: s.numStars = 1; break; } s.p.x = rng.Double(SIZE); s.p.y = rng.Double(SIZE); s.p.z = rng.Double(SIZE); s.seed = 0; s.customSys = 0; /* * 0 - ~500ly from sol: explored * ~500ly - ~700ly (65-90 sectors): gradual * ~700ly+: unexplored */ int dist = isqrt(1 + sx*sx + sy*sy + sz*sz); s.explored = ((dist <= 90) && ( dist <= 65 || rng.Int32(dist) <= 40)) || Faction::IsHomeSystem(SystemPath(sx, sy, sz, customCount + i)); Uint32 weight = rng.Int32(1000000); // Frequencies are low enough that we probably don't need this anymore. if (isqrt(1+sx*sx+sy*sy) > 10) { if (weight < 1) { s.starType[0] = SystemBody::TYPE_STAR_IM_BH; // These frequencies are made up } else if (weight < 3) { s.starType[0] = SystemBody::TYPE_STAR_S_BH; } else if (weight < 5) { s.starType[0] = SystemBody::TYPE_STAR_O_WF; } else if (weight < 8) { s.starType[0] = SystemBody::TYPE_STAR_B_WF; } else if (weight < 12) { s.starType[0] = SystemBody::TYPE_STAR_M_WF; } else if (weight < 15) { s.starType[0] = SystemBody::TYPE_STAR_K_HYPER_GIANT; } else if (weight < 18) { s.starType[0] = SystemBody::TYPE_STAR_G_HYPER_GIANT; } else if (weight < 23) { s.starType[0] = SystemBody::TYPE_STAR_O_HYPER_GIANT; } else if (weight < 28) { s.starType[0] = SystemBody::TYPE_STAR_A_HYPER_GIANT; } else if (weight < 33) { s.starType[0] = SystemBody::TYPE_STAR_F_HYPER_GIANT; } else if (weight < 41) { s.starType[0] = SystemBody::TYPE_STAR_B_HYPER_GIANT; } else if (weight < 48) { s.starType[0] = SystemBody::TYPE_STAR_M_HYPER_GIANT; } else if (weight < 58) { s.starType[0] = SystemBody::TYPE_STAR_K_SUPER_GIANT; } else if (weight < 68) { s.starType[0] = SystemBody::TYPE_STAR_G_SUPER_GIANT; } else if (weight < 78) { s.starType[0] = SystemBody::TYPE_STAR_O_SUPER_GIANT; } else if (weight < 88) { s.starType[0] = SystemBody::TYPE_STAR_A_SUPER_GIANT; } else if (weight < 98) { s.starType[0] = SystemBody::TYPE_STAR_F_SUPER_GIANT; } else if (weight < 108) { s.starType[0] = SystemBody::TYPE_STAR_B_SUPER_GIANT; } else if (weight < 158) { s.starType[0] = SystemBody::TYPE_STAR_M_SUPER_GIANT; } else if (weight < 208) { s.starType[0] = SystemBody::TYPE_STAR_K_GIANT; } else if (weight < 250) { s.starType[0] = SystemBody::TYPE_STAR_G_GIANT; } else if (weight < 300) { s.starType[0] = SystemBody::TYPE_STAR_O_GIANT; } else if (weight < 350) { s.starType[0] = SystemBody::TYPE_STAR_A_GIANT; } else if (weight < 400) { s.starType[0] = SystemBody::TYPE_STAR_F_GIANT; } else if (weight < 500) { s.starType[0] = SystemBody::TYPE_STAR_B_GIANT; } else if (weight < 700) { s.starType[0] = SystemBody::TYPE_STAR_M_GIANT; } else if (weight < 800) { s.starType[0] = SystemBody::TYPE_STAR_O; // should be 1 but that is boring } else if (weight < 2000) { // weight < 1300 / 20500 s.starType[0] = SystemBody::TYPE_STAR_B; } else if (weight < 8000) { // weight < 7300 s.starType[0] = SystemBody::TYPE_STAR_A; } else if (weight < 37300) { // weight < 37300 s.starType[0] = SystemBody::TYPE_STAR_F; } else if (weight < 113300) { // weight < 113300 s.starType[0] = SystemBody::TYPE_STAR_G; } else if (weight < 234300) { // weight < 234300 s.starType[0] = SystemBody::TYPE_STAR_K; } else if (weight < 250000) { // weight < 250000 s.starType[0] = SystemBody::TYPE_WHITE_DWARF; } else if (weight < 900000) { //weight < 900000 s.starType[0] = SystemBody::TYPE_STAR_M; } else { s.starType[0] = SystemBody::TYPE_BROWN_DWARF; } } else { if (weight < 100) { // should be 1 but that is boring s.starType[0] = SystemBody::TYPE_STAR_O; } else if (weight < 1300) { s.starType[0] = SystemBody::TYPE_STAR_B; } else if (weight < 7300) { s.starType[0] = SystemBody::TYPE_STAR_A; } else if (weight < 37300) { s.starType[0] = SystemBody::TYPE_STAR_F; } else if (weight < 113300) { s.starType[0] = SystemBody::TYPE_STAR_G; } else if (weight < 234300) { s.starType[0] = SystemBody::TYPE_STAR_K; } else if (weight < 250000) { s.starType[0] = SystemBody::TYPE_WHITE_DWARF; } else if (weight < 900000) { s.starType[0] = SystemBody::TYPE_STAR_M; } else { s.starType[0] = SystemBody::TYPE_BROWN_DWARF; } } //Output("%d: %d%\n", sx, sy); if (s.numStars > 1) { s.starType[1] = SystemBody::BodyType(rng.Int32(SystemBody::TYPE_STAR_MIN, s.starType[0])); if (s.numStars > 2) { s.starType[2] = SystemBody::BodyType(rng.Int32(SystemBody::TYPE_STAR_MIN, s.starType[0])); s.starType[3] = SystemBody::BodyType(rng.Int32(SystemBody::TYPE_STAR_MIN, s.starType[2])); } } if ((s.starType[0] <= SystemBody::TYPE_STAR_A) && (rng.Int32(10)==0)) { // make primary a giant. never more than one giant in a system // while if (isqrt(1+sx*sx+sy*sy) > 10) { weight = rng.Int32(1000); if (weight >= 999) { s.starType[0] = SystemBody::TYPE_STAR_B_HYPER_GIANT; } else if (weight >= 998) { s.starType[0] = SystemBody::TYPE_STAR_O_HYPER_GIANT; } else if (weight >= 997) { s.starType[0] = SystemBody::TYPE_STAR_K_HYPER_GIANT; } else if (weight >= 995) { s.starType[0] = SystemBody::TYPE_STAR_B_SUPER_GIANT; } else if (weight >= 993) { s.starType[0] = SystemBody::TYPE_STAR_O_SUPER_GIANT; } else if (weight >= 990) { s.starType[0] = SystemBody::TYPE_STAR_K_SUPER_GIANT; } else if (weight >= 985) { s.starType[0] = SystemBody::TYPE_STAR_B_GIANT; } else if (weight >= 980) { s.starType[0] = SystemBody::TYPE_STAR_O_GIANT; } else if (weight >= 975) { s.starType[0] = SystemBody::TYPE_STAR_K_GIANT; } else if (weight >= 950) { s.starType[0] = SystemBody::TYPE_STAR_M_HYPER_GIANT; } else if (weight >= 875) { s.starType[0] = SystemBody::TYPE_STAR_M_SUPER_GIANT; } else { s.starType[0] = SystemBody::TYPE_STAR_M_GIANT; } } else if (isqrt(1+sx*sx+sy*sy) > 5) s.starType[0] = SystemBody::TYPE_STAR_M_GIANT; else s.starType[0] = SystemBody::TYPE_STAR_M; //Output("%d: %d%\n", sx, sy); } s.name = GenName(s, customCount + i, rng); //Output("%s: \n", s.name.c_str()); m_systems.push_back(s); } }