예제 #1
0
 public static void FillTiles(VMArchitecture arch, short tile, short x, short y, sbyte level, int xtimes, int ytimes)
 {
     for (int xo = 0; xo < xtimes; xo++)
     {
         var x2 = (short)(x + xo);
         if (x2 < 1 || x2 >= arch.Width - 1)
         {
             continue;
         }
         for (int yo = 0; yo < ytimes; yo++)
         {
             var y2 = (short)(y + yo);
             if (y2 < 1 || y2 >= arch.Height - 1)
             {
                 continue;
             }
             arch.SetFloor(x2, y2, level, new FloorTile()
             {
                 Pattern = (ushort)tile
             }, true);
         }
     }
 }
예제 #2
0
        public static void StampTilemap(VMArchitecture arch, short[] tilemap, short x, short y, sbyte level, bool skipZero)
        {
            var width  = tilemap[0];
            var height = tilemap[1];

            for (int i = 2; i < tilemap.Length; i++)
            {
                if (skipZero && tilemap[i] == 0)
                {
                    continue;
                }
                var xo = (i - 2) % width;
                var yo = (i - 2) / width;
                if (x + xo >= arch.Width - 1 || y + yo >= arch.Height - 1)
                {
                    continue;
                }
                arch.SetFloor((short)(x + xo), (short)(y + yo), level, new LotView.Model.FloorTile()
                {
                    Pattern = (ushort)tilemap[i]
                }, true);
            }
        }
예제 #3
0
        public static PatternReplaceCount FloorPatternRect(VMArchitecture target, Rectangle rect, ushort dir, ushort pattern, sbyte level) //returns floors covered
        {
            PatternReplaceCount floorsCovered = new PatternReplaceCount(true);

            if (rect.Width == 0 && rect.Height == 0)
            {
                //dot mode, just fill a tile. can be a diagonal.
                if (rect.X < 0 || rect.X >= target.Width || rect.Y < 0 || rect.Y >= target.Width)
                {
                    return(floorsCovered);
                }
                var wall = target.GetWall((short)rect.X, (short)rect.Y, level);
                if ((wall.Segments & AnyDiag) > 0 && pattern < 65534)
                {
                    bool side = ((wall.Segments & WallSegments.HorizontalDiag) > 0) ? (dir < 2) : (dir < 1 || dir > 2);
                    if (side)
                    {
                        if (wall.TopLeftStyle != pattern)
                        {
                            floorsCovered.Add(wall.TopLeftStyle);
                            wall.TopLeftStyle = pattern;
                        }
                    }
                    else
                    {
                        if (wall.TopLeftPattern != pattern)
                        {
                            floorsCovered.Add(wall.TopLeftPattern);
                            wall.TopLeftPattern = pattern;
                        }
                    }
                    target.SetWall((short)rect.X, (short)rect.Y, level, wall);
                }
                else if ((wall.Segments & AnyDiag) == 0)
                {
                    var floor = target.GetFloor((short)rect.X, (short)rect.Y, level);
                    if (floor.Pattern != pattern)
                    {
                        var old = floor.Pattern;
                        floor.Pattern = pattern;
                        if (target.SetFloor((short)rect.X, (short)rect.Y, level, floor, false))
                        {
                            floorsCovered.DAdd(old);
                        }
                    }
                }
                return(floorsCovered);
            }

            var xEnd = Math.Min(target.Width, rect.X + rect.Width + 1);
            var yEnd = Math.Min(target.Height, rect.Y + rect.Height + 1);

            for (int y = Math.Max(0, rect.Y); y < yEnd; y++)
            {
                for (int x = Math.Max(0, rect.X); x < xEnd; x++)
                {
                    var wall = target.GetWall((short)x, (short)y, level);
                    if ((wall.Segments & AnyDiag) > 0) //diagonal floors are stored in walls
                    {
                        if (pattern < 65534)
                        {
                            continue;
                        }
                        if (wall.TopLeftStyle != pattern)
                        {
                            wall.TopLeftStyle = pattern;
                            floorsCovered.Add(wall.TopLeftStyle);
                        }

                        if (wall.TopLeftPattern != pattern)
                        {
                            wall.TopLeftPattern = pattern;
                            floorsCovered.Add(wall.TopLeftPattern);
                        }
                        target.SetWall((short)x, (short)y, level, wall);
                    }
                    else
                    {
                        var floor = target.GetFloor((short)x, (short)y, level);
                        if (floor.Pattern != pattern)
                        {
                            var old = floor.Pattern;
                            floor.Pattern = pattern;
                            if (target.SetFloor((short)x, (short)y, level, floor, false))
                            {
                                floorsCovered.DAdd(old);
                            }
                        }
                    }
                }
            }
            return(floorsCovered);
        }
