From de1a55de5e470563d5081130f6770e9fd1f173b4 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Mon, 15 Apr 2024 20:12:25 -0700 Subject: [PATCH] Only reproduce on world in home stellar system. --- data.py | 2 ++ game.sqlite | Bin 389120 -> 389120 bytes population.py | 8 ++++---- server.py | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) 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 baf6bb04d9f62d59be15ad2646a2345bde2c3543..f2d42c8354b4b8f427f28547e38c97062ca7bc45 100644 GIT binary patch delta 800 zcmX|8O=uHQ5Pt7%lDGNYwrFDi;)Xy;s{IMYdZ=P;h!%=kT0t+RzHZiJ<7PL_Ce@0e zsfKDqA!QX2gcetkfh64{xX+?FDmOPV%E_-sM)$ zIud)Uk&+?lAUhN}78#113`d4pBcTL@Xi$CXIMB}iH!jX|7ubMpJ2rfP<%q(w7vsFd zrbHs~88zf&O$MYkI=i0TBcsOrm2V z$#Alg;w7U1Va?*R(V(l!F`SJi<%|#&D*H}y#3-B18WSf-S`v9lNo0j7 zt~%u^)|y^6(=^yur5WNYGtyZlD=7v{6|v^dxiJlVh^}nfPsB`|HxM{ya{%DC>}ZI~ zk|@NpNja95Wll~TMff<@+P=8WH1I>CeK^CXXnh*_wRXiLQI3jXUzADuOuvUMcg)|6lU4u^wsk9)8 zBz;+~&NDy9T6uGH1)`aW@(MZRg$rezcSE?KdZ&vF05ydG4XlW!5Nx%Um!}8U;jE5R za0b@R0sw07RK5#Vj(`vz?7u!Y4)wWld> zlggkvu)ADeX{8W_5CtAI_I`L$=%UV{hBNw%O6~U|pQJA>QX4PO+AIArF*!?UV_9GN ZX<9#mZr;)#h0Lo*QP*!>QOvim`~%`o;(P!A delta 701 zcmXw!Pe>F|9LL{#v*UCBPFn4@u8t#8td{BOL5L#Mi-#a9yA}DIeeKLPJG0L0SR09o zV%Q(FCdeY#4uyD#sF4P`)gegn)}>1*bm(M-5aB_Z-PwMZ2k-Oy{`pO9#-=u7iwVd+ zXdH;K;JE%g%>4yya2;?5xQ)oi@M3V?PVKuG^w0FOIM&(<=d9u2thE!&S`S0b&7wrb zYeFCy5Zp-$A~C3NU81UxSBOdr)@G>L!r^YKFWg$nj!0QjbYFVoswNZFV1Dp3i691@2m&xb z(xVC~h?9(2B}IM&B=LPRu!V()T*iW-jy|o?!@gia*~J3HlB(?xNPy$ z^IZLGvKIIeVi0WiA8E1QO%H9u1qbKh9IRge`yYjB0Yv4&LxX2VZkNWOQyN2|Ji7PU zd9{UhJJHe?XQht0%tQS#?qdEx-P!A63aCD6$6YPMFs?gzmH 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: