예제 #1
0
    def reregister(self, tran, obj):
        # nearly identical to register, just now we know the galaxy
        # to add this information tu AIList
        log.debug("Reregistering player", obj.oid)
        counter = 1
        while 1:
            try:
                obj.name = u'Rebel faction %d' % counter
                obj.login = '******' % counter
#                log.debug("Trying", obj.name)
                password = hashlib.sha1(str(random.randrange(0, 1e10))).hexdigest()
                tran.gameMngr.registerPlayer(obj.login, obj, obj.oid)
                log.debug("Player registered")
                tran.db[OID_UNIVERSE].players.append(obj.oid)
                tran.gameMngr.clientMngr.createAiAccount(None, obj.login, password, obj.name)
                break
            except CreatePlayerException:
#                log.debug("Name exists")
                counter += 1
        # after succesfull registration, register it to the AI system
        aiList = AIList(tran.gameMngr.configDir, tran.gameMngr.gameName)
        aiList.add(obj.login, password, 'ais_rebel')
        aiList.setGalaxy(obj.login, tran.db[obj.galaxies[0]].name)
        # grant techs and so on
        self.cmd(obj).update(tran, obj)
예제 #2
0
 def setupEnvironment(self, tran, obj):
     # check required players
     universe = tran.db[OID_UNIVERSE]
     players = {}
     for playerType in (T_AIRENPLAYER, T_AIMUTPLAYER, T_AIPIRPLAYER, T_AIEDENPLAYER):
         found = 0
         for playerID in universe.players:
             player = tran.db[playerID]
             if obj.oid in player.galaxies and player.type == playerType:
                 players[playerType] = player
                 found = 1
                 break
         if found:
             continue
         # create new player
         log.debug("Creating new player", playerType)
         player = self.new(playerType)
         self.cmd(player).register(tran, player)
         aiList = AIList(tran.gameMngr.configDir, tran.gameMngr.gameName)
         aiList.setGalaxy(player.login, obj.name)
         player.galaxies.append(obj.oid)
         players[playerType] = player
     # great we have all players - scan planets
     for systemID in obj.systems:
         system = tran.db[systemID]
         for planetID in system.planets:
             planet = tran.db[planetID]
             # renegades
             if planet.plStratRes in (SR_TL1A, SR_TL1B) and planet.owner == OID_NONE:
                 # populate planet
                 log.debug("Adding renegades", planetID)
                 self.cmd(planet).changeOwner(tran, planet, players[T_AIRENPLAYER].oid, 1)
                 planet.slots.append(Utils.newStructure(tran, Rules.Tech.RENEGADEBASE, planet.owner))
                 planet.storPop = 3000
             # pirates
             if planet.plStratRes in (SR_TL3A, SR_TL3B, SR_TL3C) and planet.owner == OID_NONE:
                 # populate planet
                 log.debug("Adding pirates", planetID)
                 self.cmd(planet).changeOwner(tran, planet, players[T_AIPIRPLAYER].oid, 1)
                 planet.slots.append(Utils.newStructure(tran, Rules.Tech.PIRATEBASE, planet.owner))
                 planet.storPop = 5000
                 if planet.plSlots > 1:
                     planet.slots.append(Utils.newStructure(tran, Rules.Tech.PIRATEDEN, planet.owner))
                     planet.storPop += 1000
             # EDEN
             if planet.plStratRes in (SR_TL5A, SR_TL5B, SR_TL5C) and planet.owner == OID_NONE:
                 # populate planet
                 log.debug("Adding EDEN", planetID)
                 self.cmd(planet).changeOwner(tran, planet, players[T_AIEDENPLAYER].oid, 1)
                 if planet.plSlots < 2:
                     planet.plSlots = 2
                     if planet.plMaxSlots < 2:
                         planet.plMaxSlots = 2
                     if planet.plDiameter < 2000:
                         planet.plDiameter = 2000
                 planet.slots.append(Utils.newStructure(tran, Rules.Tech.EDENBASE, planet.owner))
                 planet.slots.append(Utils.newStructure(tran, Rules.Tech.EDENSTATION, planet.owner))
                 planet.storPop = 3000
             # mutants
             if planet.plDisease != 0 and planet.owner == OID_NONE:
                 # populate planet
                 log.debug("Adding mutants", planetID)
                 self.cmd(planet).changeOwner(tran, planet, players[T_AIMUTPLAYER].oid, 1)
                 planet.slots.append(Utils.newStructure(tran, Rules.Tech.MUTANTBASE, planet.owner))
                 planet.storPop = 3000
