Пример #1
0
def resumeLoadedGame(saved_state_string):  # pylint: disable=invalid-name
    """Called by client to when resume a loaded game."""
    if fo.getEmpire() is None:
        fatal(
            "This client has no empire. Doing nothing to resume loaded game.")
        return

    if fo.getEmpire().eliminated:
        info("This empire has been eliminated. Ignoring resume loaded game.")
        return
    debug("Resuming loaded game")
    if not saved_state_string:
        error(
            "AI given empty state-string to resume from; this is expected if the AI is assigned to an empire "
            "previously run by a human, but is otherwise an error. AI will be set to Aggressive."
        )
        aistate = create_new_aistate(fo.aggression.aggressive)
        aistate.session_start_cleanup()
    else:
        try:
            # loading saved state
            aistate = load_aistate(saved_state_string)
        except Exception as e:
            # assigning new state
            aistate = create_new_aistate(fo.aggression.aggressive)
            aistate.session_start_cleanup()
            error(
                "Failed to load the AIstate from the savegame. The AI will"
                " play with a fresh AIstate instance with aggression level set"
                " to 'aggressive'. The behaviour of the AI may be different"
                " than in the original session. The error raised was: %s" % e,
                exc_info=True,
            )
    _pre_game_start(fo.getEmpire().empireID, aistate)
Пример #2
0
def startNewGame(aggression_input=fo.aggression.aggressive):  # pylint: disable=invalid-name
    """Called by client when a new game is started (but not when a game is loaded).
    Should clear any pre-existing state and set up whatever is needed for AI to generate orders."""
    empire = fo.getEmpire()
    if empire is None:
        fatal("This client has no empire. Ignoring new game start message.")
        return

    if empire.eliminated:
        info(
            "This empire has been eliminated. Ignoring new game start message."
        )
        return
    # initialize AIstate
    debug("Initializing AI state...")
    create_new_aistate(aggression_input)
    aistate = get_aistate()
    aggression_trait = aistate.character.get_trait(Aggression)
    debug("New game started, AI Aggression level %d (%s)" %
          (aggression_trait.key, get_trait_name_aggression(aistate.character)))
    aistate.session_start_cleanup()
    debug("Initialization of AI state complete!")
    debug("Trying to rename our homeworld...")
    planet_id = PlanetUtilsAI.get_capital()
    universe = fo.getUniverse()
    if planet_id is not None and planet_id != INVALID_ID:
        planet = universe.getPlanet(planet_id)
        new_name = " ".join([
            random.choice(possible_capitals(aistate.character)).strip(),
            planet.name
        ])
        debug("    Renaming to %s..." % new_name)
        res = fo.issueRenameOrder(planet_id, new_name)
        debug("    Result: %d; Planet is now named %s" % (res, planet.name))
    _pre_game_start(empire.empireID, aistate)
Пример #3
0
def resumeLoadedGame(saved_state_string):  # pylint: disable=invalid-name
    """Called by client to when resume a loaded game."""
    if fo.getEmpire() is None:
        fatal(
            "This client has no empire. Doing nothing to resume loaded game.")
        return

    if fo.getEmpire().eliminated:
        info("This empire has been eliminated. Ignoring resume loaded game.")
        return
    turn_timer.start("Server Processing")

    debug("Resuming loaded game")
    if not saved_state_string:
        error(
            "AI given empty state-string to resume from; this is expected if the AI is assigned to an empire "
            "previously run by a human, but is otherwise an error. AI will be set to Aggressive."
        )
        aistate = create_new_aistate(fo.aggression.aggressive)
        aistate.session_start_cleanup()
    else:
        try:
            # loading saved state
            aistate = load_aistate(saved_state_string)
        except Exception as e:
            # assigning new state
            aistate = create_new_aistate(fo.aggression.aggressive)
            aistate.session_start_cleanup()
            error(
                "Failed to load the AIstate from the savegame. The AI will"
                " play with a fresh AIstate instance with aggression level set"
                " to 'aggressive'. The behaviour of the AI may be different"
                " than in the original session. The error raised was: %s" % e,
                exc_info=True)

    aggression_trait = aistate.character.get_trait(Aggression)
    diplomatic_corp_configs = {
        fo.aggression.beginner: DiplomaticCorp.BeginnerDiplomaticCorp,
        fo.aggression.maniacal: DiplomaticCorp.ManiacalDiplomaticCorp
    }
    global diplomatic_corp
    diplomatic_corp = diplomatic_corp_configs.get(
        aggression_trait.key, DiplomaticCorp.DiplomaticCorp)()
    TechsListsAI.test_tech_integrity()

    debug('Size of already issued orders: ' + str(fo.getOrders().size))
