private static MapCellState DeserializeMapCellState(BinaryReader Reader, MapCell cell, MapPoint point)
        {
            if (cell == null)
            {
                return(null);
            }
            MapCellState state = new MapCellState(cell, point);

            state.Place = DeserializeMapPlaceState(Reader, cell.Place);

            MapWall northWall = cell.GetWall(MapDirection.North);
            MapWall southWall = cell.GetWall(MapDirection.South);
            MapWall westWall  = cell.GetWall(MapDirection.West);
            MapWall eastWall  = cell.GetWall(MapDirection.East);

            if (northWall != null)
            {
                state.SetWall(MapDirection.North, DeserializeMapWallState(Reader, northWall, MapDirection.North));
            }
            if (southWall != null)
            {
                state.SetWall(MapDirection.South, DeserializeMapWallState(Reader, southWall, MapDirection.South));
            }
            if (westWall != null)
            {
                state.SetWall(MapDirection.North, DeserializeMapWallState(Reader, westWall, MapDirection.West));
            }
            if (eastWall != null)
            {
                state.SetWall(MapDirection.North, DeserializeMapWallState(Reader, eastWall, MapDirection.East));
            }

            return(state);
        }
        private List <FrameworkElement> RenderCell(MapCellState cell, Rect cellArea)
        {
            List <FrameworkElement> result = new List <FrameworkElement>();

            if (cell == null)
            {
                return(result);
            }

            result.Add(RenderPlace(cell.Place, cellArea));
            result.Add(RenderWall(cell.GetWall(MapDirection.South), cellArea));
            result.Add(RenderWall(cell.GetWall(MapDirection.West), cellArea));
            result.Add(RenderWall(cell.GetWall(MapDirection.North), cellArea));
            result.Add(RenderWall(cell.GetWall(MapDirection.East), cellArea));
            result.Add(RenderWallCorner(cell.GetWall(MapDirection.North), cell.GetWall(MapDirection.West), cellArea));
            result.Add(RenderWallCorner(cell.GetWall(MapDirection.North), cell.GetWall(MapDirection.East), cellArea));
            result.Add(RenderWallCorner(cell.GetWall(MapDirection.South), cell.GetWall(MapDirection.West), cellArea));
            result.Add(RenderWallCorner(cell.GetWall(MapDirection.South), cell.GetWall(MapDirection.East), cellArea));

            while (result.Remove(null))
            {
                ;
            }

            return(result);
        }
