Beispiel #1
0
        public void Apply(Surface surface)
        {
            // change the bits in the map
            var template = surface.TileSet.Templates[brushTemplate.N];
            var tile = surface.TileSetRenderer.Data(brushTemplate.N);
            var pos = surface.GetBrushLocation();

            if (surface.GetModifiers() == Keys.Shift)
            {
                FloodFillWithBrush(surface, pos);
                return;
            }

            for (var u = 0; u < template.Size.X; u++)
                for (var v = 0; v < template.Size.Y; v++)
                {
                    var cell = pos + new CVec(u, v);
                    if (surface.Map.Contains(cell))
                    {
                        var z = u + v * template.Size.X;
                        if (tile != null && tile[z].Length > 0)
                        {
                            var index = template.PickAny ? (byte)((u + pos.X) % 4 + ((v + pos.Y) % 4) * 4) : (byte)z;
                            surface.Map.MapTiles.Value[cell] = new TerrainTile(brushTemplate.N, index);
                        }

                        var ch = new int2((pos.X + u) / Surface.ChunkSize, (pos.Y + v) / Surface.ChunkSize);
                        if (surface.Chunks.ContainsKey(ch))
                        {
                            surface.Chunks[ch].Dispose();
                            surface.Chunks.Remove(ch);
                        }
                    }
                }
        }
Beispiel #2
0
        public void Preview(Surface surface, SGraphics g)
        {
            /* todo: include the player
                * in the brush so we can color new buildings too */

            surface.DrawActor(g, surface.GetBrushLocation(), Actor, null);
        }
Beispiel #3
0
 public void Preview(Surface surface, SGraphics g)
 {
     g.DrawImage(brushTemplate.Bitmap,
             surface.TileSetRenderer.TileSize * surface.GetBrushLocation().X * surface.Zoom + surface.GetOffset().X,
             surface.TileSetRenderer.TileSize * surface.GetBrushLocation().Y * surface.Zoom + surface.GetOffset().Y,
             brushTemplate.Bitmap.Width * surface.Zoom,
             brushTemplate.Bitmap.Height * surface.Zoom);
 }
Beispiel #4
0
 public void Preview(Surface surface, SGraphics g)
 {
     g.DrawImage(Brush.Bitmap,
             surface.TileSet.TileSize * surface.GetBrushLocation().X * surface.Zoom + surface.GetOffset().X,
             surface.TileSet.TileSize * surface.GetBrushLocation().Y * surface.Zoom + surface.GetOffset().Y,
             Brush.Bitmap.Width * surface.Zoom,
             Brush.Bitmap.Height * surface.Zoom);
 }
Beispiel #5
0
		static string NextActorName(Surface surface)
		{
			var id = 0;
			for (;;)
			{
				var possible = "Actor{0}".F(id++);
				if (!surface.Map.Actors.Value.ContainsKey(possible)) return possible;
			}
		}
Beispiel #6
0
 static CPos FindEdge(Surface s, CPos p, CVec d, TerrainTile replace)
 {
     for (;;)
     {
         var q = p + d;
         if (!s.Map.Contains(q)) return p;
         if (s.Map.MapTiles.Value[q].Type != replace.Type) return p;
         p = q;
     }
 }
Beispiel #7
0
		public void Apply(Surface surface)
		{
			if (surface.Map.Actors.Value.Any(a => a.Value.Location() == surface.GetBrushLocation()))
				return;

			var owner = surface.NewActorOwner;
			var id = NextActorName(surface);
			surface.Map.Actors.Value[id] = new ActorReference(actorTemplate.Info.Name.ToLowerInvariant())
			{
				new LocationInit(surface.GetBrushLocation()),
				new OwnerInit(owner)
			};
		}
Beispiel #8
0
		public void Apply(Surface surface)
		{
			var type = (byte)resourceTemplate.Info.ResourceType;
			var index = (byte)random.Next(resourceTemplate.Info.MaxDensity);
			surface.Map.MapResources.Value[surface.GetBrushLocation()] = new ResourceTile(type, index);

			var ch = new int2(surface.GetBrushLocation().X / Surface.ChunkSize,
				surface.GetBrushLocation().Y / Surface.ChunkSize);

			if (surface.Chunks.ContainsKey(ch))
			{
				surface.Chunks[ch].Dispose();
				surface.Chunks.Remove(ch);
			}
		}
