Beispiel #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:
        print "This client has no empire. Doing nothing to resume loaded game."
        return

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

    global foAIstate
    print "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."
        )
        foAIstate = AIstate.AIstate(fo.aggression.aggressive)
        foAIstate.session_start_cleanup()
    else:
        import savegame_codec
        try:
            # loading saved state
            foAIstate = savegame_codec.load_savegame_string(saved_state_string)
        except Exception as e:
            # assigning new state
            foAIstate = AIstate.AIstate(fo.aggression.aggressive)
            foAIstate.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 = foAIstate.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))
Beispiel #2
0
def resumeLoadedGame(saved_state_string):  # pylint: disable=invalid-name
    """Called by client to when resume a loaded game."""
    if fo.getEmpire() is None:
        print "This client has no empire. Doing nothing to resume loaded game."
        return

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

    global foAIstate
    print "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.")
        foAIstate = AIstate.AIstate(fo.aggression.aggressive)
        foAIstate.session_start_cleanup()
    else:
        import savegame_codec
        try:
            # loading saved state
            foAIstate = savegame_codec.load_savegame_string(saved_state_string)
        except Exception as e:
            # assigning new state
            foAIstate = AIstate.AIstate(fo.aggression.aggressive)
            foAIstate.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 = foAIstate.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()
Beispiel #3
0
def test_not_unicode_decode_raises_error():
    with pytest.raises(SaveDecompressException,
                       match="Fail to decode base64 savestate"):
        load_savegame_string("шишка")
Beispiel #4
0
def test_not_gziped_decode_raises_error():
    with pytest.raises(SaveDecompressException,
                       match="Fail to decompress savestate"):
        load_savegame_string("aaaa")
Beispiel #5
0
def test_bytes_decode_to_object(serialized_object):
    obj, serialized_bytes = serialized_object
    assert obj == load_savegame_string(serialized_bytes.encode("utf-8"))
Beispiel #6
0
def test_string_decode_to_object(serialized_object):
    obj, serialized_string = serialized_object
    assert obj == load_savegame_string(serialized_string)
Beispiel #7
0
def test_string_with_sepcial_caracters_encoded_and_decoded_back(
        obj, pack_object):
    encoded = pack_object(obj)
    assert obj == load_savegame_string(encoded)
def test_decode_not_base64():
    with pytest.raises(SaveDecompressException,
                       match="Fail to decode base64 savestate"):
        load_savegame_string("///")
def test_save_load_game_from_bytes(save_string, state):
    result = load_savegame_string(save_string.encode("utf-8"))
    assert result == state
def test_save_load_game_from_string(save_string, state):
    result = load_savegame_string(save_string)
    assert result == state
Beispiel #11
0
def load_aistate(savegame_string):
    import savegame_codec
    global _aistate
    _aistate = savegame_codec.load_savegame_string(savegame_string)
    return _aistate