Ejemplo n.º 1
0
        public short[] GetCells(short centerCell, MapRecord map)
        {
            MapPoint     mapPoint = new MapPoint(centerCell);
            List <short> list     = new List <short>();

            for (int i = this.MinRadius; i <= (int)this.Radius; i++)
            {
                switch (this.Direction)
                {
                case DirectionsEnum.DIRECTION_EAST:
                    MapPoint.AddCellIfValid(mapPoint.X + i, mapPoint.Y + i, map, list);

                    break;

                case DirectionsEnum.DIRECTION_SOUTH_EAST:
                    MapPoint.AddCellIfValid(mapPoint.X + i, mapPoint.Y, map, list);

                    break;

                case DirectionsEnum.DIRECTION_SOUTH:
                    MapPoint.AddCellIfValid(mapPoint.X + i, mapPoint.Y - i, map, list);

                    break;

                case DirectionsEnum.DIRECTION_SOUTH_WEST:
                    MapPoint.AddCellIfValid(mapPoint.X, mapPoint.Y - i, map, list);

                    break;

                case DirectionsEnum.DIRECTION_WEST:
                    MapPoint.AddCellIfValid(mapPoint.X - i, mapPoint.Y - i, map, list);

                    break;

                case DirectionsEnum.DIRECTION_NORTH_WEST:
                    MapPoint.AddCellIfValid(mapPoint.X - i, mapPoint.Y, map, list);

                    break;

                case DirectionsEnum.DIRECTION_NORTH:
                    MapPoint.AddCellIfValid(mapPoint.X - i, mapPoint.Y + i, map, list);

                    break;

                case DirectionsEnum.DIRECTION_NORTH_EAST:
                    MapPoint.AddCellIfValid(mapPoint.X, mapPoint.Y + i, map, list);

                    break;
                }
            }

            return(list.ToArray());
        }
Ejemplo n.º 2
0
        public short[] GetCells(short centerCell, MapRecord map)
        {
            MapPoint     mapPoint = new MapPoint(centerCell);
            List <short> list     = new List <short>();

            short[] result;

            if (this.Radius == 0)
            {
                if (this.MinRadius == 0)
                {
                    list.Add(centerCell);
                }
                result = list.ToArray();
            }
            else
            {
                int i    = mapPoint.X - (int)this.Radius;
                int num  = 0;
                int num2 = 1;
                while (i <= mapPoint.X + (int)this.Radius)
                {
                    for (int j = -num; j <= num; j++)
                    {
                        if (this.MinRadius == 0 || System.Math.Abs(mapPoint.X - i) + System.Math.Abs(j) >= (int)this.MinRadius)
                        {
                            MapPoint.AddCellIfValid(i, j + mapPoint.Y, map, list);
                        }
                    }
                    if (num == (int)this.Radius)
                    {
                        num2 = -num2;
                    }
                    num += num2;
                    i++;
                }
                result = list.ToArray();
            }
            return(result);
        }
