예제 #1
0
        public Mission(string name, Mod game, Map map)
        {
            Mod     = game;
            Map     = map;
            Name    = name;
            ModName = game.Name;
            MapName = map.Name;
            var testAI  = game.AllAis.FirstOrDefault(ai => ai.ShortName.Contains("NullAI"));
            var player1 = new Player {
                Name = "Player 1", Color = Colors.Blue, Alliance = "Alliance 1", IsHuman = true, IsRequired = true
            };
            var player2 = new Player {
                Name = "Player 2", Color = Colors.Red, Alliance = "Alliance 2", IsHuman = false,
            };

            StartingPlayer = player1;
            Players.Add(player1);
            Players.Add(player2);
            Regions.Add(new Region {
                Name = "Region 1"
            });

            var gamePreloadTrigger = new Trigger();

            Triggers.Add(gamePreloadTrigger);
            gamePreloadTrigger.Logic.Add(new GamePreloadCondition());
            gamePreloadTrigger.Name = "Initialization";

            var gameStartTrigger = new Trigger();

            Triggers.Add(gameStartTrigger);
            gameStartTrigger.Logic.Add(new GameStartedCondition());
            gameStartTrigger.Name = "Game Start";
            var unitType   = game.UnitDefs.First();
            var startUnits = new UnitStartInfo[]  {};

            gamePreloadTrigger.Logic.Add(new CreateUnitsAction(startUnits));

            var widgets = new[] { "cmd_unit_mover.lua", "init_startup_info_selector.lua", "gui_center_n_select.lua", "gui_take_remind.lua", "gui_startup_info_selector.lua", "gui_local_colors.lua", "spring_direct_launch.lua" };

            foreach (var widget in widgets)
            {
                DisabledWidgets.Add(widget);
            }
            var gadgets = new string[] { "game_over.lua", "game_end.lua", "awards.lua" };

            foreach (var gadget in gadgets)
            {
                DisabledGadgets.Add(gadget);
            }
            if (game.Name.Contains("Zero-K"))
            {
                RapidTag = "zk:stable";
            }
            Items = new CompositeObservableCollection <Trigger, Region>(Triggers, Regions);
        }
예제 #2
0
        public Mod GetMod(string modName)
        {
            if (disposed) throw new ObjectDisposedException("Unitsync has already been released.");
            if (modName == null) throw new ArgumentNullException("modName");
            NativeMethods.RemoveAllArchives();
            NativeMethods.GetPrimaryModCount(); // pre-requisite for the following calls
            var archiveName = GetModArchiveName(modName);
            SetLoadingStatus("Loading Mod (Reading Mod Files)");
            NativeMethods.AddAllArchives(archiveName);
            var modIndex = NativeMethods.GetPrimaryModIndex(modName);
            string[] sides;
            SetLoadingStatus("Loading Mod (Mod Information)");
            var mod = new Mod
                      {
                          Name = modName,
                          ArchiveName = archiveName,
                          UnitDefs = ReadUnits(),
                          StartUnits = new Dictionary<string, string>(GetStartUnits(modName, out sides)),
                          Sides = sides,
                          Checksum = (int)NativeMethods.GetPrimaryModChecksumFromName(modName),
                          Options = GetModOptions(archiveName).ToArray(),
                          SideIcons = GetSideIcons(sides).ToArray(),
                          Dependencies = GetModDependencies(modIndex).Where(x => x != modName && !string.IsNullOrEmpty(x)).ToArray(),
                          AllAis = GetAis().ToArray(),
                          ModAis = GetAis().Where(ai => ai.IsLuaAi).ToArray(),
                      };
            try
            {
                int infoItemCount = NativeMethods.GetPrimaryModInfoCount(modIndex);
                for (int i = 0; i < infoItemCount; i++)
                {
                    string key = NativeMethods.GetInfoKey(i);
                    //string desc = NativeMethods.GetInfoDescription(i);
                    //string type = NativeMethods.GetInfoType(i);
                    //Trace.TraceInformation(String.Format("Unitsync mod info: ({0}) key: {1}; type: {2}, desc: {3}", i, key, type, desc));
                    ProcessModInfoItem(i, key, ref mod);
                }
            }
            catch (Exception ex)
            {
                throw new UnitSyncException(String.Format("Error loading mod info for ({0}): {1}", modName, ex));
            }

            SetLoadingStatus("Loading Mod (Widgets)");
            mod.Widgets = GetFilesInVfsDirectory("LuaUI/Widgets", "*.lua", VfsMode.Zip).Select(Path.GetFileName).ToArray();
            SetLoadingStatus("Loading Mod (Gadgets)");
            mod.Gadgets = GetFilesInVfsDirectory("LuaRules/Gadgets", "*.lua", VfsMode.Zip).Select(Path.GetFileName).ToArray();
            ReadUnits();

            if (mod.Sides.Length == 0) Debug.WriteLine("Mod has no faction");
            if (mod.UnitDefs.Length == 0) Debug.WriteLine("No unit found.");

            NativeMethods.RemoveAllArchives();
            TraceErrors();
            return mod;
        }