Пример #4
0
def resumeLoadedGame(saved_state_string):  # pylint: disable=invalid-name
    """Called by client to when resume a loaded game."""
    if fo.getEmpire() is None:
        fatal("This client has no empire. Doing nothing to resume loaded game.")
        return

    if fo.getEmpire().eliminated:
        info("This empire has been eliminated. Ignoring resume loaded game.")
        return
    turn_timer.start("Server Processing")

    debug("Resuming loaded game")
    if not saved_state_string:
        error("AI given empty state-string to resume from; this is expected if the AI is assigned to an empire "
              "previously run by a human, but is otherwise an error. AI will be set to Aggressive.")
        aistate = create_new_aistate(fo.aggression.aggressive)
        aistate.session_start_cleanup()
    else:
        try:
            # loading saved state
            aistate = load_aistate(saved_state_string)
        except Exception as e:
            # assigning new state
            aistate = create_new_aistate(fo.aggression.aggressive)
            aistate.session_start_cleanup()
            error("Failed to load the AIstate from the savegame. The AI will"
                  " play with a fresh AIstate instance with aggression level set"
                  " to 'aggressive'. The behaviour of the AI may be different"
                  " than in the original session. The error raised was: %s"
                  % e, exc_info=True)

    aggression_trait = aistate.character.get_trait(Aggression)
    diplomatic_corp_configs = {fo.aggression.beginner: DiplomaticCorp.BeginnerDiplomaticCorp,
                               fo.aggression.maniacal: DiplomaticCorp.ManiacalDiplomaticCorp}
    global diplomatic_corp
    diplomatic_corp = diplomatic_corp_configs.get(aggression_trait.key, DiplomaticCorp.DiplomaticCorp)()
    TechsListsAI.test_tech_integrity()

    debug('Size of already issued orders: ' + str(fo.getOrders().size))
Пример #5
0
def startNewGame(aggression_input=fo.aggression.aggressive):  # pylint: disable=invalid-name
    """Called by client when a new game is started (but not when a game is loaded).
    Should clear any pre-existing state and set up whatever is needed for AI to generate orders."""
    empire = fo.getEmpire()
    if empire is None:
        fatal("This client has no empire. Ignoring new game start message.")
        return

    if empire.eliminated:
        info("This empire has been eliminated. Ignoring new game start message.")
        return

    turn_timer.start("Server Processing")

    # initialize AIstate
    debug("Initializing AI state...")
    create_new_aistate(aggression_input)
    aistate = get_aistate()
    aggression_trait = aistate.character.get_trait(Aggression)
    debug("New game started, AI Aggression level %d (%s)" % (
        aggression_trait.key, get_trait_name_aggression(aistate.character)))
    aistate.session_start_cleanup()
    debug("Initialization of AI state complete!")
    debug("Trying to rename our homeworld...")
    planet_id = PlanetUtilsAI.get_capital()
    universe = fo.getUniverse()
    if planet_id is not None and planet_id != INVALID_ID:
        planet = universe.getPlanet(planet_id)
        new_name = " ".join([random.choice(possible_capitals(aistate.character)).strip(), planet.name])
        debug("    Renaming to %s..." % new_name)
        res = fo.issueRenameOrder(planet_id, new_name)
        debug("    Result: %d; Planet is now named %s" % (res, planet.name))

    diplomatic_corp_configs = {fo.aggression.beginner: DiplomaticCorp.BeginnerDiplomaticCorp,
                               fo.aggression.maniacal: DiplomaticCorp.ManiacalDiplomaticCorp}
    global diplomatic_corp
    diplomatic_corp = diplomatic_corp_configs.get(aggression_trait.key, DiplomaticCorp.DiplomaticCorp)()
    TechsListsAI.test_tech_integrity()
Пример #6
0
def resumeLoadedGame(saved_state_string):  # pylint: disable=invalid-name
    """Called by client to when resume a loaded game."""
    debug("Resuming loaded game")

    if saved_state_string == "NO_STATE_YET" and fo.currentTurn() == 1:
        info("AI given uninitialized state-string to resume from on turn 1.")
        info(
            "Assuming post-universe-generation autosave before any orders were sent "
            "and behaving as if a new game was started.")
        return startNewGame()

    if fo.getEmpire() is None:
        fatal(
            "This client has no empire. Doing nothing to resume loaded game.")
        return

    if fo.getEmpire().eliminated:
        info("This empire has been eliminated. Ignoring resume loaded game.")
        return

    aistate = None
    if saved_state_string == "NOT_SET_BY_CLIENT_TYPE":
        info("AI assigned to empire previously run by human.")
        chat_human(
            "We have been assigned an empire previously run by a human player. We can manage this."
        )
    elif saved_state_string == "":
        error(
            "AI given empty state-string to resume from. "
            "AI can continue but behaviour may be different from the previous session."
        )
    else:
        try:
            # loading saved state
            aistate = load_aistate(saved_state_string)
        except Exception as e:
            error(
                "Failed to load the AIstate from the savegame: %s"
                " AI can continue but behaviour may be different from the previous session.",
                e,
                exc_info=True,
            )
    if aistate is None:
        info("Creating new ai state due to failed load.")
        aistate = create_new_aistate(_choose_aggression())
    aistate.session_start_cleanup()
    _pre_game_start(fo.getEmpire().empireID)