コード例 #1
0
        void LoadWaypoints(IniSection waypointSection)
        {
            var actorCount = Map.ActorDefinitions.Count;
            var wps        = waypointSection
                             .Where(kv => Exts.ParseIntegerInvariant(kv.Value) > 0)
                             .Select(kv => Pair.New(Exts.ParseIntegerInvariant(kv.Key),
                                                    LocationFromMapOffset(Exts.ParseIntegerInvariant(kv.Value), MapSize)));

            // Add waypoint actors
            foreach (var kv in wps)
            {
                if (kv.First <= 7)
                {
                    var ar = new ActorReference("mpspawn")
                    {
                        new LocationInit((CPos)kv.Second),
                        new OwnerInit("Neutral")
                    };

                    Map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
                    spawnCount++;
                }
                else
                {
                    var ar = new ActorReference("waypoint")
                    {
                        new LocationInit((CPos)kv.Second),
                        new OwnerInit("Neutral")
                    };

                    Map.ActorDefinitions.Add(new MiniYamlNode("waypoint" + kv.First, ar.Save()));
                }
            }
        }
コード例 #2
0
        public MiniYaml Save()
        {
            Func <object, bool> saveInit = init =>
            {
                var factionInit = init as FactionInit;
                if (factionInit != null && factionInit.Faction == Owner.Faction)
                {
                    return(false);
                }

                // TODO: Other default values will need to be filtered
                // here after we have built a properties panel
                return(true);
            };

            return(actor.Save(saveInit));
        }
コード例 #3
0
        public override void SaveWaypoint(int waypointNumber, ActorReference waypointReference)
        {
            var waypointName = "waypoint" + waypointNumber;

            if (waypointNumber == 98)
            {
                waypointName = "DefaultCameraPosition";
            }
            Map.ActorDefinitions.Add(new MiniYamlNode(waypointName, waypointReference.Save()));
        }
コード例 #4
0
		static void ReadActors(Map map, IniFile file, string type, int2 fullSize)
		{
			var structuresSection = file.GetSection(type, true);
			foreach (var kv in structuresSection)
			{
				var isDeployed = false;
				var entries = kv.Value.Split(',');

				var name = entries[1].ToLowerInvariant();

				if (DeployableActors.ContainsKey(name))
				{
					name = DeployableActors[name];
					isDeployed = true;
				}

				var health = short.Parse(entries[2]);
				var rx = int.Parse(entries[3]);
				var ry = int.Parse(entries[4]);
				var facing = (byte)(byte.Parse(entries[5]) + 96);

				var dx = rx - ry + fullSize.X - 1;
				var dy = rx + ry - fullSize.X - 1;
				var cell = new MPos(dx / 2, dy).ToCPos(map);

				var ar = new ActorReference(name)
				{
					new LocationInit(cell),
					new OwnerInit("Neutral")
				};

				if (health != 256)
					ar.Add(new HealthInit(100 * health / 256));

				if (facing != 96)
					ar.Add(new FacingInit(WAngle.FromFacing(facing)));

				if (isDeployed)
					ar.Add(new DeployStateInit(DeployState.Deployed));

				if (!map.Rules.Actors.ContainsKey(name))
					Console.WriteLine("Ignoring unknown actor type: `{0}`".F(name));
				else
					map.ActorDefinitions.Add(new MiniYamlNode("Actor" + map.ActorDefinitions.Count, ar.Save()));
			}
		}
コード例 #5
0
        public MiniYaml Save()
        {
            Func <object, bool> saveInit = init =>
            {
                var race = init as RaceInit;
                if (race != null && race.Race == Owner.Race)
                {
                    return(false);
                }

                // TODO: Other default values will need to be filtered
                // here after we have built a properties panel
                return(true);
            };

            return(actor.Save(saveInit));
        }
コード例 #6
0
        public override void SaveWaypoint(int waypointNumber, ActorReference waypointReference)
        {
            var waypointName = "waypoint" + waypointNumber;

            if (waypointNumber == 25)
            {
                waypointName = "DefaultFlareLocation";
            }
            else if (waypointNumber == 26)
            {
                waypointName = "DefaultCameraPosition";
            }
            else if (waypointNumber == 27)
            {
                waypointName = "DefaultChinookTarget";
            }
            Map.ActorDefinitions.Add(new MiniYamlNode(waypointName, waypointReference.Save()));
        }
コード例 #7
0
		static void ReadWaypoints(Map map, IniFile file, int2 fullSize)
		{
			var waypointsSection = file.GetSection("Waypoints", true);
			foreach (var kv in waypointsSection)
			{
				var pos = int.Parse(kv.Value);
				var ry = pos / 1000;
				var rx = pos - ry * 1000;
				var dx = rx - ry + fullSize.X - 1;
				var dy = rx + ry - fullSize.X - 1;
				var cell = new MPos(dx / 2, dy).ToCPos(map);

				int wpindex;
				var ar = new ActorReference((!int.TryParse(kv.Key, out wpindex) || wpindex > 7) ? "waypoint" : "mpspawn");
				ar.Add(new LocationInit(cell));
				ar.Add(new OwnerInit("Neutral"));

				map.ActorDefinitions.Add(new MiniYamlNode("Actor" + map.ActorDefinitions.Count, ar.Save()));
			}
		}
コード例 #8
0
        void ReadCncTrees(IniFile file)
        {
            var terrain = file.GetSection("TERRAIN", true);

            if (terrain == null)
            {
                return;
            }

            foreach (var kv in terrain)
            {
                var loc = Exts.ParseIntegerInvariant(kv.Key);
                var ar  = new ActorReference(kv.Value.Split(',')[0].ToLowerInvariant())
                {
                    new LocationInit(new CPos(loc % mapSize, loc / mapSize)),
                    new OwnerInit("Neutral")
                };

                map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
            }
        }
コード例 #9
0
        public MiniYaml Save()
        {
            Func <object, bool> saveInit = init =>
            {
                if (init is FactionInit factionInit && factionInit.Value == Owner.Faction)
                {
                    return(false);
                }

                if (init is HealthInit healthInit && healthInit.Value == 100)
                {
                    return(false);
                }

                // TODO: Other default values will need to be filtered
                // here after we have built a properties panel
                return(true);
            };

            return(reference.Save(saveInit));
        }
コード例 #10
0
		static void ReadTerrainActors(Map map, IniFile file, int2 fullSize)
		{
			var terrainSection = file.GetSection("Terrain", true);
			foreach (var kv in terrainSection)
			{
				var pos = int.Parse(kv.Key);
				var ry = pos / 1000;
				var rx = pos - ry * 1000;
				var dx = rx - ry + fullSize.X - 1;
				var dy = rx + ry - fullSize.X - 1;
				var cell = new MPos(dx / 2, dy).ToCPos(map);
				var name = kv.Value.ToLowerInvariant();

				var ar = new ActorReference(name);
				ar.Add(new LocationInit(cell));
				ar.Add(new OwnerInit("Neutral"));

				if (!map.Rules.Actors.ContainsKey(name))
					Console.WriteLine("Ignoring unknown actor type: `{0}`".F(name));
				else
					map.ActorDefinitions.Add(new MiniYamlNode("Actor" + map.ActorDefinitions.Count, ar.Save()));
			}
		}