Ejemplo n.º 3
0
        public short[] GetCells(short centerCell, MapRecord map)
        {
            List <short> list = new List <short>();

            if (this.MinRadius == 0)
            {
                list.Add(centerCell);
            }
            System.Collections.Generic.List <DirectionsEnum> list2 = this.DisabledDirections.ToList <DirectionsEnum>();
            if (this.OnlyPerpendicular)
            {
                switch (this.Direction)
                {
                case DirectionsEnum.DIRECTION_EAST:
                case DirectionsEnum.DIRECTION_WEST:
                    list2.Add(DirectionsEnum.DIRECTION_EAST);
                    list2.Add(DirectionsEnum.DIRECTION_WEST);
                    break;

                case DirectionsEnum.DIRECTION_SOUTH_EAST:
                case DirectionsEnum.DIRECTION_NORTH_WEST:
                    list2.Add(DirectionsEnum.DIRECTION_SOUTH_EAST);
                    list2.Add(DirectionsEnum.DIRECTION_NORTH_WEST);
                    break;

                case DirectionsEnum.DIRECTION_SOUTH:
                case DirectionsEnum.DIRECTION_NORTH:
                    list2.Add(DirectionsEnum.DIRECTION_SOUTH);
                    list2.Add(DirectionsEnum.DIRECTION_NORTH);
                    break;

                case DirectionsEnum.DIRECTION_SOUTH_WEST:
                case DirectionsEnum.DIRECTION_NORTH_EAST:
                    list2.Add(DirectionsEnum.DIRECTION_NORTH_EAST);
                    list2.Add(DirectionsEnum.DIRECTION_SOUTH_WEST);
                    break;
                }
            }
            MapPoint mapPoint = new MapPoint(centerCell);

            for (int i = (int)this.Radius; i > 0; i--)
            {
                if (i >= (int)this.MinRadius)
                {
                    if (!this.Diagonal)
                    {
                        if (!list2.Contains(DirectionsEnum.DIRECTION_SOUTH_EAST))
                        {
                            MapPoint.AddCellIfValid(mapPoint.X + i, mapPoint.Y, map, list);
                        }
                        if (!list2.Contains(DirectionsEnum.DIRECTION_NORTH_WEST))
                        {
                            MapPoint.AddCellIfValid(mapPoint.X - i, mapPoint.Y, map, list);
                        }
                        if (!list2.Contains(DirectionsEnum.DIRECTION_NORTH_EAST))
                        {
                            MapPoint.AddCellIfValid(mapPoint.X, mapPoint.Y + i, map, list);
                        }
                        if (!list2.Contains(DirectionsEnum.DIRECTION_SOUTH_WEST))
                        {
                            MapPoint.AddCellIfValid(mapPoint.X, mapPoint.Y - i, map, list);
                        }
                    }
                    if (this.Diagonal || this.AllDirections)
                    {
                        if (!list2.Contains(DirectionsEnum.DIRECTION_SOUTH))
                        {
                            MapPoint.AddCellIfValid(mapPoint.X + i, mapPoint.Y - i, map, list);
                        }
                        if (!list2.Contains(DirectionsEnum.DIRECTION_NORTH))
                        {
                            MapPoint.AddCellIfValid(mapPoint.X - i, mapPoint.Y + i, map, list);
                        }
                        if (!list2.Contains(DirectionsEnum.DIRECTION_EAST))
                        {
                            MapPoint.AddCellIfValid(mapPoint.X + i, mapPoint.Y + i, map, list);
                        }
                        if (!list2.Contains(DirectionsEnum.DIRECTION_WEST))
                        {
                            MapPoint.AddCellIfValid(mapPoint.X - i, mapPoint.Y - i, map, list);
                        }
                    }
                }
            }
            return(list.ToArray());
        }
