def initialise(self): """\ Minisec """ dbconn.use(self.game) trans = dbconn.begin() try: RulesetBase.initialise(self) # Need to create the top level universe object... universe = Object(type='tp.server.rules.base.objects.Universe') universe.id = 0 universe.name = "The Universe" universe.size = SIZE universe.parent = 0 universe.posx = 0 universe.posy = 0 universe.turn = 0 universe.insert() trans.commit() except: trans.rollback() raise
def populate(self, seed, system_min, system_max, planet_min, planet_max): """\ --populate <game> <random seed> <min systems> <max systems> <min planets> <max planets> Populate a universe with a number of systems and planets. The number of systems in the universe is dictated by min/max systems. The number of planets per system is dictated by min/max planets. """ dbconn.use(self.game) trans = dbconn.begin() try: MinisecRuleset.populate(self, seed, system_min, system_max, planet_min, planet_max) # Add a random smattering of resources to planets... r = random.Random() r.seed(int(seed)) for planetid, time in Object.bytype('tp.server.rules.base.objects.Planet'): planet = Object(id=planetid) ids = r.sample(range(1, 4), r.randint(0, 3)) for id in ids: planet.resources_add(id, r.randint(0, 10), Planet.ACCESSABLE) planet.resources_add(id, r.randint(0, 100), Planet.MINABLE) planet.resources_add(id, r.randint(0, 1000), Planet.INACCESSABLE) planet.save() trans.commit() except: trans.rollback() raise
def player(self, username, password, email='Unknown', comment='A Minisec Player'): """\ Create a Solar System, Planet, and initial Fleet for the player, positioned randomly within the Universe. """ dbconn.use(self.game) trans = dbconn.begin() try: user = RulesetBase.player(self, username, password, email, comment) # FIXME: Hack! This however means that player x will always end up in the same place.. r = random.Random() r.seed(user.id) pos = r.randint(SIZE * -1, SIZE) * 1000, r.randint( SIZE * -1, SIZE) * 1000, r.randint(SIZE * -1, SIZE) * 1000 system = Object(type='tp.server.rules.base.objects.System') system.name = "%s Solar System" % username system.parent = 0 system.size = r.randint(800000, 2000000) (system.posx, system.posy, junk) = pos ReparentOne(system) system.owner = user.id system.save() planet = Object(type='tp.server.rules.timtrader.objects.Planet') planet.name = "%s Planet" % username planet.parent = system.id planet.size = 100 planet.posx = system.posx + r.randint(1, 100) * 1000 planet.posy = system.posy + r.randint(1, 100) * 1000 planet.owner = user.id # Get the player's planet object and add the empire capital planet.resources_add(Resource.byname('Header Quarter'), 1) planet.resources_add(Resource.byname('Credit'), 10000) planet.save() fleet = Object(type='tp.server.rules.minisec.objects.Fleet') fleet.parent = planet.id fleet.size = 3 fleet.name = "%s First Fleet" % username fleet.ships = {1: 3} (fleet.posx, fleet.posy, fleet.posz) = (planet.posx, planet.posy, planet.posz) fleet.owner = user.id fleet.save() trans.commit() except: trans.rollback() raise
def populate(self, seed, system_min, system_max, planet_min, planet_max): """\ --populate <game> <random seed> <min systems> <max systems> <min planets> <max planets> Populate a universe with a number of systems and planets. The number of systems in the universe is dictated by min/max systems. The number of planets per system is dictated by min/max planets. """ seed, system_min, system_max, planet_min, planet_max = ( int(seed), int(system_min), int(system_max), int(planet_min), int(planet_max)) dbconn.use(self.game) trans = dbconn.begin() try: # FIXME: Assuming that the Universe and the Galaxy exist. r = random.Random() r.seed(int(seed)) # Create this many systems for i in range(0, r.randint(system_min, system_max)): pos = r.randint(SIZE * -1, SIZE) * 1000, r.randint( SIZE * -1, SIZE) * 1000, r.randint(SIZE * -1, SIZE) * 1000 # Add system system = Object(type='tp.server.rules.base.objects.System') system.name = "System %s" % i system.size = r.randint(800000, 2000000) system.posx = pos[0] system.posy = pos[1] system.insert() ReparentOne(system) system.save() print "Created system (%s) with the id: %i" % (system.name, system.id) # In each system create a number of planets for j in range(0, r.randint(planet_min, planet_max)): planet = Object(type='tp.server.rules.base.objects.Planet') planet.name = "Planet %i in %s" % (j, system.name) planet.size = r.randint(1000, 10000) planet.parent = system.id planet.posx = pos[0] + r.randint(1, 100) * 1000 planet.posy = pos[1] + r.randint(1, 100) * 1000 planet.insert() print "Created planet (%s) with the id: %i" % (planet.name, planet.id) trans.commit() except: trans.rollback() raise
def player(self, username, password, email='Unknown', comment='A Minisec Player'): """\ Create a Solar System, Planet, and initial Fleet for the player, positioned randomly within the Universe. """ dbconn.use(self.game) trans = dbconn.begin() try: user = RulesetBase.player(self, username, password, email, comment) # FIXME: Hack! This however means that player x will always end up in the same place.. r = random.Random() r.seed(user.id) pos = r.randint(SIZE*-1, SIZE)*1000, r.randint(SIZE*-1, SIZE)*1000, r.randint(SIZE*-1, SIZE)*1000 system = Object(type='tp.server.rules.base.objects.System') system.name = "%s Solar System" % username system.parent = 0 system.size = r.randint(800000, 2000000) (system.posx, system.posy, junk) = pos ReparentOne(system) system.owner = user.id system.save() planet = Object(type='tp.server.rules.timtrader.objects.Planet') planet.name = "%s Planet" % username planet.parent = system.id planet.size = 100 planet.posx = system.posx+r.randint(1,100)*1000 planet.posy = system.posy+r.randint(1,100)*1000 planet.owner = user.id # Get the player's planet object and add the empire capital planet.resources_add(Resource.byname('Header Quarter'), 1) planet.resources_add(Resource.byname('Credit'), 10000) planet.save() fleet = Object(type='tp.server.rules.minisec.objects.Fleet') fleet.parent = planet.id fleet.size = 3 fleet.name = "%s First Fleet" % username fleet.ships = {1:3} (fleet.posx, fleet.posy, fleet.posz) = (planet.posx, planet.posy, planet.posz) fleet.owner = user.id fleet.save() trans.commit() except: trans.rollback() raise
def remove(self): trans = dbconn.begin() try: # Move the other orders down t = self.table update(t, (t.c.slot >= bindparam('s')) & (t.c.oid==bindparam('o')), {'slot': t.c.slot-1}).execute(s=self.slot, o=self.oid) self.object.save() SQLTypedBase.remove(self) trans.commit() except Exception, e: trans.rollback() raise
def populate(self, seed, system_min, system_max, planet_min, planet_max): """\ --populate <game> <random seed> <min systems> <max systems> <min planets> <max planets> Populate a universe with a number of systems and planets. The number of systems in the universe is dictated by min/max systems. The number of planets per system is dictated by min/max planets. """ seed, system_min, system_max, planet_min, planet_max = (int(seed), int(system_min), int(system_max), int(planet_min), int(planet_max)) dbconn.use(self.game) trans = dbconn.begin() try: # FIXME: Assuming that the Universe and the Galaxy exist. r = random.Random() r.seed(int(seed)) # Create this many systems for i in range(0, r.randint(system_min, system_max)): pos = r.randint(SIZE*-1, SIZE)*1000, r.randint(SIZE*-1, SIZE)*1000, r.randint(SIZE*-1, SIZE)*1000 # Add system system = Object(type='tp.server.rules.base.objects.System') system.name = "System %s" % i system.size = r.randint(800000, 2000000) system.posx = pos[0] system.posy = pos[1] system.insert() ReparentOne(system) system.save() print "Created system (%s) with the id: %i" % (system.name, system.id) # In each system create a number of planets for j in range(0, r.randint(planet_min, planet_max)): planet = Object(type='tp.server.rules.base.objects.Planet') planet.name = "Planet %i in %s" % (j, system.name) planet.size = r.randint(1000, 10000) planet.parent = system.id planet.posx = pos[0]+r.randint(1,100)*1000 planet.posy = pos[1]+r.randint(1,100)*1000 planet.insert() print "Created planet (%s) with the id: %i" % (planet.name, planet.id) trans.commit() except: trans.rollback() raise
def save(self): trans = dbconn.begin() try: # Update the modtime... self.object.save() if not hasattr(self, 'id'): id = self.realid(self.oid, self.slot) if id != -1: self.id = id SQLTypedBase.save(self) trans.commit() except Exception, e: trans.rollback() raise
def remove(self): trans = dbconn.begin() try: # Move the other orders down t = self.table update(t, (t.c.slot >= bindparam('s')) & (t.c.oid == bindparam('o')), { 'slot': t.c.slot - 1 }).execute(s=self.slot, o=self.oid) self.object.save() SQLTypedBase.remove(self) trans.commit() except Exception, e: trans.rollback() raise
def player(self, username, password, email='Unknown', comment='A Minisec Player'): """\ Create a Solar System, Planet, and initial Fleet for the player, positioned randomly within the Universe. """ dbconn.use(self.game) trans = dbconn.begin() try: user, system, planet, fleet = MinisecRuleset.player(self, username, password, email, comment) # Get the player's planet object and add the empire capital planet.resources_add(10, 1) planet.resources_add(11, 1) planet.save() trans.commit() except: trans.rollback() raise
def insert(self): trans = dbconn.begin() try: t = self.table number = self.number(self.oid) if self.slot == -1: self.slot = number elif self.slot <= number: # Need to move all the other orders down update(t, (t.c.slot >= bindparam('s')) & (t.c.oid==bindparam('o')), {'slot': t.c.slot+1}).execute(s=self.slot, o=self.oid) else: raise NoSuch("Cannot insert to that slot number.") self.save() trans.commit() except Exception, e: trans.rollback() raise
def insert(self): trans = dbconn.begin() try: t = self.table number = self.number(self.oid) if self.slot == -1: self.slot = number elif self.slot <= number: # Need to move all the other orders down update(t, (t.c.slot >= bindparam('s')) & (t.c.oid == bindparam('o')), { 'slot': t.c.slot + 1 }).execute(s=self.slot, o=self.oid) else: raise NoSuch("Cannot insert to that slot number.") self.save() trans.commit() except Exception, e: trans.rollback() raise
def populate(self, seed, system_min, system_max, planet_min, planet_max): """\ --populate <game> <random seed> <min systems> <max systems> <min planets> <max planets> Populate a universe with a number of systems and planets. The number of systems in the universe is dictated by min/max systems. The number of planets per system is dictated by min/max planets. """ dbconn.use(self.game) trans = dbconn.begin() try: MinisecRuleset.populate(self, seed, system_min, system_max, planet_min, planet_max) # Add a random smattering of resources to planets... r = random.Random() r.seed(int(seed)) for planetid, time in Object.bytype( 'tp.server.rules.base.objects.Planet'): planet = Object(id=planetid) ids = r.sample(range(1, 4), r.randint(0, 3)) for id in ids: planet.resources_add(id, r.randint(0, 10), Planet.ACCESSABLE) planet.resources_add(id, r.randint(0, 100), Planet.MINABLE) planet.resources_add(id, r.randint(0, 1000), Planet.INACCESSABLE) planet.save() trans.commit() except: trans.rollback() raise
def player(self, username, password, email='Unknown', comment='A Minisec Player'): """\ Create a Solar System, Planet, and initial Fleet for the player, positioned randomly within the Universe. """ dbconn.use(self.game) trans = dbconn.begin() try: user, system, planet, fleet = MinisecRuleset.player( self, username, password, email, comment) # Get the player's planet object and add the empire capital planet.resources_add(10, 1) planet.resources_add(11, 1) planet.save() trans.commit() except: trans.rollback() raise
def populate(self, seed, system_min, system_max, planet_min, planet_max): """\ --populate <game> <random seed> <min systems> <max systems> <min planets> <max planets> Populate a universe with a number of systems and planets. The number of systems in the universe is dictated by min/max systems. The number of planets per system is dictated by min/max planets. """ # Convert arguments to integers seed, system_min, system_max, planet_min, planet_max = (int(seed), int(system_min), int(system_max), int(planet_min), int(planet_max)) dbconn.use(self.game) trans = dbconn.begin() try: RulesetBase.populate(self, seed) r = Resource(Resource.byname('Ship Parts Factory')) # FIXME: Assuming that the Universe and the Galaxy exist. r = random.Random() r.seed(seed) # Create the actual systems and planets. for i in range(0, r.randint(system_min, system_max)): pos = r.randint(SIZE*-1, SIZE)*1000, r.randint(SIZE*-1, SIZE)*1000, r.randint(SIZE*-1, SIZE)*1000 # Add system system = Object(type='tp.server.rules.base.objects.System') system.name = "System %s" % i system.size = r.randint(800000, 2000000) system.posx = pos[0] system.posy = pos[1] system.insert() ReparentOne(system) system.save() print "Created system (%s) with the id: %i" % (system.name, system.id) # In each system create a number of planets for j in range(0, r.randint(planet_min, planet_max)): planet = Object(type='tp.server.rules.timtrader.objects.Planet') planet.name = "Planet %i in %s" % (j, system.name) planet.size = r.randint(1000, 10000) planet.parent = system.id planet.posx = pos[0]+r.randint(1,100)*1000 planet.posy = pos[1]+r.randint(1,100)*1000 planet.insert() print "Created planet (%s) with the id: %i" % (planet.name, planet.id) # FIXME: Add minerals Iron, Uranium mine = False for mineral in minerals: # Does this planet have this mineral if r.random()*100 > mineral.probability: # Add a smattering of minerals planet.resources_add(id, r.randint(0, mineral.density), Planet.MINEABLE) mine = True # Add a mine to each planet which has minerals if mine: planet.resources_add(Resource.byname('Mine'), 1, Planet.ACCESSABLE) # FIXME: Add growing resources for grow in growing: if r.random()*100 > grow.probability: # Add a smattering of breeding grounds planet.resources_add(Resource.byname(''), 1, Planet.ACCESSABLE) # Add a smattering of the same stocks planet.resources_add(Resource.byname(''), r.randint(0, grow.density), Planet.MINEABLE) # Add 1 fishery/slaughter house to each location # FIXME: Add a other industries in random locations for factory in factories: pass # FIXME: Add a bunch of cities planet.save() trans.commit() except: trans.rollback() raise
def initialise(self, seed=None): """\ Minisec """ dbconn.use(self.game) trans = dbconn.begin() try: MinisecRuleset.initialise(self) reader = csv.DictReader(open(os.path.join(self.files, "resources.csv"), "r")) for row in reader: r = Resource() for name, cell in row.iteritems(): if cell is '': continue setattr(r, name, convert(getattr(Resource.table.c, name), cell)) pprint.pprint(r.__dict__) r.insert() reader = csv.DictReader(open(os.path.join(self.files, "categories.csv"), "r")) for row in reader: c = Category() for name, cell in row.iteritems(): setattr(c, name, cell) pprint.pprint(c.__dict__) c.insert() # Create the properties that a design might have p = Property() p.categories = [Category.byname('Misc')] p.name = "speed" p.displayname = "Speed" p.desc = "The maximum number of parsecs the ship can move each turn." p.calculate = """\ (lambda (design bits) (let ((n (apply + bits))) (cons n (string-append (number->string (/ n 1000000)) " kpcs")))) """ p.insert() p = Property() p.categories = [Category.byname('Production')] p.name = "cost" p.displayname = "Cost" p.desc = "The number of components needed to build the ship" p.calculate = """\ (lambda (design bits) (let ((n (apply + bits))) (cons n (string-append (number->string n) " turns")) ) ) """ p.insert() p = Property() p.categories = [Category.byname('Combat')] p.name = "hp" p.displayname = "Hit Points" p.desc = "The amount of damage the ship can take." p.calculate = """\ (lambda (design bits) (let ((n (apply + bits))) (cons n (string-append (number->string n) " HP")))) """ p.insert() p = Property() p.categories = [Category.byname('Combat')] p.name = "backup-damage" p.displayname = "Backup Damage" p.desc = "The amount of damage that the ship will do when using it's backup weapon. (IE When it draws a battle round.)" p.calculate = """\ (lambda (design bits) (let ((n (apply + bits))) (cons n (string-append (number->string n) " HP")))) """ p.insert() p = Property() p.categories = [Category.byname('Combat')] p.name = "primary-damage" p.displayname = "Primary Damage" p.desc = "The amount of damage that the ship will do when using it's primary weapon. (IE When it wins a battle round.)" p.calculate = """\ (lambda (design bits) (let ((n (apply + bits))) (cons n (string-append (number->string n) " HP")))) """ p.insert() p = Property() p.categories = [Category.byname('Misc')] p.name = "escape" p.displayname = "Escape Chance" p.desc = "The chance the ship has of escaping from battle." p.calculate = """\ (lambda (design bits) (let ((n (apply + bits))) (cons n (string-append (number->string (* n 100)) " %")))) """ p.insert() p = Property() p.categories = [Category.byname('Misc')] p.name = "colonise" p.displayname = "Can Colonise Planets" p.desc = "Can the ship colonise planets/" p.calculate = """\ (lambda (design bits) (let ((n (apply + bits))) (cons n (if (> n 1) "Yes" "No")))) """ p.insert() c = Component() c.categories = [Category.byname('Combat')] c.name = "Missile" c.desc = "Missile which does 1HP of damage." c.properties = {} c.properties[Property.byname('primary-damage')] = None c.insert() c = Component() c.categories = [Category.byname('Combat')] c.name = "Laser" c.desc = "Lasers which do 1HP of damage." c.properties = {} c.properties[Property.byname('backup-damage')] = """(lambda (design) 0.25)""" c.insert() c = Component() c.categories = [Category.byname('Combat')] c.name = "Armor Plate" c.desc = "Armor Plate which absorbes 1HP of damage." c.properties = {} c.properties[Property.byname('hp')] = None c.insert() c = Component() c.categories = [Category.byname('Misc')] c.name = "Colonisation Pod" c.desc = "A part which allows a ship to colonise a planet." c.properties = {} c.properties[Property.byname('colonise')] = None c.insert() c = Component() c.categories = [Category.byname('Misc')] c.name = "Escape Thrusters" c.desc = "A part which allows a ship to escape combat." c.properties = {} c.properties[Property.byname('escape')] = """(lambda (design) 0.25)""" c.insert() c = Component() c.categories = [Category.byname('Misc')] c.name = "Primary Engine" c.desc = "A part which allows a ship to move through space." c.properties = {} c.properties[Property.byname('speed')] = """(lambda (design) 1000000)""" c.insert() d = Design() d.name = "Scout" d.desc = "A fast light ship with advanced sensors." d.owner = -1 d.categories = [Category.byname('Misc')] d.components = [] d.components.append((Component.byname('Escape Thrusters'), 4)) d.components.append((Component.byname('Armor Plate'), 2)) d.components.append((Component.byname('Primary Engine'), 5)) d.insert() d = Design() d.name = "Frigate" d.desc = "A general purpose ship with weapons and ability to colonise new planets." d.owner = -1 d.categories = [Category.byname('Misc')] d.components = [] d.components.append((Component.byname('Armor Plate'), 4)) d.components.append((Component.byname('Primary Engine'), 2)) d.components.append((Component.byname('Colonisation Pod'), 1)) d.components.append((Component.byname('Missile'), 2)) d.insert() d = Design() d.name = "Battleship" d.desc = "A heavy ship who's main purpose is to blow up other ships." d.owner = -1 d.categories = [Category.byname('Misc')] d.components = [] d.components.append((Component.byname('Armor Plate'), 6)) d.components.append((Component.byname('Primary Engine'), 3)) d.components.append((Component.byname('Missile'), 3)) d.components.append((Component.byname('Laser'), 4)) d.insert() trans.commit() except: trans.rollback() raise # FIXME: Need to populate the database with the MiniSec design stuff, # - Firepower # - Armor/HP # - Speed # - Sensors (scouts ability to disappear).... pass
def initialise(self, seed=None): """\ TIM Trader """ trans = dbconn.begin() try: RulesetBase.initialise(self) # Need to create the top level universe object... universe = Object(type='tp.server.rules.base.objects.Universe') universe.id = 0 universe.name = "The Universe" universe.size = SIZE universe.parent = 0 universe.posx = 0 universe.posy = 0 universe.turn = 0 universe.insert() # Create all the resources, they consist of, # - One resource for each resource specified in resources.csv # - One resource for each factory specified in prodcon.csv reader = csv.DictReader(open(os.path.join(self.files, "resources.csv"), "r")) for row in reader: if row['namesingular'] is '': continue r = Resource() for name, cell in row.iteritems(): if cell is '': continue try: setattr(r, name, convert(getattr(Resource.table.c, name), cell)) except AttributeError, e: # FIXME: These shouldn't really occur... pass r.transportable = bool(row['transportable']) r.insert() import ProducersConsumers for factory in ProducersConsumers.loadfile(os.path.join(self.files, "prodcon.csv")): # FIXME: Make these auto generated resources much nicer... # Ignore the special case factories which are also goods. try: r = Resource(Resource.byname(factory.name)) r.desc += "\n" except NoSuch: r = Resource() r.namesingular = factory.name r.nameplural = factory.name r.desc = "" r.weight = 1000 r.size = 1000 r.desc += "Converts" for product in factory.products: # FIXME: Should also display if usage of this resource is required to grow.... r.desc += "\n\t%s -> %s" % product r.products = factory.products r.save() trans.commit()
def initialise(self, seed=None): """\ TIM Trader """ trans = dbconn.begin() try: RulesetBase.initialise(self) # Need to create the top level universe object... universe = Object(type='tp.server.rules.base.objects.Universe') universe.id = 0 universe.name = "The Universe" universe.size = SIZE universe.parent = 0 universe.posx = 0 universe.posy = 0 universe.turn = 0 universe.insert() # Create all the resources, they consist of, # - One resource for each resource specified in resources.csv # - One resource for each factory specified in prodcon.csv reader = csv.DictReader( open(os.path.join(self.files, "resources.csv"), "r")) for row in reader: if row['namesingular'] is '': continue r = Resource() for name, cell in row.iteritems(): if cell is '': continue try: setattr(r, name, convert(getattr(Resource.table.c, name), cell)) except AttributeError, e: # FIXME: These shouldn't really occur... pass r.transportable = bool(row['transportable']) r.insert() import ProducersConsumers for factory in ProducersConsumers.loadfile( os.path.join(self.files, "prodcon.csv")): # FIXME: Make these auto generated resources much nicer... # Ignore the special case factories which are also goods. try: r = Resource(Resource.byname(factory.name)) r.desc += "\n" except NoSuch: r = Resource() r.namesingular = factory.name r.nameplural = factory.name r.desc = "" r.weight = 1000 r.size = 1000 r.desc += "Converts" for product in factory.products: # FIXME: Should also display if usage of this resource is required to grow.... r.desc += "\n\t%s -> %s" % product r.products = factory.products r.save() trans.commit()
def populate(self, seed, system_min, system_max, planet_min, planet_max): """\ --populate <game> <random seed> <min systems> <max systems> <min planets> <max planets> Populate a universe with a number of systems and planets. The number of systems in the universe is dictated by min/max systems. The number of planets per system is dictated by min/max planets. """ # Convert arguments to integers seed, system_min, system_max, planet_min, planet_max = ( int(seed), int(system_min), int(system_max), int(planet_min), int(planet_max)) dbconn.use(self.game) trans = dbconn.begin() try: RulesetBase.populate(self, seed) r = Resource(Resource.byname('Ship Parts Factory')) # FIXME: Assuming that the Universe and the Galaxy exist. r = random.Random() r.seed(seed) # Create the actual systems and planets. for i in range(0, r.randint(system_min, system_max)): pos = r.randint(SIZE * -1, SIZE) * 1000, r.randint( SIZE * -1, SIZE) * 1000, r.randint(SIZE * -1, SIZE) * 1000 # Add system system = Object(type='tp.server.rules.base.objects.System') system.name = "System %s" % i system.size = r.randint(800000, 2000000) system.posx = pos[0] system.posy = pos[1] system.insert() ReparentOne(system) system.save() print "Created system (%s) with the id: %i" % (system.name, system.id) # In each system create a number of planets for j in range(0, r.randint(planet_min, planet_max)): planet = Object( type='tp.server.rules.timtrader.objects.Planet') planet.name = "Planet %i in %s" % (j, system.name) planet.size = r.randint(1000, 10000) planet.parent = system.id planet.posx = pos[0] + r.randint(1, 100) * 1000 planet.posy = pos[1] + r.randint(1, 100) * 1000 planet.insert() print "Created planet (%s) with the id: %i" % (planet.name, planet.id) # FIXME: Add minerals Iron, Uranium mine = False for mineral in minerals: # Does this planet have this mineral if r.random() * 100 > mineral.probability: # Add a smattering of minerals planet.resources_add(id, r.randint(0, mineral.density), Planet.MINEABLE) mine = True # Add a mine to each planet which has minerals if mine: planet.resources_add(Resource.byname('Mine'), 1, Planet.ACCESSABLE) # FIXME: Add growing resources for grow in growing: if r.random() * 100 > grow.probability: # Add a smattering of breeding grounds planet.resources_add(Resource.byname(''), 1, Planet.ACCESSABLE) # Add a smattering of the same stocks planet.resources_add(Resource.byname(''), r.randint(0, grow.density), Planet.MINEABLE) # Add 1 fishery/slaughter house to each location # FIXME: Add a other industries in random locations for factory in factories: pass # FIXME: Add a bunch of cities planet.save() trans.commit() except: trans.rollback() raise
def initialise(self, seed=None): """\ Minisec """ dbconn.use(self.game) trans = dbconn.begin() try: MinisecRuleset.initialise(self) reader = csv.DictReader( open(os.path.join(self.files, "resources.csv"), "r")) for row in reader: r = Resource() for name, cell in row.iteritems(): if cell is '': continue setattr(r, name, convert(getattr(Resource.table.c, name), cell)) pprint.pprint(r.__dict__) r.insert() reader = csv.DictReader( open(os.path.join(self.files, "categories.csv"), "r")) for row in reader: c = Category() for name, cell in row.iteritems(): setattr(c, name, cell) pprint.pprint(c.__dict__) c.insert() # Create the properties that a design might have p = Property() p.categories = [Category.byname('Misc')] p.name = "speed" p.displayname = "Speed" p.desc = "The maximum number of parsecs the ship can move each turn." p.calculate = """\ (lambda (design bits) (let ((n (apply + bits))) (cons n (string-append (number->string (/ n 1000000)) " kpcs")))) """ p.insert() p = Property() p.categories = [Category.byname('Production')] p.name = "cost" p.displayname = "Cost" p.desc = "The number of components needed to build the ship" p.calculate = """\ (lambda (design bits) (let ((n (apply + bits))) (cons n (string-append (number->string n) " turns")) ) ) """ p.insert() p = Property() p.categories = [Category.byname('Combat')] p.name = "hp" p.displayname = "Hit Points" p.desc = "The amount of damage the ship can take." p.calculate = """\ (lambda (design bits) (let ((n (apply + bits))) (cons n (string-append (number->string n) " HP")))) """ p.insert() p = Property() p.categories = [Category.byname('Combat')] p.name = "backup-damage" p.displayname = "Backup Damage" p.desc = "The amount of damage that the ship will do when using it's backup weapon. (IE When it draws a battle round.)" p.calculate = """\ (lambda (design bits) (let ((n (apply + bits))) (cons n (string-append (number->string n) " HP")))) """ p.insert() p = Property() p.categories = [Category.byname('Combat')] p.name = "primary-damage" p.displayname = "Primary Damage" p.desc = "The amount of damage that the ship will do when using it's primary weapon. (IE When it wins a battle round.)" p.calculate = """\ (lambda (design bits) (let ((n (apply + bits))) (cons n (string-append (number->string n) " HP")))) """ p.insert() p = Property() p.categories = [Category.byname('Misc')] p.name = "escape" p.displayname = "Escape Chance" p.desc = "The chance the ship has of escaping from battle." p.calculate = """\ (lambda (design bits) (let ((n (apply + bits))) (cons n (string-append (number->string (* n 100)) " %")))) """ p.insert() p = Property() p.categories = [Category.byname('Misc')] p.name = "colonise" p.displayname = "Can Colonise Planets" p.desc = "Can the ship colonise planets/" p.calculate = """\ (lambda (design bits) (let ((n (apply + bits))) (cons n (if (> n 1) "Yes" "No")))) """ p.insert() c = Component() c.categories = [Category.byname('Combat')] c.name = "Missile" c.desc = "Missile which does 1HP of damage." c.properties = {} c.properties[Property.byname('primary-damage')] = None c.insert() c = Component() c.categories = [Category.byname('Combat')] c.name = "Laser" c.desc = "Lasers which do 1HP of damage." c.properties = {} c.properties[Property.byname( 'backup-damage')] = """(lambda (design) 0.25)""" c.insert() c = Component() c.categories = [Category.byname('Combat')] c.name = "Armor Plate" c.desc = "Armor Plate which absorbes 1HP of damage." c.properties = {} c.properties[Property.byname('hp')] = None c.insert() c = Component() c.categories = [Category.byname('Misc')] c.name = "Colonisation Pod" c.desc = "A part which allows a ship to colonise a planet." c.properties = {} c.properties[Property.byname('colonise')] = None c.insert() c = Component() c.categories = [Category.byname('Misc')] c.name = "Escape Thrusters" c.desc = "A part which allows a ship to escape combat." c.properties = {} c.properties[Property.byname( 'escape')] = """(lambda (design) 0.25)""" c.insert() c = Component() c.categories = [Category.byname('Misc')] c.name = "Primary Engine" c.desc = "A part which allows a ship to move through space." c.properties = {} c.properties[Property.byname( 'speed')] = """(lambda (design) 1000000)""" c.insert() d = Design() d.name = "Scout" d.desc = "A fast light ship with advanced sensors." d.owner = -1 d.categories = [Category.byname('Misc')] d.components = [] d.components.append((Component.byname('Escape Thrusters'), 4)) d.components.append((Component.byname('Armor Plate'), 2)) d.components.append((Component.byname('Primary Engine'), 5)) d.insert() d = Design() d.name = "Frigate" d.desc = "A general purpose ship with weapons and ability to colonise new planets." d.owner = -1 d.categories = [Category.byname('Misc')] d.components = [] d.components.append((Component.byname('Armor Plate'), 4)) d.components.append((Component.byname('Primary Engine'), 2)) d.components.append((Component.byname('Colonisation Pod'), 1)) d.components.append((Component.byname('Missile'), 2)) d.insert() d = Design() d.name = "Battleship" d.desc = "A heavy ship who's main purpose is to blow up other ships." d.owner = -1 d.categories = [Category.byname('Misc')] d.components = [] d.components.append((Component.byname('Armor Plate'), 6)) d.components.append((Component.byname('Primary Engine'), 3)) d.components.append((Component.byname('Missile'), 3)) d.components.append((Component.byname('Laser'), 4)) d.insert() trans.commit() except: trans.rollback() raise # FIXME: Need to populate the database with the MiniSec design stuff, # - Firepower # - Armor/HP # - Speed # - Sensors (scouts ability to disappear).... pass