コード例 #11
0
        void ReadTrees(IniFile file)
        {
            var terrain = file.GetSection("TERRAIN", true);

            if (terrain == null)
            {
                return;
            }

            foreach (var kv in terrain)
            {
                var loc       = Exts.ParseIntegerInvariant(kv.Key);
                var treeActor = ParseTreeActor(kv.Value);

                var ar = new ActorReference(treeActor)
                {
                    new LocationInit(ParseActorLocation(treeActor, loc)),
                    new OwnerInit("Neutral")
                };

                var actorCount = Map.ActorDefinitions.Count;
                Map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
            }
        }
コード例 #12
0
        static void ReadOverlay(Map map, IniFile file, int2 fullSize)
        {
            var overlaySection    = file.GetSection("OverlayPack");
            var overlayCompressed = Convert.FromBase64String(string.Concat(overlaySection.Select(kvp => kvp.Value)));
            var overlayPack       = new byte[1 << 18];
            var temp = new byte[1 << 18];

            UnpackLCW(overlayCompressed, overlayPack, temp);

            var overlayDataSection    = file.GetSection("OverlayDataPack");
            var overlayDataCompressed = Convert.FromBase64String(string.Concat(overlayDataSection.Select(kvp => kvp.Value)));
            var overlayDataPack       = new byte[1 << 18];

            UnpackLCW(overlayDataCompressed, overlayDataPack, temp);

            var overlayIndex = new CellLayer <int>(map);

            overlayIndex.Clear(0xFF);

            for (var y = 0; y < fullSize.Y; y++)
            {
                for (var x = fullSize.X * 2 - 2; x >= 0; x--)
                {
                    var dx = (ushort)x;
                    var dy = (ushort)(y * 2 + x % 2);

                    var uv = new MPos(dx / 2, dy);
                    var rx = (ushort)((dx + dy) / 2 + 1);
                    var ry = (ushort)(dy - rx + fullSize.X + 1);

                    if (!map.Resources.Contains(uv))
                    {
                        continue;
                    }

                    overlayIndex[uv] = rx + 512 * ry;
                }
            }

            foreach (var cell in map.AllCells)
            {
                var overlayType = overlayPack[overlayIndex[cell]];
                if (overlayType == 0xFF)
                {
                    continue;
                }

                if (OverlayToActor.TryGetValue(overlayType, out var actorType))
                {
                    if (string.IsNullOrEmpty(actorType))
                    {
                        continue;
                    }

                    var shape = new Size(1, 1);
                    if (OverlayShapes.TryGetValue(overlayType, out shape))
                    {
                        // Only import the top-left cell of multi-celled overlays
                        var aboveType = overlayPack[overlayIndex[cell - new CVec(1, 0)]];
                        if (shape.Width > 1 && aboveType != 0xFF)
                        {
                            if (OverlayToActor.TryGetValue(aboveType, out var a) && a == actorType)
                            {
                                continue;
                            }
                        }

                        var leftType = overlayPack[overlayIndex[cell - new CVec(0, 1)]];
                        if (shape.Height > 1 && leftType != 0xFF)
                        {
                            if (OverlayToActor.TryGetValue(leftType, out var a) && a == actorType)
                            {
                                continue;
                            }
                        }
                    }

                    // Fix position of vein hole actors
                    var location = cell;
                    if (actorType == "veinhole")
                    {
                        location -= new CVec(1, 1);
                    }

                    var ar = new ActorReference(actorType)
                    {
                        new LocationInit(location),
                        new OwnerInit("Neutral")
                    };

                    if (OverlayToHealth.TryGetValue(overlayType, out var damageState))
                    {
                        var health = 100;
                        if (damageState == DamageState.Critical)
                        {
                            health = 25;
                        }
                        else if (damageState == DamageState.Heavy)
                        {
                            health = 50;
                        }
                        else if (damageState == DamageState.Medium)
                        {
                            health = 75;
                        }

                        if (health != 100)
                        {
                            ar.Add(new HealthInit(health));
                        }
                    }

                    map.ActorDefinitions.Add(new MiniYamlNode("Actor" + map.ActorDefinitions.Count, ar.Save()));

                    continue;
                }

                // TS maps encode the non-harvestable border tiles as overlay
                // Only convert to vein resources if the overlay data specifies non-border frames
                if (overlayType == 0x7E)
                {
                    var frame = overlayDataPack[overlayIndex[cell]];
                    if (frame < 48 || frame > 60)
                    {
                        continue;
                    }

                    // Pick half or full density based on the frame
                    map.Resources[cell] = new ResourceTile(3, (byte)(frame == 52 ? 1 : 2));
                    continue;
                }

                var resourceType = ResourceFromOverlay
                                   .Where(kv => kv.Value.Contains(overlayType))
                                   .Select(kv => kv.Key)
                                   .FirstOrDefault();

                if (resourceType != 0)
                {
                    map.Resources[cell] = new ResourceTile(resourceType, overlayDataPack[overlayIndex[cell]]);
                    continue;
                }

                Console.WriteLine("{0} unknown overlay {1}", cell, overlayType);
            }
        }
コード例 #13
0
ファイル: ImportTSMapCommand.cs プロジェクト: CH4Code/OpenRA
        static void ReadOverlay(Map map, IniFile file, int2 fullSize)
        {
            var overlaySection = file.GetSection("OverlayPack");
            var overlayCompressed = Convert.FromBase64String(overlaySection.Aggregate(string.Empty, (a, b) => a + b.Value));
            var overlayPack = new byte[1 << 18];
            var temp = new byte[1 << 18];
            UnpackLCW(overlayCompressed, overlayPack, temp);

            var overlayDataSection = file.GetSection("OverlayDataPack");
            var overlayDataCompressed = Convert.FromBase64String(overlayDataSection.Aggregate(string.Empty, (a, b) => a + b.Value));
            var overlayDataPack = new byte[1 << 18];
            UnpackLCW(overlayDataCompressed, overlayDataPack, temp);

            for (var y = 0; y < fullSize.Y; y++)
            {
                for (var x = fullSize.X * 2 - 2; x >= 0; x--)
                {
                    var dx = (ushort)x;
                    var dy = (ushort)(y * 2 + x % 2);

                    var uv = new MPos(dx / 2, dy);
                    var rx = (ushort)((dx + dy) / 2 + 1);
                    var ry = (ushort)(dy - rx + fullSize.X + 1);

                    if (!map.Resources.Contains(uv))
                        continue;

                    var idx = rx + 512 * ry;
                    var overlayType = overlayPack[idx];
                    if (overlayType == 0xFF)
                        continue;

                    string actorType;
                    if (OverlayToActor.TryGetValue(overlayType, out actorType))
                    {
                        var ar = new ActorReference(actorType)
                        {
                            new LocationInit(uv.ToCPos(map)),
                            new OwnerInit("Neutral")
                        };

                        map.ActorDefinitions.Add(new MiniYamlNode("Actor" + map.ActorDefinitions.Count, ar.Save()));
                        continue;
                    }

                    var resourceType = ResourceFromOverlay
                        .Where(kv => kv.Value.Contains(overlayType))
                        .Select(kv => kv.Key)
                        .FirstOrDefault();

                    if (resourceType != 0)
                    {
                        map.Resources[uv] = new ResourceTile(resourceType, overlayDataPack[idx]);
                        continue;
                    }

                    Console.WriteLine("{0} unknown overlay {1}", uv, overlayType);
                }
            }
        }
