Skip to content

Commit

Permalink
Universe generation: fixed issue with "random" galaxy shape
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Vezzra committed Oct 2, 2015
1 parent ee10bb7 commit f86856e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
46 changes: 23 additions & 23 deletions default/python/universe_generation/galaxy.py
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions default/python/universe_generation/universe_generator.py
Expand Up @@ -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

Expand Down

0 comments on commit f86856e

Please sign in to comment.