Example #1
0
        public void AddSmudge(CPos loc)
        {
            if (Game.CosmeticRandom.Next(0, 100) <= Info.SmokePercentage)
            {
                world.AddFrameEndTask(w => w.Add(new Smoke(w, loc.CenterPosition, Info.SmokeType)));
            }

            if (!dirty.ContainsKey(loc) && !tiles.ContainsKey(loc))
            {
                // No smudge; create a new one
                var st = smudges.Keys.Random(world.SharedRandom);
                dirty[loc] = new Smudge {
                    Type = st, Depth = 0, Sprite = smudges[st][0]
                };
            }
            else
            {
                // Existing smudge; make it deeper
                var tile     = dirty.ContainsKey(loc) ? dirty[loc] : tiles[loc];
                var maxDepth = smudges[tile.Type].Length;
                if (tile.Depth < maxDepth - 1)
                {
                    tile.Depth++;
                    tile.Sprite = smudges[tile.Type][tile.Depth];
                }

                dirty[loc] = tile;
            }
        }
Example #2
0
		public void WorldLoaded(World w, WorldRenderer wr)
		{
			world = w;
			tiles = new Dictionary<CPos, Smudge>();
			dirty = new Dictionary<CPos, Smudge>();
			smudges = new Dictionary<string, Sprite[]>();

			var types = world.Map.SequenceProvider.Sequences(Info.Sequence);
			foreach (var t in types)
			{
				var seq = world.Map.SequenceProvider.GetSequence(Info.Sequence, t);
				var sprites = Exts.MakeArray(seq.Length, x => seq.GetSprite(x));
				smudges.Add(t, sprites);
			}

			// Add map smudges
			foreach (var s in w.Map.Smudges.Value.Where(s => smudges.Keys.Contains(s.Type)))
			{
				var smudge = new Smudge
				{
					Type = s.Type,
					Depth = s.Depth,
					Sprite = smudges[s.Type][s.Depth]
				};

				tiles.Add((CPos)s.Location, smudge);
			}
		}
Example #3
0
        public void WorldLoaded(World w, WorldRenderer wr)
        {
            world   = w;
            tiles   = new Dictionary <CPos, Smudge>();
            dirty   = new Dictionary <CPos, Smudge>();
            smudges = new Dictionary <string, Sprite[]>();

            var types = SequenceProvider.Sequences(Info.Sequence);

            foreach (var t in types)
            {
                var seq     = SequenceProvider.GetSequence(Info.Sequence, t);
                var sprites = Exts.MakeArray(seq.Length, x => seq.GetSprite(x));
                smudges.Add(t, sprites);
            }

            // Add map smudges
            foreach (var s in w.Map.Smudges.Value.Where(s => smudges.Keys.Contains(s.Type)))
            {
                var smudge = new Smudge
                {
                    Type   = s.Type,
                    Depth  = s.Depth,
                    Sprite = smudges[s.Type][s.Depth]
                };

                tiles.Add((CPos)s.Location, smudge);
            }
        }
Example #4
0
        public void AddSmudge(CPos loc)
        {
            if (Game.CosmeticRandom.Next(0, 100) <= Info.SmokePercentage)
                world.AddFrameEndTask(w => w.Add(new SpriteEffect(world.Map.CenterOfCell(loc), w, Info.SmokeType, Info.SmokeSequence, Info.SmokePalette)));

            // A null Sprite indicates a deleted smudge.
            if ((!dirty.ContainsKey(loc) || dirty[loc].Sprite == null) && !tiles.ContainsKey(loc))
            {
                // No smudge; create a new one
                var st = smudges.Keys.Random(Game.CosmeticRandom);
                dirty[loc] = new Smudge { Type = st, Depth = 0, Sprite = smudges[st][0] };
            }
            else
            {
                // Existing smudge; make it deeper
                // A null Sprite indicates a deleted smudge.
                var tile = dirty.ContainsKey(loc) && dirty[loc].Sprite != null ? dirty[loc] : tiles[loc];
                var maxDepth = smudges[tile.Type].Length;
                if (tile.Depth < maxDepth - 1)
                {
                    tile.Depth++;
                    tile.Sprite = smudges[tile.Type][tile.Depth];
                }

                dirty[loc] = tile;
            }
        }
