Exemplo n.º 1
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.
            }
        }
Exemplo n.º 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="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);
        }