Add life and people.
10% of habitable planets have life on them and 12 of those have people on them (named after their star.)
This commit is contained in:
parent
b049f588ab
commit
8109192d7f
12
README.md
12
README.md
|
|
@ -226,3 +226,15 @@ bio is (well, shall be) in the planet table but pop should have it's own
|
|||
table.
|
||||
|
||||
|
||||
Mon Apr 15 09:13:22 PDT 2024
|
||||
Let's add some people.
|
||||
|
||||
I'm thinking that, say, 10% of planets (with non-zero bio capacity)
|
||||
should have naturally occurring life. (Any planet with life will have
|
||||
maximum life, because that's life.) If there are 10000 planets with bio
|
||||
capacity that means 1000 planets with life, if we want only about 10
|
||||
sentient species that's 1% of those, eh?
|
||||
|
||||
Population can move around. Planets, space stations, ships, where else?
|
||||
|
||||
|
||||
|
|
|
|||
5
data.py
5
data.py
|
|
@ -20,7 +20,7 @@
|
|||
from random import randint, expovariate, seed
|
||||
import sqlite3
|
||||
from poisson import poisson
|
||||
import stars
|
||||
import population, stars
|
||||
|
||||
|
||||
FILENAME = './game.sqlite'
|
||||
|
|
@ -33,6 +33,8 @@ def initialize_db_tables(filename):
|
|||
c = conn.cursor()
|
||||
for statement in stars.TABLES:
|
||||
c.execute(statement)
|
||||
for statement in population.TABLES:
|
||||
c.execute(statement)
|
||||
c.close()
|
||||
conn.commit()
|
||||
return conn
|
||||
|
|
@ -58,6 +60,7 @@ def open_db(filename=FILENAME):
|
|||
def main(filename):
|
||||
conn = initialize_db_tables(filename)
|
||||
stars.init_db(conn)
|
||||
population.init_db(conn)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
BIN
game.sqlite
BIN
game.sqlite
Binary file not shown.
|
|
@ -0,0 +1,71 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright © 2024 Simon Forman
|
||||
#
|
||||
# This file is part of game
|
||||
#
|
||||
# game is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# game is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with game. If not see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
'''
|
||||
'''
|
||||
from random import sample
|
||||
|
||||
# Database stuff. SQL, etc.
|
||||
|
||||
TABLES = [
|
||||
'''\
|
||||
create table populations (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
species TEXT,
|
||||
pop INTEGER,
|
||||
planet INTEGER,
|
||||
FOREIGN KEY(planet) REFERENCES planets(id)
|
||||
)''',
|
||||
]
|
||||
|
||||
|
||||
INITIAL_POP = 1000
|
||||
|
||||
def init_db(conn):
|
||||
print('Generating population data.')
|
||||
c = conn.cursor()
|
||||
c.execute('''\
|
||||
select id, bio, industrial_capacity
|
||||
from planets
|
||||
where bio > 10000 and industrial_capacity > 10000
|
||||
''')
|
||||
home_worlds = sample(list(c.fetchall()), 12)
|
||||
for planet_id, bio, industrial_capacity 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)
|
||||
people_name += 'ians'
|
||||
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))
|
||||
print(planet_id, bio, industrial_capacity)
|
||||
c.close()
|
||||
conn.commit()
|
||||
|
||||
|
||||
def get_name_of_planets_star(db_cursor, planet_id):
|
||||
db_cursor.execute('''\
|
||||
select stars.name from stars
|
||||
join planets
|
||||
on stars.id = planets.star
|
||||
and planets.id = ?
|
||||
''',
|
||||
(planet_id,)
|
||||
)
|
||||
return db_cursor.fetchone()[0]
|
||||
|
||||
23
stars.py
23
stars.py
|
|
@ -36,7 +36,14 @@ Stars have what qualities?
|
|||
|
||||
'''
|
||||
from math import log10
|
||||
from random import randint, expovariate, seed, gauss, lognormvariate
|
||||
from random import (
|
||||
expovariate,
|
||||
gauss,
|
||||
lognormvariate,
|
||||
randint,
|
||||
random,
|
||||
seed,
|
||||
)
|
||||
from poisson import poisson
|
||||
from wordlist import generate_name
|
||||
|
||||
|
|
@ -81,7 +88,9 @@ TABLES = [
|
|||
# low/high near and far from the star and high/low in the mid-
|
||||
# range, but for now I'm just going to use random numbers.
|
||||
'''bio_capacity INTEGER,
|
||||
bio INTEGER DEFAULT 0,
|
||||
industrial_capacity INTEGER,
|
||||
industry INTEGER DEFAULT 0,
|
||||
'''
|
||||
'''star INTEGER,
|
||||
FOREIGN KEY(star) REFERENCES stars(id)
|
||||
|
|
@ -170,18 +179,22 @@ def how_many_planets():
|
|||
return n
|
||||
|
||||
|
||||
import sqlite3
|
||||
def has_life():
|
||||
return random() < 0.1 # Ten percent chance of life
|
||||
|
||||
def generate_planets_for_star(c):
|
||||
star_id = c.lastrowid
|
||||
for ordo in range(1, how_many_planets() + 1):
|
||||
bio_capacity = round(lognormvariate(10, 5))
|
||||
bio = bio_capacity if has_life() else 0
|
||||
c.execute('insert into planets'
|
||||
'(ordo, star, bio_capacity, industrial_capacity)'
|
||||
' values (?, ?, ?, ?)',
|
||||
'(ordo, star, bio_capacity, bio, industrial_capacity)'
|
||||
' values (?, ?, ?, ?, ?)',
|
||||
(
|
||||
ordo,
|
||||
star_id,
|
||||
round(lognormvariate(10, 5)),
|
||||
bio_capacity,
|
||||
bio,
|
||||
round(lognormvariate(10, 5)),
|
||||
)
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue