Minor cleanup, comments.
This commit is contained in:
parent
8109192d7f
commit
5ebcb27009
|
|
@ -238,3 +238,12 @@ sentient species that's 1% of those, eh?
|
||||||
Population can move around. Planets, space stations, ships, where else?
|
Population can move around. Planets, space stations, ships, where else?
|
||||||
|
|
||||||
|
|
||||||
|
Just a note: I'm not happy with the Poisson layout of the star systems,
|
||||||
|
too uniform, I know I've said that elsewhere. I'm also not happy with
|
||||||
|
the radiuseses of the stars, the little ones are hard to click on. It's
|
||||||
|
not so bad because you can click on the labels, but still. It would be
|
||||||
|
neat to have a scattering of stars on the background, just tiny points of
|
||||||
|
light, cosmetic only, no game function. Then the "real" stars could all
|
||||||
|
be several pixels uh radius for clickability eh?
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,8 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with game. If not see <http://www.gnu.org/licenses/>.
|
# along with game. If not see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
'''
|
|
||||||
'''
|
|
||||||
from random import sample
|
from random import sample
|
||||||
|
|
||||||
# Database stuff. SQL, etc.
|
|
||||||
|
|
||||||
TABLES = [
|
TABLES = [
|
||||||
'''\
|
'''\
|
||||||
|
|
@ -36,21 +33,27 @@ TABLES = [
|
||||||
|
|
||||||
|
|
||||||
INITIAL_POP = 1000
|
INITIAL_POP = 1000
|
||||||
|
INITIAL_NUMBER_OF_SENTIENT_PEOPLES = 12
|
||||||
|
|
||||||
|
|
||||||
def init_db(conn):
|
def init_db(conn):
|
||||||
print('Generating population data.')
|
print('Generating population data.')
|
||||||
|
|
||||||
|
# Find the not-too-crappy planets.
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute('''\
|
c.execute('''\
|
||||||
select id, bio, industrial_capacity
|
select id, bio, industrial_capacity
|
||||||
from planets
|
from planets
|
||||||
where bio > 10000 and industrial_capacity > 10000
|
where bio > 10000 and industrial_capacity > 10000
|
||||||
''')
|
''')
|
||||||
home_worlds = sample(list(c.fetchall()), 12)
|
# Note that bio is initialized to full capacity whereas industry is 0.
|
||||||
|
|
||||||
|
# Select some and set initial population and industry.
|
||||||
|
home_worlds = sample(list(c.fetchall()), INITIAL_NUMBER_OF_SENTIENT_PEOPLES)
|
||||||
for planet_id, bio, industrial_capacity in home_worlds:
|
for planet_id, bio, industrial_capacity in home_worlds:
|
||||||
bio -= INITIAL_POP # We know bio is above 10000 from the query above.
|
bio -= INITIAL_POP # We know bio is above 10000 from the query above.
|
||||||
ind = min(INITIAL_POP, industrial_capacity)
|
ind = min(INITIAL_POP, industrial_capacity)
|
||||||
people_name = get_name_of_planets_star(c, planet_id)
|
people_name = get_name_of_planets_star(c, planet_id) + 'ians'
|
||||||
people_name += 'ians'
|
|
||||||
c.execute('update planets set bio = ?, industry = ? where id = ?', (bio, ind, planet_id))
|
c.execute('update planets set bio = ?, industry = ? where id = ?', (bio, ind, planet_id))
|
||||||
c.execute('insert into populations(species, pop, planet) values (?, ?, ?)', (people_name, INITIAL_POP, planet_id))
|
c.execute('insert into populations(species, pop, planet) values (?, ?, ?)', (people_name, INITIAL_POP, planet_id))
|
||||||
print(planet_id, bio, industrial_capacity)
|
print(planet_id, bio, industrial_capacity)
|
||||||
|
|
@ -59,6 +62,7 @@ def init_db(conn):
|
||||||
|
|
||||||
|
|
||||||
def get_name_of_planets_star(db_cursor, planet_id):
|
def get_name_of_planets_star(db_cursor, planet_id):
|
||||||
|
# My first ever JOIN statement! Squeeeee!
|
||||||
db_cursor.execute('''\
|
db_cursor.execute('''\
|
||||||
select stars.name from stars
|
select stars.name from stars
|
||||||
join planets
|
join planets
|
||||||
|
|
@ -68,4 +72,3 @@ def get_name_of_planets_star(db_cursor, planet_id):
|
||||||
(planet_id,)
|
(planet_id,)
|
||||||
)
|
)
|
||||||
return db_cursor.fetchone()[0]
|
return db_cursor.fetchone()[0]
|
||||||
|
|
||||||
|
|
|
||||||
13
stars.py
13
stars.py
|
|
@ -149,6 +149,10 @@ def get_planets_for_star_named(conn, name):
|
||||||
# about to happen (drawing these planet data into the GUI) so it
|
# about to happen (drawing these planet data into the GUI) so it
|
||||||
# would be daft to worry about it (after working this all out, that
|
# would be daft to worry about it (after working this all out, that
|
||||||
# is.)
|
# is.)
|
||||||
|
#
|
||||||
|
# Now that I can do JOIN's I could write a mighty SQL statement that
|
||||||
|
# did all the work in the DB! I could be like the old programmers of
|
||||||
|
# yore!
|
||||||
|
|
||||||
for ordo, bio_capacity, industrial_capacity in c.fetchall():
|
for ordo, bio_capacity, industrial_capacity in c.fetchall():
|
||||||
assert bio_capacity >= 0
|
assert bio_capacity >= 0
|
||||||
|
|
@ -168,11 +172,15 @@ def generate_stars(width, height, minimum_distance_between_stars):
|
||||||
name = generate_name()
|
name = generate_name()
|
||||||
while name in unique_names:
|
while name in unique_names:
|
||||||
name = generate_name()
|
name = generate_name()
|
||||||
|
# I did get a name collision early on!
|
||||||
unique_names.add(name)
|
unique_names.add(name)
|
||||||
yield x, y, round(1 + expovariate(1)), name
|
yield x, y, round(1 + expovariate(1)), name
|
||||||
|
|
||||||
|
|
||||||
def how_many_planets():
|
def how_many_planets():
|
||||||
|
'''
|
||||||
|
Return a non-negative integer, the number of planets a star should have.
|
||||||
|
'''
|
||||||
n = round(gauss(5, 5))
|
n = round(gauss(5, 5))
|
||||||
while n < 0:
|
while n < 0:
|
||||||
n = round(gauss(5, 5))
|
n = round(gauss(5, 5))
|
||||||
|
|
@ -180,9 +188,12 @@ def how_many_planets():
|
||||||
|
|
||||||
|
|
||||||
def has_life():
|
def has_life():
|
||||||
return random() < 0.1 # Ten percent chance of life
|
# Ten percent chance of life
|
||||||
|
return random() < 0.1
|
||||||
|
|
||||||
|
|
||||||
def generate_planets_for_star(c):
|
def generate_planets_for_star(c):
|
||||||
|
# Only call this just after creating a star.
|
||||||
star_id = c.lastrowid
|
star_id = c.lastrowid
|
||||||
for ordo in range(1, how_many_planets() + 1):
|
for ordo in range(1, how_many_planets() + 1):
|
||||||
bio_capacity = round(lognormvariate(10, 5))
|
bio_capacity = round(lognormvariate(10, 5))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue