예제 #1
0
파일: Map.cs 프로젝트: zhangolove/OpenRA
        public CellLayer <byte> LoadMapHeight()
        {
            var tiles = new CellLayer <byte>(this);

            using (var s = Container.GetContent("map.bin"))
            {
                var header = new BinaryDataHeader(s, MapSize);
                if (header.HeightsOffset > 0)
                {
                    s.Position = header.HeightsOffset;
                    for (var i = 0; i < MapSize.X; i++)
                    {
                        for (var j = 0; j < MapSize.Y; j++)
                        {
                            tiles[new MPos(i, j)] = s.ReadUInt8().Clamp((byte)0, Grid.MaximumTerrainHeight);
                        }
                    }
                }
            }

            if (Grid.MaximumTerrainHeight > 0)
            {
                tiles.CellEntryChanged += UpdateProjection;
            }

            return(tiles);
        }
예제 #2
0
파일: Map.cs 프로젝트: ushalin/OpenRA
        public CellLayer <TerrainTile> LoadMapTiles()
        {
            var tiles = new CellLayer <TerrainTile>(this);

            using (var s = Container.GetContent("map.bin"))
            {
                var header = new BinaryDataHeader(s, MapSize);
                if (header.TilesOffset > 0)
                {
                    s.Position = header.TilesOffset;
                    for (var i = 0; i < MapSize.X; i++)
                    {
                        for (var j = 0; j < MapSize.Y; j++)
                        {
                            var tile  = s.ReadUInt16();
                            var index = s.ReadUInt8();

                            // TODO: Remember to remove this when rewriting tile variants / PickAny
                            if (index == byte.MaxValue)
                            {
                                index = (byte)(i % 4 + (j % 4) * 4);
                            }

                            tiles[new MPos(i, j)] = new TerrainTile(tile, index);
                        }
                    }
                }
            }

            return(tiles);
        }
예제 #3
0
파일: Map.cs 프로젝트: ushalin/OpenRA
        public CellLayer <byte> LoadMapHeight()
        {
            var maxHeight = cachedTileSet.Value.MaxGroundHeight;
            var tiles     = new CellLayer <byte>(this);

            using (var s = Container.GetContent("map.bin"))
            {
                var header = new BinaryDataHeader(s, MapSize);
                if (header.HeightsOffset > 0)
                {
                    s.Position = header.HeightsOffset;
                    for (var i = 0; i < MapSize.X; i++)
                    {
                        for (var j = 0; j < MapSize.Y; j++)
                        {
                            tiles[new MPos(i, j)] = s.ReadUInt8().Clamp((byte)0, maxHeight);
                        }
                    }
                }
            }

            return(tiles);
        }
예제 #4
0
파일: Map.cs 프로젝트: ushalin/OpenRA
        public CellLayer <ResourceTile> LoadResourceTiles()
        {
            var resources = new CellLayer <ResourceTile>(this);

            using (var s = Container.GetContent("map.bin"))
            {
                var header = new BinaryDataHeader(s, MapSize);
                if (header.ResourcesOffset > 0)
                {
                    s.Position = header.ResourcesOffset;
                    for (var i = 0; i < MapSize.X; i++)
                    {
                        for (var j = 0; j < MapSize.Y; j++)
                        {
                            var type    = s.ReadUInt8();
                            var density = s.ReadUInt8();
                            resources[new MPos(i, j)] = new ResourceTile(type, density);
                        }
                    }
                }
            }

            return(resources);
        }