예제 #4
0
        /// <summary>
        /// Fills a room with a certain Floor pattern. Returns floors covered
        /// </summary>
        public static PatternReplaceCount FloorPatternFill(VMArchitecture target, Point pos, ushort pattern, sbyte level) //for first floor gen, curRoom should be 1. For floors above, it should be the last genmap result
        {
            if (pattern > 65533 || pos.X < 0 || pos.X >= target.Width || pos.Y < 0 || pos.Y >= target.Height)
            {
                return(new PatternReplaceCount());
            }

            pos.X = Math.Max(Math.Min(pos.X, target.Width - 1), 0);
            pos.Y = Math.Max(Math.Min(pos.Y, target.Height - 1), 0);
            var walls = target.Walls[level - 1];

            var width  = target.Width;
            var height = target.Height;
            PatternReplaceCount floorsCovered = new PatternReplaceCount(true);

            byte[] Map = new byte[target.Width * target.Height];

            //flood fill recursively. Each time choose find and choose the first "0" as the base.
            //The first recursion (outside) cannot fill into diagonals.
            var spread = new Stack <Point>();

            spread.Push(pos);
            while (spread.Count > 0)
            {
                var item = spread.Pop();

                var plusX = (item.X + 1) % width;
                var minX  = (item.X + width - 1) % width;
                var plusY = (item.Y + 1) % height;
                var minY  = (item.Y + height - 1) % height;

                var mainWalls = walls[item.X + item.Y * width];
                var floor     = target.GetFloor((short)item.X, (short)item.Y, level);
                if ((byte)mainWalls.Segments > 15)
                {
                    //draw floor onto a diagonal;
                    var  wall  = walls[item.X + item.Y * width];
                    byte flags = Map[item.X + item.Y * width];

                    if (flags == 3)
                    {
                        continue;
                    }
                    if ((mainWalls.Segments & WallSegments.HorizontalDiag) > 0)
                    {
                        flags = (byte)(3 - flags);
                    }

                    if ((flags & 1) == 1 && wall.TopLeftPattern != pattern)
                    {
                        floorsCovered.Add(wall.TopLeftPattern);
                        wall.TopLeftPattern = pattern;
                    }
                    else if ((flags & 2) == 2 && wall.TopLeftStyle != pattern)
                    {
                        floorsCovered.Add(wall.TopLeftStyle);
                        wall.TopLeftStyle = pattern;
                    }

                    walls[item.X + item.Y * width] = wall;
                    continue; //don't spread on diagonals for now
                }
                else
                {
                    //normal tile, draw a floor here.
                    if (floor.Pattern != pattern)
                    {
                        var old = floor.Pattern;
                        floor.Pattern = pattern;
                        if (target.SetFloor((short)item.X, (short)item.Y, level, floor, false))
                        {
                            floorsCovered.DAdd(old);
                        }
                    }
                }

                if (Map[plusX + item.Y * width] < 3 && (mainWalls.Segments & WallSegments.BottomRight) == 0)
                {
                    SpreadOnto(walls, plusX, item.Y, 0, Map, width, height, spread, pattern, true);
                }

                if (Map[minX + item.Y * width] < 3 && (mainWalls.Segments & WallSegments.TopLeft) == 0)
                {
                    SpreadOnto(walls, minX, item.Y, 2, Map, width, height, spread, pattern, true);
                }

                if (Map[item.X + plusY * width] < 3 && (mainWalls.Segments & WallSegments.BottomLeft) == 0)
                {
                    SpreadOnto(walls, item.X, plusY, 1, Map, width, height, spread, pattern, true);
                }

                if (Map[item.X + minY * width] < 3 && (mainWalls.Segments & WallSegments.TopRight) == 0)
                {
                    SpreadOnto(walls, item.X, minY, 3, Map, width, height, spread, pattern, true);
                }

                walls[item.X + item.Y * width] = mainWalls;
            }
            return(floorsCovered);
        }