コード例 #14
0
        static void ReadOverlay(Map map, IniFile file, int2 fullSize)
        {
            var overlaySection    = file.GetSection("OverlayPack");
            var overlayCompressed = Convert.FromBase64String(overlaySection.Aggregate(string.Empty, (a, b) => a + b.Value));
            var overlayPack       = new byte[1 << 18];
            var temp = new byte[1 << 18];

            UnpackLCW(overlayCompressed, overlayPack, temp);

            var overlayDataSection    = file.GetSection("OverlayDataPack");
            var overlayDataCompressed = Convert.FromBase64String(overlayDataSection.Aggregate(string.Empty, (a, b) => a + b.Value));
            var overlayDataPack       = new byte[1 << 18];

            UnpackLCW(overlayDataCompressed, overlayDataPack, temp);

            var overlayIndex = new CellLayer <int>(map);

            overlayIndex.Clear(0xFF);

            for (var y = 0; y < fullSize.Y; y++)
            {
                for (var x = fullSize.X * 2 - 2; x >= 0; x--)
                {
                    var dx = (ushort)x;
                    var dy = (ushort)(y * 2 + x % 2);

                    var uv = new MPos(dx / 2, dy);
                    var rx = (ushort)((dx + dy) / 2 + 1);
                    var ry = (ushort)(dy - rx + fullSize.X + 1);

                    if (!map.Resources.Contains(uv))
                    {
                        continue;
                    }

                    overlayIndex[uv] = rx + 512 * ry;
                }
            }

            foreach (var cell in map.AllCells)
            {
                var overlayType = overlayPack[overlayIndex[cell]];
                if (overlayType == 0xFF)
                {
                    continue;
                }

                if (OverlayToActor.TryGetValue(overlayType, out var actorType))
                {
                    var shape = new Size(1, 1);
                    if (OverlayShapes.TryGetValue(overlayType, out shape))
                    {
                        // Only import the top-left cell of multi-celled overlays
                        var aboveType = overlayPack[overlayIndex[cell - new CVec(1, 0)]];
                        if (shape.Width > 1 && aboveType != 0xFF)
                        {
                            if (OverlayToActor.TryGetValue(aboveType, out var a) && a == actorType)
                            {
                                continue;
                            }
                        }

                        var leftType = overlayPack[overlayIndex[cell - new CVec(0, 1)]];
                        if (shape.Height > 1 && leftType != 0xFF)
                        {
                            if (OverlayToActor.TryGetValue(leftType, out var a) && a == actorType)
                            {
                                continue;
                            }
                        }
                    }

                    var ar = new ActorReference(actorType)
                    {
                        new LocationInit(cell),
                        new OwnerInit("Neutral")
                    };

                    if (OverlayToHealth.TryGetValue(overlayType, out var damageState))
                    {
                        var health = 100;
                        if (damageState == DamageState.Critical)
                        {
                            health = 25;
                        }
                        else if (damageState == DamageState.Heavy)
                        {
                            health = 50;
                        }
                        else if (damageState == DamageState.Medium)
                        {
                            health = 75;
                        }

                        if (health != 100)
                        {
                            ar.Add(new HealthInit(health));
                        }
                    }

                    map.ActorDefinitions.Add(new MiniYamlNode("Actor" + map.ActorDefinitions.Count, ar.Save()));

                    continue;
                }

                var resourceType = ResourceFromOverlay
                                   .Where(kv => kv.Value.Contains(overlayType))
                                   .Select(kv => kv.Key)
                                   .FirstOrDefault();

                if (resourceType != 0)
                {
                    map.Resources[cell] = new ResourceTile(resourceType, overlayDataPack[overlayIndex[cell]]);
                    continue;
                }

                Console.WriteLine("{0} unknown overlay {1}", cell, overlayType);
            }
        }
コード例 #15
0
        public static void LoadActors(IniFile file, string section, List <string> players, int mapSize, Map map)
        {
            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(255 - facing));
                    }

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

                    var actorCount = map.ActorDefinitions.Count;

                    if (!map.Rules.Actors.ContainsKey(parts[1].ToLowerInvariant()))
                    {
                        Console.WriteLine("Ignoring unknown actor type: `{0}`".F(parts[1].ToLowerInvariant()));
                    }
                    else
                    {
                        map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, actor.Save()));
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Malformed actor definition: `{0}`".F(s));
                }
            }
        }
コード例 #16
0
        void LoadWaypoints(IniSection waypointSection)
        {
            var actorCount = Map.ActorDefinitions.Count;
            var wps = waypointSection
                .Where(kv => Exts.ParseIntegerInvariant(kv.Value) > 0)
                .Select(kv => Pair.New(Exts.ParseIntegerInvariant(kv.Key),
                    LocationFromMapOffset(Exts.ParseIntegerInvariant(kv.Value), MapSize)));

            // Add waypoint actors skipping duplicate entries
            foreach (var kv in wps.DistinctBy(location => location.Second))
            {
                if (!singlePlayer && kv.First <= 7)
                {
                    var ar = new ActorReference("mpspawn")
                    {
                        new LocationInit((CPos)kv.Second),
                        new OwnerInit("Neutral")
                    };

                    Map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
                    spawnCount++;
                }
                else
                {
                    var ar = new ActorReference("waypoint")
                    {
                        new LocationInit((CPos)kv.Second),
                        new OwnerInit("Neutral")
                    };

                    SaveWaypoint(kv.First, ar);
                }
            }
        }
コード例 #17
0
        void ReadTrees(IniFile file)
        {
            var terrain = file.GetSection("TERRAIN", true);
            if (terrain == null)
                return;

            foreach (var kv in terrain)
            {
                var loc = Exts.ParseIntegerInvariant(kv.Key);
                var treeActor = ParseTreeActor(kv.Value);

                var ar = new ActorReference(treeActor)
                {
                    new LocationInit(ParseActorLocation(treeActor, loc)),
                    new OwnerInit("Neutral")
                };

                var actorCount = Map.ActorDefinitions.Count;
                Map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
            }
        }
