예제 #1
0
		/// <summary>
		/// Post-deserialization tasks
		/// </summary>
		public void PostLoad()
		{
			// when a mission is deserialized or the game is changed, the triggers hold null or old references to unitdefs
			foreach (var unit in AllUnits)
			{
				var unitDef = Mod.UnitDefs.FirstOrDefault(ud => unit.UnitDefName == ud.Name);
                //if (unitDef == null) unitDef = Mod.UnitDefs.FirstOrDefault(ud => unit.UnitDef.FullName == ud.FullName);   // this doesn't work - unit.UnitDef will be null
				unit.UnitDef = unitDef ?? Mod.UnitDefs.First(); // if unit not found, use first valid unitdef - show warning?
			}

			// create AI references
			foreach (var player in Players)
			{
				// try finding an ai with same name and version
				var ai = mod.AllAis.FirstOrDefault(a => a.Version == player.AIVersion && a.ShortName == player.AIDll);
				if (ai == null)
				{
					// just try to find an ai with the same name
					ai = mod.AllAis.FirstOrDefault(a => a.ShortName == player.AIDll);
				}
				player.AI = ai;
			}

			// compatibility
			if (regions == null) regions = new ObservableCollection<Region>();
			if (folders == null) folders = new Dictionary<string, string>();

            foreach (Trigger trigger in Triggers)
            {
                foreach (Action action in trigger.Actions)
                {
                    if (action is LockUnitsAction && ((LockUnitsAction)action).Players == null)
                    {
                        ((LockUnitsAction)action).Players = new ObservableCollection<Player>();
                    }
                    else if (action is UnlockUnitsAction && ((UnlockUnitsAction)action).Players == null)
                    {
                        ((UnlockUnitsAction)action).Players = new ObservableCollection<Player>();
                    }
                }
            }

			// get rid of legacy dummies
			foreach (var trigger in triggers) foreach (var item in trigger.Logic.ToArray()) if (item is DummyAction || item is DummyCondition) trigger.Logic.Remove(item);
			Items = new CompositeObservableCollection<Trigger, Region>(Triggers, Regions);
		}
예제 #2
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);
		}