Exemplo n.º 1
0
        public static uint DistanceToPoint(short a, short b)
        {
            Point point1 = PathingUtils.CellIdToCoord(a);
            Point point2 = PathingUtils.CellIdToCoord(b);

            return((uint)Math.Sqrt((point1.X - point2.X) * (point1.X - point2.X) + (point1.Y - point2.Y) * (point1.Y - point2.Y)));
        }
Exemplo n.º 2
0
        public int GetCellInDirection(DirectionsEnum direction, short step)
        {
            Point ThatCell;

            switch (direction)
            {
            case DirectionsEnum.DIRECTION_EAST:
            {
                ThatCell = new Point(Location.X + step, Location.Y + step);
                break;
            }

            case DirectionsEnum.DIRECTION_SOUTH_EAST:
            {
                ThatCell = new Point(Location.X + step, Location.Y);
                break;
            }

            case DirectionsEnum.DIRECTION_SOUTH:
            {
                ThatCell = new Point(Location.X + step, Location.Y - step);
                break;
            }

            case DirectionsEnum.DIRECTION_SOUTH_WEST:
            {
                ThatCell = new Point(Location.X, Location.Y - step);
                break;
            }

            case DirectionsEnum.DIRECTION_WEST:
            {
                ThatCell = new Point(Location.X - step, Location.Y - step);
                break;
            }

            case DirectionsEnum.DIRECTION_NORTH_WEST:
            {
                ThatCell = new Point(Location.X - step, Location.Y);
                break;
            }

            case DirectionsEnum.DIRECTION_NORTH:
            {
                ThatCell = new Point(Location.X - step, Location.Y + step);
                break;
            }

            case DirectionsEnum.DIRECTION_NORTH_EAST:
            {
                ThatCell = new Point(Location.X, Location.Y + step);
                break;
            }

            default:
                throw new Exception("Unknown direction : " + direction);
            }
            return(PathingUtils.CoordToCellId(ThatCell.X, ThatCell.Y));
        }
Exemplo n.º 3
0
        public static short[] CellsByDistance(short[] cells, short current)
        {
            Dictionary <int, int> distances = new Dictionary <int, int>();

            for (int i = 0; i < cells.Length; i++)
            {
                distances[cells[i]] = (short)PathingUtils.DistanceToPoint2(PathingUtils.CellIdToCoord(cells[i]), PathingUtils.CellIdToCoord(current));
            }
            return(cells.OrderByDescending(elem => distances[elem]).ToArray());
        }
Exemplo n.º 4
0
        public List <int> GetConnectedCells()
        {
            List <int> list = new List <int>();

            list.Add(PathingUtils.CoordToCellId(Location.X - 1, Location.Y));
            list.Add(PathingUtils.CoordToCellId(Location.X, Location.Y - 1));
            list.Add(PathingUtils.CoordToCellId(Location.X + 1, Location.Y));
            list.Add(PathingUtils.CoordToCellId(Location.X, Location.Y + 1));
            return(list);
        }
Exemplo n.º 5
0
        private double PointWeight(Point point)
        {
            double result = 1;
            int    cellId = PathingUtils.CoordToCellId(point.X, point.Y);
            int    speed  = currentMap.Cells[cellId].Speed;

            if (speed >= 0)
            {
                result = result + (5 - speed);
            }
            else
            {
                result = result + (11 + Math.Abs(speed));
            }
            return(result);
        }
Exemplo n.º 6
0
        private void SortOpenList()
        {
            bool ok = false;

            while (!ok)
            {
                ok = true;
                Cell temp;
                for (int i = 0; i < openList.Count - 1; i++)
                {
                    if (openList[i].F > openList[i + 1].F && PathingUtils.DistanceToPoint(openList[i].Location, destinationCell.Location) < PathingUtils.DistanceToPoint(openList[i + 1].Location, destinationCell.Location))
                    {
                        temp            = openList[i];
                        openList[i]     = openList[i + 1];
                        openList[i + 1] = temp;
                        ok = false;
                    }
                }
            }
        }
Exemplo n.º 7
0
 public short[] GetCompressedPath(short startCellId, short destinationCellId)
 {
     return(PathingUtils.GetCompressedPath(Find(startCellId, destinationCellId)).ToArray());
 }