Exemplo n.º 1
0
        public static bool VerifyEraseWall(VMArchitecture target, Point pos, int length, int direction, sbyte level)
        {
            pos += WLStartOff[direction];
            bool diagCheck = (direction % 2 == 1);

            for (int i = 0; i < length; i++)
            {
                if (pos.X <= 0 || pos.X >= target.Width || pos.Y <= 0 || pos.Y >= target.Height)
                {
                    return(false);
                }
                var wall = target.GetWall((short)pos.X, (short)pos.Y, level);
                wall.Segments &= ~WLMainSeg[direction];
                if (!target.Context.CheckWallValid(LotTilePos.FromBigTile((short)pos.X, (short)pos.Y, level), wall))
                {
                    return(false);
                }

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

                    if (!target.Context.CheckWallValid(LotTilePos.FromBigTile((short)tPos.X, (short)tPos.Y, level), wall))
                    {
                        return(false);
                    }
                }
                pos += WLStep[direction];
            }
            return(true);
        }
Exemplo n.º 2
0
        public static bool VerifyDrawWall(VMArchitecture target, Point pos, int length, int direction, sbyte level)
        {
            pos += WLStartOff[direction];
            bool diagCheck = (direction % 2 == 1);

            for (int i = 0; i < length; i++)
            {
                if (target.OutsideClip((short)pos.X, (short)pos.Y, level))
                {
                    return(false);
                }
                var wall = target.GetWall((short)pos.X, (short)pos.Y, level);
                if ((wall.Segments & AnyDiag) == 0 && (!diagCheck || (wall.Segments == 0)))
                {
                    wall.Segments |= WLMainSeg[direction];
                    if (!target.Context.CheckWallValid(LotTilePos.FromBigTile((short)pos.X, (short)pos.Y, level), wall))
                    {
                        return(false);
                    }
                    if (!diagCheck)
                    {
                        var tPos = pos + WLSubOff[direction / 2]; //get the other side of the wall
                        if (target.OutsideClip((short)tPos.X, (short)tPos.Y, level))
                        {
                            return(false);                                                         //both sides of wall must be in bounds
                        }
                        wall = target.GetWall((short)tPos.X, (short)tPos.Y, level);
                        if (!(level == 1 || target.Supported[level - 2][pos.Y * target.Width + pos.X] || target.Supported[level - 2][tPos.Y * target.Width + tPos.X]))
                        {
                            return(false);
                        }
                        if ((wall.Segments & AnyDiag) == 0)
                        {
                            wall.Segments |= WLSubSeg[direction / 2];
                            if (!target.Context.CheckWallValid(LotTilePos.FromBigTile((short)tPos.X, (short)tPos.Y, level), wall))
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (!(level == 1 || target.Supported[level - 2][pos.Y * target.Width + pos.X]))
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    return(false);
                }
                pos += WLStep[direction];
            }
            return(true);
        }
Exemplo n.º 3
0
        public static int EraseWall(VMArchitecture target, Point pos, int length, int direction, ushort pattern, ushort style, sbyte level)
        {
            if (!VerifyEraseWall(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]) > 0)
                {
                    totalWalls++;
                }
                wall.Segments &= ~WLMainSeg[direction];
                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];

                    target.SetWall((short)tPos.X, (short)tPos.Y, level, wall);
                }
                pos += WLStep[direction];
            }
            return(totalWalls);
        }
Exemplo n.º 4
0
        public static int GetPatternDirection(VMArchitecture target, Point pos, ushort pattern, int direction, int altDir, sbyte level)
        {
            if (pos.X < 0 || pos.X >= target.Width || pos.Y < 0 || pos.Y >= target.Height)
            {
                return(-1);
            }

            var wall = target.GetWall((short)pos.X, (short)pos.Y, level);

            if ((wall.Segments & WallSegments.HorizontalDiag) > 0)
            {
                return(direction);
            }
            else if ((wall.Segments & WallSegments.VerticalDiag) > 0)
            {
                return(direction);
            }

            if ((wall.Segments & (WallSegments)(1 << direction)) > 0)
            {
            }
            else if ((wall.Segments & (WallSegments)(1 << altDir)) > 0)
            {
                direction = altDir;
            }
            else
            {
                return(-1);
            }

            return(direction);
        }