コード例 #18
0
ファイル: MapImporter.cs プロジェクト: wandsmire/OpenSA
        void LoadActors()
        {
            for (var a = 0; a < numberOfActors; a++)
            {
                var id   = stream.ReadInt32();
                var type = stream.ReadInt32();
                var x    = (int)Math.Round((float)stream.ReadInt32() / map.Grid.TileSize.Width);
                var y    = (int)Math.Round((float)stream.ReadInt32() / map.Grid.TileSize.Height);

                var invalidLocation = false;
                if (x < 0 || x > mapSize.Width || y < 0 || y > mapSize.Height)
                {
                    Console.WriteLine("Invalid coordinates {0},{1} for actor type {2}.".F(x, y, type));
                    invalidLocation = true;
                }

                stream.Seek(4, SeekOrigin.Current);
                var numberOfProperties = stream.ReadInt32();
                stream.Seek(4, SeekOrigin.Current);
                if (numberOfProperties > 0)
                {
                    for (var p = 0; p < numberOfProperties; p++)
                    {
                        var key   = stream.ReadASCII(128);
                        var value = stream.ReadInt32();
                        Console.WriteLine(key + ": " + value);
                    }
                }

                if (!ActorMap.ContainsKey(type))
                {
                    Console.WriteLine("Ignoring unknown actor type: `{0}` @ {1},{2}".F(type, x, y));
                    continue;
                }

                if (invalidLocation)
                {
                    continue;
                }

                var actorInfo = ActorMap[type];
                var actorType = actorInfo.ActorType.ToLowerInvariant();
                var actor     = new ActorReference(actorType)
                {
                    new LocationInit(new CPos(x + MapCordonWidth, y + MapCordonWidth)),
                };

                if (actorInfo.Color == Color.White)
                {
                    actor.Add(new OwnerInit("Neutral"));
                }
                if (actorInfo.Color == Color.Green)
                {
                    actor.Add(new OwnerInit("Ants"));
                }
                if (actorInfo.Color == Color.Blue)
                {
                    actor.Add(new OwnerInit("Beetles"));
                }
                if (actorInfo.Color == Color.Red)
                {
                    actor.Add(new OwnerInit("Spiders"));
                }
                if (actorInfo.Color == Color.Yellow)
                {
                    actor.Add(new OwnerInit("Wasps"));
                }
                if (actorInfo.Color == Color.Black)
                {
                    actor.Add(new OwnerInit("Creeps"));
                }

                AddPlayer(actorInfo.Color);

                var actorCount = map.ActorDefinitions.Count;

                if (!map.Rules.Actors.ContainsKey(actorType))
                {
                    Console.WriteLine("Ignoring unknown actor type: `{0}`".F(actorType));
                }
                else
                {
                    map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, actor.Save()));
                }
            }
        }
コード例 #19
0
ファイル: D2MapImporter.cs プロジェクト: amjadtbssm/d2
        /* Add Spawn Points related functions */

        void CreateSpawnPoint(CPos pos)
        {
            var a = new ActorReference("mpspawn")
            {
                new LocationInit(pos),
                new OwnerInit("Neutral")
            };

            map.ActorDefinitions.Add(new MiniYamlNode("SpawnPoint" + map.ActorDefinitions.Count, a.Save()));
        }
コード例 #20
0
		static void ReadActors(Map map, IniFile file, string type, int2 fullSize)
		{
			var structuresSection = file.GetSection(type, true);
			foreach (var kv in structuresSection)
			{
				var isDeployed = false;
				var entries = kv.Value.Split(',');

				var name = entries[1].ToLowerInvariant();

				if (DeployableActors.ContainsKey(name))
				{
					name = DeployableActors[name];
					isDeployed = true;
				}

				if (ReplaceActors.ContainsKey(name))
				{
					name = ReplaceActors[name];
				}

				var health = short.Parse(entries[2]);
				var rx = int.Parse(entries[3]);
				var ry = int.Parse(entries[4]);
				var facing = (byte)(byte.Parse(entries[5]) + 96);

				var dx = rx - ry + fullSize.X - 1;
				var dy = rx + ry - fullSize.X - 1;
				var cell = new MPos(dx / 2, dy).ToCPos(map);

				var ar = new ActorReference(name)
				{
					new LocationInit(cell),
					new OwnerInit("Neutral"),
					new HealthInit(100 * health / 256),
					new FacingInit(facing),
				};

				if (isDeployed)
					ar.Add(new DeployStateInit(DeployState.Deployed));

				if (!map.Rules.Actors.ContainsKey(name))
					Console.WriteLine("Ignoring unknown actor type: `{0}`".F(name));
				else
					map.ActorDefinitions.Add(new MiniYamlNode("Actor" + map.ActorDefinitions.Count, ar.Save()));
			}
		}
コード例 #21
0
		static void ReadTerrainActors(Map map, IniFile file, int2 fullSize)
		{
			var terrainSection = file.GetSection("Terrain", true);
			foreach (var kv in terrainSection)
			{
				var pos = int.Parse(kv.Key);
				var ry = pos / 1000;
				var rx = pos - ry * 1000;
				var dx = rx - ry + fullSize.X - 1;
				var dy = rx + ry - fullSize.X - 1;
				var cell = new MPos(dx / 2, dy).ToCPos(map);
				var name = kv.Value.ToLowerInvariant();

				if (ReplaceActors.ContainsKey(name))
				{
					name = ReplaceActors[name];
				}

				var ar = new ActorReference(name);
				ar.Add(new LocationInit(cell));
				ar.Add(new OwnerInit("Neutral"));

				if (!map.Rules.Actors.ContainsKey(name))
					Console.WriteLine("Ignoring unknown actor type: `{0}`".F(name));
				else
					map.ActorDefinitions.Add(new MiniYamlNode("Actor" + map.ActorDefinitions.Count, ar.Save()));
			}
		}
コード例 #22
0
		static void ReadWaypoints(Map map, IniFile file, int2 fullSize)
		{
			var waypointsSection = file.GetSection("Waypoints", true);
			foreach (var kv in waypointsSection)
			{
				var pos = int.Parse(kv.Value);
				var ry = pos / 1000;
				var rx = pos - ry * 1000;
				var dx = rx - ry + fullSize.X - 1;
				var dy = rx + ry - fullSize.X - 1;
				var cell = new MPos(dx / 2, dy).ToCPos(map);

				int wpindex;
				var ar = new ActorReference((!int.TryParse(kv.Key, out wpindex) || wpindex > 7) ? "waypoint" : "mpspawn");
				ar.Add(new LocationInit(cell));
				ar.Add(new OwnerInit("Neutral"));

				map.ActorDefinitions.Add(new MiniYamlNode("Actor" + map.ActorDefinitions.Count, ar.Save()));
			}
		}
