Пример #1
0
    def _get_empire_string(self, player_id):
        empire = fo.getEmpire(fo.playerEmpireID(player_id))

        empire_color = (empire.colour.r, empire.colour.g, empire.colour.b,
                        empire.colour.a)

        return ("    " + self._formatter.underline(
            self._formatter.blue(empire.empireID)) +
                self._formatter.colored(empire_color, " %s" % empire.name) +
                self._formatter.white(' by %s' % fo.playerName(player_id)))
Пример #2
0
def handle_debug_chat(sender, message):
    human_id = [x for x in fo.allPlayerIDs() if fo.playerIsHost(x)][0]
    ais = [x for x in fo.allPlayerIDs() if not fo.playerIsHost(x)]
    if sender != human_id:
        pass  # don't chat with bots
    elif message == 'stop':
        global debug_mode
        debug_mode = False
        if ais[0] == fo.playerID():
            chat_human("exiting debug mode")
    elif debug_mode:
        out, err = shell(message)
        if out:
            chat_human(WHITE % out)
        if err:
            chat_human(RED % err)
    elif message.startswith('start'):
        try:
            player_id = int(message[5:].strip())
        except ValueError as e:
            print e
            return
        if player_id == fo.playerID():
            global debug_mode
            debug_mode = True
            # add some variables to scope
            lines = [
                'import FreeOrionAI as foAI', 'ai = foAI.foAIstate',
                'u = fo.getUniverse()', 'e = fo.getEmpire()'
            ]
            shell(';'.join(lines))
            chat_human(WHITE % "Entering debug mode. print 'stop' to exit.")
            chat_human(
                WHITE %
                " Local vars: <u>u</u>(universe), <u>e</u>(empire), <u>ai</u>(aistate)"
            )

    elif message == 'help':
        if ais[0] == fo.playerID():
            chat_human(WHITE % "Chat commands:")
            chat_human(
                WHITE %
                "  <u><rgba 0 255 255 255>start id</rgba></u>: start debug for selected empire"
            )
            chat_human(WHITE %
                       "  <u><rgba 0 255 255 255>stop</rgba></u>: stop debug")
            chat_human(WHITE % "Empire ids:")
            for player in fo.allPlayerIDs():
                if not fo.playerIsHost(player):
                    chat_human(
                        '  <rgba {0.colour.r} {0.colour.g} {0.colour.b} {0.colour.a}>id={0.empireID} empire_name={0.name}</rgba> player_name={1}'
                        .format(fo.getEmpire(fo.playerEmpireID(player)),
                                fo.playerName(player)))
Пример #3
0
def handle_debug_chat(sender, message):
    global debug_mode
    human_id = [x for x in fo.allPlayerIDs() if fo.playerIsHost(x)][0]
    ais = [x for x in fo.allPlayerIDs() if not fo.playerIsHost(x)]
    is_debug_chat = False
    if message == ENTERING_DEBUG_MESSAGE:
        is_debug_chat = True
    if sender != human_id:
        return is_debug_chat  # don't chat with bots
    elif message == 'stop':
        is_debug_chat = True
        if debug_mode:
            chat_human("exiting debug mode")
        debug_mode = False
    elif debug_mode:
        print('>', message, end='')
        is_debug_chat = True
        out, err = [x.strip('\n') for x in shell(message)]
        if out:
            chat_human(WHITE % out)
        if err:
            chat_human(RED % err)
    elif message.startswith('start'):
        is_debug_chat = True
        try:
            player_id = int(message[5:].strip())
        except ValueError as e:
            error(e)
            chat_human(str(e))
            return True
        if player_id == fo.playerID():
            debug_mode = True

            initial_code = [
                'from aistate_interface import get_aistate',
            ]

            # add some variables to scope: (name, help text, value)
            scopes_variable = (
                ('ai', 'aistate', 'get_aistate()'),
                ('u', 'universe', 'fo.getUniverse()'),
                ('e', 'empire', 'fo.getEmpire()'),
            )
            for var, _, code in scopes_variable:
                initial_code.append('%s = %s' % (var, code))

            shell(';'.join(initial_code))

            variable_template = '<u><rgba 255 255 0 255>%s</rgba></u>%s %s'
            variables = (variable_template % (var, ' ' * (3 - len(var)), name) for var, name, _ in scopes_variable)
            chat_human(WHITE % "%s\n"
                               "Print <rgba 255 255 0 255>'stop'</rgba> to exit.\n"
                               "Local variables:\n"
                               "  %s" % (ENTERING_DEBUG_MESSAGE, '\n  '.join(variables)))

    elif message == 'help':
        is_debug_chat = True
        if ais[0] == fo.playerID():
            chat_human(WHITE % "Chat commands:")
            chat_human(WHITE % "  <u><rgba 0 255 255 255>start id</rgba></u>: start debug for selected empire")
            chat_human(WHITE % "  <u><rgba 0 255 255 255>stop</rgba></u>: stop debug")
            chat_human(WHITE % "Empire ids:")
            for player in fo.allPlayerIDs():
                if not fo.playerIsHost(player):
                    chat_human('  <rgba {0.colour.r} {0.colour.g} {0.colour.b} {0.colour.a}>id={0.empireID} empire_name={0.name}</rgba> player_name={1}'.format(fo.getEmpire(fo.playerEmpireID(player)), fo.playerName(player)))
    return is_debug_chat