Exemplo n.º 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)
                    {
                        wall.TopRightStyle      = style;
                        wall.BottomLeftPattern  = pattern;
                        wall.BottomRightPattern = pattern;
                    }
                    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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public static PatternReplaceCount WallPatternDot(VMArchitecture target, Point pos, ushort pattern, int direction, int altDir, sbyte level)
        {
            if (pos.X < 0 || pos.X >= target.Width || pos.Y < 0 || pos.Y > target.Height)
            {
                return new PatternReplaceCount {
                           Total = -1
                }
            }
            ;

            //pattern replace count used a little differently here. cost still stores replaced cost, but total stores replaced direction.
            PatternReplaceCount replaceCost = new PatternReplaceCount(false);
            ushort replaced = 0;
            var    wall     = target.GetWall((short)pos.X, (short)pos.Y, level);

            //direction starts lefttop, righttop
            if ((wall.Segments & WallSegments.HorizontalDiag) > 0 && wall.TopRightStyle == 1)
            {
                if (direction < 2)
                {
                    //bottom (bottom right pattern)
                    replaced = wall.BottomRightPattern;
                    wall.BottomRightPattern = pattern;
                }
                else
                {
                    //top (bottom left pattern)
                    replaced = wall.BottomLeftPattern;
                    wall.BottomLeftPattern = pattern;
                }
                target.SetWall((short)pos.X, (short)pos.Y, level, wall);

                if (replaced == pattern)
                {
                    return new PatternReplaceCount {
                               Total = -1
                    }
                }
                ;
                replaceCost.Add(replaced);
                replaceCost.Total = direction;
                return(replaceCost);
            }
            else if ((wall.Segments & WallSegments.VerticalDiag) > 0 && wall.TopRightStyle == 1)
            {
                if (direction > 0 && direction < 3)
                {
                    //left
                    replaced = wall.BottomLeftPattern;

                    wall.BottomLeftPattern = pattern;
                }
                else
                {
                    //right
                    replaced = wall.BottomRightPattern;
                    wall.BottomRightPattern = pattern;
                }
                target.SetWall((short)pos.X, (short)pos.Y, level, wall);
                if (replaced == pattern)
                {
                    return new PatternReplaceCount {
                               Total = -1
                    }
                }
                ;
                replaceCost.Add(replaced);
                replaceCost.Total = direction;
                return(replaceCost);
            }

            if ((wall.Segments & (WallSegments)(1 << direction)) > 0)
            {
            }
            else if ((wall.Segments & (WallSegments)(1 << altDir)) > 0)
            {
                direction = altDir;
            }
            else
            {
                return(new PatternReplaceCount {
                    Total = -1
                });
            }

            if (direction == 0 && wall.TopLeftThick)
            {
                replaced = wall.TopLeftPattern; wall.TopLeftPattern = pattern;
            }
            else if (direction == 1 && wall.TopRightThick)
            {
                replaced = wall.TopRightPattern; wall.TopRightPattern = pattern;
            }
            else if (direction == 2 && pos.X < target.Width && target.GetWall((short)(pos.X + 1), (short)pos.Y, level).TopLeftThick)
            {
                replaced = wall.BottomRightPattern; wall.BottomRightPattern = pattern;
            }
            else if (direction == 3 && pos.Y < target.Height && target.GetWall((short)pos.X, (short)(pos.Y + 1), level).TopRightThick)
            {
                replaced = wall.BottomLeftPattern; wall.BottomLeftPattern = pattern;
            }
            target.SetWall((short)pos.X, (short)pos.Y, level, wall);

            if (replaced == pattern)
            {
                return new PatternReplaceCount {
                           Total = -1
                }
            }
            ;
            replaceCost.Add(replaced);
            replaceCost.Total = direction;
            return(replaceCost);
        }
