Skip to content

Commit

Permalink
Rewrote the Space Object algorithms, decided rouge moons are a feature
Browse files Browse the repository at this point in the history
  • Loading branch information
QBFreak committed Sep 18, 2018
1 parent 0b7abcf commit 0ff8ca7
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions world/spaceobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ class SpaceObject(object):
various types of objects you might find in space. It has all of the generic
functions necessary for an object that appears scattered through space.
"""
def __init__(self, seed, scale=2, selection=1):
def __init__(self, seed, occurs=75):
self.seed = seed
self.scale = scale
self.selection = selection
self.occurs = occurs
# Simplex Noise doesn't work on integers, so lets get some seeded
# random offsets (non-integer) for x, y, and z to overcome this limitation.
random.seed(self.seed)
Expand All @@ -53,24 +52,24 @@ def object_at_coordinates(self, coordinates):
"""
x, y, z = coordinates
n = snoise3(x + self.xoffset, y + self.yoffset, z + self.zoffset)
o = int(n * self.scale)
return o == self.selection
o = int(n * 100)
return o <= self.occurs


class Star(SpaceObject):
"""
One of the most basic space objects, the star simply exists
"""
def __init__(self, seed=39, scale=2, selection=1):
super(Star, self).__init__(seed, scale, selection)
def __init__(self, seed=39, occurs=75):
super(Star, self).__init__(seed=seed, occurs=occurs)


class Planet(Star):
"""
The planet exists only where there are stars, but not in every location
"""
def __init__(self, seed=39, scale=2, selection=1):
super(Planet, self).__init__(seed, scale, selection)
def __init__(self, seed=39, occurs=75):
super(Planet, self).__init__(seed=seed, occurs=occurs)
self.occurs = 75

def object_at_coordinates(self, coordinates):
Expand All @@ -86,15 +85,21 @@ class Moon(Planet):
"""
The moon exists only where there is a planet, but not in every location
"""
def __init__(self, seed=39, scale=2, selection=1):
super(Moon, self).__init__(seed, scale, selection)
def __init__(self, seed=39, occurs=75):
super(Moon, self).__init__(seed=seed, occurs=occurs)
self.planet_occurs = 75
self.moon_occurs = 30

def object_at_coordinates(self, coordinates):
if super(Moon, self).object_at_coordinates(coordinates):
# Because random was seeded in SpaceObject.__init__(), it's ready
# to produce consistent results for us.
# Well. Almost. We call it twice here, so that kinda makes a mess
# of our consistancy in regards to Planets, where we only call it once
# However, since we're using the `<= occurs` method, the results
# aren't too bad. It masks the worst of it. The side benefit is
# that we end up with < 10 rouge moons in 1000 systems
# We can call that a feature :)
return random.randint(0, 100) <= self.planet_occurs \
and random.randint(0, 100) <= self.moon_occurs
else:
Expand Down

0 comments on commit 0ff8ca7

Please sign in to comment.