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 (
|
create table populations (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
species TEXT,
|
species TEXT,
|
||||||
|
home_star INTEGER,
|
||||||
pop INTEGER,
|
pop INTEGER,
|
||||||
planet INTEGER,
|
planet INTEGER,
|
||||||
vessel INTEGER,
|
vessel INTEGER,
|
||||||
station INTEGER,
|
station INTEGER,
|
||||||
|
FOREIGN KEY(home_star) REFERENCES stars(id),
|
||||||
FOREIGN KEY(planet) REFERENCES planets(id)
|
FOREIGN KEY(planet) REFERENCES planets(id)
|
||||||
check (
|
check (
|
||||||
( case when planet is null then 0 else 1 end
|
( 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 = conn.cursor()
|
||||||
c.execute(
|
c.execute(
|
||||||
'''\
|
'''\
|
||||||
select id, bio, industrial_capacity
|
select id, bio, industrial_capacity, star
|
||||||
from planets
|
from planets
|
||||||
where bio > 10000 and industrial_capacity > 10000
|
where bio > 10000 and industrial_capacity > 10000
|
||||||
'''
|
'''
|
||||||
|
|
@ -40,7 +40,7 @@ def init_db(conn):
|
||||||
|
|
||||||
# Select some and set initial population and industry.
|
# Select some and set initial population and industry.
|
||||||
home_worlds = sample(list(c.fetchall()), INITIAL_NUMBER_OF_SENTIENT_PEOPLES)
|
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.
|
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) + 'ians'
|
people_name = get_name_of_planets_star(c, planet_id) + 'ians'
|
||||||
|
|
@ -49,8 +49,8 @@ def init_db(conn):
|
||||||
(bio, ind, planet_id),
|
(bio, ind, planet_id),
|
||||||
)
|
)
|
||||||
c.execute(
|
c.execute(
|
||||||
'insert into populations(species, pop, planet) values (?, ?, ?)',
|
'insert into populations(species, home_star, pop, planet) values (?, ?, ?, ?)',
|
||||||
(people_name, INITIAL_POP, planet_id),
|
(people_name, home_star_id, INITIAL_POP, planet_id),
|
||||||
)
|
)
|
||||||
# print(planet_id, bio, industrial_capacity)
|
# print(planet_id, bio, industrial_capacity)
|
||||||
c.close()
|
c.close()
|
||||||
|
|
|
||||||
|
|
@ -74,16 +74,16 @@ def population_grows(db_cursor):
|
||||||
select populations.id, populations.pop, planets.id, planets.bio
|
select populations.id, populations.pop, planets.id, planets.bio
|
||||||
from populations join planets
|
from populations join planets
|
||||||
on populations.planet = planets.id
|
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
|
# People are only legally allowed to reproduce in their home
|
||||||
# stellar systems.
|
# stellar systems.
|
||||||
pops = list(db_cursor.fetchall())
|
pops = list(db_cursor.fetchall())
|
||||||
for pop_id, pop, planet_id, bio in pops:
|
for pop_id, pop, planet_id, bio in pops:
|
||||||
if pop > bio:
|
if pop > bio:
|
||||||
# famine and death! Woe!
|
# famine and death! Woe!
|
||||||
print('WARNING population crash on planet {planet_id}!')
|
print(f'WARNING population crash on planet {planet_id}!')
|
||||||
pop = bio >> 1
|
pop = bio >> 1
|
||||||
bio //= 10
|
bio //= 10
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue