Only reproduce on world in home stellar system.
This commit is contained in:
parent
c432d3c6a7
commit
de1a55de5e
2
data.py
2
data.py
|
|
@ -60,10 +60,12 @@ TABLES = [
|
|||
create table populations (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
species TEXT,
|
||||
home_star INTEGER,
|
||||
pop INTEGER,
|
||||
planet INTEGER,
|
||||
vessel INTEGER,
|
||||
station INTEGER,
|
||||
FOREIGN KEY(home_star) REFERENCES stars(id),
|
||||
FOREIGN KEY(planet) REFERENCES planets(id)
|
||||
check (
|
||||
( case when planet is null then 0 else 1 end
|
||||
|
|
|
|||
BIN
game.sqlite
BIN
game.sqlite
Binary file not shown.
|
|
@ -31,7 +31,7 @@ def init_db(conn):
|
|||
c = conn.cursor()
|
||||
c.execute(
|
||||
'''\
|
||||
select id, bio, industrial_capacity
|
||||
select id, bio, industrial_capacity, star
|
||||
from planets
|
||||
where bio > 10000 and industrial_capacity > 10000
|
||||
'''
|
||||
|
|
@ -40,7 +40,7 @@ def init_db(conn):
|
|||
|
||||
# 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, home_star_id in home_worlds:
|
||||
bio -= INITIAL_POP # We know bio is above 10000 from the query above.
|
||||
ind = min(INITIAL_POP, industrial_capacity)
|
||||
people_name = get_name_of_planets_star(c, planet_id) + 'ians'
|
||||
|
|
@ -49,8 +49,8 @@ def init_db(conn):
|
|||
(bio, ind, planet_id),
|
||||
)
|
||||
c.execute(
|
||||
'insert into populations(species, pop, planet) values (?, ?, ?)',
|
||||
(people_name, INITIAL_POP, planet_id),
|
||||
'insert into populations(species, home_star, pop, planet) values (?, ?, ?, ?)',
|
||||
(people_name, home_star_id, INITIAL_POP, planet_id),
|
||||
)
|
||||
# print(planet_id, bio, industrial_capacity)
|
||||
c.close()
|
||||
|
|
|
|||
|
|
@ -74,16 +74,16 @@ def population_grows(db_cursor):
|
|||
select populations.id, populations.pop, planets.id, planets.bio
|
||||
from populations join planets
|
||||
on populations.planet = planets.id
|
||||
and populations.home_star = planets.star
|
||||
'''
|
||||
)
|
||||
# and populations.home_star = planets.star
|
||||
# People are only legally allowed to reproduce in their home
|
||||
# stellar systems.
|
||||
pops = list(db_cursor.fetchall())
|
||||
for pop_id, pop, planet_id, bio in pops:
|
||||
if pop > bio:
|
||||
# famine and death! Woe!
|
||||
print('WARNING population crash on planet {planet_id}!')
|
||||
print(f'WARNING population crash on planet {planet_id}!')
|
||||
pop = bio >> 1
|
||||
bio //= 10
|
||||
else:
|
||||
|
|
|
|||
Loading…
Reference in New Issue