Example #5
0
        public void AddSmudge(CPos loc)
        {
            if (!world.Map.Contains(loc))
            {
                return;
            }

            if (Game.CosmeticRandom.Next(0, 100) <= Info.SmokePercentage)
            {
                world.AddFrameEndTask(w => w.Add(new SpriteEffect(world.Map.CenterOfCell(loc), w, Info.SmokeType, Info.SmokeSequence, Info.SmokePalette)));
            }

            // A null Sequence indicates a deleted smudge.
            if ((!dirty.ContainsKey(loc) || dirty[loc].Sequence == null) && !tiles.ContainsKey(loc))
            {
                // No smudge; create a new one
                var st = smudges.Keys.Random(Game.CosmeticRandom);
                dirty[loc] = new Smudge {
                    Type = st, Depth = 0, Sequence = smudges[st]
                };
            }
            else
            {
                // Existing smudge; make it deeper
                // A null Sequence indicates a deleted smudge.
                var tile     = dirty.ContainsKey(loc) && dirty[loc].Sequence != null ? dirty[loc] : tiles[loc];
                var maxDepth = smudges[tile.Type].Length;
                if (tile.Depth < maxDepth - 1)
                {
                    tile.Depth++;
                }

                dirty[loc] = tile;
            }
        }
Example #6
0
        public void AddSmudge(CPos loc)
        {
            if (!world.Map.Contains(loc))
            {
                return;
            }

            if ((!dirty.ContainsKey(loc) || dirty[loc].Sprite == null) && !tiles.ContainsKey(loc))
            {
                //no smudge; create a new one

                var st = smudges.Keys.Random(WarGame.CosmeticRandom);

                dirty[loc] = new Smudge()
                {
                    Type = st, Depth = 0, Sprite = smudges[st][0]
                };
            }
            else
            {
                var tile     = dirty.ContainsKey(loc) && dirty[loc].Sprite != null ? dirty[loc] : tiles[loc];
                var maxDepth = smudges[tile.Type].Length;
                if (tile.Depth < maxDepth - 1)
                {
                    tile.Depth++;
                    tile.Sprite = smudges[tile.Type][tile.Depth];
                }

                dirty[loc] = tile;
            }
        }
Example #7
0
        public void AddSmudge(CPos loc)
        {
            if (Game.CosmeticRandom.Next(0, 100) <= Info.SmokePercentage)
                world.AddFrameEndTask(w => w.Add(new Smoke(w, world.Map.CenterOfCell(loc), Info.SmokeType)));

            if (!dirty.ContainsKey(loc) && !tiles.ContainsKey(loc))
            {
                // No smudge; create a new one
                var st = smudges.Keys.Random(world.SharedRandom);
                dirty[loc] = new Smudge { Type = st, Depth = 0, Sprite = smudges[st][0] };
            }
            else
            {
                // Existing smudge; make it deeper
                var tile = dirty.ContainsKey(loc) ? dirty[loc] : tiles[loc];
                var maxDepth = smudges[tile.Type].Length;
                if (tile.Depth < maxDepth - 1)
                {
                    tile.Depth++;
                    tile.Sprite = smudges[tile.Type][tile.Depth];
                }

                dirty[loc] = tile;
            }
        }
Example #8
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);
            }
        }
Example #9
0
        public void WorldLoaded(World w, WorldRenderer wr)
        {
            world   = w;
            tiles   = new Dictionary <CPos, Smudge>();
            dirty   = new Dictionary <CPos, Smudge>();
            smudges = new Dictionary <string, Sprite[]>();

            var types = world.Map.SequenceProvider.Sequences(Info.Sequence);

            foreach (var t in types)
            {
                var seq     = world.Map.SequenceProvider.GetSequence(Info.Sequence, t);
                var sprites = Exts.MakeArray(seq.Length, x => seq.GetSprite(x));
                smudges.Add(t, sprites);
            }

            // 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);
            }
        }
