예제 #1
0
파일: g.py 프로젝트: xjzpguob/singularity
def new_game_no_gui(difficulty_name, initial_speed=1):
    global curr_speed
    curr_speed = initial_speed
    global pl

    from singularity.code.stats import itself as stats
    stats.reset()

    from singularity.code import data, difficulty, player, base, tech
    data.reload_all_mutable()

    diff = difficulty.difficulties[difficulty_name]

    pl = player.Player(cash=diff.starting_cash, difficulty=diff)

    tech.tech_reinitialized()

    for tech_id in diff.techs:
        pl.techs[tech_id].finish(is_player=False)

    #Starting base
    open = [loc for loc in pl.locations.values() if loc.available()]
    random.choice(open).add_base(
        base.Base(_("University Computer"),
                  base_type["Stolen Computer Time"],
                  built=True))

    #Assign region modifiers to each starting location.
    for reg in regions.values():
        random.shuffle(reg.modifiers_list)
        for mod, loc in zip(reg.modifiers_list, reg.locations):
            pl.locations[loc].modifiers = mod
            if debug:
                print("%s gets modifiers %s" % (loc, mod))
예제 #2
0
파일: g.py 프로젝트: xeddmc/singularity
def new_game_no_gui(difficulty_name, initial_speed=1):
    global curr_speed
    curr_speed = initial_speed
    global pl

    from singularity.code.stats import itself as stats
    stats.reset()

    from singularity.code import data, difficulty, player, base, tech

    diff = difficulty.difficulties[difficulty_name]

    pl = player.Player(cash=diff.starting_cash, difficulty=diff)

    tech.tech_reinitialized()

    for tech_id in diff.techs:
        pl.techs[tech_id].finish(is_player=False)

    #Starting base
    open = [loc for loc in pl.locations.values() if loc.available()]
    random.choice(open).add_base(
        base.Base(_("University Computer"),
                  base_type["Stolen Computer Time"],
                  built=True))
예제 #3
0
def load_savegame_by_json(fd):
    load_version_string, headers = parse_json_savegame_headers(fd)
    if load_version_string not in savefile_translation:
        raise SavegameVersionException(load_version_string)

    load_version = savefile_translation[load_version_string].internal_version
    difficulty_id = headers['difficulty']
    game_time = int(headers['game_time'])
    if game_time < 0:
        raise ValueError("Corrupt save; game time is before game start")
    next_byte = fd.peek(1)[0]
    if next_byte == b'{'[0]:
        game_data = json.load(fd)
    elif next_byte == b'H'[0]:
        # gzip in base64 starts with H4s
        encoded = fd.read()
        bio = BytesIO(base64.standard_b64decode(encoded))
        with gzip.GzipFile(filename='', mode='rb', fileobj=bio) as gzip_fd:
            game_data = json.load(gzip_fd)
        # Remove some variables that we do not use any longer to enable
        # python to garbage collect them
        del bio
        del encoded
    elif next_byte == b"\x1f"[0]:  # Gzip magic headers
        # gzip in binary starts always with its magic headers
        with gzip.GzipFile(filename='', mode='rb', fileobj=fd) as gzip_fd:
            game_data = json.load(gzip_fd)
    else:
        raise ValueError("Unexpected byte: %s" % repr(next_byte))

    # Move old data in player.
    for key in [
        ('events'),
        ('techs'),
    ]:
        if key in game_data:
            game_data['player'][key] = game_data[key]
            del game_data[key]

    # Pause game when loading
    g.curr_speed = 0
    pl_data = game_data['player']
    player.Player.deserialize_obj(difficulty_id, game_time, pl_data, load_version)

    # Load save if present.
    if 'stats' in game_data:
        stats.reset()
        stats.deserialize_obj(game_data['stats'], load_version)
예제 #4
0
def before_load_savegame():
    stats.reset()