def generate_systems(pos_list, gsd): """ Generates and populates star systems at all positions in specified list. """ sys_list = [] for position in pos_list: star_type = pick_star_type(gsd.age) system = fo.create_system(star_type, "", position.x, position.y) if system == fo.invalid_object(): # create system failed, report an error and try to continue with next position util.report_error( "Python generate_systems: create system at position (%f, %f) failed" % (position.x, position.y)) continue sys_list.append(system) for orbit in range(fo.sys_get_num_orbits(system)): # check for each orbit if a planet shall be created by determining planet size planet_size = planets.calc_planet_size(star_type, orbit, gsd.planetDensity, gsd.shape) if planet_size in planets.planet_sizes: # ok, we want a planet, determine planet type and generate the planet planet_type = planets.calc_planet_type(star_type, orbit, planet_size) if fo.create_planet(planet_size, planet_type, system, orbit, "") == fo.invalid_object(): # create planet failed, report an error and try to continue with next orbit util.report_error( "Python generate_systems: create planet in system %d failed" % system) return sys_list
def generate_systems(pos_list, gsd): """ Generates and populates star systems at all positions in specified list. """ sys_list = [] for position in pos_list: star_type = pick_star_type(gsd.age) system = fo.create_system(star_type, "", position.x, position.y) if system == fo.invalid_object(): # create system failed, report an error and try to continue with next position util.report_error("Python generate_systems: create system at position (%f, %f) failed" % (position.x, position.y)) continue sys_list.append(system) for orbit in range(0, fo.sys_get_num_orbits(system) - 1): # check for each orbit if a planet shall be created by determining planet size planet_size = planets.calc_planet_size(star_type, orbit, gsd.planetDensity, gsd.shape) if planet_size in planets.planet_sizes: # ok, we want a planet, determine planet type and generate the planet planet_type = planets.calc_planet_type(star_type, orbit, planet_size) if fo.create_planet(planet_size, planet_type, system, orbit, "") == fo.invalid_object(): # create planet failed, report an error and try to continue with next orbit util.report_error("Python generate_systems: create planet in system %d failed" % system) return sys_list
def add_planets_to_vicinity(vicinity, num_planets, gsd): """ Adds the specified number of planets to the specified systems. """ print "Adding", num_planets, "planets to the following systems:", vicinity # first, compile a list containing all the free orbits in the specified systems # begin with adding the free orbits of all systems that have a real star (that is, no neutron star, black hole, # and not no star), if that isn't enough, also one, by one, add the free orbits of neutron star, black hole and # no star systems (in that order) until we have enough free orbits # for that, we use this list of tuples # the first tuple contains all real star types, the following tuples the neutron, black hole and no star types, # so we can iterate over this list and only add the free orbits of systems that match the respective star types # each step # this way we can prioritize the systems we want to add planets to by star type acceptable_star_types_list = [ star_types_real, (fo.starType.noStar, ), (fo.starType.neutron, ), (fo.starType.blackHole, ) ] # store the free orbits as a list of tuples of (system, orbit) free_orbits_map = [] # now, iterate over the list of acceptable star types for acceptable_star_types in acceptable_star_types_list: # check all systems in the list of systems we got passed into this function for system in vicinity: # if this system has a star type we want to accept in this step, add its free orbits to our list if fo.sys_get_star_type(system) in acceptable_star_types: free_orbits_map.extend([ (system, orbit) for orbit in fo.sys_free_orbits(system) ]) # check if we got enough free orbits after completing this step # we want 4 times as much free orbits as planets we want to add, that means each system shouldn't get more # than 2-3 additional planets on average if len(free_orbits_map) > (num_planets * 4): break # if we got less free orbits than planets that should be added, something is wrong # in that case abort and log an error if len(free_orbits_map) < num_planets: report_error( "Python add_planets_to_vicinity: less free orbits than planets to add - cancelled" ) print "...free orbits available:", free_orbits_map # as we will pop the free orbits from this list afterwards, shuffle it to randomize the order of the orbits random.shuffle(free_orbits_map) # add the requested number of planets while num_planets > 0: # get the next free orbit from the list we just compiled system, orbit = free_orbits_map.pop() # check the star type of the system containing the orbit we got star_type = fo.sys_get_star_type(system) if star_type in [fo.starType.noStar, fo.starType.blackHole]: # if it is a black hole or has no star, change the star type # pick a star type, continue until we get a real star # don't accept neutron, black hole or no star print "...system picked to add a planet has star type", star_type while star_type not in star_types_real: star_type = pick_star_type(gsd.age) print "...change that to", star_type fo.sys_set_star_type(system, star_type) # pick a planet size, continue until we get a size that matches the HS_ACCEPTABLE_PLANET_SIZES option planet_size = fo.planetSize.unknown while planet_size not in HS_ACCEPTABLE_PLANET_SIZES: planet_size = calc_planet_size(star_type, orbit, fo.galaxySetupOption.high, gsd.shape) # pick an according planet type planet_type = calc_planet_type(star_type, orbit, planet_size) # finally, create the planet in the system and orbit we got print "...adding", planet_size, planet_type, "planet to system", system if fo.create_planet(planet_size, planet_type, system, orbit, "") == fo.invalid_object(): report_error( "Python add_planets_to_vicinity: create planet in system %d failed" % system) # continue with next planet num_planets -= 1
def add_planets_to_vicinity(vicinity, num_planets, gsd): """ Adds the specified number of planets to the specified systems. """ print "Adding", num_planets, "planets to the following systems:", vicinity # first, compile a list containing all the free orbits in the specified systems # begin with adding the free orbits of all systems that have a real star (that is, no neutron star, black hole, # and not no star), if that isn't enough, also one, by one, add the free orbits of neutron star, black hole and # no star systems (in that order) until we have enough free orbits # for that, we use this list of tuples # the first tuple contains all real star types, the following tuples the neutron, black hole and no star types, # so we can iterate over this list and only add the free orbits of systems that match the respective star types # each step # this way we can prioritize the systems we want to add planets to by star type acceptable_star_types_list = [ star_types_real, (fo.starType.noStar,), (fo.starType.neutron,), (fo.starType.blackHole,) ] # store the free orbits as a list of tuples of (system, orbit) free_orbits_map = [] # now, iterate over the list of acceptable star types for acceptable_star_types in acceptable_star_types_list: # check all systems in the list of systems we got passed into this function for system in vicinity: # if this system has a star type we want to accept in this step, add its free orbits to our list if fo.sys_get_star_type(system) in acceptable_star_types: free_orbits_map.extend([(system, orbit) for orbit in fo.sys_free_orbits(system)]) # check if we got enough free orbits after completing this step # we want 4 times as much free orbits as planets we want to add, that means each system shouldn't get more # than 2-3 additional planets on average if len(free_orbits_map) > (num_planets * 4): break # if we got less free orbits than planets that should be added, something is wrong # in that case abort and log an error if len(free_orbits_map) < num_planets: report_error("Python add_planets_to_vicinity: less free orbits than planets to add - cancelled") print "...free orbits available:", free_orbits_map # as we will pop the free orbits from this list afterwards, shuffle it to randomize the order of the orbits random.shuffle(free_orbits_map) # add the requested number of planets while num_planets > 0: # get the next free orbit from the list we just compiled system, orbit = free_orbits_map.pop() # check the star type of the system containing the orbit we got star_type = fo.sys_get_star_type(system) if star_type in [fo.starType.noStar, fo.starType.blackHole]: # if it is a black hole or has no star, change the star type # pick a star type, continue until we get a real star # don't accept neutron, black hole or no star print "...system picked to add a planet has star type", star_type while star_type not in star_types_real: star_type = pick_star_type(gsd.age) print "...change that to", star_type fo.sys_set_star_type(system, star_type) # pick a planet size, continue until we get a size that matches the HS_ACCEPTABLE_PLANET_SIZES option planet_size = fo.planetSize.unknown while planet_size not in HS_ACCEPTABLE_PLANET_SIZES: planet_size = calc_planet_size(star_type, orbit, fo.galaxySetupOption.high, gsd.shape) # pick an according planet type planet_type = calc_planet_type(star_type, orbit, planet_size) # finally, create the planet in the system and orbit we got print "...adding", planet_size, planet_type, "planet to system", system if fo.create_planet(planet_size, planet_type, system, orbit, "") == fo.invalid_object(): report_error("Python add_planets_to_vicinity: create planet in system %d failed" % system) # continue with next planet num_planets -= 1