Example #1
0
    def startGame(self):
        db = self.app.layoutDatabase
        game = LocalGame(db, SIZE[0], SIZE[1], onceOnly=True)

        for i in range(AICOUNT):
            game.addBot('ranger')

        self.onStart.execute(game)
Example #2
0
    def practiseClicked(self):
        db = self.app.layoutDatabase

        SIZE = (3, 1)
        AICOUNT = 5

        game = LocalGame(db, SIZE[0], SIZE[1], onceOnly=True)

        for i in range(AICOUNT):
            game.addBot('ranger')

        self.app.connector.openGameObject(game)
Example #3
0
    def startGame(self, level=None):
        db = mapLayout.LayoutDatabase(pathGetter=self.theme.getPath,
                                      blocks=self.mapBlocks)
        gameType = 'solo'
        self.game = game = LocalGame(
            db,
            self.size[0],
            self.size[1],
            onceOnly=True,
            blockRatio=self.blockRatio,
            duration=self.duration * 60,
            level=level,
            gameType=gameType,
        )
        if self.testMode:
            game.world.setTestMode()

        self.ais[:] = []

        try:
            for i in range(self.aiCount):
                if self.stackTeams:
                    ai = game.addBot(self.aiClass, team=game.world.teams[0])
                else:
                    ai = game.addBot(self.aiClass)
                self.ais.append(ai)
        except ImportError:
            print('AI module not found: %s' % (self.aiClass, ),
                  file=sys.stderr)
            sys.exit(1)
        except AttributeError:
            print(
                ('AI module does not define BotClass: %s' % (self.aiClass, )),
                file=sys.stderr)
            sys.exit(1)

        # Create a client and an interface.
        if self.isolate:
            rgame = RemoteGame(db)
            hub = LocalHub(game)
            self.tweener = UIMsgThrottler()
            if self.delay:
                delayer = DelayNodeHub(self.delay)
                hub.connectNode(delayer)
                delayer.connectNode(self.tweener)
            else:
                hub.connectNode(self.tweener)
            self.tweener.connectNode(rgame)
            self.rgame = rgame
            rgame.connected(game.world.dumpEverything())
            self.uiAgent = agent = PandaUIAgent(self, rgame)
        else:
            self.tweener = LocalGameTweener(game)
            self.uiAgent = agent = PandaUIAgent(self, game)
        agent.onDisconnectRequest.addListener(self.stop)
        agent.onConnectionLost.addListener(self.stop)

        agent.show()
Example #4
0
    def startListenServer(self, halfMapWidth=3, mapHeight=2):
        if self.server is not None and self.server.running:
            return
        game = LocalGame(self.layoutDatabase,
                         saveReplay=True,
                         gamePrefix='LAN',
                         level=StandardLobbyLevel((halfMapWidth, mapHeight),
                                                  lobbySettings=None))
        self.server = TrosnothServerFactory(game)

        self.server.onShutdown.addListener(self._serverShutdown)
        self.server.startListening()
Example #5
0
    def startServer(
            self, halfMapWidth=3, mapHeight=2,
            gameDuration=0, invisibleGame=False):
        if self.server is not None and self.server.running:
            return
        game = LocalGame(
            self.layoutDatabase, halfMapWidth, mapHeight,
            duration=gameDuration * 60,
            saveReplay=True, gamePrefix='LAN')
        self.server = TrosnothServerFactory(game)
        self.serverInvisible = invisibleGame

        self.server.onShutdown.addListener(self._serverShutdown)
        self.server.startListening()
Example #6
0
    def createGame(self):
        '''
        Creates a new game and returns the game id.
        '''
        gameId = self.nextId
        self.nextId += 1
        authTagMan = self.authManager.newTagManager()

        game = LocalGame(
            layoutDatabase=self.layoutDatabase,
            maxPerTeam=self.settings.maxPerTeam,
            authTagManager=authTagMan,
            saveReplay=True,
            gamePrefix='Server',
            replayPath=REPLAY_SUB_PATH,
            level=StandardLobbyLevel(self.settings.lobbySize),
        )
        server = TrosnothServerFactory(game, authTagMan)

        def onShutdown():
            server.stopListening()
            del self.servers[gameId]
            del self.gameStats[game]
            game.world.onSwitchStats.removeListener(switchGameStats)
            if gameId == self.primaryGameId:
                self.primaryGameId = None
                self.onPrimaryGameChanged(None)

        server.onShutdown.addListener(onShutdown)
        server.startListening()

        self.gameStats[game] = None
        switchGameStats = partial(self.switchGameStats, game=game)
        game.world.onSwitchStats.addListener(switchGameStats)

        if murmur.state == 'initialised':
            game.world.onChangeVoiceChatRooms.addListener(murmur.setupRooms)

        log.info('Created game (id=%d)' % (gameId, ))
        self.servers[gameId] = server
        self.broadcast('a new game has been created')
        if self.primaryGameId is None:
            self.primaryGameId = gameId
            self.onPrimaryGameChanged(server)

        return gameId
    def startServer(self, halfMapWidth=3, mapHeight=2, gameDuration=0):
        if self.server is not None and self.server.running:
            log.warning('Refusing to start local game: one is already running')
            return

        game = LocalGame(self.app.layoutDatabase,
                         halfMapWidth,
                         mapHeight,
                         duration=gameDuration * 60,
                         saveReplay=True,
                         gamePrefix='LAN')

        self.server = TrosnothServerFactory(game)
        self.server.onShutdown.addListener(self._serverShutdown)
        self.server.startListening()

        # Start listening for game requests on the lan.
        self.multicaster = UDPMulticaster(self._getGames)