From f86856e56422e2095186defca80329a5f2a5a94a Mon Sep 17 00:00:00 2001 From: Vezzra Date: Fri, 2 Oct 2015 15:26:06 +0200 Subject: [PATCH] Universe generation: fixed issue with "random" galaxy shape When the "random" galaxy shape was chosen, calc_planet_size failed when trying to access the GALAXY_SHAPE_MOD_TO_PLANET_SIZE_DIST universe table, as it doesn't contain an entry for "random", and the galaxy shape that calc_star_system_positions picked didn't get passed on to calc_planet_size, which instead used "random". Fixed now. --- default/python/universe_generation/galaxy.py | 46 +++++++++---------- .../universe_generation/universe_generator.py | 10 ++-- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/default/python/universe_generation/galaxy.py b/default/python/universe_generation/galaxy.py index 45231d8ed1f..4b69bc9e98e 100644 --- a/default/python/universe_generation/galaxy.py +++ b/default/python/universe_generation/galaxy.py @@ -437,52 +437,52 @@ def recalc_universe_width(positions): return actual_width, new_positions -def calc_star_system_positions(shape, size): +def calc_star_system_positions(gsd): """ Calculates list of positions (x, y) for a given galaxy shape, number of systems and width Uses universe generator helper functions provided by the API """ # if shape is "random", randomly pick a galaxy shape - if shape == fo.galaxyShape.random: - shape = choice(shapes) + if gsd.shape == fo.galaxyShape.random: + gsd.shape = choice(shapes) # calculate typical width for universe based on number of systems - width = calc_universe_width(shape, size) + width = calc_universe_width(gsd.shape, gsd.size) print "Set universe width to", width fo.set_universe_width(width) positions = [] - print "Creating", shape, "galaxy shape" - if shape == fo.galaxyShape.spiral2: - spiral_galaxy_calc_positions(positions, 2, size, width) - elif shape == fo.galaxyShape.spiral3: - spiral_galaxy_calc_positions(positions, 3, size, width) - elif shape == fo.galaxyShape.spiral4: - spiral_galaxy_calc_positions(positions, 4, size, width) - elif shape == fo.galaxyShape.elliptical: - elliptical_galaxy_calc_positions(positions, size, width) - elif shape == fo.galaxyShape.disc: - disc_galaxy_calc_positions(positions, size, width) - elif shape == fo.galaxyShape.cluster: + print "Creating", gsd.shape, "galaxy shape" + if gsd.shape == fo.galaxyShape.spiral2: + spiral_galaxy_calc_positions(positions, 2, gsd.size, width) + elif gsd.shape == fo.galaxyShape.spiral3: + spiral_galaxy_calc_positions(positions, 3, gsd.size, width) + elif gsd.shape == fo.galaxyShape.spiral4: + spiral_galaxy_calc_positions(positions, 4, gsd.size, width) + elif gsd.shape == fo.galaxyShape.elliptical: + elliptical_galaxy_calc_positions(positions, gsd.size, width) + elif gsd.shape == fo.galaxyShape.disc: + disc_galaxy_calc_positions(positions, gsd.size, width) + elif gsd.shape == fo.galaxyShape.cluster: # Typically a galaxy with 100 systems should have ~5 clusters - avg_clusters = size / 20 + avg_clusters = gsd.size / 20 if avg_clusters < 2: avg_clusters = 2 # Add a bit of random variation (+/- 20%) clusters = randint((avg_clusters * 8) / 10, (avg_clusters * 12) / 10) if clusters >= 2: - cluster_galaxy_calc_positions(positions, clusters, size, width) - elif shape == fo.galaxyShape.ring: - ring_galaxy_calc_positions(positions, size, width) - elif shape == fo.galaxyShape.irregular: - irregular_galaxy_calc_positions(positions, size, width) + cluster_galaxy_calc_positions(positions, clusters, gsd.size, width) + elif gsd.shape == fo.galaxyShape.ring: + ring_galaxy_calc_positions(positions, gsd.size, width) + elif gsd.shape == fo.galaxyShape.irregular: + irregular_galaxy_calc_positions(positions, gsd.size, width) # Check if any positions have been calculated... if not positions: # ...if not, fall back on box shape - box_galaxy_calc_positions(positions, size, width) + box_galaxy_calc_positions(positions, gsd.size, width) # to avoid having too much "extra space" around the system positions of our galaxy map, recalculate the universe # width and shift all positions accordingly diff --git a/default/python/universe_generation/universe_generator.py b/default/python/universe_generation/universe_generator.py index 00eccbee82d..cceecb2758f 100755 --- a/default/python/universe_generation/universe_generator.py +++ b/default/python/universe_generation/universe_generator.py @@ -60,15 +60,15 @@ def create_universe(psd_map): # make sure there are enough systems for the given number of players print "Universe creation requested with %d systems for %d players" % (gsd.size, total_players) - size = max(gsd.size, (total_players * 3)) - if size > gsd.size: - # gsd.size = size + min_size = total_players * 3 + if min_size > gsd.size: + gsd.size = min_size print "Too few systems for the requested number of players, number of systems adjusted accordingly" - print "Creating universe with %d systems for %d players" % (size, total_players) + print "Creating universe with %d systems for %d players" % (gsd.size, total_players) # calculate star system positions seed_rng(seed_pool.pop()) - system_positions = calc_star_system_positions(gsd.shape, size) + system_positions = calc_star_system_positions(gsd) size = len(system_positions) print gsd.shape, "Star system positions calculated, final number of systems:", size