Esempio n. 1
0
    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
Esempio n. 3
0
	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()
Esempio n. 4
0
	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()
	def do(self):
		# We are going to have to modify the object so lets load it
		fleet = Object(self.oid)
		planet = Object(self.target)

		# Do checks :)
		message = Message()
		message.slot = -1
		message.bid = fleet.owner
		message.subject = "Colonise failed."

		if planet.posx != fleet.posx or planet.posy != fleet.posy or planet.posz != planet.posz:
			print "Colonise of Planet %s (%s) (by %s-%s) failed. The fleet was not orbiting the planet!" % (planet.id, planet.name, fleet.id, fleet.name)
			message.body = """\
Colonise of %s <b>failed</b> because %s was not orbiting the planet.<br>
The order has been removed.""" % (planet.name, fleet.name)
			message.insert()

			self.remove()
			return	
	
		if not planet.type.endswith('Planet'):
			print "Colonise of Planet %s (%s) (by %s-%s) failed. %s not a planet!" % (planet.id, planet.name, fleet.id, fleet.name, planet.name)
			message.body = """\
Colonise of %s <b>failed</b> because %s is not a Planet!<br>
The order has been removed.""" % (planet.name, planet.name)
			message.insert()

			self.remove()
			return

		if not planet.owner in (-1, 0):
			print "Colonise of Planet %s (%s) (by %s-%s) failed. %s is owned by %s." % (planet.id, planet.name, fleet.id, fleet.name, planet.name, planet.owner)
			message.body = """\
Colonise of %s <b>failed</b> because %s is already colonised by %s!<br>
You can decolonised the planet by bombing the bejesus out of it.
The order has been removed.""" % (planet.name, planet.name, planet.owner)
			message.insert()

			self.remove()
			return

		if not fleet.ships.has_key(Frigate) or fleet.ships[Frigate] < 1:
			print "Colonise of Planet %s (%s) (by %s-%s) failed. %s has no frigates." % (planet.id, planet.name, fleet.id, fleet.name, fleet.name)
			message.body = """\
Colonise of %s <b>failed</b> because %s does not have any Frigates!<br>
The order has been removed.""" % (planet.name, fleet.name)
			message.insert()

			self.remove()
			return

		print "Colonise of Planet %s (%s) (by %s-%s) succeeded." % (planet.id, planet.name, fleet.id, fleet.name)
		message.subject = "Colonise success."
		message.body = """\
Colonisation of %s <b>succeded</b>.""" % (planet.name,)
		message.insert()
		
		planet.owner = fleet.owner
		fleet.ships[Frigate] -= 1

		planet.save()
		fleet.save()

		self.remove()