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 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 do(self): builder = Object(self.oid) if not hasattr(builder, "owner"): print "Could not do a build order because it was on an unownable object." self.remove() if self.turns() > 1: # Add another year to worked... self.worked += 1 print "Worked %s, %s left until built." % (self.worked, self.turns()) self.save() return # Build new fleet object fleet = Object(type='tp.server.rules.minisec.objects.Fleet') # Type Fleet fleet.parent = builder.id fleet.posx = builder.posx fleet.posy = builder.posy fleet.posz = builder.posz fleet.size = 1 fleet.owner = builder.owner fleet.ships = self.ships fleet.insert() fleet.name = self.name fleet.save() message = Message() message.slot = -1 message.bid = builder.owner message.subject = "Fleet built" message.body = """\ A new fleet (%s) has been built and is orbiting %s. It consists of: """ % (fleet.name, builder.name) for type, number in fleet.ships.items(): if number > 1: message.body += "%s %ss" % (number, Fleet.ship_types[type]) else: message.body += "%s %s" % (number, Fleet.ship_types[type]) message.insert() self.remove()
def do(self): builder = Object(self.oid) # FIXME: Check that this is a planet # FIXME: Check that this planet has the headquarter resource if False: print "Could not do a build order because it was on a planet headquaters. (This should not happen.)" self.remove() # Check that there are enough components to build this ship... # Build new fleet object fleet = Object(type='tp.server.rules.minisec.objects.Fleet') # Check if there is a design which matches this amount of components. If not create it... # Type Fleet fleet.parent = builder.id fleet.posx = builder.posx fleet.posy = builder.posy fleet.posz = builder.posz fleet.size = 1 fleet.owner = builder.owner fleet.ships = self.ships fleet.insert() fleet.name = self.name fleet.save() message = Message() message.slot = -1 message.bid = builder.owner message.subject = "Fleet built" message.body = """\ A new ship (%s) has been built and is orbiting %s. """ % (fleet.name, builder.name) message.insert() self.remove()