示例#3
0
        private static void SerializeMapCellState(BinaryWriter Writer, MapCellState CellState)
        {
            if (CellState == null)
            {
                return;
            }

            MapWallState northWall = CellState.GetWall(MapDirection.North);
            MapWallState southWall = CellState.GetWall(MapDirection.South);
            MapWallState westWall  = CellState.GetWall(MapDirection.West);
            MapWallState eastWall  = CellState.GetWall(MapDirection.East);

            SerializeMapPlaceState(Writer, CellState.Place);

            if (northWall != null)
            {
                SerializeMapWallState(Writer, northWall);
            }
            if (southWall != null)
            {
                SerializeMapWallState(Writer, southWall);
            }
            if (westWall != null)
            {
                SerializeMapWallState(Writer, westWall);
            }
            if (eastWall != null)
            {
                SerializeMapWallState(Writer, eastWall);
            }
        }
        /// <summary>
        /// Обработка волны в конкретной клетке
        /// </summary>
        /// <param name="Point">Клетка</param>
        /// <param name="WaveValue">Значение волны</param>
        private void Wave(MapPoint Point, UInt16 WaveValue)
        {
            if (endflag)
            {
                return;
            }

            if (Waves[Point.X - Area.Area.Position.X,
                      Point.Y - Area.Area.Position.Y] != UInt16.MaxValue)
            {
                return;
            }

            if (Point.Equals(To.Point))
            {
                endflag = true;
                return;
            }

            Waves[Point.X - Area.Area.Position.X, Point.Y - Area.Area.Position.Y] = WaveValue;

            MapCellState left  = GetMapCell(Point, -1, 0);
            MapCellState right = GetMapCell(Point, +1, 0);
            MapCellState up    = GetMapCell(Point, 0, -1);
            MapCellState down  = GetMapCell(Point, 0, +1);

            if ((left != null) && Area.CheckCellInArea(left) && (left.Place.Passability > 0))
            {
                Wave(left.Point, WaveValue++);
            }

            if ((right != null) && Area.CheckCellInArea(right) && (right.Place.Passability > 0))
            {
                Wave(right.Point, WaveValue++);
            }

            if ((up != null) && Area.CheckCellInArea(up) && (up.Place.Passability > 0))
            {
                Wave(up.Point, WaveValue++);
            }

            if ((down != null) && Area.CheckCellInArea(down) && (down.Place.Passability > 0))
            {
                Wave(down.Point, WaveValue++);
            }
        }
        public void Render()
        {
            if (Canvas == null)
            {
                return;
            }
            Canvas.Children.Clear();

            if (TargetMap == null)
            {
                return;
            }

            MapState map = TargetMap.Map;

            if (map == null)
            {
                return;
            }

            double width       = Canvas.ActualWidth;
            double height      = Canvas.ActualHeight;
            ushort beginLevel  = Math.Min(TargetRange.Begin.Level, TargetRange.End.Level);
            ushort endLevel    = Math.Max(TargetRange.Begin.Level, TargetRange.End.Level);
            ushort beginX      = Math.Min(TargetRange.Begin.X, TargetRange.End.X);
            ushort endX        = Math.Max(TargetRange.Begin.X, TargetRange.End.X);
            ushort beginY      = Math.Min(TargetRange.Begin.Y, TargetRange.End.Y);
            ushort endY        = Math.Max(TargetRange.Begin.Y, TargetRange.End.Y);
            ushort cellsCountX = (ushort)(endX - beginX + 1);
            ushort cellsCountY = (ushort)(endY - beginY + 1);
            double cellWidth   = width / cellsCountX;
            double cellHeight  = height / cellsCountY;

            cellWidth = cellHeight = Math.Floor(Math.Min(cellWidth, cellHeight));
            Size cellSize = new Size(cellWidth, cellHeight);

            for (ushort level = beginLevel; level <= endLevel; level++)
            {
                for (ushort x = beginX; x <= endX; x++)
                {
                    for (ushort y = beginY; y <= endY; y++)
                    {
                        MapCellState cell = map[level, x, y];

                        Point cellLocation = new Point((x - beginX) * cellWidth, (y - beginY) * cellHeight);
                        Rect  cellArea     = new Rect(cellLocation, cellSize);
                        //cellArea.Width += 1;
                        //cellArea.Height += 1;

                        List <FrameworkElement> cellRender = null;

                        if (cell != null)
                        {
                            cellRender = RenderCell(cell, cellArea);
                        }
                        else
                        {
                            cellRender = RenderNullCell(cellArea);
                        }

                        if (cellRender == null)
                        {
                            continue;
                        }

                        foreach (FrameworkElement cellRenderItem in cellRender)
                        {
                            if (cellRenderItem == null)
                            {
                                continue;
                            }
                            Canvas.Children.Add(cellRenderItem);
                        }
                    }
                }
            }

            if (IsGridLinesVisible)
            {
                for (ushort x = beginX; x <= endX + 1; x++)
                {
                    FrameworkElement gridLine = RenderVerticalGridLine(new Point((x - beginX) * cellWidth, 0), new Point((x - beginX) * cellWidth, cellHeight * cellsCountY));
                    if (gridLine != null)
                    {
                        Canvas.Children.Add(gridLine);
                    }
                }

                for (ushort y = beginY; y <= endY + 1; y++)
                {
                    FrameworkElement gridLine = RenderHorizontalGridLine(new Point(0, (y - beginX) * cellHeight), new Point(cellWidth * cellsCountX, (y - beginX) * cellHeight));
                    if (gridLine != null)
                    {
                        Canvas.Children.Add(gridLine);
                    }
                }
            }

            //foreach (MapActiveObjectState activeObject in map.ActiveObjectList)
            //{
            //    if (activeObject == null) continue;
            //    FrameworkElement renderObject = RenderActiveObject(activeObject, area);
            //    if (renderObject == null) continue;
            //    Canvas.Children.Add(renderObject);
            //}
        }
        private static MapCellState DeserializeMapCellState(BinaryReader Reader, MapCell cell, MapPoint point)
        {
            if (cell == null) return null;
            MapCellState state = new MapCellState(cell, point);

            state.Place = DeserializeMapPlaceState(Reader, cell.Place);

            MapWall northWall = cell.GetWall(MapDirection.North);
            MapWall southWall = cell.GetWall(MapDirection.South);
            MapWall westWall = cell.GetWall(MapDirection.West);
            MapWall eastWall = cell.GetWall(MapDirection.East);

            if (northWall != null)
                state.SetWall(MapDirection.North, DeserializeMapWallState(Reader, northWall, MapDirection.North));
            if (southWall != null)
                state.SetWall(MapDirection.South, DeserializeMapWallState(Reader, southWall, MapDirection.South));
            if (westWall != null)
                state.SetWall(MapDirection.North, DeserializeMapWallState(Reader, westWall, MapDirection.West));
            if (eastWall != null)
                state.SetWall(MapDirection.North, DeserializeMapWallState(Reader, eastWall, MapDirection.East));

            return state;
        }
示例#7
0
    private void SetMapCellState(MapCoordinates pos, MapCellState newState)
    {
        var cell = GetMapCellData(pos);

        cell.state = newState;
    }
        private static void SerializeMapCellState(BinaryWriter Writer, MapCellState CellState)
        {
            if (CellState == null) return;

            MapWallState northWall = CellState.GetWall(MapDirection.North);
            MapWallState southWall = CellState.GetWall(MapDirection.South);
            MapWallState westWall = CellState.GetWall(MapDirection.West);
            MapWallState eastWall = CellState.GetWall(MapDirection.East);

            SerializeMapPlaceState(Writer, CellState.Place);

            if (northWall != null) SerializeMapWallState(Writer, northWall);
            if (southWall != null) SerializeMapWallState(Writer, southWall);
            if (westWall != null) SerializeMapWallState(Writer, westWall);
            if (eastWall != null) SerializeMapWallState(Writer, eastWall);
        }