예제 #3
0
 void ProcessModInfoItem(int index, string key, ref Mod mod)
 {
     switch (key)
     {
         case "description":
             mod.Description = NativeMethods.GetInfoValueString(index);
             break;
         case "mutator":
             mod.Mutator = NativeMethods.GetInfoValueString(index);
             break;
         case "name":
             mod.Name = NativeMethods.GetInfoValueString(index);
             break;
         case "shortname":
             mod.ShortName = NativeMethods.GetInfoValueString(index);
             break;
         case "version":
             mod.PrimaryModVersion = NativeMethods.GetInfoValueString(index);
             break;
     }
 }
예제 #4
0
        public Mod GetMod(string modName)
        {
            if (disposed) throw new ObjectDisposedException("Unitsync has already been released.");
            if (modName == null) throw new ArgumentNullException("modName");
            NativeMethods.RemoveAllArchives();
            NativeMethods.GetPrimaryModCount(); // pre-requisite for the following calls
            var archiveName = GetModArchiveName(modName);
            SetLoadingStatus("Loading Mod (Reading Mod Files)");
            NativeMethods.AddAllArchives(archiveName);
            var modIndex = NativeMethods.GetPrimaryModIndex(modName);
            string[] sides;
            SetLoadingStatus("Loading Mod (Mod Information)");
            var mod = new Mod
                      {
                          Name = modName,
                          ArchiveName = archiveName,
                          UnitDefs = ReadUnits(),
                          Desctiption = NativeMethods.GetPrimaryModDescription(modIndex),
                          Game = NativeMethods.GetPrimaryModGame(modIndex),
                          Mutator = NativeMethods.GetPrimaryModMutator(modIndex),
                          ShortGame = NativeMethods.GetPrimaryModShortGame(modIndex),
                          ShortName = NativeMethods.GetPrimaryModShortName(modIndex),
                          PrimaryModVersion = NativeMethods.GetPrimaryModVersion(modIndex),
                          StartUnits = new Dictionary<string, string>(GetStartUnits(modName, out sides)),
                          Sides = sides,
                          Checksum = (int)NativeMethods.GetPrimaryModChecksumFromName(modName),
                          Options = GetModOptions(archiveName).ToArray(),
                          SideIcons = GetSideIcons(sides).ToArray(),
                          Dependencies = GetModDependencies(modIndex).Where(x => x != modName && !string.IsNullOrEmpty(x)).ToArray(),
                          AllAis = GetAis().ToArray(),
                          ModAis = GetAis().Where(ai => ai.IsLuaAi).ToArray(),
                      };
            SetLoadingStatus("Loading Mod (Widgets)");
            mod.Widgets = GetFilesInVfsDirectory("LuaUI/Widgets", "*.lua", VfsMode.Mod).Select(Path.GetFileName).ToArray();
            SetLoadingStatus("Loading Mod (Gadgets)");
            mod.Gadgets = GetFilesInVfsDirectory("LuaRules/Gadgets", "*.lua", VfsMode.Mod).Select(Path.GetFileName).ToArray();
            ReadUnits();

            if (mod.Sides.Length == 0) Debug.WriteLine("Mod has no faction");
            if (mod.UnitDefs.Length == 0) Debug.WriteLine("No unit found.");

            NativeMethods.RemoveAllArchives();
            TraceErrors();
            return mod;
        }
