Esempio n. 1
0
        public TerrainRenderer(World world, WorldRenderer wr)
        {
            theater = wr.Theater;
            mapTiles = world.Map.MapTiles.Value;

            terrain = new TerrainSpriteLayer(world, wr, theater.Sheet, BlendMode.Alpha,
                wr.Palette("terrain"), wr.World.Type != WorldType.Editor);

            foreach (var cell in world.Map.AllCells)
                UpdateCell(cell);

            world.Map.MapTiles.Value.CellEntryChanged += UpdateCell;
            world.Map.MapHeight.Value.CellEntryChanged += UpdateCell;
        }
Esempio n. 2
0
        public TerrainRenderer(World world, WorldRenderer wr)
        {
            theater  = wr.Theater;
            mapTiles = world.Map.MapTiles.Value;

            terrain = new TerrainSpriteLayer(world, wr, theater.Sheet, BlendMode.Alpha,
                                             wr.Palette("terrain"), wr.World.Type != WorldType.Editor);

            foreach (var cell in world.Map.AllCells)
            {
                UpdateCell(cell);
            }

            world.Map.MapTiles.Value.CellEntryChanged  += UpdateCell;
            world.Map.MapHeight.Value.CellEntryChanged += UpdateCell;
        }
Esempio n. 3
0
		public void WorldLoaded(World w, WorldRenderer wr)
		{
			var first = smudges.First().Value.First();
			var sheet = first.Sheet;
			if (smudges.Values.Any(sprites => sprites.Any(s => s.Sheet != sheet)))
				throw new InvalidDataException("Resource sprites span multiple sheets. Try loading their sequences earlier.");

			var blendMode = first.BlendMode;
			if (smudges.Values.Any(sprites => sprites.Any(s => s.BlendMode != blendMode)))
				throw new InvalidDataException("Smudges specify different blend modes. "
					+ "Try using different smudge types for smudges that use different blend modes.");

			render = new TerrainSpriteLayer(w, wr, sheet, blendMode, wr.Palette(Info.Palette), wr.World.Type != WorldType.Editor);

			// Add map smudges
			foreach (var s in w.Map.SmudgeDefinitions)
			{
				var name = s.Key;
				var vals = name.Split(' ');
				var type = vals[0];

				if (!smudges.ContainsKey(type))
					continue;

				var loc = vals[1].Split(',');
				var cell = new CPos(Exts.ParseIntegerInvariant(loc[0]), Exts.ParseIntegerInvariant(loc[1]));
				var depth = Exts.ParseIntegerInvariant(vals[2]);

				var smudge = new Smudge
				{
					Type = type,
					Depth = depth,
					Sprite = smudges[type][depth]
				};

				tiles.Add(cell, smudge);
				render.Update(cell, smudge.Sprite);
			}
		}
