MCPcopy Create free account
hub / github.com/SurceBeats/Atlas / __init__

Method __init__

pymodules/__universe_init_solarsystem.py:11–83  ·  view source on GitHub ↗
(self, seed, index, constants)

Source from the content-addressed store, hash-verified

9
10class SolarSystem:
11 def __init__(self, seed, index, constants):
12 self.seed = seed
13 self.index = index
14 self.constants = constants
15 random.seed(seed)
16 self.name = generate_name(seed + index, "system")
17 self.num_planets = random.randint(1, 6)
18 self.planets = {}
19
20 self.star_system_type = self.determine_star_system_type()
21 self.stars = self.generate_stars()
22
23 for i in range(self.num_planets):
24 from pymodules.__universe_init_planet import Planet
25
26 planet_seed = int(
27 hashlib.sha256(f"{self.seed}-{seedmaster(4)}-{i}".encode()).hexdigest(),
28 16,
29 )
30 planet_name = generate_name(planet_seed, "planet")
31
32 star_mass = self.constants.M_SUN
33 if self.stars:
34 star_type = self.stars[0]["Type"]
35 mass_factors = {"Red Dwarf": 0.2, "Yellow Dwarf": 1.0, "Blue Giant": 10.0, "Red Giant": 1.2, "White Dwarf": 0.6, "Neutron Star": 1.4} # 0.08-0.45 solar masses # ~1 solar mass (like our Sun) # 2-50+ solar masses # 0.3-8 solar masses (evolved stars) # 0.5-1.4 solar masses # 1.1-2.2 solar masses
36 star_mass *= mass_factors.get(star_type, 1.0)
37
38 self.planets[i] = Planet(planet_seed, planet_name, self.constants, star_mass)
39
40 extra_planet_probabilities = {
41 6: 0.35,
42 7: 0.25,
43 8: 0.10,
44 9: 0.05,
45 # Beyond ten planets, a frontier world (one of the FRONTIER_TYPES)
46 10: 0.30,
47 }
48
49 for extra_planet_index, probability in extra_planet_probabilities.items():
50 if self.num_planets != extra_planet_index:
51 break
52
53 extra_seed = int(
54 hashlib.sha256(f"{self.seed}-extra-planet-{extra_planet_index}".encode()).hexdigest(),
55 16,
56 )
57
58 random.seed(extra_seed)
59
60 if random.random() < probability:
61 from pymodules.__universe_init_planet import Planet, FRONTIER_TYPES, FRONTIER_SLOTS
62
63 # The 11th planet's type comes from one of FRONTIER_SLOTS slots; one with no
64 # type yet means no 11th planet
65 frontier_type = None
66 if extra_planet_index == 10:
67 slot = random.randint(1, FRONTIER_SLOTS)
68 if slot > len(FRONTIER_TYPES):

Callers

nothing calls this directly

Calls 8

generate_starsMethod · 0.95
generate_nameFunction · 0.90
seedmasterFunction · 0.90
PlanetClass · 0.90
seedMethod · 0.80
randintMethod · 0.45
randomMethod · 0.45

Tested by

no test coverage detected