Ejemplo n.º 4
0
        public short[] GetCells(short centerCell, MapRecord map)
        {
            MapPoint     mapPoint = new MapPoint(centerCell);
            List <short> list     = new List <short>();

            short[] result;
            if (this.Radius == 0)
            {
                if (this.MinRadius == 0)
                {
                    list.Add(centerCell);
                }
                result = list.ToArray();
            }
            else
            {
                int num  = 0;
                int num2 = 1;
                switch (this.Direction)
                {
                case DirectionsEnum.DIRECTION_SOUTH_EAST:
                    for (int i = mapPoint.X; i <= mapPoint.X + (int)this.Radius; i++)
                    {
                        for (int j = -num; j <= num; j++)
                        {
                            if (this.MinRadius == 0 || System.Math.Abs(mapPoint.X - i) + System.Math.Abs(j) >= (int)this.MinRadius)
                            {
                                MapPoint.AddCellIfValid(i, j + mapPoint.Y, map, list);
                            }
                        }
                        num += num2;
                    }
                    break;

                case DirectionsEnum.DIRECTION_SOUTH_WEST:
                    for (int j = mapPoint.Y; j >= mapPoint.Y - (int)this.Radius; j--)
                    {
                        for (int i = -num; i <= num; i++)
                        {
                            if (this.MinRadius == 0 || System.Math.Abs(i) + System.Math.Abs(mapPoint.Y - j) >= (int)this.MinRadius)
                            {
                                MapPoint.AddCellIfValid(i + mapPoint.X, j, map, list);
                            }
                        }
                        num += num2;
                    }
                    break;

                case DirectionsEnum.DIRECTION_NORTH_WEST:
                    for (int i = mapPoint.X; i >= mapPoint.X - (int)this.Radius; i--)
                    {
                        for (int j = -num; j <= num; j++)
                        {
                            if (this.MinRadius == 0 || System.Math.Abs(mapPoint.X - i) + System.Math.Abs(j) >= (int)this.MinRadius)
                            {
                                MapPoint.AddCellIfValid(i, j + mapPoint.Y, map, list);
                            }
                        }
                        num += num2;
                    }
                    break;

                case DirectionsEnum.DIRECTION_NORTH_EAST:
                    for (int j = mapPoint.Y; j <= mapPoint.Y + (int)this.Radius; j++)
                    {
                        for (int i = -num; i <= num; i++)
                        {
                            if (this.MinRadius == 0 || System.Math.Abs(i) + System.Math.Abs(mapPoint.Y - j) >= (int)this.MinRadius)
                            {
                                MapPoint.AddCellIfValid(i + mapPoint.X, j, map, list);
                            }
                        }
                        num += num2;
                    }
                    break;
                }
                result = list.ToArray();
            }
            return(result);
        }
Ejemplo n.º 5
0
        public short[] GetCells(short centerCell, MapRecord map)
        {
            MapPoint     mapPoint = new MapPoint(centerCell);
            List <short> list     = new List <short>();

            list.Add(centerCell);

            for (int i = 1; i < Radius + 1; i++)
            {
                var adj = mapPoint.GetCellInDirection(DirectionsEnum.DIRECTION_EAST, (short)i);
                if (adj != null)
                {
                    list.Add(adj.CellId);

                    MapPoint next = adj;

                    foreach (var cell in next.GetCellsInDirection(DirectionsEnum.DIRECTION_NORTH_WEST, (short)(i * 2)))
                    {
                        if (cell == null)
                        {
                            return(new short[0]);
                        }
                        if (!list.Contains(cell.CellId))
                        {
                            MapPoint.AddCellIfValid(cell.X, cell.Y, map, list);
                            next = cell;
                        }
                    }

                    foreach (var cell in next.GetCellsInDirection(DirectionsEnum.DIRECTION_SOUTH_WEST, (short)(i * 2)))
                    {
                        if (cell == null)
                        {
                            return(new short[0]);
                        }
                        if (!list.Contains(cell.CellId))
                        {
                            MapPoint.AddCellIfValid(cell.X, cell.Y, map, list);
                            next = cell;
                        }
                    }

                    foreach (var cell in next.GetCellsInDirection(DirectionsEnum.DIRECTION_SOUTH_EAST, (short)(i * 2)))
                    {
                        if (cell == null)
                        {
                            return(new short[0]);
                        }
                        if (!list.Contains(cell.CellId))
                        {
                            MapPoint.AddCellIfValid(cell.X, cell.Y, map, list);
                            next = cell;
                        }
                    }

                    foreach (var cell in next.GetCellsInDirection(DirectionsEnum.DIRECTION_NORTH_EAST, (short)(i * 2)))
                    {
                        if (cell == null)
                        {
                            return(new short[0]);
                        }
                        if (!list.Contains(cell.CellId))
                        {
                            MapPoint.AddCellIfValid(cell.X, cell.Y, map, list);
                            next = cell;
                        }
                    }
                }
                else
                {
                    list.Clear();
                }
            }

            return(list.ToArray());
        }