コード例 #23
0
		static void ReadOverlay(Map map, IniFile file, int2 fullSize)
		{
			var overlaySection = file.GetSection("OverlayPack");
			var overlayCompressed = Convert.FromBase64String(overlaySection.Aggregate(string.Empty, (a, b) => a + b.Value));
			var overlayPack = new byte[1 << 18];
			var temp = new byte[1 << 18];
			UnpackLCW(overlayCompressed, overlayPack, temp);

			var overlayDataSection = file.GetSection("OverlayDataPack");
			var overlayDataCompressed = Convert.FromBase64String(overlayDataSection.Aggregate(string.Empty, (a, b) => a + b.Value));
			var overlayDataPack = new byte[1 << 18];
			UnpackLCW(overlayDataCompressed, overlayDataPack, temp);

			var overlayIndex = new CellLayer<int>(map);
			overlayIndex.Clear(0xFF);

			for (var y = 0; y < fullSize.Y; y++)
			{
				for (var x = fullSize.X * 2 - 2; x >= 0; x--)
				{
					var dx = (ushort)x;
					var dy = (ushort)(y * 2 + x % 2);

					var uv = new MPos(dx / 2, dy);
					var rx = (ushort)((dx + dy) / 2 + 1);
					var ry = (ushort)(dy - rx + fullSize.X + 1);

					if (!map.Resources.Contains(uv))
						continue;

					overlayIndex[uv] = rx + 512 * ry;
				}
			}

			foreach (var cell in map.AllCells)
			{
				var overlayType = overlayPack[overlayIndex[cell]];
				if (overlayType == 0xFF)
					continue;

				string actorType;
				if (OverlayToActor.TryGetValue(overlayType, out actorType))
				{
					var shape = new Size(1, 1);
					if (OverlayShapes.TryGetValue(overlayType, out shape))
					{
						// Only import the top-left cell of multi-celled overlays
						var aboveType = overlayPack[overlayIndex[cell - new CVec(1, 0)]];
						if (shape.Width > 1 && aboveType != 0xFF)
						{
							string a;
							if (OverlayToActor.TryGetValue(aboveType, out a) && a == actorType)
								continue;
						}

						var leftType = overlayPack[overlayIndex[cell - new CVec(0, 1)]];
						if (shape.Height > 1 && leftType != 0xFF)
						{
							string a;
							if (OverlayToActor.TryGetValue(leftType, out a) && a == actorType)
								continue;
						}
					}

					var ar = new ActorReference(actorType)
					{
						new LocationInit(cell),
						new OwnerInit("Neutral")
					};

					DamageState damageState;
					if (OverlayToHealth.TryGetValue(overlayType, out damageState))
					{
						var health = 100;
						if (damageState == DamageState.Critical)
							health = 25;
						else if (damageState == DamageState.Heavy)
							health = 50;
						else if (damageState == DamageState.Medium)
							health = 75;

						if (health != 100)
							ar.Add(new HealthInit(health));
					}

					map.ActorDefinitions.Add(new MiniYamlNode("Actor" + map.ActorDefinitions.Count, ar.Save()));

					continue;
				}

				var resourceType = ResourceFromOverlay
					.Where(kv => kv.Value.Contains(overlayType))
						.Select(kv => kv.Key)
						.FirstOrDefault();

				if (resourceType != 0)
				{
					map.Resources[cell] = new ResourceTile(resourceType, overlayDataPack[overlayIndex[cell]]);
					continue;
				}

				Console.WriteLine("{0} unknown overlay {1}", cell, overlayType);
			}
		}
コード例 #24
0
        void LoadWaypoints(IniSection waypointSection)
        {
            var actorCount = Map.ActorDefinitions.Count;
            var wps        = waypointSection
                             .Where(kv => Exts.ParseIntegerInvariant(kv.Value) > 0)
                             .Select(kv => (WaypointNumber: Exts.ParseIntegerInvariant(kv.Key),
                                            Location: LocationFromMapOffset(Exts.ParseIntegerInvariant(kv.Value), MapSize)));

            // Add waypoint actors skipping duplicate entries
            foreach (var kv in wps.DistinctBy(location => location.Location))
            {
                if (!singlePlayer && kv.WaypointNumber <= 7)
                {
                    var ar = new ActorReference("mpspawn")
                    {
                        new LocationInit((CPos)kv.Location),
                        new OwnerInit("Neutral")
                    };

                    Map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
                    spawnCount++;
                }
                else
                {
                    var ar = new ActorReference("waypoint")
                    {
                        new LocationInit((CPos)kv.Location),
                        new OwnerInit("Neutral")
                    };

                    SaveWaypoint(kv.WaypointNumber, ar);
                }
            }
        }
コード例 #25
0
        void FillMap()
        {
            while (stream.Position < stream.Length)
            {
                var tileInfo = stream.ReadUInt16();
                var tileSpecialInfo = stream.ReadUInt16();
                var tile = GetTile(tileInfo);

                var locationOnMap = GetCurrentTilePositionOnMap();

                map.MapTiles.Value[locationOnMap] = tile;

                // Spice
                if (tileSpecialInfo == 1)
                    map.MapResources.Value[locationOnMap] = new ResourceTile(1, 1);
                if (tileSpecialInfo == 2)
                    map.MapResources.Value[locationOnMap] = new ResourceTile(1, 2);

                // Actors
                if (actorDataByActorCode.ContainsKey(tileSpecialInfo))
                {
                    var kvp = actorDataByActorCode[tileSpecialInfo];
                    if (!rules.Actors.ContainsKey(kvp.First.ToLower()))
                        throw new InvalidOperationException("Actor with name {0} could not be found in the rules YAML file!".F(kvp.First));

                    var a = new ActorReference(kvp.First)
                    {
                        new LocationInit(locationOnMap),
                        new OwnerInit(kvp.Second)
                    };
                    map.ActorDefinitions.Add(new MiniYamlNode("Actor" + map.ActorDefinitions.Count, a.Save()));
                }
            }
        }
コード例 #26
0
ファイル: D2MapImporter.cs プロジェクト: amjadtbssm/d2
        /* Adding Spice Blooms related functions */

        void CreateSpiceBloom(CPos pos)
        {
            var a = new ActorReference("spicebloom.spawnpoint")
            {
                new LocationInit(pos),
                new OwnerInit("Neutral")
            };

            map.ActorDefinitions.Add(new MiniYamlNode("SpiceBloom" + map.ActorDefinitions.Count, a.Save()));
        }