Beispiel #9
0
        public void Apply(Surface surface)
        {
            surface.Map.MapResources.Value[surface.GetBrushLocation().X, surface.GetBrushLocation().Y]
                = new TileReference<byte, byte>
                {
                    type = (byte)Resource.Info.ResourceType,
                    index = (byte)random.Next(Resource.Info.SpriteNames.Length)
                };

            var ch = new int2((surface.GetBrushLocation().X) / Surface.ChunkSize,
                (surface.GetBrushLocation().Y) / Surface.ChunkSize);

            if (surface.Chunks.ContainsKey(ch))
            {
                surface.Chunks[ch].Dispose();
                surface.Chunks.Remove(ch);
            }
        }
Beispiel #10
0
        public void Apply(Surface surface)
        {
            surface.Map.MapResources.Value[surface.GetBrushLocation().X, surface.GetBrushLocation().Y]
                = new TileReference<byte, byte>
                {
                    Type = (byte)resourceTemplate.Info.ResourceType,
                    Index = (byte)random.Next(resourceTemplate.Info.MaxDensity)
                };

            var ch = new int2(surface.GetBrushLocation().X / Surface.ChunkSize,
                surface.GetBrushLocation().Y / Surface.ChunkSize);

            if (surface.Chunks.ContainsKey(ch))
            {
                surface.Chunks[ch].Dispose();
                surface.Chunks.Remove(ch);
            }
        }
Beispiel #11
0
		void FloodFillWithBrush(Surface s, CPos pos)
		{
			var queue = new Queue<CPos>();
			var replace = s.Map.MapTiles.Value[pos];
			var touched = new bool[s.Map.MapSize.X, s.Map.MapSize.Y];

			Action<int, int> maybeEnqueue = (x, y) =>
			{
				var c = new CPos(x, y);
				if (s.Map.Contains(c) && !touched[x, y])
				{
					queue.Enqueue(c);
					touched[x, y] = true;
				}
			};

			queue.Enqueue(pos);
			while (queue.Count > 0)
			{
				var p = queue.Dequeue();
				if (s.Map.MapTiles.Value[p].Type != replace.Type)
					continue;

				var a = FindEdge(s, p, new CVec(-1, 0), replace);
				var b = FindEdge(s, p, new CVec(1, 0), replace);

				for (var x = a.X; x <= b.X; x++)
				{
					s.Map.MapTiles.Value[new CPos(x, p.Y)] = new TerrainTile(brushTemplate.N, (byte)0);
					if (s.Map.MapTiles.Value[new CPos(x, p.Y - 1)].Type == replace.Type)
						maybeEnqueue(x, p.Y - 1);
					if (s.Map.MapTiles.Value[new CPos(x, p.Y + 1)].Type == replace.Type)
						maybeEnqueue(x, p.Y + 1);
				}
			}

			/* TODO: optimize */
			foreach (var ch in s.Chunks.Values) ch.Dispose();
			s.Chunks.Clear();
		}
Beispiel #12
0
        public void Apply(Surface surface)
        {
            // change the bits in the map
            var template = surface.TileSet.Templates[brushTemplate.N];
            var tile = surface.TileSetRenderer.Data(brushTemplate.N);
            var pos = surface.GetBrushLocation();

            if (surface.GetModifiers() == Keys.Shift)
            {
                FloodFillWithBrush(surface, pos);
                return;
            }

            for (var u = 0; u < template.Size.X; u++)
                for (var v = 0; v < template.Size.Y; v++)
                {
                    if (surface.Map.IsInMap(new CVec(u, v) + pos))
                    {
                        var z = u + v * template.Size.X;
                        if (tile[z].Length > 0)
                            surface.Map.MapTiles.Value[u + pos.X, v + pos.Y] =
                                new TileReference<ushort, byte>
                                {
                                    Type = brushTemplate.N,
                                    Index = template.PickAny ? (byte)((u + pos.X) % 4 + ((v + pos.Y) % 4) * 4) : (byte)z,
                                };

                        var ch = new int2((pos.X + u) / Surface.ChunkSize, (pos.Y + v) / Surface.ChunkSize);
                        if (surface.Chunks.ContainsKey(ch))
                        {
                            surface.Chunks[ch].Dispose();
                            surface.Chunks.Remove(ch);
                        }
                    }
                }
        }
Beispiel #13
0
 public void Preview(Surface surface, SGraphics g)
 {
     surface.DrawImage(g, resourceTemplate.Bitmap, surface.GetBrushLocation(), false, null);
 }
