Exemplo n.º 1
0
        void LoadActors(IniFile file, string section)
        {
            foreach (var s in file.GetSection(section, true))
            {
                //Structures: num=owner,type,health,location,turret-facing,trigger
                //Units: num=owner,type,health,location,facing,action,trigger
                //Infantry: num=owner,type,health,location,subcell,action,facing,trigger

                try
                {

                    var parts = s.Value.Split(',');
                    var loc = int.Parse(parts[3]);
                    if (parts[0] == "")
                        parts[0] = "Neutral";

                    if (!Players.Contains(parts[0]))
                        Players.Add(parts[0]);

                    var actor = new ActorReference(parts[1].ToLowerInvariant())
                    {
                        new LocationInit(new CPos(loc % MapSize, loc / MapSize)),
                        new OwnerInit(parts[0]),
                        new HealthInit(float.Parse(parts[2], NumberFormatInfo.InvariantInfo)/256),
                        new FacingInit((section == "INFANTRY") ? int.Parse(parts[6]) : int.Parse(parts[4])),
                    };

                    if (section == "INFANTRY")
                        actor.Add(new SubCellInit(int.Parse(parts[4])));

                    if (!Rules.Info.ContainsKey(parts[1].ToLowerInvariant()))
                        errorHandler("Ignoring unknown actor type: `{0}`".F(parts[1].ToLowerInvariant()));
                    else
                        Map.Actors.Value.Add("Actor" + ActorCount++, actor);
                }
                catch (Exception)
                {
                    errorHandler("Malformed actor definition: `{0}`".F(s));
                }
            }
        }
Exemplo n.º 2
0
        public void ConvertIniMap(string iniFile)
        {
            var file = new IniFile(FileSystem.Open(iniFile));
            var basic = file.GetSection("Basic");
            var map = file.GetSection("Map");
            var legacyMapFormat = (IniMapFormat)int.Parse(basic.GetValue("NewINIFormat", "0"));
            var XOffset = int.Parse(map.GetValue("X", "0"));
            var YOffset = int.Parse(map.GetValue("Y", "0"));
            var Width = int.Parse(map.GetValue("Width", "0"));
            var Height = int.Parse(map.GetValue("Height", "0"));
            MapSize = (legacyMapFormat == IniMapFormat.RedAlert) ? 128 : 64;

            Map.Title = basic.GetValue("Name", "(null)");
            Map.Author = "Westwood Studios";
            Map.Tileset = Truncate(map.GetValue("Theater", "TEMPERAT"), 8);
            Map.MapSize.X = MapSize;
            Map.MapSize.Y = MapSize;
            Map.Bounds = Rectangle.FromLTRB(XOffset, YOffset, XOffset + Width, YOffset + Height);
            Map.Selectable = true;

            Map.Smudges = Lazy.New(() => new List<SmudgeReference>());
            Map.Actors = Lazy.New(() => new Dictionary<string, ActorReference>());
            Map.MapResources = Lazy.New(() => new TileReference<byte, byte>[MapSize, MapSize]);
            Map.MapTiles = Lazy.New(() => new TileReference<ushort, byte>[MapSize, MapSize]);

            if (legacyMapFormat == IniMapFormat.RedAlert)
            {
                UnpackRATileData(ReadPackedSection(file.GetSection("MapPack")));
                UnpackRAOverlayData(ReadPackedSection(file.GetSection("OverlayPack")));
                ReadRATrees(file);
            }
            else // CNC
            {
                UnpackCncTileData(FileSystem.Open(iniFile.Substring(0, iniFile.Length - 4) + ".bin"));
                ReadCncOverlay(file);
                ReadCncTrees(file);
            }

            LoadActors(file, "STRUCTURES");
            LoadActors(file, "UNITS");
            LoadActors(file, "INFANTRY");
            LoadSmudges(file, "SMUDGE");

            foreach (var p in Players)
                LoadPlayer(file, p, (legacyMapFormat == IniMapFormat.RedAlert));

            var wps = file.GetSection("Waypoints")
                    .Where(kv => int.Parse(kv.Value) > 0)
                    .Select(kv => Pair.New(int.Parse(kv.Key),
                        LocationFromMapOffset(int.Parse(kv.Value), MapSize)))
                    .ToArray();

            // Add waypoint actors
            foreach( var kv in wps )
            {
                var a = new ActorReference("waypoint");
                a.Add(new LocationInit((CPos)kv.Second));
                a.Add(new OwnerInit("Neutral"));
                Map.Actors.Value.Add("waypoint" + kv.First, a);
            }
        }