예제 #3
0
    def enableTime(self, tran, obj, force = 0, deleteSP = 0, enable = 1):
        log.debug('IGalaxy', 'Checking for time...')
        if not force:
            if obj.timeEnabled:
                return
            canRun = 0
            # there must be at least 1/2 positions already assigned
            #if len(obj.startingPos) <= obj.numOfStartPos / 2 and obj.creationTime < time.time() - 2 * 24 * 3600:
            #   log.debug("Half galaxy populated", len(obj.startingPos), obj.numOfStartPos)
            #   canRun = 1
            # at least two days must pass from creation
            if not obj.startingPos and not obj.bookedCreation:
                log.debug("All positions taken, starting galaxy")
                canRun = 1
            if obj.creationTime < time.time() - 2 * 24 * 3600:
                log.debug("Two days passed", obj.creationTime, time.time() - 2 * 24 * 3600)
                canRun = 1
            if not canRun:
                return 0
        # spawn rebel player on all vacant starting positions
        for positionID in copy.copy(obj.startingPos):
            obj.startingPos.remove(positionID)
            # create new player
            log.debug("Creating new Rebel player", T_AIPLAYER)
            player = self.new(T_AIPLAYER)
            self.cmd(player).register(tran, player)
            player.galaxies.append(obj.oid)
            playerID = player.oid
            # finish AI list
            aiList = AIList(tran.gameMngr.configDir, tran.gameMngr.gameName)
            aiList.setGalaxy(player.login, obj.name)
            # TODO tweak more planet's attrs
            planet = tran.db[positionID]
            # Grant starting technologies (at medium improvement)
            for techID in Rules.techs.keys():
                if Rules.techs[techID].isStarting:
                    player.techs[techID] = (Rules.techBaseImprovement + Rules.techMaxImprovement) / 2
            self.cmd(planet).changeOwner(tran, planet, playerID, 1)
            planet.slots = [
                Utils.newStructure(tran, Tech.PWRPLANTNUK1, playerID, STRUCT_STATUS_ON),
                Utils.newStructure(tran, Tech.FARM1, playerID, STRUCT_STATUS_ON),
                Utils.newStructure(tran, Tech.FARM1, playerID, STRUCT_STATUS_ON),
                Utils.newStructure(tran, Tech.FARM1, playerID, STRUCT_STATUS_ON),
                Utils.newStructure(tran, Tech.ANCFACTORY, playerID, STRUCT_STATUS_ON),
                Utils.newStructure(tran, Tech.ANCFACTORY, playerID, STRUCT_STATUS_ON),
                Utils.newStructure(tran, Tech.ANCRESLAB, playerID, STRUCT_STATUS_ON),
                Utils.newStructure(tran, Tech.REPAIR1, playerID, STRUCT_STATUS_ON),
            ]
            planet.storPop = Rules.startingPopulation
            planet.storBio = Rules.startingBio
            planet.storEn = Rules.startingEn
            planet.scannerPwr = Rules.startingScannerPwr
            planet.morale = Rules.maxMorale
            # fleet
            # add basic ships designs
            tempTechs = [Tech.FTLENG1, Tech.SCOCKPIT1, Tech.SCANNERMOD1, Tech.CANNON1,
                Tech.CONBOMB1, Tech.SMALLHULL1, Tech.MEDIUMHULL2, Tech.COLONYMOD2]
            for techID in tempTechs:
                player.techs[techID] = 1
            dummy, scoutID = tran.gameMngr.cmdPool[T_AIPLAYER].addShipDesign(tran, player, "Scout", Tech.SMALLHULL1,
                {Tech.FTLENG1:3, Tech.SCOCKPIT1:1, Tech.SCANNERMOD1:1})
            dummy, fighterID = tran.gameMngr.cmdPool[T_AIPLAYER].addShipDesign(tran, player, "Fighter", Tech.SMALLHULL1,
                {Tech.FTLENG1:3, Tech.SCOCKPIT1:1, Tech.CANNON1:1})
            dummy, bomberID = tran.gameMngr.cmdPool[T_AIPLAYER].addShipDesign(tran, player, "Bomber", Tech.SMALLHULL1,
                {Tech.FTLENG1:3, Tech.SCOCKPIT1:1, Tech.CONBOMB1:1})
            dummy, colonyID = tran.gameMngr.cmdPool[T_AIPLAYER].addShipDesign(tran, player, "Colony Ship", Tech.MEDIUMHULL2,
                {Tech.FTLENG1:4, Tech.SCOCKPIT1:1, Tech.COLONYMOD2:1})
            for techID in tempTechs:
                del player.techs[techID]
            # add small fleet
            log.debug('Creating fleet')
            system = tran.db[planet.compOf]
            fleet = tran.gameMngr.cmdPool[T_FLEET].new(T_FLEET)
            tran.db.create(fleet)
            log.debug('Creating fleet - created', fleet.oid)
            tran.gameMngr.cmdPool[T_FLEET].create(tran, fleet, system, playerID)
            log.debug('Creating fleet - addShips')
            tran.gameMngr.cmdPool[T_FLEET].addNewShip(tran, fleet, scoutID)
            tran.gameMngr.cmdPool[T_FLEET].addNewShip(tran, fleet, scoutID)
            tran.gameMngr.cmdPool[T_FLEET].addNewShip(tran, fleet, fighterID)
            tran.gameMngr.cmdPool[T_FLEET].addNewShip(tran, fleet, fighterID)
            tran.gameMngr.cmdPool[T_FLEET].addNewShip(tran, fleet, colonyID)
            system.scannerPwrs[playerID] = Rules.startingScannerPwr
        # do scanner evaluation because of all new players
        self.cmd(obj).processSCAN2Phase(tran, obj, None)
            # add player to universe
#            log.debug('Adding player to universe')
#            universe = tran.db[OID_UNIVERSE]
#            universe.players.append(playerID)

        # ok, enable time
        log.message('IGalaxy', 'Enabling time for', obj.oid)
        obj.timeEnabled = enable
        # close galaxy
        if deleteSP:
            obj.startingPos = []
        # load new galaxy
        # TODO
        # enable time for players
        for systemID in obj.systems:
            system = tran.db[systemID]
            for planetID in system.planets:
                planet = tran.db[planetID]
                if planet.owner != OID_NONE:
                    player = tran.db[planet.owner]
                    if player.timeEnabled != enable:
                        player.timeEnabled = enable
                        player.lastLogin = time.time()
                        if enable:
                            Utils.sendMessage(tran, player, MSG_ENABLED_TIME, player.oid, None)