Пример #1
0
        /// <summary>
        /// Setup code called before game runs.
        /// </summary>
        protected override void BeginRun()
        {
            base.BeginRun();

            var recordingpath = Options.RecordingPath ?? string.Empty;

            var recording = BuildRecording(recordingpath);

            if (recording != null)
            {
                m_subsystems.GetMainSystem <Menus.MenuSystem>().PostEvent(new Events.LoadReplay(recording));
                m_subsystems.GetMainSystem <Menus.MenuSystem>().PostEvent(new Events.SwitchScreen(ScreenType.Replay));
                return;
            }

            if (Options.Stage != null || Options.Player1 != null)
            {
                var p1 = GetPlayer(Options.Player1);
                var p2 = GetPlayer(Options.Player2);
                var p3 = Options.Player3 != null?GetPlayer(Options.Player3) : null;

                var p4 = Options.Player4 != null?GetPlayer(Options.Player4) : null;

                StageProfile stage  = null;
                var          stages = m_subsystems.GetMainSystem <Menus.MenuSystem>().GetSubSystem <ProfileLoader>().StageProfiles;
                if (Options.Stage != null)
                {
                    var filePath = $"stages/{Options.Stage}.def";
                    stage = stages.FirstOrDefault(o =>
                                                  string.Equals(o.Filepath, $"stages/{Options.Stage}.def", StringComparison.OrdinalIgnoreCase));
                    if (stage == null)
                    {
                        throw new EvaluationException($"Error message: Can't open stage :{filePath}");
                    }
                }

                stage = stage ?? stages.FirstOrDefault();

                var team1Mode = p3 != null ? TeamMode.Simul : TeamMode.Single;
                var team2Mode = p4 != null ? TeamMode.Simul : TeamMode.Single;
                var init      = new Combat.EngineInitialization(CombatMode.Versus,
                                                                team1Mode, team2Mode,
                                                                p1.Profile, 0, PlayerMode.Human, p3?.Profile, 0, PlayerMode.Ai,
                                                                p2.Profile, 0, PlayerMode.Human, p4?.Profile, 0, PlayerMode.Ai,
                                                                stage);

                m_subsystems.GetMainSystem <Menus.MenuSystem>().PostEvent(new Events.SetupCombat(init));
                m_subsystems.GetMainSystem <Menus.MenuSystem>().PostEvent(new Events.SwitchScreen(ScreenType.Versus));
                return;
            }

            m_subsystems.GetMainSystem <Menus.MenuSystem>().PostEvent(new Events.SwitchScreen(ScreenType.Title));
        }
Пример #2
0
        public void Set(EngineInitialization init)
        {
            if (init == null)
            {
                throw new ArgumentNullException(nameof(init));
            }

            Initialization = init;

            Stage = new Stage(this, init.Stage);

            Team1.CreatePlayers(init.Team1Mode, init.Team1P1, init.Team1P2);
            Team2.CreatePlayers(init.Team2Mode, init.Team2P1, init.Team2P2);

            GetSubSystem <Random>().Seed(init.Seed);

            Reset();
        }
Пример #3
0
        public void Set(EngineInitialization init)
        {
            if (init == null)
            {
                throw new ArgumentNullException("init");
            }

            m_init = init;

            m_stage = new Stage(this, init.Stage);

            Team1.CreatePlayers(init.P1, null);
            Team2.CreatePlayers(init.P2, null);

            GetSubSystem <Random>().Seed(init.Seed);

            Reset();
        }