Beispiel #14
0
 int2 FindEdge(Surface s, int2 p, int2 d, TileReference<ushort, byte> replace)
 {
     for (; ; )
     {
         var q = p + d;
         if (!s.Map.IsInMap(q)) return p;
         if (!s.Map.MapTiles.Value[q.X, q.Y].Equals(replace)) return p;
         p = q;
     }
 }
Beispiel #15
0
		public void Preview(Surface surface, SGraphics g)
		{
			surface.DrawActor(g, surface.GetBrushLocation(), actorTemplate,
				surface.GetPaletteForPlayer(surface.NewActorOwner));
		}
Beispiel #16
0
        void FloodFillWithBrush(Surface s, int2 pos)
        {
            var queue = new Queue<int2>();
            var replace = s.Map.MapTiles.Value[pos.X, pos.Y];
            var touched = new bool[s.Map.MapSize.X, s.Map.MapSize.Y];

            Action<int, int> MaybeEnqueue = (x, y) =>
            {
                if (s.Map.IsInMap(x, y) && !touched[x, y])
                {
                    queue.Enqueue(new int2(x, y));
                    touched[x, y] = true;
                }
            };

            queue.Enqueue(pos);
            while (queue.Count > 0)
            {
                var p = queue.Dequeue();
                if (!s.Map.MapTiles.Value[p.X, p.Y].Equals(replace))
                    continue;

                var a = FindEdge(s, p, new int2(-1, 0), replace);
                var b = FindEdge(s, p, new int2(1, 0), replace);

                for (var x = a.X; x <= b.X; x++)
                {
                    s.Map.MapTiles.Value[x, p.Y] = new TileReference<ushort, byte> { type = Brush.N, index = (byte)0 };
                    if (s.Map.MapTiles.Value[x, p.Y - 1].Equals(replace))
                        MaybeEnqueue(x, p.Y - 1);
                    if (s.Map.MapTiles.Value[x, p.Y + 1].Equals(replace))
                        MaybeEnqueue(x, p.Y + 1);
                }
            }

            /* todo: optimize */
            foreach (var ch in s.Chunks.Values) ch.Dispose();
            s.Chunks.Clear();
        }
Beispiel #17
0
 static CPos FindEdge(Surface s, CPos p, CVec d, TileReference<ushort, byte> replace)
 {
     for (;;)
     {
         var q = p + d;
         if (!s.Map.IsInMap(q)) return p;
         if (s.Map.MapTiles.Value[q.X, q.Y].Type != replace.Type) return p;
         p = q;
     }
 }
Beispiel #18
0
		public void Preview(Surface surface, SGraphics g)
		{
			surface.DrawImage(g, resourceTemplate.Bitmap, surface.GetBrushLocation(), false, null);
		}
Beispiel #19
0
        void FloodFillWithBrush(Surface s, CPos pos)
        {
            var queue = new Queue<CPos>();
            var replace = s.Map.MapTiles.Value[pos.X, pos.Y];
            var touched = new bool[s.Map.MapSize.X, s.Map.MapSize.Y];

            Action<int, int> maybeEnqueue = (x, y) =>
            {
                if (s.Map.IsInMap(x, y) && !touched[x, y])
                {
                    queue.Enqueue(new CPos(x, y));
                    touched[x, y] = true;
                }
            };

            queue.Enqueue(pos);
            while (queue.Count > 0)
            {
                var p = queue.Dequeue();
                if (s.Map.MapTiles.Value[p.X, p.Y].Type != replace.Type)
                    continue;

                var a = FindEdge(s, p, new CVec(-1, 0), replace);
                var b = FindEdge(s, p, new CVec(1, 0), replace);

                for (var x = a.X; x <= b.X; x++)
                {
                    s.Map.MapTiles.Value[x, p.Y] = new TileReference<ushort, byte> { Type = brushTemplate.N, Index = (byte)0 };
                    if (s.Map.MapTiles.Value[x, p.Y - 1].Type == replace.Type)
                        maybeEnqueue(x, p.Y - 1);
                    if (s.Map.MapTiles.Value[x, p.Y + 1].Type == replace.Type)
                        maybeEnqueue(x, p.Y + 1);
                }
            }

            /* TODO: optimize */
            foreach (var ch in s.Chunks.Values) ch.Dispose();
            s.Chunks.Clear();
        }
Beispiel #20
0
 public void Preview(Surface surface, SGraphics g)
 {
     surface.DrawActor(g, surface.GetBrushLocation(), actorTemplate,
                       surface.GetPaletteForPlayer(surface.NewActorOwner));
 }