コード例 #27
0
        protected void Run(Utility utility, string[] args)
        {
            // HACK: The engine code assumes that Game.modData is set.
            Game.ModData = ModData = utility.ModData;

            var filename = args[1];

            using (var stream = File.OpenRead(filename))
            {
                var headerString = stream.ReadASCII(4);
                var headerVers   = stream.ReadInt32();

                if (headerString != "MAP_")
                {
                    throw new ArgumentException("Map file did not start with MAP_");
                }

                if (headerVers < 0x300)
                {
                    throw new ArgumentException("Map version was too low.");
                }

                var width  = stream.ReadInt32();
                var height = stream.ReadInt32();
                stream.ReadInt32();                 // Tileset num???
                var tilesetName = "BARREN";

                filename = filename.ToLowerInvariant();

                var scnFilename = filename.Replace(".map", ".scn");
                using (var scn = File.OpenRead(scnFilename))
                {
                    var scnFile = new ScnFile(scn);
                    foreach (var scnSection in scnFile.Entries)
                    {
                        if (scnSection.Name != "SetDefaultTerrain")
                        {
                            continue;
                        }

                        tilesetName = scnSection.ValuesStr.ToUpperInvariant();
                    }
                }

                Map = new Map(ModData, ModData.DefaultTileSets[tilesetName], width + 2, height + 2)
                {
                    Title  = Path.GetFileNameWithoutExtension(filename),
                    Author = "Dark Reign",
                };

                Map.RequiresMod = ModData.Manifest.Id;

                SetBounds(Map, width + 2, height + 2);

                var byte1Hash           = new HashSet <byte>();
                var byte2Hash           = new HashSet <byte>();
                var byte3Hash           = new HashSet <byte>();
                var byte4Hash           = new HashSet <byte>();
                var byte5Hash           = new HashSet <byte>();
                var byte6Hash           = new HashSet <byte>();
                var unknownTileTypeHash = new HashSet <int>();

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        var byte1 = stream.ReadUInt8();                         // Tile type 0-63, with art variations repeated 1-4
                        var byte2 = stream.ReadUInt8();                         // Which art variation to use. 0 = 1-4, 1 = 5-8
                        var byte3 = stream.ReadUInt8();                         // Base elevation, defaults to 2.
                        var byte4 = stream.ReadUInt8();                         // Unknown, defaults to 36. Seems to be elevation related.
                        var byte5 = stream.ReadUInt8();                         // Unknown, defaults to 73. Seems to be elevation related.
                        var byte6 = stream.ReadUInt8();                         // Unknown, defaults to 146. Seems to be elevation related.

                        if (!byte1Hash.Contains(byte1))
                        {
                            byte1Hash.Add(byte1);
                        }
                        if (!byte2Hash.Contains(byte2))
                        {
                            byte2Hash.Add(byte2);
                        }
                        if (!byte3Hash.Contains(byte3))
                        {
                            byte3Hash.Add(byte3);
                        }
                        if (!byte4Hash.Contains(byte4))
                        {
                            byte4Hash.Add(byte4);
                        }
                        if (!byte5Hash.Contains(byte5))
                        {
                            byte5Hash.Add(byte5);
                        }
                        if (!byte6Hash.Contains(byte6))
                        {
                            byte6Hash.Add(byte6);
                        }

                        var  subindex  = (byte)(byte1 / 64);
                        byte variation = (byte)(subindex * (byte2 + 1));
                        int  tileType  = byte1 % 64;

                        if (tileType >= 16)
                        {
                            unknownTileTypeHash.Add(tileType);
                            tileType = 1;                             // TODO: Handle edge sprites
                        }

                        Map.Tiles[new CPos(x + 1, y + 1)] = new TerrainTile((ushort)tileType, variation);                         // types[i, j], byte1
                    }
                }

                // What's after the tiles? Water/Taelon?
                stream.ReadInt32();                 // Always one
                stream.ReadInt32();                 // Always 256
                int length = stream.ReadInt32();    // Byte length of remaining data

                byte1Hash = new HashSet <byte>();
                var byteList = new List <byte>();
                for (int i = 0; i < length; i++)
                {
                    var byte1 = stream.ReadUInt8();
                    if (!byte1Hash.Contains(byte1))
                    {
                        byte1Hash.Add(byte1);
                    }

                    byteList.Add(byte1);
                }

                using (var scn = File.OpenRead(scnFilename))
                {
                    var scnFile = new ScnFile(scn);

                    MapPlayers = new MapPlayers(Map.Rules, 0);
                    SetMapPlayers(scnFile, Players, MapPlayers);

                    // Place start locations
                    int i = 0;
                    foreach (var scnSection in scnFile.Entries)
                    {
                        if (scnSection.Name != "SetStartLocation")
                        {
                            continue;
                        }

                        int divisor = 24;
                        int x       = Convert.ToInt32(scnSection.Values[0]) / divisor;
                        int y       = Convert.ToInt32(scnSection.Values[1]) / divisor;
                        if (x != 0 && y != 0)
                        {
                            var ar = new ActorReference("mpspawn")
                            {
                                new LocationInit(new CPos(x + 1, y + 1)),
                                new OwnerInit("Neutral")
                            };

                            Map.ActorDefinitions.Add(new MiniYamlNode("Actor" + i++, ar.Save()));
                        }
                    }

                    // Parse map thingies
                    foreach (var scnSection in scnFile.Entries)
                    {
                        if (scnSection.Name != "AddThingAt")
                        {
                            continue;
                        }

                        string type = scnSection.Values[1];
                        int    x    = Convert.ToInt32(scnSection.Values[2]);
                        int    y    = Convert.ToInt32(scnSection.Values[3]);

                        var matchingActor = string.Empty;

                        if (thingNames.ContainsKey(type))
                        {
                            matchingActor = thingNames[type];
                        }
                        else if (!knownUnknownThings.Contains(type))
                        {
                            throw new Exception("Unknown thing name: " + type);
                        }

                        if (x >= 0 && y >= 0 && !string.IsNullOrEmpty(matchingActor))
                        {
                            var ar = new ActorReference(matchingActor)
                            {
                                new LocationInit(new CPos(x + 1, y + 1)),
                                new OwnerInit("Neutral")
                            };

                            Map.ActorDefinitions.Add(new MiniYamlNode("Actor" + i++, ar.Save()));
                        }
                    }

                    int currentTeam = 0;

                    if (!skipActors)
                    {
                        // Units
                        foreach (var scnSection in scnFile.Entries)
                        {
                            if (scnSection.Name == "SetDefaultTeam")
                            {
                                currentTeam = Convert.ToInt32(scnSection.ValuesStr);
                                continue;
                            }

                            if (scnSection.Name != "PutUnitAt")
                            {
                                continue;
                            }

                            int playerIndex = GetMatchingPlayerIndex(currentTeam);                             // to skip creeps and neutral if necessary

                            string type = scnSection.Values[1];
                            int    x    = Convert.ToInt32(scnSection.Values[2]);
                            int    y    = Convert.ToInt32(scnSection.Values[3]);

                            var matchingActor = string.Empty;

                            if (unitNames.ContainsKey(type))
                            {
                                matchingActor = unitNames[type];
                            }
                            else if (!knownUnknownUnits.Contains(type))
                            {
                                throw new Exception("Unknown unit name: " + type);
                            }

                            if (x >= 0 && y >= 0 && !string.IsNullOrEmpty(matchingActor))
                            {
                                var ar = new ActorReference(matchingActor)
                                {
                                    new LocationInit(new CPos(x + 1, y + 1)),
                                    new OwnerInit(MapPlayers.Players.Values.First(p => p.Team == playerIndex).Name)
                                };

                                Map.ActorDefinitions.Add(new MiniYamlNode("Actor" + i++, ar.Save()));
                            }
                        }

                        // Do buildings
                        foreach (var scnSection in scnFile.Entries)
                        {
                            if (scnSection.Name == "SetDefaultTeam")
                            {
                                currentTeam = Convert.ToInt32(scnSection.ValuesStr);
                                continue;
                            }

                            if (scnSection.Name != "AddBuildingAt")
                            {
                                continue;
                            }

                            int playerIndex = GetMatchingPlayerIndex(currentTeam);                             // to skip creeps and neutral if necessary

                            string type = scnSection.Values[1];
                            int    x    = Convert.ToInt32(scnSection.Values[2]);
                            int    y    = Convert.ToInt32(scnSection.Values[3]);

                            var matchingActor = string.Empty;

                            if (buildingNames.ContainsKey(type))
                            {
                                matchingActor = buildingNames[type];
                            }
                            else if (!knownUnknownBuildings.Contains(type))
                            {
                                throw new Exception("Unknown building name: " + type);
                            }

                            var isResource = type == "impww" || type == "impmn";
                            var ownerName  = isResource
                                                                ? "Neutral"
                                                                : MapPlayers.Players.Values.First(p => p.Team == playerIndex).Name;

                            if (isResource == true)
                            {
                                throw new ArgumentException("FART");
                            }

                            if (x >= 0 && y >= 0 && !string.IsNullOrEmpty(matchingActor))
                            {
                                var ar = new ActorReference(matchingActor)
                                {
                                    new LocationInit(new CPos(x + 1, y + 1)),
                                    new OwnerInit(ownerName)
                                };

                                Map.ActorDefinitions.Add(new MiniYamlNode("Actor" + i++, ar.Save()));
                            }
                        }
                    }

                    // Do resources
                    foreach (var scnSection in scnFile.Entries)
                    {
                        if (scnSection.Name != "AddBuildingAt")
                        {
                            continue;
                        }

                        string type = scnSection.Values[1];
                        int    x    = Convert.ToInt32(scnSection.Values[2]);
                        int    y    = Convert.ToInt32(scnSection.Values[3]);

                        var isResource = type == "impww" || type == "impmn";
                        if (!isResource)
                        {
                            continue;
                        }

                        var matchingActor = string.Empty;

                        if (buildingNames.ContainsKey(type))
                        {
                            matchingActor = buildingNames[type];
                        }

                        if (x >= 0 && y >= 0 && !string.IsNullOrEmpty(matchingActor))
                        {
                            var ar = new ActorReference(matchingActor)
                            {
                                new LocationInit(new CPos(x + 1, y + 1)),
                                new OwnerInit("Neutral")
                            };

                            Map.ActorDefinitions.Add(new MiniYamlNode("Actor" + i++, ar.Save()));
                        }
                    }
                }

                // Reset teams var
                foreach (var playersValue in MapPlayers.Players.Values)
                {
                    playersValue.Team = 0;
                }

                Map.PlayerDefinitions = MapPlayers.ToMiniYaml();
            }

            Map.FixOpenAreas();

            var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap";

            Map.Save(ZipFileLoader.Create(dest));
            Console.WriteLine(dest + " saved.");
        }
