Example #1
0
        public override void ResizeTo(
            int newR,
            int newC,
            int newH,
            bool wrtCeiling)
        {
            var mapResizeService = new MapResizeService();

            var newMap = mapResizeService.ResizeMap(
                newR,
                newC,
                newH,
                MapSize,
                MapData,
                wrtCeiling);

            if (newMap != null)
            {
                // update Routes
                if (wrtCeiling && newH != MapSize.Height)
                {
                    var d = newH - MapSize.Height;
                    foreach (RmpEntry rmp in Rmp)
                    {
                        if (newH < MapSize.Height)
                        {
                            rmp.Height = (byte)(rmp.Height + d);
                        }
                        else
                        {
                            rmp.Height += (byte)d;
                        }
                    }
                }

                // delete route-nodes outside the new bounds
                if (newC < MapSize.Cols ||
                    newR < MapSize.Rows ||
                    newH < MapSize.Height)
                {
                    Rmp.CheckRouteEntries(newC, newR, newH);
                }

                MapData       = newMap;
                MapSize       = new MapSize(newR, newC, newH);
                CurrentHeight = (byte)(MapSize.Height - 1);
                MapChanged    = true;
            }
        }
Example #2
0
        /// <summary>
        /// Resizes the current Map.
        /// </summary>
        /// <param name="rows">total rows in the new Map</param>
        /// <param name="cols">total columns in the new Map</param>
        /// <param name="levs">total levels in the new Map</param>
        /// <param name="ceiling">true to add extra levels above the top level,
        /// false to add extra levels below the ground level - but only if a
        /// height difference is found for either case</param>
        public override void MapResize(
            int rows,
            int cols,
            int levs,
            bool ceiling)
        {
            var tileList = MapResizeService.ResizeMapDimensions(
                rows, cols, levs,
                MapSize,
                MapTiles,
                ceiling);

            if (tileList != null)
            {
                MapChanged = true;

                if (levs != MapSize.Levs && ceiling)                 // adjust route-nodes ->
                {
                    int delta = levs - MapSize.Levs;                 // NOTE: map levels are reversed
                    foreach (RouteNode node in Routes)               // so adding levels to the ceiling needs to push the existing nodes down.
                    {
                        node.Lev += delta;
                    }
                }

                if (cols < MapSize.Cols ||                 // check for and ask if user wants to delete any route-nodes outside the new bounds
                    rows < MapSize.Rows ||
                    levs < MapSize.Levs)
                {
                    RouteCheckService.CheckNodeBounds(this);
                }

                MapTiles = tileList;
                MapSize  = new MapSize(rows, cols, levs);

                Level = 0;                 // fires a LevelChangedEvent.
            }
        }
Example #3
0
        public virtual void ResizeTo(
            int newR,
            int newC,
            int newH,
            bool wrtCeiling)
        {
            var mapResizeService = new MapResizeService();
            var newMap           = mapResizeService.ResizeMap(
                newR,
                newC,
                newH,
                MapSize,
                MapData,
                wrtCeiling);

            if (newMap != null)
            {
                MapData        = newMap;
                MapSize        = new MapSize(newR, newC, newH);
                _currentHeight = (byte)(MapSize.Height - 1);
                MapChanged     = true;
            }
        }
        /// <summary>
        /// Resizes the current Map.
        /// </summary>
        /// <param name="rows">total rows in the new Map</param>
        /// <param name="cols">total columns in the new Map</param>
        /// <param name="levs">total levels in the new Map</param>
        /// <param name="zType">MRZT_TOP to add or subtract delta-levels
        /// starting at the top level, MRZT_BOT to add or subtract delta-levels
        /// starting at the ground level - but only if a height difference is
        /// found for either case</param>
        /// <returns>a bitwise int of changes
        ///          0x0 - no changes
        ///          0x1 - Map changed
        ///          0x2 - Routes changed</returns>
        public override int MapResize(
            int rows,
            int cols,
            int levs,
            MapResizeService.MapResizeZtype zType)
        {
            int bit = 0x0;

            var tileList = MapResizeService.GetResizedTileList(
                rows, cols, levs,
                MapSize,
                MapTiles,
                zType);

            if (tileList != null)
            {
                bit |= 0x1;

                int
                    preRows = MapSize.Rows,
                    preCols = MapSize.Cols,
                    preLevs = MapSize.Levs;

                if (zType == MapResizeService.MapResizeZtype.MRZT_TOP &&              // adjust route-nodes ->
                    Routes.Any())
                {
                    bit |= 0x2;

                    int delta = (levs - preLevs);                       // NOTE: map levels are inverted so adding or subtracting levels
                    // to the top needs to push any existing node-levels down or up.
                    foreach (RouteNode node in Routes)
                    {
                        if (node.Lev < 128)                         // allow nodes that are OoB to come back into view
                        {
                            if ((node.Lev += delta) < 0)            // NOTE: node x/y/z are stored as bytes.
                            {
                                node.Lev += 256;                    // -> ie. level -1 = level 255
                            }
                        }
                        else
                        {
                            if ((node.Lev += delta - 256) < 0)                                  // nodes above the highest Maplevel maintain
                            {
                                node.Lev += 256;                                                // their relative z-level
                            }
                        }
                    }
                }

                MapSize  = new MapSize(rows, cols, levs);
                MapTiles = tileList;

                if (RouteCheckService.CheckNodeBounds(this))
                {
                    bit |= 0x2;
                }

                ClearRouteNodes();
                SetupRouteNodes();

                Level = 0;                 // fires a LevelChangedEvent.
            }
            return(bit);
        }