예제 #5
0
        //things 2 note
        //default style is 1
        //default pattern is 0
        //mid drawing pattern/style is 255
        public static int DrawWall(VMArchitecture target, Point pos, int length, int direction, ushort pattern, ushort style, sbyte level, bool force)
        {
            if (!force && !VerifyDrawWall(target, pos, length, direction, level))
            {
                return(0);
            }

            int totalWalls = 0;

            pos += WLStartOff[direction];
            bool diagCheck = (direction % 2 == 1);

            for (int i = 0; i < length; i++)
            {
                var wall = target.GetWall((short)pos.X, (short)pos.Y, level);
                if ((wall.Segments & (WLMainSeg[direction] | AnyDiag)) == 0 && (!diagCheck || (wall.Segments == 0)))
                {
                    //no wall here already, apply it.
                    wall.Segments |= WLMainSeg[direction];
                    if (diagCheck)
                    {
                        var floor = target.GetFloor((short)pos.X, (short)pos.Y, level);
                        wall.TopRightStyle      = style;
                        wall.BottomLeftPattern  = pattern;
                        wall.BottomRightPattern = pattern;
                        wall.TopLeftStyle       = floor.Pattern;
                        wall.TopLeftPattern     = floor.Pattern;
                        floor.Pattern           = 0;
                        target.SetFloor((short)pos.X, (short)pos.Y, level, floor, true);
                    }
                    else if (WLMainSeg[direction] == WallSegments.TopRight)
                    {
                        wall.TopRightStyle   = style;
                        wall.TopRightPattern = pattern;
                    }
                    else
                    {
                        wall.TopLeftStyle   = style;
                        wall.TopLeftPattern = pattern;
                    }

                    totalWalls++;
                    target.SetWall((short)pos.X, (short)pos.Y, level, wall);

                    if (!diagCheck)
                    {
                        var tPos = pos + WLSubOff[direction / 2];
                        wall           = target.GetWall((short)tPos.X, (short)tPos.Y, level);
                        wall.Segments |= WLSubSeg[direction / 2];

                        if (WLSubSeg[direction / 2] == WallSegments.BottomRight)
                        {
                            wall.BottomRightPattern = pattern;
                        }
                        else
                        {
                            wall.BottomLeftPattern = pattern;
                        }

                        target.SetWall((short)tPos.X, (short)tPos.Y, level, wall);
                    }
                }
                pos += WLStep[direction];
            }
            return(totalWalls);
        }
        //returns floors covered
        public static int FloorPatternRect(VMArchitecture target, Rectangle rect, ushort dir, ushort pattern, sbyte level)
        {
            int floorsCovered = 0;
            if (rect.Width == 0 && rect.Height == 0)
            {
                //dot mode, just fill a tile. can be a diagonal.
                if (rect.X < 0 || rect.X >= target.Width || rect.Y < 0 || rect.Y >= target.Width) return 0;
                var wall = target.GetWall((short)rect.X, (short)rect.Y, level);
                if ((wall.Segments & AnyDiag) > 0)
                {
                    bool side = ((wall.Segments & WallSegments.HorizontalDiag) > 0) ? (dir < 2) : (dir < 1 || dir > 2);
                    if (side)
                    {
                        if (wall.TopLeftStyle != pattern)
                        {
                            floorsCovered++;
                            wall.TopLeftStyle = pattern;
                        }
                    }
                    else
                    {
                        if (wall.TopLeftPattern != pattern)
                        {
                            floorsCovered++;
                            wall.TopLeftPattern = pattern;
                        }
                    }
                    target.SetWall((short)rect.X, (short)rect.Y, level, wall);
                }
                else
                {
                    var floor = target.GetFloor((short)rect.X, (short)rect.Y, level);
                    if (floor.Pattern != pattern)
                    {
                        floor.Pattern = pattern;
                        if (target.SetFloor((short)rect.X, (short)rect.Y, level, floor, false)) floorsCovered += 2;
                    }
                }
                return floorsCovered;
            }

            var xEnd = Math.Min(target.Width, rect.X + rect.Width+1);
            var yEnd = Math.Min(target.Height, rect.Y + rect.Height+1);
            for (int y = Math.Max(0, rect.Y); y < yEnd; y++)
            {
                for (int x = Math.Max(0, rect.X); x < xEnd; x++)
                {
                    var wall = target.GetWall((short)x, (short)y, level);
                    if ((wall.Segments & AnyDiag) > 0) //diagonal floors are stored in walls
                    {
                        if (wall.TopLeftStyle != pattern)
                        {
                            wall.TopLeftStyle = pattern;
                            floorsCovered++;
                        }

                        if (wall.TopLeftPattern != pattern)
                        {
                            wall.TopLeftPattern = pattern;
                            floorsCovered++;
                        }
                        target.SetWall((short)x, (short)y, level, wall);
                    }
                    else
                    {
                        var floor = target.GetFloor((short)x, (short)y, level);
                        if (floor.Pattern != pattern)
                        {
                            floor.Pattern = pattern;
                            if (target.SetFloor((short)x, (short)y, level, floor, false)) floorsCovered += 2;
                        }
                    }
                }
            }
            return floorsCovered;
        }
        //for first floor gen, curRoom should be 1. For floors above, it should be the last genmap result
        /// <summary>
        /// Fills a room with a certain Floor pattern. Returns floors covered
        /// </summary>
        public static int FloorPatternFill(VMArchitecture target, Point pos, ushort pattern, sbyte level)
        {
            if (pos.X < 0 || pos.X >= target.Width || pos.Y < 0 || pos.Y >= target.Height) return 0;

            pos.X = Math.Max(Math.Min(pos.X, target.Width - 1), 0);
            pos.Y = Math.Max(Math.Min(pos.Y, target.Height - 1), 0);
            var walls = target.Walls[level-1];

            var width = target.Width;
            var height = target.Height;
            int floorsCovered = 0;

            byte[] Map = new byte[target.Width * target.Height];

            //flood fill recursively. Each time choose find and choose the first "0" as the base.
            //The first recursion (outside) cannot fill into diagonals.
            var spread = new Stack<Point>();
            spread.Push(pos);
            while (spread.Count > 0)
            {
                var item = spread.Pop();

                var plusX = (item.X + 1) % width;
                var minX = (item.X + width - 1) % width;
                var plusY = (item.Y + 1) % height;
                var minY = (item.Y + height - 1) % height;

                var mainWalls = walls[item.X + item.Y * width];
                var floor = target.GetFloor((short)item.X, (short)item.Y, level);
                if ((byte)mainWalls.Segments > 15)
                {
                    //draw floor onto a diagonal;
                    var wall = walls[item.X + item.Y * width];
                    byte flags = Map[item.X + item.Y * width];

                    if (flags == 3) continue;
                    if ((mainWalls.Segments & WallSegments.HorizontalDiag) > 0) flags = (byte)(3 - flags);

                        if ((flags & 1) == 1 && wall.TopLeftPattern != pattern)
                        {
                            floorsCovered++;
                            wall.TopLeftPattern = pattern;
                        }
                        else if ((flags & 2) == 2 && wall.TopLeftStyle != pattern)
                        {
                            floorsCovered++;
                            wall.TopLeftStyle = pattern;
                        }

                    walls[item.X + item.Y * width] = wall;
                    continue; //don't spread on diagonals for now
                }
                else
                {
                    //normal tile, draw a floor here.
                    if (floor.Pattern != pattern)
                    {
                        floor.Pattern = pattern;
                        if (target.SetFloor((short)item.X, (short)item.Y, level, floor, false)) floorsCovered++;
                    }

                }

                if (Map[plusX + item.Y * width] < 3 && (mainWalls.Segments & WallSegments.BottomRight) == 0)
                    SpreadOnto(walls, plusX, item.Y, 0, Map, width, height, spread, pattern, true);

                if (Map[minX + item.Y * width] < 3 && (mainWalls.Segments & WallSegments.TopLeft) == 0)
                    SpreadOnto(walls, minX, item.Y, 2, Map, width, height, spread, pattern, true);

                if (Map[item.X + plusY * width] < 3 && (mainWalls.Segments & WallSegments.BottomLeft) == 0)
                    SpreadOnto(walls, item.X, plusY, 1, Map, width, height, spread, pattern, true);

                if (Map[item.X + minY * width] < 3 && (mainWalls.Segments & WallSegments.TopRight) == 0)
                    SpreadOnto(walls, item.X, minY, 3, Map, width, height, spread, pattern, true);

                walls[item.X + item.Y * width] = mainWalls;
            }
            return floorsCovered;
        }