Exemplo n.º 3
0
		void LoadActors(IniFile file, string section)
		{
			foreach (var s in file.GetSection(section, true))
			{
				// Structures: num=owner,type,health,location,turret-facing,trigger
				// Units: num=owner,type,health,location,facing,action,trigger
				// Infantry: num=owner,type,health,location,subcell,action,facing,trigger
				try
				{
					var parts = s.Value.Split(',');
					if (parts[0] == "")
						parts[0] = "Neutral";

					if (!players.Contains(parts[0]))
						players.Add(parts[0]);

					var loc = Exts.ParseIntegerInvariant(parts[3]);
					var health = Exts.ParseIntegerInvariant(parts[2]) * 100 / 256;
					var facing = (section == "INFANTRY") ? Exts.ParseIntegerInvariant(parts[6]) : Exts.ParseIntegerInvariant(parts[4]);

					var actor = new ActorReference(parts[1].ToLowerInvariant())
					{
						new LocationInit(new CPos(loc % mapSize, loc / mapSize)),
						new OwnerInit(parts[0]),
					};

					var initDict = actor.InitDict;
					if (health != 100)
						initDict.Add(new HealthInit(health));
					if (facing != 0)
						initDict.Add(new FacingInit(facing));

					if (section == "INFANTRY")
						actor.Add(new SubCellInit(Exts.ParseIntegerInvariant(parts[4])));

					if (!rules.Actors.ContainsKey(parts[1].ToLowerInvariant()))
						errorHandler("Ignoring unknown actor type: `{0}`".F(parts[1].ToLowerInvariant()));
					else
						map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, actor.Save()));
				}
				catch (Exception)
				{
					errorHandler("Malformed actor definition: `{0}`".F(s));
				}
			}
		}
Exemplo n.º 4
0
        public void ConvertIniMap(string iniFile)
        {
            var file = new IniFile(GlobalFileSystem.Open(iniFile));
            var basic = file.GetSection("Basic");
            var mapSection = file.GetSection("Map");
            var legacyMapFormat = (IniMapFormat)Exts.ParseIntegerInvariant(basic.GetValue("NewINIFormat", "0"));
            var offsetX = Exts.ParseIntegerInvariant(mapSection.GetValue("X", "0"));
            var offsetY = Exts.ParseIntegerInvariant(mapSection.GetValue("Y", "0"));
            var width = Exts.ParseIntegerInvariant(mapSection.GetValue("Width", "0"));
            var height = Exts.ParseIntegerInvariant(mapSection.GetValue("Height", "0"));
            mapSize = (legacyMapFormat == IniMapFormat.RedAlert) ? 128 : 64;
            var size = new Size(mapSize, mapSize);

            var tileset = Truncate(mapSection.GetValue("Theater", "TEMPERAT"), 8);
            map = Map.FromTileset(rules.TileSets[tileset]);
            map.Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(iniFile));
            map.Author = "Westwood Studios";
            map.MapSize.X = mapSize;
            map.MapSize.Y = mapSize;
            map.Bounds = Rectangle.FromLTRB(offsetX, offsetY, offsetX + width, offsetY + height);
            map.Selectable = true;

            map.Smudges = Exts.Lazy(() => new List<SmudgeReference>());
            map.Actors = Exts.Lazy(() => new Dictionary<string, ActorReference>());
            map.MapResources = Exts.Lazy(() => new CellLayer<ResourceTile>(TileShape.Rectangle, size));
            map.MapTiles = Exts.Lazy(() => new CellLayer<TerrainTile>(TileShape.Rectangle, size));

            map.Options = new MapOptions();

            if (legacyMapFormat == IniMapFormat.RedAlert)
            {
                UnpackRATileData(ReadPackedSection(file.GetSection("MapPack")));
                UnpackRAOverlayData(ReadPackedSection(file.GetSection("OverlayPack")));
                ReadRATrees(file);
            }
            else
            {
                // CnC
                using (var s = GlobalFileSystem.Open(iniFile.Substring(0, iniFile.Length - 4) + ".bin"))
                    UnpackCncTileData(s);
                ReadCncOverlay(file);
                ReadCncTrees(file);
            }

            LoadActors(file, "STRUCTURES");
            LoadActors(file, "UNITS");
            LoadActors(file, "INFANTRY");
            LoadSmudges(file, "SMUDGE");

            foreach (var p in players)
                LoadPlayer(file, p, legacyMapFormat == IniMapFormat.RedAlert);

            var wps = file.GetSection("Waypoints")
                    .Where(kv => Exts.ParseIntegerInvariant(kv.Value) > 0)
                    .Select(kv => Pair.New(Exts.ParseIntegerInvariant(kv.Key),
                        LocationFromMapOffset(Exts.ParseIntegerInvariant(kv.Value), mapSize)))
                    .ToArray();

            // Add waypoint actors
            foreach (var kv in wps)
            {
                if (kv.First <= 7)
                {
                    var a = new ActorReference("mpspawn");
                    a.Add(new LocationInit((CPos)kv.Second));
                    a.Add(new OwnerInit("Neutral"));
                    map.Actors.Value.Add("Actor" + map.Actors.Value.Count.ToString(), a);
                }
                else
                {
                    var a = new ActorReference("waypoint");
                    a.Add(new LocationInit((CPos)kv.Second));
                    a.Add(new OwnerInit("Neutral"));
                    map.Actors.Value.Add("waypoint" + kv.First, a);
                }
            }
        }