예제 #5
0
		public Mission(string name, Mod game, Map map)
		{
			Mod = game;
			Map = map;
			Name = name;
			ModName = game.Name;
			MapName = map.Name;
			var testAI = game.AllAis.FirstOrDefault(ai => ai.ShortName.Contains("NullAI"));
			var player1 = new Player { Name = "Player 1", Color = Colors.Blue, Alliance = "Alliance 1", IsHuman = true, IsRequired = true };
			var player2 = new Player { Name = "Player 2", Color = Colors.Red, Alliance = "Alliance 2", IsHuman = false, };
			StartingPlayer = player1;
			Players.Add(player1);
			Players.Add(player2);
			Regions.Add(new Region { Name = "Region 1" });

            var gamePreloadTrigger = new Trigger();
			Triggers.Add(gamePreloadTrigger);
			gamePreloadTrigger.Logic.Add(new GamePreloadCondition());
            gamePreloadTrigger.Name = "Initialization";

            var gameStartTrigger = new Trigger();
            Triggers.Add(gameStartTrigger);
            gameStartTrigger.Logic.Add(new GameStartedCondition());
            gameStartTrigger.Name = "Game Start";
			var unitType = game.UnitDefs.First();
			var startUnits = new UnitStartInfo[]  {};
			gamePreloadTrigger.Logic.Add(new CreateUnitsAction(startUnits));

            var widgets = new[] { "gui_pauseScreen.lua", "cmd_unit_mover.lua", "init_startup_info_selector.lua", "gui_center_n_select.lua", "gui_take_remind.lua", "gui_startup_info_selector.lua", "gui_local_colors.lua", "spring_direct_launch.lua" };
			foreach (var widget in widgets) DisabledWidgets.Add(widget);
			var gadgets = new string[] { "game_over.lua", "game_end.lua", "awards.lua" };
			foreach (var gadget in gadgets) DisabledGadgets.Add(gadget);
			if (game.Name.Contains("Zero-K")) RapidTag = "zk:stable";
			Items = new CompositeObservableCollection<Trigger, Region>(Triggers, Regions);
		}
예제 #6
0
        public Mod GetMod(string modName)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("Unitsync has already been released.");
            }
            if (modName == null)
            {
                throw new ArgumentNullException("modName");
            }
            NativeMethods.RemoveAllArchives();
            NativeMethods.GetPrimaryModCount(); // pre-requisite for the following calls
            var archiveName = GetModArchiveName(modName);

            SetLoadingStatus("Loading Mod (Reading Mod Files)");
            NativeMethods.AddAllArchives(archiveName);
            var modIndex = NativeMethods.GetPrimaryModIndex(modName);

            string[] sides;
            SetLoadingStatus("Loading Mod (Mod Information)");
            var mod = new Mod
            {
                Name         = modName,
                ArchiveName  = archiveName,
                UnitDefs     = ReadUnits(),
                StartUnits   = new Dictionary <string, string>(GetStartUnits(modName, out sides)),
                Sides        = sides,
                Checksum     = (int)NativeMethods.GetPrimaryModChecksumFromName(modName),
                Options      = GetModOptions(archiveName).ToArray(),
                SideIcons    = GetSideIcons(sides).ToArray(),
                Dependencies = GetModDependencies(modIndex).Where(x => x != modName && !string.IsNullOrEmpty(x)).ToArray(),
                AllAis       = GetAis().ToArray(),
                ModAis       = GetAis().Where(ai => ai.IsLuaAi).ToArray(),
            };

            try
            {
                int infoItemCount = NativeMethods.GetPrimaryModInfoCount(modIndex);
                for (int i = 0; i < infoItemCount; i++)
                {
                    string key = NativeMethods.GetInfoKey(i);
                    //string desc = NativeMethods.GetInfoDescription(i);
                    //string type = NativeMethods.GetInfoType(i);
                    //Trace.TraceInformation(String.Format("Unitsync mod info: ({0}) key: {1}; type: {2}, desc: {3}", i, key, type, desc));
                    ProcessModInfoItem(i, key, ref mod);
                }
            }
            catch (Exception ex)
            {
                throw new UnitSyncException(String.Format("Error loading mod info for ({0}): {1}", modName, ex));
            }

            SetLoadingStatus("Loading Mod (Widgets)");
            mod.Widgets = GetFilesInVfsDirectory("LuaUI/Widgets", "*.lua", VfsMode.Zip).Select(Path.GetFileName).ToArray();
            SetLoadingStatus("Loading Mod (Gadgets)");
            mod.Gadgets = GetFilesInVfsDirectory("LuaRules/Gadgets", "*.lua", VfsMode.Zip).Select(Path.GetFileName).ToArray();
            ReadUnits();

            if (mod.Sides.Length == 0)
            {
                Debug.WriteLine("Mod has no faction");
            }
            if (mod.UnitDefs.Length == 0)
            {
                Debug.WriteLine("No unit found.");
            }

            NativeMethods.RemoveAllArchives();
            TraceErrors();
            return(mod);
        }