Example #10
0
        public void Add(Smudge smudge)
        {
            Smudge.Add(smudge);
            if (smudge.CheckVisibility())
            {
                visibleSmudge.Add(smudge);
            }

            if (Smudge.Count > 256)
            {
                for (int i = 0; i < Smudge.Count; i++)
                {
                    if (!Smudge[i].IsDissolving)
                    {
                        Smudge[i].BeginDissolve();
                        break;
                    }
                }
            }
        }
Example #11
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);
            }
        }
Example #12
0
        public void WorldLoaded(World w, WorldRenderer wr)
        {
            var sprites   = smudges.Values.SelectMany(v => Exts.MakeArray(v.Length, x => v.GetSprite(x))).ToList();
            var sheet     = sprites[0].Sheet;
            var blendMode = sprites[0].BlendMode;

            if (sprites.Any(s => s.Sheet != sheet))
            {
                throw new InvalidDataException("Resource sprites span multiple sheets. Try loading their sequences earlier.");
            }

            if (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), w.Type != WorldType.Editor);

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

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

                tiles.Add(kv.Key, smudge);
                render.Update(kv.Key, seq, s.Depth);
            }
        }
Example #13
0
        public void WorldLoaded(World w, WorldRenderer wr)
        {
            var sprites     = smudges.Values.SelectMany(v => Exts.MakeArray(v.Length, x => v.GetSprite(x))).ToList();
            var sheet       = sprites[0].Sheet;
            var blendMode   = sprites[0].BlendMode;
            var emptySprite = new Sprite(sheet, Rectangle.Empty, TextureChannel.Alpha);

            if (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.");
            }

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

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

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

                tiles.Add(kv.Key, smudge);
                render.Update(kv.Key, seq, paletteReference, s.Depth);
            }
        }
Example #14
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);
			}
		}
Example #15
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);
            }
        }
Example #16
0
        public static (Rectangle, Action <Graphics>) Render(TheaterType theater, Point topLeft, Size tileSize, Smudge smudge)
        {
            var tint            = smudge.Tint;
            var imageAttributes = new ImageAttributes();

            if (tint != Color.White)
            {
                var colorMatrix = new ColorMatrix(new float[][]
                {
                    new float[] { tint.R / 255.0f, 0, 0, 0, 0 },
                    new float[] { 0, tint.G / 255.0f, 0, 0, 0 },
                    new float[] { 0, 0, tint.B / 255.0f, 0, 0 },
                    new float[] { 0, 0, 0, tint.A / 255.0f, 0 },
                    new float[] { 0, 0, 0, 0, 1 },
                }
                                                  );
                imageAttributes.SetColorMatrix(colorMatrix);
            }

            if (Globals.TheTilesetManager.GetTileData(theater.Tilesets, smudge.Type.Name, smudge.Icon, out Tile tile))
            {
                var location     = new Point(topLeft.X * tileSize.Width, topLeft.Y * tileSize.Height);
                var smudgeBounds = new Rectangle(location, smudge.Type.RenderSize);

                void render(Graphics g)
                {
                    g.DrawImage(tile.Image, smudgeBounds, 0, 0, tile.Image.Width, tile.Image.Height, GraphicsUnit.Pixel, imageAttributes);
                }

                return(smudgeBounds, render);
            }
            else
            {
                Debug.Print(string.Format("Smudge {0} ({1}) not found", smudge.Type.Name, smudge.Icon));
                return(Rectangle.Empty, (g) => { });
            }
        }
Example #17
0
        public void WorldLoaded(World w, WorldRenderer wr)
        {
            world = w;
            tiles = new Dictionary<CPos, Smudge>();
            dirty = new Dictionary<CPos, Smudge>();
            smudges = new Dictionary<string, Sprite[]>();

            var types = world.Map.SequenceProvider.Sequences(Info.Sequence);
            foreach (var t in types)
            {
                var seq = world.Map.SequenceProvider.GetSequence(Info.Sequence, t);
                var sprites = Exts.MakeArray(seq.Length, x => seq.GetSprite(x));
                smudges.Add(t, sprites);
            }

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