예제 #5
0
        public Map(ModData modData, IReadOnlyPackage package)
        {
            this.modData = modData;
            Package      = package;

            if (!Package.Contains("map.yaml") || !Package.Contains("map.bin"))
            {
                throw new InvalidDataException("Not a valid map\n File: {0}".F(package.Name));
            }

            var yaml = new MiniYaml(null, MiniYaml.FromStream(Package.GetStream("map.yaml"), package.Name));

            foreach (var field in YamlFields)
            {
                field.Deserialize(this, yaml.Nodes);
            }

            if (MapFormat != SupportedMapFormat)
            {
                throw new InvalidDataException("Map format {0} is not supported.\n File: {1}".F(MapFormat, package.Name));
            }

            PlayerDefinitions = MiniYaml.NodesOrEmpty(yaml, "Players");
            ActorDefinitions  = MiniYaml.NodesOrEmpty(yaml, "Actors");

            Grid = modData.Manifest.Get <MapGrid>();

            var size = new Size(MapSize.X, MapSize.Y);

            Tiles     = new CellLayer <TerrainTile>(Grid.Type, size);
            Resources = new CellLayer <ResourceTile>(Grid.Type, size);
            Height    = new CellLayer <byte>(Grid.Type, size);

            using (var s = Package.GetStream("map.bin"))
            {
                var header = new BinaryDataHeader(s, MapSize);
                if (header.TilesOffset > 0)
                {
                    s.Position = header.TilesOffset;
                    for (var i = 0; i < MapSize.X; i++)
                    {
                        for (var j = 0; j < MapSize.Y; j++)
                        {
                            var tile  = s.ReadUInt16();
                            var index = s.ReadUInt8();

                            // TODO: Remember to remove this when rewriting tile variants / PickAny
                            if (index == byte.MaxValue)
                            {
                                index = (byte)(i % 4 + (j % 4) * 4);
                            }

                            Tiles[new MPos(i, j)] = new TerrainTile(tile, index);
                        }
                    }
                }

                if (header.ResourcesOffset > 0)
                {
                    s.Position = header.ResourcesOffset;
                    for (var i = 0; i < MapSize.X; i++)
                    {
                        for (var j = 0; j < MapSize.Y; j++)
                        {
                            var type    = s.ReadUInt8();
                            var density = s.ReadUInt8();
                            Resources[new MPos(i, j)] = new ResourceTile(type, density);
                        }
                    }
                }

                if (header.HeightsOffset > 0)
                {
                    s.Position = header.HeightsOffset;
                    for (var i = 0; i < MapSize.X; i++)
                    {
                        for (var j = 0; j < MapSize.Y; j++)
                        {
                            Height[new MPos(i, j)] = s.ReadUInt8().Clamp((byte)0, Grid.MaximumTerrainHeight);
                        }
                    }
                }
            }

            if (Grid.MaximumTerrainHeight > 0)
            {
                Tiles.CellEntryChanged  += UpdateProjection;
                Height.CellEntryChanged += UpdateProjection;
            }

            PostInit();

            Uid = ComputeUID(Package);
        }
예제 #6
0
파일: Map.cs 프로젝트: ushardul/OpenRA
        public CellLayer<ResourceTile> LoadResourceTiles()
        {
            var resources = new CellLayer<ResourceTile>(this);

            using (var s = Container.GetContent("map.bin"))
            {
                var header = new BinaryDataHeader(s, MapSize);
                if (header.ResourcesOffset > 0)
                {
                    s.Position = header.ResourcesOffset;
                    for (var i = 0; i < MapSize.X; i++)
                    {
                        for (var j = 0; j < MapSize.Y; j++)
                        {
                            var type = s.ReadUInt8();
                            var density = s.ReadUInt8();
                            resources[new MPos(i, j)] = new ResourceTile(type, density);
                        }
                    }
                }
            }

            return resources;
        }
예제 #7
0
파일: Map.cs 프로젝트: ushardul/OpenRA
        public CellLayer<TerrainTile> LoadMapTiles()
        {
            var tiles = new CellLayer<TerrainTile>(this);
            using (var s = Container.GetContent("map.bin"))
            {
                var header = new BinaryDataHeader(s, MapSize);
                if (header.TilesOffset > 0)
                {
                    s.Position = header.TilesOffset;
                    for (var i = 0; i < MapSize.X; i++)
                    {
                        for (var j = 0; j < MapSize.Y; j++)
                        {
                            var tile = s.ReadUInt16();
                            var index = s.ReadUInt8();

                            // TODO: Remember to remove this when rewriting tile variants / PickAny
                            if (index == byte.MaxValue)
                                index = (byte)(i % 4 + (j % 4) * 4);

                            tiles[new MPos(i, j)] = new TerrainTile(tile, index);
                        }
                    }
                }
            }

            return tiles;
        }