Esempio n. 4
0
        public void WorldLoaded(World w, WorldRenderer wr)
        {
            /* based on SmudgeLayer.cs */
            var first = sideSprites.First().Value.First();
            var sheet = first.Sheet;
            if (sideSprites.Values.Any(sprites => sprites.Any(s => s.Sheet != sheet)))
                throw new InvalidDataException("Resource sprites span multiple sheets. Try loading their sequences earlier.");

            var blendMode = first.BlendMode;
            if (sideSprites.Values.Any(sprites => sprites.Any(s => s.BlendMode != blendMode)))
                throw new InvalidDataException("Smudges specify different blend modes. "
                    + "Try using different smudge types for smudges that use different blend modes.");

            render = new TerrainSpriteLayer(w, wr, sheet, blendMode, wr.Palette(Info.Palette), wr.World.Type != WorldType.Editor);

            var tilesLayer = w.Map.Tiles;
            for (var v = 0; v < tilesLayer.Size.Height; v++)
            {
                for (var u = 0; u < tilesLayer.Size.Width; u++)
                {
                    var mpos = new MPos(u, v);
                    var tile = tilesLayer[mpos];

                    if (tile.Type == 143)
                    {
                        ClearSides clear = ClearSides.None;

                        if (u > 0)
                        {
                            var leftPos = new MPos(u - 1, v);
                            var leftTile = tilesLayer[leftPos];
                            if (!(leftTile.Type >= 126 && leftTile.Type <= 143) &&
                                !(leftTile.Type >= 160 && leftTile.Type <= 175))
                            {
                                clear |= ClearSides.Left;
                            }
                        }

                        if (v > 0)
                        {
                            var topPos = new MPos(u, v - 1);
                            var topTile = tilesLayer[topPos];
                            if (!(topTile.Type >= 126 && topTile.Type <= 143) &&
                                !(topTile.Type >= 160 && topTile.Type <= 175))
                            {
                                clear |= ClearSides.Top;
                            }
                        }

                        if (u < tilesLayer.Size.Width - 1)
                        {
                            var rightPos = new MPos(u + 1, v);
                            var rightTile = tilesLayer[rightPos];
                            if (!(rightTile.Type >= 126 && rightTile.Type <= 143) &&
                                !(rightTile.Type >= 160 && rightTile.Type <= 175))
                            {
                                clear |= ClearSides.Right;
                            }
                        }

                        if (v < tilesLayer.Size.Height - 1)
                        {
                            var bottomPos = new MPos(u, v + 1);
                            var bottomTile = tilesLayer[bottomPos];
                            if (!(bottomTile.Type >= 126 && bottomTile.Type <= 143) &&
                                !(bottomTile.Type >= 160 && bottomTile.Type <= 175))
                            {
                                clear |= ClearSides.Bottom;
                            }
                        }

                        if (clear != ClearSides.None)
                        {
                            CPos cpos = mpos.ToCPos(w.Map);
                            Sprite sprite = sideSprites["rock"][SpriteMap[clear]];
                            render.Update(cpos, sprite);
                        }
                    }

                    if (tile.Type == 175)
                    {
                        ClearSides clear = ClearSides.None;

                        if (u > 0)
                        {
                            var leftPos = new MPos(u - 1, v);
                            var leftTile = tilesLayer[leftPos];
                            if (!(leftTile.Type >= 160 && leftTile.Type <= 175))
                            {
                                clear |= ClearSides.Left;
                            }
                        }

                        if (v > 0)
                        {
                            var topPos = new MPos(u, v - 1);
                            var topTile = tilesLayer[topPos];
                            if (!(topTile.Type >= 160 && topTile.Type <= 175))
                            {
                                clear |= ClearSides.Top;
                            }
                        }

                        if (u < tilesLayer.Size.Width - 1)
                        {
                            var rightPos = new MPos(u + 1, v);
                            var rightTile = tilesLayer[rightPos];
                            if (!(rightTile.Type >= 160 && rightTile.Type <= 175))
                            {
                                clear |= ClearSides.Right;
                            }
                        }

                        if (v < tilesLayer.Size.Height - 1)
                        {
                            var bottomPos = new MPos(u, v + 1);
                            var bottomTile = tilesLayer[bottomPos];
                            if (!(bottomTile.Type >= 160 && bottomTile.Type <= 175))
                            {
                                clear |= ClearSides.Bottom;
                            }
                        }

                        if (clear != ClearSides.None)
                        {
                            CPos cpos = mpos.ToCPos(w.Map);
                            Sprite sprite = sideSprites["rough"][SpriteMap[clear]];
                            render.Update(cpos, sprite);
                        }
                    }

                    if (tile.Type == 159)
                    {
                        ClearSides clear = ClearSides.None;

                        if (u > 0)
                        {
                            var leftPos = new MPos(u - 1, v);
                            var leftTile = tilesLayer[leftPos];
                            if (!(leftTile.Type >= 144 && leftTile.Type <= 159))
                            {
                                clear |= ClearSides.Left;
                            }
                        }

                        if (v > 0)
                        {
                            var topPos = new MPos(u, v - 1);
                            var topTile = tilesLayer[topPos];
                            if (!(topTile.Type >= 144 && topTile.Type <= 159))
                            {
                                clear |= ClearSides.Top;
                            }
                        }

                        if (u < tilesLayer.Size.Width - 1)
                        {
                            var rightPos = new MPos(u + 1, v);
                            var rightTile = tilesLayer[rightPos];
                            if (!(rightTile.Type >= 144 && rightTile.Type <= 159))
                            {
                                clear |= ClearSides.Right;
                            }
                        }

                        if (v < tilesLayer.Size.Height - 1)
                        {
                            var bottomPos = new MPos(u, v + 1);
                            var bottomTile = tilesLayer[bottomPos];
                            if (!(bottomTile.Type >= 144 && bottomTile.Type <= 159))
                            {
                                clear |= ClearSides.Bottom;
                            }
                        }

                        if (clear != ClearSides.None)
                        {
                            CPos cpos = mpos.ToCPos(w.Map);
                            Sprite sprite = sideSprites["dune"][SpriteMap[clear]];
                            render.Update(cpos, sprite);
                        }
                    }
                }
            }
        }