コード例 #28
0
        public virtual void SaveWaypoint(int waypointNumber, ActorReference waypointReference)
        {
            var waypointName = "waypoint" + waypointNumber;

            Map.ActorDefinitions.Add(new MiniYamlNode(waypointName, waypointReference.Save()));
        }
コード例 #29
0
        enum IniMapFormat { RedAlert = 3 }         // otherwise, cnc (2 variants exist, we don't care to differentiate)

        public void ConvertIniMap(string iniFile)
        {
            using (var stream = GlobalFileSystem.Open(iniFile))
            {
                var file            = new IniFile(stream);
                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 tileset = Truncate(mapSection.GetValue("Theater", "TEMPERAT"), 8);
                map = new Map(rules.TileSets[tileset], mapSize, mapSize)
                {
                    Title  = basic.GetValue("Name", Path.GetFileNameWithoutExtension(iniFile)),
                    Author = "Westwood Studios"
                };

                var tl = new PPos(offsetX, offsetY);
                var br = new PPos(offsetX + width - 1, offsetY + height - 1);
                map.SetBounds(tl, br);

                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);
                }

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

                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)));

                // Add waypoint actors
                foreach (var kv in wps)
                {
                    if (kv.First <= 7)
                    {
                        var ar = new ActorReference("mpspawn")
                        {
                            new LocationInit((CPos)kv.Second),
                            new OwnerInit("Neutral")
                        };

                        map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
                    }
                    else
                    {
                        var ar = new ActorReference("waypoint")
                        {
                            new LocationInit((CPos)kv.Second),
                            new OwnerInit("Neutral")
                        };

                        map.ActorDefinitions.Add(new MiniYamlNode("waypoint" + kv.First, ar.Save()));
                    }
                }

                // Create default player definitions only if there are no players to import
                mapPlayers = new MapPlayers(map.Rules, (players.Count == 0) ? map.SpawnPoints.Value.Length : 0);
                foreach (var p in players)
                {
                    LoadPlayer(file, p, legacyMapFormat == IniMapFormat.RedAlert);
                }
                map.PlayerDefinitions = mapPlayers.ToMiniYaml();
            }
        }
コード例 #30
0
        void UnpackOverlayData(MemoryStream ms)
        {
            for (var j = 0; j < MapSize; j++)
            {
                for (var i = 0; i < MapSize; i++)
                {
                    var o   = ms.ReadUInt8();
                    var res = Pair.New((byte)0, (byte)0);

                    if (o != 255 && overlayResourceMapping.ContainsKey(redAlertOverlayNames[o]))
                    {
                        res = overlayResourceMapping[redAlertOverlayNames[o]];
                    }

                    var cell = new CPos(i, j);
                    Map.Resources[cell] = new ResourceTile(res.First, res.Second);

                    if (o != 255 && overlayActors.Contains(redAlertOverlayNames[o]))
                    {
                        var ar = new ActorReference(redAlertOverlayNames[o])
                        {
                            new LocationInit(cell),
                            new OwnerInit("Neutral")
                        };

                        var actorCount = Map.ActorDefinitions.Count;
                        Map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
                    }
                }
            }
        }
コード例 #31
0
        public void LoadActors(IniFile file, string section, List<string> players, int mapSize, Map map)
        {
            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 actorType = parts[1].ToLowerInvariant();

                    var actor = new ActorReference(actorType) {
                        new LocationInit(ParseActorLocation(actorType, loc)),
                        new OwnerInit(parts[0]),
                    };

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

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

                    var actorCount = map.ActorDefinitions.Count;

                    if (!map.Rules.Actors.ContainsKey(parts[1].ToLowerInvariant()))
                        Console.WriteLine("Ignoring unknown actor type: `{0}`".F(parts[1].ToLowerInvariant()));
                    else
                        map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, actor.Save()));
                }
                catch (Exception)
                {
                    Console.WriteLine("Malformed actor definition: `{0}`".F(s));
                }
            }
        }
コード例 #32
0
        void UnpackOverlayData(MemoryStream ms)
        {
            for (var j = 0; j < MapSize; j++)
            {
                for (var i = 0; i < MapSize; i++)
                {
                    var o = ms.ReadUInt8();
                    var res = Pair.New((byte)0, (byte)0);

                    if (o != 255 && overlayResourceMapping.ContainsKey(redAlertOverlayNames[o]))
                        res = overlayResourceMapping[redAlertOverlayNames[o]];

                    var cell = new CPos(i, j);
                    Map.Resources[cell] = new ResourceTile(res.First, res.Second);

                    if (o != 255 && overlayActors.Contains(redAlertOverlayNames[o]))
                    {
                        var ar = new ActorReference(redAlertOverlayNames[o])
                        {
                            new LocationInit(cell),
                            new OwnerInit("Neutral")
                        };

                        var actorCount = Map.ActorDefinitions.Count;
                        Map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
                    }
                }
            }
        }
コード例 #33
0
        void ReadOverlay(IniFile file)
        {
            var overlay = file.GetSection("OVERLAY", true);
            if (overlay == null)
                return;

            foreach (var kv in overlay)
            {
                var loc = Exts.ParseIntegerInvariant(kv.Key);
                var cell = new CPos(loc % MapSize, loc / MapSize);

                var res = Pair.New((byte)0, (byte)0);
                var type = kv.Value.ToLowerInvariant();
                if (overlayResourceMapping.ContainsKey(type))
                    res = overlayResourceMapping[type];

                Map.Resources[cell] = new ResourceTile(res.First, res.Second);
                if (overlayActors.Contains(type))
                {
                    var ar = new ActorReference(type)
                    {
                        new LocationInit(cell),
                        new OwnerInit("Neutral")
                    };

                    var actorCount = Map.ActorDefinitions.Count;
                    Map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
                }
            }
        }
コード例 #34
0
 public virtual void SaveWaypoint(int waypointNumber, ActorReference waypointReference)
 {
     var waypointName = "waypoint" + waypointNumber;
     Map.ActorDefinitions.Add(new MiniYamlNode(waypointName, waypointReference.Save()));
 }