Exemplo n.º 5
0
        void LoadActors(IniFile file, string section)
        {
            foreach (var s in file.GetSection(section, true))
            {
                //Structures: num=owner,type,health,location,turret-facing,trigger
                //Units: num=owner,type,health,location,facing,action,trigger
                //Infantry: num=owner,type,health,location,subcell,action,facing,trigger

                try
                {

                    var parts = s.Value.Split(',');
                    var loc = int.Parse(parts[3]);
                    if (parts[0] == "")
                        parts[0] = "Neutral";

                    if (!Players.Contains(parts[0]))
                        Players.Add(parts[0]);

                    var stance = ActorStance.Stance.None;
                    switch (parts[5])
                    {
                        case "Area Guard":
                        case "Guard":
                            stance = ActorStance.Stance.Guard;
                            break;
                        case "Defend Base":
                            stance = ActorStance.Stance.Defend;
                            break;
                        case "Hunt":
                        case "Rampage":
                        case "Attack Base":
                        case "Attack Units":
                        case "Attack Civil.":
                        case "Attack Tarcom":
                            stance = ActorStance.Stance.Hunt;
                            break;
                        case "Retreat":
                        case "Return":
                            stance = ActorStance.Stance.Retreat;
                            break;
                        // do we care about `Harvest' and `Sticky'?
                    }

                    var actor = new ActorReference(parts[1].ToLowerInvariant())
                    {
                        new LocationInit(new int2(loc % MapSize, loc / MapSize)),
                        new OwnerInit(parts[0]),
                        new HealthInit(float.Parse(parts[2], NumberFormatInfo.InvariantInfo)/256),
                        new FacingInit((section == "INFANTRY") ? int.Parse(parts[6]) : int.Parse(parts[4])),
                        new ActorStanceInit(stance),
                    };

                    if (section == "INFANTRY")
                        actor.Add(new SubCellInit(int.Parse(parts[4])));

                    if (!Rules.Info.ContainsKey(parts[1].ToLowerInvariant()))
                        errorHandler("Ignoring unknown actor type: `{0}`".F(parts[1].ToLowerInvariant()));
                    else
                        Map.Actors.Value.Add("Actor" + ActorCount++, actor);
                }
                catch (Exception)
                {
                    errorHandler("Malformed actor definition: `{0}`".F(s));
                }
            }
        }
Exemplo n.º 6
0
		public bool HandleMouseInput(MouseInput mi)
		{
			// Exclusively uses left and right mouse buttons, but nothing else
			if (mi.Button != MouseButton.Left && mi.Button != MouseButton.Right)
				return false;

			if (mi.Button == MouseButton.Right)
			{
				if (mi.Event == MouseInputEvent.Up)
				{
					editorWidget.ClearBrush();
					return true;
				}

				return false;
			}

			var cell = worldRenderer.Viewport.ViewToWorld(mi.Location);
			if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Down)
			{
				// Check the actor is inside the map
				if (!footprint.All(c => world.Map.MapTiles.Value.Contains(cell + locationOffset + c)))
					return true;

				var newActorReference = new ActorReference(Actor.Name);
				newActorReference.Add(new OwnerInit(owner.Name));

				cell += locationOffset;
				newActorReference.Add(new LocationInit(cell));

				var ios = Actor.TraitInfoOrDefault<IOccupySpaceInfo>();
				if (ios != null && ios.SharesCell)
				{
					var subcell = editorLayer.FreeSubCellAt(cell);
					if (subcell != SubCell.Invalid)
						newActorReference.Add(new SubCellInit(subcell));
				}

				var initDict = newActorReference.InitDict;

				if (Actor.HasTraitInfo<IFacingInfo>())
					initDict.Add(new FacingInit(facing));

				if (Actor.HasTraitInfo<TurretedInfo>())
					initDict.Add(new TurretFacingInit(facing));

				editorLayer.Add(newActorReference);
			}

			return true;
		}