view eosd @ 479:1de67f332f00

Fix several synchro issues
author Thibaut Girka <thib@sitedethib.com>
date Wed, 28 Dec 2011 19:42:48 +0100
parents 44c5e7d4b615
children 2f53be1b2f60
line wrap: on
line source

#!/usr/bin/env python
# -*- encoding: utf-8 -*-
##
## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation; version 3 only.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##

import argparse
import os

import pyximport
pyximport.install()

from pytouhou.resource.loader import Loader
from pytouhou.game.background import Background
from pytouhou.ui.gamerunner import GameRunner
from pytouhou.games.eosd import EoSDGame
from pytouhou.game.player import PlayerState
from pytouhou.formats.t6rp import T6RP


def main(path, stage_num, rank, character, replay, data, port, remote):
    players = [PlayerState(character=character)]

    if replay:
        with open(replay, 'rb') as file:
            replay = T6RP.read(file)
        rank = replay.rank
        character = replay.character
        if not replay.levels[stage_num-1]:
            raise Exception
        from pytouhou.utils.random import Random
        prng = Random(replay.levels[stage_num-1].random_seed)
    else:
        prng = None

    if port != 0:
        from pytouhou.network import Network
        from pytouhou.utils.random import Random

        players = [PlayerState(character=0), PlayerState(character=2)]

        if remote:
            remote_addr, remote_port = remote.split(':')
            addr = remote_addr, int(remote_port)
            selected_player = 0
        else:
            addr = None
            selected_player = 1

        prng = Random(0)
        con = Network(port, addr, selected_player)
    else:
        con = None

    resource_loader = Loader()
    resource_loader.scan_archives(os.path.join(path, name)
                                    for name in data)
    game = EoSDGame(resource_loader, players, stage_num, rank, 16,
                    prng=prng)

    # Load stage data
    stage = resource_loader.get_stage('stage%d.std' % stage_num)

    background_anm_wrapper = resource_loader.get_anm_wrapper(('stg%dbg.anm' % stage_num,))
    background = Background(stage, background_anm_wrapper)

    # Main loop
    runner = GameRunner(resource_loader, game, background, replay=replay, con=con)
    runner.start()


parser = argparse.ArgumentParser(description='Libre reimplementation of the Touhou 6 engine.')

parser.add_argument('data', metavar='DAT', default=('CM.DAT', 'ST.DAT'), nargs='*', help='Game’s .DAT data files')
parser.add_argument('-p', '--path', metavar='DIRECTORY', default='.', help='Game directory path.')
parser.add_argument('-s', '--stage', metavar='STAGE', type=int, required=True, help='Stage, 1 to 7 (Extra).')
parser.add_argument('-r', '--rank', metavar='RANK', type=int, default=0, help='Rank, from 0 (Easy, default) to 3 (Lunatic).')
parser.add_argument('-c', '--character', metavar='CHARACTER', type=int, default=0, help='Select the character to use, from 0 (ReimuA, default) to 3 (MarisaB).')
parser.add_argument('--replay', metavar='REPLAY', help='Select a replay')
parser.add_argument('--port', metavar='PORT', type=int, default=0, help='Port to use for netplay')
parser.add_argument('--remote', metavar='REMOTE', default=None, help='Remote address')

args = parser.parse_args()

main(args.path, args.stage, args.rank, args.character, args.replay, tuple(args.data), args.port, args.remote)