def handle_debug_chat(sender, message):
    global debug_mode
    human_id = [x for x in fo.allPlayerIDs() if fo.playerIsHost(x)][0]
    ais = [x for x in fo.allPlayerIDs() if not fo.playerIsHost(x)]
    is_debug_chat = False
    if message == ENTERING_DEBUG_MESSAGE:
        is_debug_chat = True
    if sender != human_id:
        return is_debug_chat  # don't chat with bots
    elif message == 'stop':
        is_debug_chat = True
        if debug_mode:
            chat_human("exiting debug mode")
        debug_mode = False
    elif debug_mode:
        print '>', message,
        is_debug_chat = True
        out, err = [x.strip('\n') for x in shell(message)]
        if out:
            chat_human(WHITE % out)
        if err:
            chat_human(RED % err)
    elif message.startswith('start'):
        is_debug_chat = True
        try:
            player_id = int(message[5:].strip())
        except ValueError as e:
            print e
            chat_human(str(e))
            return True
        if player_id == fo.playerID():
            debug_mode = True

            initial_code = [
                'import FreeOrionAI as foAI',
            ]

            # add some variables to scope: (name, help text, value)
            scopes_variable = (
                ('ai', 'aistate', 'foAI.foAIstate'),
                ('u', 'universe', 'fo.getUniverse()'),
                ('e', 'empire', 'fo.getEmpire()'),
            )
            for var, _, code in scopes_variable:
                initial_code.append('%s = %s' % (var, code))

            shell(';'.join(initial_code))

            variable_template = '<u><rgba 255 255 0 255>%s</rgba></u>%s %s'
            variables = (variable_template % (var, ' ' * (3 - len(var)), name)
                         for var, name, _ in scopes_variable)
            chat_human(WHITE % "%s\n"
                       "Print <rgba 255 255 0 255>'stop'</rgba> to exit.\n"
                       "Local variables:\n"
                       "  %s" %
                       (ENTERING_DEBUG_MESSAGE, '\n  '.join(variables)))

    elif message == 'help':
        is_debug_chat = True
        if ais[0] == fo.playerID():
            chat_human(WHITE % "Chat commands:")
            chat_human(
                WHITE %
                "  <u><rgba 0 255 255 255>start id</rgba></u>: start debug for selected empire"
            )
            chat_human(WHITE %
                       "  <u><rgba 0 255 255 255>stop</rgba></u>: stop debug")
            chat_human(WHITE % "Empire ids:")
            for player in fo.allPlayerIDs():
                if not fo.playerIsHost(player):
                    chat_human(
                        '  <rgba {0.colour.r} {0.colour.g} {0.colour.b} {0.colour.a}>id={0.empireID} empire_name={0.name}</rgba> player_name={1}'
                        .format(fo.getEmpire(fo.playerEmpireID(player)),
                                fo.playerName(player)))
    return is_debug_chat
Пример #5
0
 def get_empire_color(self, player_id):
     empire = fo.getEmpire(fo.playerEmpireID(player_id))
     return empire.colour
Пример #6
0
 def get_empire_name(self, player_id):
     empire = fo.getEmpire(fo.playerEmpireID(player_id))
     return empire.name
Пример #7
0
def handle_debug_chat(sender, message):
    global debug_mode
    human_id = [x for x in fo.allPlayerIDs() if fo.playerIsHost(x)][0]
    ais = [x for x in fo.allPlayerIDs() if not fo.playerIsHost(x)]
    is_debug_chat = False
    if message == ENTERING_DEBUG_MESSAGE:
        is_debug_chat = True
    if sender != human_id:
        return is_debug_chat  # don't chat with bots
    elif message == 'stop':
        is_debug_chat = True
        if debug_mode:
            chat_human("exiting debug mode")
        debug_mode = False
    elif debug_mode:
        is_debug_chat = True
        out, err = shell(message)
        if out:
            chat_human(WHITE % out)
        if err:
            chat_human(RED % err)
    elif message.startswith('start'):
        is_debug_chat = True
        try:
            player_id = int(message[5:].strip())
        except ValueError as e:
            print e
            chat_human(str(e))
            return True
        if player_id == fo.playerID():
            debug_mode = True
            # add some variables to scope
            lines = ['import FreeOrionAI as foAI',
                     'ai = foAI.foAIstate',
                     'u = fo.getUniverse()',
                     'e = fo.getEmpire()'
                     ]
            shell(';'.join(lines))
            # Notify all players this AI entering debug mode
            fo.sendChatMessage(-1, WHITE % ENTERING_DEBUG_MESSAGE)
            chat_human(WHITE % "Print 'stop' to exit.")
            chat_human(WHITE % " Local vars: <u>u</u>(universe), <u>e</u>(empire), <u>ai</u>(aistate)")

    elif message == 'help':
        is_debug_chat = True
        if ais[0] == fo.playerID():
            chat_human(WHITE % "Chat commands:")
            chat_human(WHITE % "  <u><rgba 0 255 255 255>start id</rgba></u>: start debug for selected empire")
            chat_human(WHITE % "  <u><rgba 0 255 255 255>stop</rgba></u>: stop debug")
            chat_human(WHITE % "Empire ids:")
            for player in fo.allPlayerIDs():
                if not fo.playerIsHost(player):
                    chat_human('  <rgba {0.colour.r} {0.colour.g} {0.colour.b} {0.colour.a}>id={0.empireID} empire_name={0.name}</rgba> player_name={1}'.format(fo.getEmpire(fo.playerEmpireID(player)), fo.playerName(player)))
    return is_debug_chat