Esempio n. 5
0
 public void WorldLoaded(World w, WorldRenderer wr)
 {
     theater = wr.Theater;
     render = new TerrainSpriteLayer(w, wr, theater.Sheet, BlendMode.Alpha, wr.Palette(info.Palette), wr.World.Type != WorldType.Editor);
 }
Esempio n. 6
0
        public void WorldLoaded(World w, WorldRenderer wr)
        {
            var first = smudges.First().Value.First();
            var sheet = first.Sheet;
            if (smudges.Values.Any(sprites => sprites.Any(s => s.Sheet != sheet)))
                throw new InvalidDataException("Resource sprites span multiple sheets. Try loading their sequences earlier.");

            var blendMode = first.BlendMode;
            if (smudges.Values.Any(sprites => sprites.Any(s => s.BlendMode != blendMode)))
                throw new InvalidDataException("Smudges specify different blend modes. "
                    + "Try using different smudge types for smudges that use different blend modes.");

            render = new TerrainSpriteLayer(w, wr, sheet, blendMode, wr.Palette(Info.Palette), wr.World.Type != WorldType.Editor);

            // Add map smudges
            foreach (var kv in Info.InitialSmudges)
            {
                var s = kv.Value;
                if (!smudges.ContainsKey(s.Type))
                    continue;

                var smudge = new Smudge
                {
                    Type = s.Type,
                    Depth = s.Depth,
                    Sprite = smudges[s.Type][s.Depth]
                };

                tiles.Add(kv.Key, smudge);
                render.Update(kv.Key, smudge.Sprite);
            }
        }
Esempio n. 7
0
        void IWorldLoaded.WorldLoaded(World w, WorldRenderer wr)
        {
            // Initialize tile cache
            // This includes the region outside the visible area to cover any sprites peeking outside the map
            foreach (var uv in w.Map.AllCells.MapCoords)
            {
                var pos = w.Map.CenterOfCell(uv.ToCPos(map));
                var screen = wr.Screen3DPosition(pos - new WVec(0, 0, pos.Z));
                var variant = (byte)Game.CosmeticRandom.Next(info.ShroudVariants.Length);
                tileInfos[uv] = new TileInfo(screen, variant);
            }

            // Dirty the whole projected space
            DirtyCells(map.AllCells.MapCoords.Select(uv => (PPos)uv));

            // All tiles are visible in the editor
            if (w.Type == WorldType.Editor)
                visibleUnderShroud = _ => true;
            else
                visibleUnderShroud = puv => map.Contains(puv);

            visibleUnderFog = puv => map.Contains(puv);

            var shroudSheet = shroudSprites[0].Sheet;
            if (shroudSprites.Any(s => s.Sheet != shroudSheet))
                throw new InvalidDataException("Shroud sprites span multiple sheets. Try loading their sequences earlier.");

            var shroudBlend = shroudSprites[0].BlendMode;
            if (shroudSprites.Any(s => s.BlendMode != shroudBlend))
                throw new InvalidDataException("Shroud sprites must all use the same blend mode.");

            var fogSheet = fogSprites[0].Sheet;
            if (fogSprites.Any(s => s.Sheet != fogSheet))
                throw new InvalidDataException("Fog sprites span multiple sheets. Try loading their sequences earlier.");

            var fogBlend = fogSprites[0].BlendMode;
            if (fogSprites.Any(s => s.BlendMode != fogBlend))
                throw new InvalidDataException("Fog sprites must all use the same blend mode.");

            shroudLayer = new TerrainSpriteLayer(w, wr, shroudSheet, shroudBlend, wr.Palette(info.ShroudPalette), false);
            fogLayer = new TerrainSpriteLayer(w, wr, fogSheet, fogBlend, wr.Palette(info.FogPalette), false);
        }