コード例 #35
0
        void ReadOverlay(IniFile file)
        {
            var overlay = file.GetSection("OVERLAY", true);

            if (overlay == null)
            {
                return;
            }

            foreach (var kv in overlay)
            {
                var loc  = Exts.ParseIntegerInvariant(kv.Key);
                var cell = new CPos(loc % MapSize, loc / MapSize);

                var res  = Pair.New((byte)0, (byte)0);
                var type = kv.Value.ToLowerInvariant();
                if (overlayResourceMapping.ContainsKey(type))
                {
                    res = overlayResourceMapping[type];
                }

                Map.Resources[cell] = new ResourceTile(res.First, res.Second);
                if (overlayActors.Contains(type))
                {
                    var ar = new ActorReference(type)
                    {
                        new LocationInit(cell),
                        new OwnerInit("Neutral")
                    };

                    var actorCount = Map.ActorDefinitions.Count;
                    Map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
                }
            }
        }
コード例 #36
0
        void FillMap()
        {
            while (stream.Position < stream.Length)
            {
                var tileInfo        = stream.ReadUInt16();
                var tileSpecialInfo = stream.ReadUInt16();
                var tile            = GetTile(tileInfo);

                var locationOnMap = GetCurrentTilePositionOnMap();

                map.MapTiles.Value[locationOnMap] = tile;

                // Spice
                if (tileSpecialInfo == 1)
                {
                    map.MapResources.Value[locationOnMap] = new ResourceTile(1, 1);
                }
                if (tileSpecialInfo == 2)
                {
                    map.MapResources.Value[locationOnMap] = new ResourceTile(1, 2);
                }

                // Actors
                if (actorDataByActorCode.ContainsKey(tileSpecialInfo))
                {
                    var kvp = actorDataByActorCode[tileSpecialInfo];
                    if (!rules.Actors.ContainsKey(kvp.First.ToLower()))
                    {
                        throw new InvalidOperationException("Actor with name {0} could not be found in the rules YAML file!".F(kvp.First));
                    }

                    var a = new ActorReference(kvp.First)
                    {
                        new LocationInit(locationOnMap),
                        new OwnerInit(kvp.Second)
                    };
                    map.ActorDefinitions.Add(new MiniYamlNode("Actor" + map.ActorDefinitions.Count, a.Save()));
                }
            }
        }
コード例 #37
0
        static void ReadOverlay(Map map, IniFile file, int2 fullSize)
        {
            var overlaySection    = file.GetSection("OverlayPack");
            var overlayCompressed = Convert.FromBase64String(overlaySection.Aggregate(string.Empty, (a, b) => a + b.Value));
            var overlayPack       = new byte[1 << 18];
            var temp = new byte[1 << 18];

            UnpackLCW(overlayCompressed, overlayPack, temp);

            var overlayDataSection    = file.GetSection("OverlayDataPack");
            var overlayDataCompressed = Convert.FromBase64String(overlayDataSection.Aggregate(string.Empty, (a, b) => a + b.Value));
            var overlayDataPack       = new byte[1 << 18];

            UnpackLCW(overlayDataCompressed, overlayDataPack, temp);

            for (var y = 0; y < fullSize.Y; y++)
            {
                for (var x = fullSize.X * 2 - 2; x >= 0; x--)
                {
                    var dx = (ushort)x;
                    var dy = (ushort)(y * 2 + x % 2);

                    var uv = new MPos(dx / 2, dy);
                    var rx = (ushort)((dx + dy) / 2 + 1);
                    var ry = (ushort)(dy - rx + fullSize.X + 1);

                    if (!map.Resources.Contains(uv))
                    {
                        continue;
                    }

                    var idx         = rx + 512 * ry;
                    var overlayType = overlayPack[idx];
                    if (overlayType == 0xFF)
                    {
                        continue;
                    }

                    string actorType;
                    if (OverlayToActor.TryGetValue(overlayType, out actorType))
                    {
                        var ar = new ActorReference(actorType)
                        {
                            new LocationInit(uv.ToCPos(map)),
                            new OwnerInit("Neutral")
                        };

                        map.ActorDefinitions.Add(new MiniYamlNode("Actor" + map.ActorDefinitions.Count, ar.Save()));
                        continue;
                    }

                    var resourceType = ResourceFromOverlay
                                       .Where(kv => kv.Value.Contains(overlayType))
                                       .Select(kv => kv.Key)
                                       .FirstOrDefault();

                    if (resourceType != 0)
                    {
                        map.Resources[uv] = new ResourceTile(resourceType, overlayDataPack[idx]);
                        continue;
                    }

                    Console.WriteLine("{0} unknown overlay {1}", uv, overlayType);
                }
            }
        }
コード例 #38
0
        static void ReadActors(Map map, IniFile file, string type, int2 fullSize)
        {
            var structuresSection = file.GetSection(type, true);

            foreach (var kv in structuresSection)
            {
                var isDeployed = false;
                var entries    = kv.Value.Split(',');

                var name = entries[1].ToLowerInvariant();

                if (DeployableActors.ContainsKey(name))
                {
                    name       = DeployableActors[name];
                    isDeployed = true;
                }

                if (ReplaceActors.ContainsKey(name))
                {
                    name = ReplaceActors[name];
                }

                var health = short.Parse(entries[2]);
                var rx     = int.Parse(entries[3]);
                var ry     = int.Parse(entries[4]);
                var facing = (byte)(224 - byte.Parse(entries[type == "Infantry" ? 7 : 5]));

                var dx   = rx - ry + fullSize.X - 1;
                var dy   = rx + ry - fullSize.X - 1;
                var cell = new MPos(dx / 2, dy).ToCPos(map);

                var ar = new ActorReference(name)
                {
                    new LocationInit(cell),
                    new OwnerInit(CreepActors.Contains(entries[1]) ? "Creeps" : "Neutral")
                };

                if (type == "Infantry")
                {
                    var subcell = 0;
                    switch (byte.Parse(entries[5]))
                    {
                    case 2: subcell = 3; break;

                    case 3: subcell = 1; break;

                    case 4: subcell = 2; break;
                    }

                    if (subcell != 0)
                    {
                        ar.Add(new SubCellInit((SubCell)subcell));
                    }
                }

                if (health != 256)
                {
                    ar.Add(new HealthInit(100 * health / 256));
                }

                ar.Add(new FacingInit(WAngle.FromFacing(facing)));

                if (isDeployed)
                {
                    ar.Add(new DeployStateInit(DeployState.Deployed));
                }

                if (!map.Rules.Actors.ContainsKey(name))
                {
                    Console.WriteLine("Ignoring unknown actor type: `{0}`".F(name));
                }
                else
                {
                    map.ActorDefinitions.Add(new MiniYamlNode("Actor" + map.ActorDefinitions.Count, ar.Save()));
                }
            }
        }
コード例 #39
0
 public override void SaveWaypoint(int waypointNumber, ActorReference waypointReference)
 {
     var waypointName = "waypoint" + waypointNumber;
     if (waypointNumber == 25)
         waypointName = "DefaultFlareLocation";
     else if (waypointNumber == 26)
         waypointName = "DefaultCameraPosition";
     else if (waypointNumber == 27)
         waypointName = "DefaultChinookTarget";
     Map.ActorDefinitions.Add(new MiniYamlNode(waypointName, waypointReference.Save()));
 }