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
Example #2
0
    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