Exemplo n.º 8
0
        public static int WallPatternDot(VMArchitecture target, Point pos, ushort pattern, int direction, int altDir, sbyte level)
        {
            if (pos.X < 0 || pos.X >= target.Width || pos.Y < 0 || pos.Y > target.Height)
            {
                return(-1);
            }

            var wall = target.GetWall((short)pos.X, (short)pos.Y, level);

            //direction starts lefttop, righttop
            if ((wall.Segments & WallSegments.HorizontalDiag) > 0)
            {
                if (direction < 2)
                {
                    //bottom (bottom right pattern)
                    wall.BottomRightPattern = pattern;
                }
                else
                {
                    //top (bottom left pattern)
                    wall.BottomLeftPattern = pattern;
                }
                target.SetWall((short)pos.X, (short)pos.Y, level, wall);
                return(direction);
            }
            else if ((wall.Segments & WallSegments.VerticalDiag) > 0)
            {
                if (direction > 0 && direction < 3)
                {
                    //left
                    wall.BottomLeftPattern = pattern;
                }
                else
                {
                    //right
                    wall.BottomRightPattern = pattern;
                }
                target.SetWall((short)pos.X, (short)pos.Y, level, wall);
                return(direction);
            }

            if ((wall.Segments & (WallSegments)(1 << direction)) > 0)
            {
            }
            else if ((wall.Segments & (WallSegments)(1 << altDir)) > 0)
            {
                direction = altDir;
            }
            else
            {
                return(-1);
            }

            if (direction == 0)
            {
                wall.TopLeftPattern = pattern;
            }
            else if (direction == 1)
            {
                wall.TopRightPattern = pattern;
            }
            else if (direction == 2)
            {
                wall.BottomRightPattern = pattern;
            }
            else if (direction == 3)
            {
                wall.BottomLeftPattern = pattern;
            }
            target.SetWall((short)pos.X, (short)pos.Y, level, wall);
            return(direction);
        }
        //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)
                    {
                        wall.TopRightStyle = style;
                        wall.BottomLeftPattern = pattern;
                        wall.BottomRightPattern = pattern;
                    }
                    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;
        }
        public static bool VerifyEraseWall(VMArchitecture target, Point pos, int length, int direction, sbyte level)
        {
            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);
                wall.Segments &= ~WLMainSeg[direction];
                if (!target.Context.CheckWallValid(LotTilePos.FromBigTile((short)pos.X, (short)pos.Y, level), wall)) return false;

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

                    if (!target.Context.CheckWallValid(LotTilePos.FromBigTile((short)tPos.X, (short)tPos.Y, level), wall)) return false;
                    pos += WLStep[direction];
                }
            }
            return true;
        }
        public static int WallPatternDot(VMArchitecture target, Point pos, ushort pattern, int direction, int altDir, sbyte level)
        {
            if (pos.X < 0 || pos.X >= target.Width || pos.Y < 0 || pos.Y > target.Height) return -1;

            var wall = target.GetWall((short)pos.X, (short)pos.Y, level);
            //direction starts lefttop, righttop
            if ((wall.Segments & WallSegments.HorizontalDiag) > 0)
            {
                if (direction < 2)
                {
                    //bottom (bottom right pattern)
                    wall.BottomRightPattern = pattern;
                }
                else
                {
                    //top (bottom left pattern)
                    wall.BottomLeftPattern = pattern;
                }
                target.SetWall((short)pos.X, (short)pos.Y, level, wall);
                return direction;
            }
            else if ((wall.Segments & WallSegments.VerticalDiag) > 0)
            {
                if (direction > 0 && direction < 3)
                {
                    //left
                    wall.BottomLeftPattern = pattern;
                }
                else
                {
                    //right
                    wall.BottomRightPattern = pattern;
                }
                target.SetWall((short)pos.X, (short)pos.Y, level, wall);
                return direction;
            }

            if ((wall.Segments & (WallSegments)(1 << direction)) > 0) { }
            else if ((wall.Segments & (WallSegments)(1 << altDir)) > 0) direction = altDir;
            else
            {
                return -1;
            }

            if (direction == 0) wall.TopLeftPattern = pattern;
            else if (direction == 1) wall.TopRightPattern = pattern;
            else if (direction == 2) wall.BottomRightPattern = pattern;
            else if (direction == 3) wall.BottomLeftPattern = pattern;
            target.SetWall((short)pos.X, (short)pos.Y, level, wall);
            return direction;
        }
 public static bool VerifyDrawWall(VMArchitecture target, Point pos, int length, int direction, sbyte level)
 {
     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 & AnyDiag) == 0 && (!diagCheck || (wall.Segments == 0)))
         {
             wall.Segments &= ~WLMainSeg[direction];
             if (!target.Context.CheckWallValid(LotTilePos.FromBigTile((short)pos.X, (short)pos.Y, level), wall)) return false;
             if (!diagCheck)
             {
                 var tPos = pos + WLSubOff[direction / 2];
                 wall = target.GetWall((short)tPos.X, (short)tPos.Y, level);
                 if (!(level == 1 || target.Supported[level - 2][pos.Y * target.Width + pos.X] || target.Supported[level - 2][tPos.Y * target.Width + tPos.X])) return false;
                 if ((wall.Segments & AnyDiag) == 0)
                 {
                     wall.Segments |= WLSubSeg[direction / 2];
                     if (!target.Context.CheckWallValid(LotTilePos.FromBigTile((short)tPos.X, (short)tPos.Y, level), wall)) return false;
                 }
                 else return false;
             } else
             {
                 if (!(level == 1 || target.Supported[level - 2][pos.Y * target.Width + pos.X])) return false;
             }
         }
         else return false;
         pos += WLStep[direction];
     }
     return true;
 }
        public static int GetPatternDirection(VMArchitecture target, Point pos, ushort pattern, int direction, int altDir, sbyte level)
        {
            if (pos.X < 0 || pos.X >= target.Width || pos.Y < 0 || pos.Y >= target.Height) return -1;

            var wall = target.GetWall((short)pos.X, (short)pos.Y, level);
            if ((wall.Segments & WallSegments.HorizontalDiag) > 0)
            {
                return direction;
            }
            else if ((wall.Segments & WallSegments.VerticalDiag) > 0)
            {
                return direction;
            }

            if ((wall.Segments & (WallSegments)(1 << direction)) > 0) { }
            else if ((wall.Segments & (WallSegments)(1 << altDir)) > 0) direction = altDir;
            else
            {
                return -1;
            }

            return direction;
        }
        //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;
        }
        public static int EraseWall(VMArchitecture target, Point pos, int length, int direction, ushort pattern, ushort style, sbyte level)
        {
            if (!VerifyEraseWall(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]) > 0) totalWalls++;
                wall.Segments &= ~WLMainSeg[direction];
                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];

                    target.SetWall((short)tPos.X, (short)tPos.Y, level, wall);
                    pos += WLStep[direction];
                }
            }
            return totalWalls;
        }
