diff --git a/data.py b/data.py index 5f7e171..eb06557 100644 --- a/data.py +++ b/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 diff --git a/game.sqlite b/game.sqlite index baf6bb0..f2d42c8 100644 Binary files a/game.sqlite and b/game.sqlite differ diff --git a/population.py b/population.py index 391a95f..dfe3ac0 100644 --- a/population.py +++ b/population.py @@ -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() diff --git a/server.py b/server.py index 32ed776..0eb6990 100644 --- a/server.py +++ b/server.py @@ -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: