コード例 #1
0
ファイル: MapAreas.cs プロジェクト: PsychoTeras/RatKing
        internal MapArea(List <TraceCell> closedTrace, TileType areaType, ServerMap map)
            : base(closedTrace.Count)
        {
            TraceCell     prevTraceCell = null;
            HashSet <int> unique        = new HashSet <int>();

            foreach (TraceCell traceCell in closedTrace)
            {
                ParseArea(traceCell, prevTraceCell, areaType, map, unique);
                prevTraceCell = traceCell;
            }
            CalculateCellsCount();
        }
コード例 #2
0
ファイル: MapAreas.cs プロジェクト: PsychoTeras/RatKing
        private void ParseArea(TraceCell traceCell, TraceCell prevTraceCell, TileType areaType,
                               ServerMap map, HashSet <int> unique)
        {
            bool       invalid;
            ShortPoint borderPoint;

            if (prevTraceCell != null && prevTraceCell.Direction == Direction.S && traceCell.Direction == Direction.W)
            {
                borderPoint = GetBorders(traceCell.X, traceCell.Y, Direction.S, areaType, map, out invalid);
                AcceptBorders(borderPoint, invalid, map, unique);
            }
            borderPoint = GetBorders(traceCell.X, traceCell.Y, traceCell.Direction, areaType, map, out invalid);
            AcceptBorders(borderPoint, invalid, map, unique);
        }
コード例 #3
0
ファイル: MapAreas.cs プロジェクト: PsychoTeras/RatKing
        private void Detect(ushort startX, ushort startY, HashSet <int> visitedTiles)
        {
            int initialValue = TraceCell.DirectionValue(startX, startY, _areaType, _map);

            if (initialValue == 0 || initialValue == 15)
            {
                return;
            }

            List <TraceCell> closedTrace = new List <TraceCell>();

            TraceCell prevCell = null;
            int       x = startX, y = startY;

            do
            {
                TraceCell cell           = null;
                int       directionValue = TraceCell.DirectionValue(x, y, _areaType, _map);
                switch (directionValue)
                {
                case 1:
                    cell = new TraceCell(x, y, Direction.N);
                    break;

                case 2:
                    cell = new TraceCell(x, y, Direction.E);
                    break;

                case 3:
                    cell = new TraceCell(x, y, Direction.E);
                    break;

                case 4:
                    cell = new TraceCell(x, y, Direction.W);
                    break;

                case 5:
                    cell = new TraceCell(x, y, Direction.N);
                    break;

                case 6:
                    cell = prevCell != null && prevCell.Direction == Direction.N
                            ? new TraceCell(x, y, Direction.W)
                            : new TraceCell(x, y, Direction.E);
                    break;

                case 7:
                    cell = new TraceCell(x, y, Direction.E);
                    break;

                case 8:
                    cell = new TraceCell(x, y, Direction.S);
                    break;

                case 9:
                    cell = prevCell != null && prevCell.Direction == Direction.E
                            ? new TraceCell(x, y, Direction.N)
                            : new TraceCell(x, y, Direction.S);
                    break;

                case 10:
                    cell = new TraceCell(x, y, Direction.S);
                    break;

                case 11:
                    cell = new TraceCell(x, y, Direction.S);
                    break;

                case 12:
                    cell = new TraceCell(x, y, Direction.W);
                    break;

                case 13:
                    cell = new TraceCell(x, y, Direction.N);
                    break;

                case 14:
                    cell = new TraceCell(x, y, Direction.W);
                    break;
                }

                if (cell != null)
                {
                    closedTrace.Add(cell);
                    visitedTiles.Add(y << 16 | x);

                    x += cell.ScreenX;
                    y += cell.ScreenY;

                    prevCell = cell;
                }
            } while (x != startX || y != startY);

            Add(new MapArea(closedTrace, _areaType, _map));
        }