예제 #8
0
파일: Map.cs 프로젝트: ushardul/OpenRA
        public CellLayer<byte> LoadMapHeight()
        {
            var maxHeight = cachedTileSet.Value.MaxGroundHeight;
            var tiles = new CellLayer<byte>(this);
            using (var s = Container.GetContent("map.bin"))
            {
                var header = new BinaryDataHeader(s, MapSize);
                if (header.HeightsOffset > 0)
                {
                    s.Position = header.HeightsOffset;
                    for (var i = 0; i < MapSize.X; i++)
                        for (var j = 0; j < MapSize.Y; j++)
                            tiles[new MPos(i, j)] = s.ReadUInt8().Clamp((byte)0, maxHeight);
                }
            }

            return tiles;
        }
예제 #9
0
파일: Map.cs 프로젝트: pchote/OpenRA
        public Map(ModData modData, IReadOnlyPackage package)
        {
            this.modData = modData;
            Package = package;

            if (!Package.Contains("map.yaml") || !Package.Contains("map.bin"))
                throw new InvalidDataException("Not a valid map\n File: {0}".F(package.Name));

            var yaml = new MiniYaml(null, MiniYaml.FromStream(Package.GetStream("map.yaml"), package.Name));
            foreach (var field in YamlFields)
                field.Deserialize(this, yaml.Nodes);

            if (MapFormat != SupportedMapFormat)
                throw new InvalidDataException("Map format {0} is not supported.\n File: {1}".F(MapFormat, package.Name));

            PlayerDefinitions = MiniYaml.NodesOrEmpty(yaml, "Players");
            ActorDefinitions = MiniYaml.NodesOrEmpty(yaml, "Actors");

            Grid = modData.Manifest.Get<MapGrid>();

            var size = new Size(MapSize.X, MapSize.Y);
            Tiles = new CellLayer<TerrainTile>(Grid.Type, size);
            Resources = new CellLayer<ResourceTile>(Grid.Type, size);
            Height = new CellLayer<byte>(Grid.Type, size);

            using (var s = Package.GetStream("map.bin"))
            {
                var header = new BinaryDataHeader(s, MapSize);
                if (header.TilesOffset > 0)
                {
                    s.Position = header.TilesOffset;
                    for (var i = 0; i < MapSize.X; i++)
                    {
                        for (var j = 0; j < MapSize.Y; j++)
                        {
                            var tile = s.ReadUInt16();
                            var index = s.ReadUInt8();

                            // TODO: Remember to remove this when rewriting tile variants / PickAny
                            if (index == byte.MaxValue)
                                index = (byte)(i % 4 + (j % 4) * 4);

                            Tiles[new MPos(i, j)] = new TerrainTile(tile, index);
                        }
                    }
                }

                if (header.ResourcesOffset > 0)
                {
                    s.Position = header.ResourcesOffset;
                    for (var i = 0; i < MapSize.X; i++)
                    {
                        for (var j = 0; j < MapSize.Y; j++)
                        {
                            var type = s.ReadUInt8();
                            var density = s.ReadUInt8();
                            Resources[new MPos(i, j)] = new ResourceTile(type, density);
                        }
                    }
                }

                if (header.HeightsOffset > 0)
                {
                    s.Position = header.HeightsOffset;
                    for (var i = 0; i < MapSize.X; i++)
                        for (var j = 0; j < MapSize.Y; j++)
                            Height[new MPos(i, j)] = s.ReadUInt8().Clamp((byte)0, Grid.MaximumTerrainHeight);
                }
            }

            if (Grid.MaximumTerrainHeight > 0)
            {
                Tiles.CellEntryChanged += UpdateProjection;
                Height.CellEntryChanged += UpdateProjection;
            }

            PostInit();

            Uid = ComputeUID(Package);
        }
예제 #10
0
파일: Map.cs 프로젝트: Roger-luo/OpenRA
		public CellLayer<byte> LoadMapHeight()
		{
			var tiles = new CellLayer<byte>(this);
			using (var s = Container.GetContent("map.bin"))
			{
				var header = new BinaryDataHeader(s, MapSize);
				if (header.HeightsOffset > 0)
				{
					s.Position = header.HeightsOffset;
					for (var i = 0; i < MapSize.X; i++)
						for (var j = 0; j < MapSize.Y; j++)
							tiles[new MPos(i, j)] = s.ReadUInt8().Clamp((byte)0, Grid.MaximumTerrainHeight);
				}
			}

			if (Grid.MaximumTerrainHeight > 0)
				tiles.CellEntryChanged += UpdateProjection;

			return tiles;
		}