Пример #4
0
        Replay.Recording BuildRecording(String filepath)
        {
            if (filepath == null) throw new ArgumentNullException("filepath");

            ProfileLoader profiles = m_subsystems.GetSubSystem<ProfileLoader>();

            if (m_subsystems.GetSubSystem<IO.FileSystem>().DoesFileExist(filepath) == false) return null;

            IO.TextFile text = m_subsystems.GetSubSystem<IO.FileSystem>().OpenTextFile(filepath);
            IO.TextSection header = text.GetSection("xnaMugen Replay Header");
            IO.TextSection data = text.GetSection("xnaMugen Replay Data");

            if (header == null || data == null) return null;

            Int32 version = header.GetAttribute<Int32>("Version", 0);
            CombatMode mode = header.GetAttribute<CombatMode>("Combat Mode", CombatMode.None);
            String p1name = header.GetAttribute<String>("Player 1 Name", null);
            String p1version = header.GetAttribute<String>("Player 1 Version", null);
            Int32 p1palette = header.GetAttribute<Int32>("Player 1 Palette", Int32.MinValue);
            String p2name = header.GetAttribute<String>("Player 2 Name", null);
            String p2version = header.GetAttribute<String>("Player 2 Version", null);
            Int32 p2palette = header.GetAttribute<Int32>("Player 2 Palette", Int32.MinValue);
            String stagepath = header.GetAttribute<String>("Stage Path", null);
            Int32 seed = header.GetAttribute<Int32>("Seed", Int32.MinValue);

            if (version != 1 || mode == CombatMode.None || stagepath == null || seed == Int32.MinValue) return null;
            if (p1name == null || p1version == null || p1palette == Int32.MinValue) return null;

            PlayerProfile p1profile = profiles.FindPlayerProfile(p1name, p1version);
            PlayerProfile p2profile = profiles.FindPlayerProfile(p2name, p2version);
            StageProfile stageprofile = profiles.FindStageProfile(stagepath);

            if (p1profile == null || p2profile == null || stageprofile == null) return null;

            Combat.EngineInitialization initsettings = new Combat.EngineInitialization(mode, p1profile, p1palette, p2profile, p2palette, stageprofile, seed);

            List<Replay.RecordingData> replaydata = new List<Replay.RecordingData>();

            Regex line_regex = new Regex(@"^(\d+),\s*(\d+),\s*(\d+),\s*(\d+),\s*(\d+)$", RegexOptions.IgnoreCase);
            StringConverter converter = profiles.GetSubSystem<StringConverter>();
            foreach (String dataline in data.Lines)
            {
                Match match = line_regex.Match(dataline);
                if (match.Success == false) continue;

                Replay.RecordingData inputdata = new Replay.RecordingData(
                    converter.Convert<Int32>(match.Groups[1].Value),
                    converter.Convert<Int32>(match.Groups[2].Value),
                    converter.Convert<Int32>(match.Groups[3].Value),
                    converter.Convert<Int32>(match.Groups[4].Value),
                    converter.Convert<Int32>(match.Groups[5].Value)
                    );

                replaydata.Add(inputdata);
            }

            return new Replay.Recording(initsettings, replaydata);
        }
Пример #5
0
        private Replay.Recording BuildRecording(string filepath)
        {
            if (filepath == null)
            {
                throw new ArgumentNullException(nameof(filepath));
            }

            var profiles = m_subsystems.GetSubSystem <ProfileLoader>();

            if (m_subsystems.GetSubSystem <IO.FileSystem>().DoesFileExist(filepath) == false)
            {
                return(null);
            }

            var text   = m_subsystems.GetSubSystem <IO.FileSystem>().OpenTextFile(filepath);
            var header = text.GetSection("xnaMugen Replay Header");
            var data   = text.GetSection("xnaMugen Replay Data");

            if (header == null || data == null)
            {
                return(null);
            }

            var version   = header.GetAttribute("Version", 0);
            var mode      = header.GetAttribute("Combat Mode", CombatMode.None);
            var p1name    = header.GetAttribute <string>("Player 1 Name", null);
            var p1version = header.GetAttribute <string>("Player 1 Version", null);
            var p1palette = header.GetAttribute("Player 1 Palette", int.MinValue);
            var p2name    = header.GetAttribute <string>("Player 2 Name", null);
            var p2version = header.GetAttribute <string>("Player 2 Version", null);
            var p2palette = header.GetAttribute("Player 2 Palette", int.MinValue);
            var stagepath = header.GetAttribute <string>("Stage Path", null);
            var seed      = header.GetAttribute("Seed", int.MinValue);

            if (version != 1 || mode == CombatMode.None || stagepath == null || seed == int.MinValue)
            {
                return(null);
            }
            if (p1name == null || p1version == null || p1palette == int.MinValue)
            {
                return(null);
            }

            var p1profile    = profiles.FindPlayerProfile(p1name, p1version);
            var p2profile    = profiles.FindPlayerProfile(p2name, p2version);
            var stageprofile = profiles.FindStageProfile(stagepath);

            if (p1profile == null || p2profile == null || stageprofile == null)
            {
                return(null);
            }

            // TODO: fix team modes and p2 profiles
            var initsettings = new Combat.EngineInitialization(mode, TeamMode.None, TeamMode.None,
                                                               p1profile, p1palette, PlayerMode.Human,
                                                               p1profile, p1palette, PlayerMode.Human,
                                                               p2profile, p2palette, PlayerMode.Human,
                                                               p2profile, p2palette, PlayerMode.Human,
                                                               stageprofile, seed);

            var replaydata = new List <Replay.RecordingData>();

            var line_regex = new Regex(@"^(\d+),\s*(\d+),\s*(\d+),\s*(\d+),\s*(\d+)$", RegexOptions.IgnoreCase);
            var converter  = profiles.GetSubSystem <StringConverter>();

            foreach (var dataline in data.Lines)
            {
                var match = line_regex.Match(dataline);
                if (match.Success == false)
                {
                    continue;
                }

                var inputdata = new Replay.RecordingData(
                    converter.Convert <int>(match.Groups[1].Value),
                    converter.Convert <int>(match.Groups[2].Value),
                    converter.Convert <int>(match.Groups[3].Value),
                    converter.Convert <int>(match.Groups[4].Value),
                    converter.Convert <int>(match.Groups[5].Value)
                    );

                replaydata.Add(inputdata);
            }

            return(new Replay.Recording(initsettings, replaydata));
        }