Exemplo n.º 16
0
        public static PatternReplaceCount WallPatternDot(VMArchitecture target, Point pos, ushort pattern, int direction, int altDir, sbyte level)
        {
            if (pos.X < 0 || pos.X >= target.Width || pos.Y < 0 || pos.Y > target.Height) return new PatternReplaceCount { Total = -1 };

            //pattern replace count used a little differently here. cost still stores replaced cost, but total stores replaced direction.
            PatternReplaceCount replaceCost = new PatternReplaceCount(false);
            ushort replaced = 0;
            var wall = target.GetWall((short)pos.X, (short)pos.Y, level);
            //direction starts lefttop, righttop
            if ((wall.Segments & WallSegments.HorizontalDiag) > 0 && wall.TopRightStyle == 1)
            {
                if (direction < 2)
                {
                    //bottom (bottom right pattern)
                    replaced = wall.BottomRightPattern;
                    wall.BottomRightPattern = pattern;
                }
                else
                {
                    //top (bottom left pattern)
                    replaced = wall.BottomLeftPattern;
                    wall.BottomLeftPattern = pattern;
                }
                target.SetWall((short)pos.X, (short)pos.Y, level, wall);
                if (replaced == pattern) return new PatternReplaceCount { Total = -1 };
                replaceCost.Add(replaced);
                replaceCost.Total = direction;
                return replaceCost;
            }
            else if ((wall.Segments & WallSegments.VerticalDiag) > 0 && wall.TopRightStyle == 1)
            {
                if (direction > 0 && direction < 3)
                {
                    //left
                    replaced = wall.BottomLeftPattern;
                    wall.BottomLeftPattern = pattern;
                }
                else
                {
                    //right
                    replaced = wall.BottomRightPattern;
                    wall.BottomRightPattern = pattern;
                }
                target.SetWall((short)pos.X, (short)pos.Y, level, wall);
                if (replaced == pattern) return new PatternReplaceCount { Total = -1 };
                replaceCost.Add(replaced);
                replaceCost.Total = direction;
                return replaceCost;
            }

            if ((wall.Segments & (WallSegments)(1 << direction)) > 0) { }
            else if ((wall.Segments & (WallSegments)(1 << altDir)) > 0) direction = altDir;
            else
            {
                return new PatternReplaceCount { Total = -1 };
            }

            if (direction == 0 && wall.TopLeftThick) { replaced = wall.TopLeftPattern; wall.TopLeftPattern = pattern; }
            else if (direction == 1 && wall.TopRightThick) { replaced = wall.TopRightPattern; wall.TopRightPattern = pattern; }
            else if (direction == 2 && pos.X < target.Width && target.GetWall((short)(pos.X + 1), (short)pos.Y, level).TopLeftThick) { replaced = wall.BottomRightPattern; wall.BottomRightPattern = pattern; }
            else if (direction == 3 && pos.Y < target.Height && target.GetWall((short)pos.X, (short)(pos.Y + 1), level).TopRightThick) { replaced = wall.BottomLeftPattern; wall.BottomLeftPattern = pattern; }
            target.SetWall((short)pos.X, (short)pos.Y, level, wall);

            if (replaced == pattern) return new PatternReplaceCount { Total = -1 };
            replaceCost.Add(replaced);
            replaceCost.Total = direction;
            return replaceCost;
        }