Пример #6
0
        public void Set(EngineInitialization init)
        {
			if (init == null) throw new ArgumentNullException("init");

			m_init = init;

            m_stage = new Stage(this, init.Stage);

            Team1.CreatePlayers(init.P1, null);
            Team2.CreatePlayers(init.P2, null);

			GetSubSystem<Random>().Seed(init.Seed);

            Reset();
        }
Пример #7
0
        Replay.Recording BuildRecording(String filepath)
        {
            if (filepath == null)
            {
                throw new ArgumentNullException("filepath");
            }

            ProfileLoader profiles = m_subsystems.GetSubSystem <ProfileLoader>();

            if (m_subsystems.GetSubSystem <IO.FileSystem>().DoesFileExist(filepath) == false)
            {
                return(null);
            }

            IO.TextFile    text   = m_subsystems.GetSubSystem <IO.FileSystem>().OpenTextFile(filepath);
            IO.TextSection header = text.GetSection("xnaMugen Replay Header");
            IO.TextSection data   = text.GetSection("xnaMugen Replay Data");

            if (header == null || data == null)
            {
                return(null);
            }

            Int32      version   = header.GetAttribute <Int32>("Version", 0);
            CombatMode mode      = header.GetAttribute <CombatMode>("Combat Mode", CombatMode.None);
            String     p1name    = header.GetAttribute <String>("Player 1 Name", null);
            String     p1version = header.GetAttribute <String>("Player 1 Version", null);
            Int32      p1palette = header.GetAttribute <Int32>("Player 1 Palette", Int32.MinValue);
            String     p2name    = header.GetAttribute <String>("Player 2 Name", null);
            String     p2version = header.GetAttribute <String>("Player 2 Version", null);
            Int32      p2palette = header.GetAttribute <Int32>("Player 2 Palette", Int32.MinValue);
            String     stagepath = header.GetAttribute <String>("Stage Path", null);
            Int32      seed      = header.GetAttribute <Int32>("Seed", Int32.MinValue);

            if (version != 1 || mode == CombatMode.None || stagepath == null || seed == Int32.MinValue)
            {
                return(null);
            }
            if (p1name == null || p1version == null || p1palette == Int32.MinValue)
            {
                return(null);
            }

            PlayerProfile p1profile    = profiles.FindPlayerProfile(p1name, p1version);
            PlayerProfile p2profile    = profiles.FindPlayerProfile(p2name, p2version);
            StageProfile  stageprofile = profiles.FindStageProfile(stagepath);

            if (p1profile == null || p2profile == null || stageprofile == null)
            {
                return(null);
            }

            Combat.EngineInitialization initsettings = new Combat.EngineInitialization(mode, p1profile, p1palette, p2profile, p2palette, stageprofile, seed);

            List <Replay.RecordingData> replaydata = new List <Replay.RecordingData>();

            Regex           line_regex = new Regex(@"^(\d+),\s*(\d+),\s*(\d+),\s*(\d+),\s*(\d+)$", RegexOptions.IgnoreCase);
            StringConverter converter  = profiles.GetSubSystem <StringConverter>();

            foreach (String dataline in data.Lines)
            {
                Match match = line_regex.Match(dataline);
                if (match.Success == false)
                {
                    continue;
                }

                Replay.RecordingData inputdata = new Replay.RecordingData(
                    converter.Convert <Int32>(match.Groups[1].Value),
                    converter.Convert <Int32>(match.Groups[2].Value),
                    converter.Convert <Int32>(match.Groups[3].Value),
                    converter.Convert <Int32>(match.Groups[4].Value),
                    converter.Convert <Int32>(match.Groups[5].Value)
                    );

                replaydata.Add(inputdata);
            }

            return(new Replay.Recording(initsettings, replaydata));
        }