Exemplo n.º 1
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.º 2
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.º 3
0
        private double PointWeight(Point point)
        {
            double result = 1;
            int    cellId = PathingUtils.CoordToCellId(point.X, point.Y);
            int    speed  = currentMap.Data.Cells[cellId].speed;

            if (speed >= 0)
            {
                result = result + (5 - speed);
            }
            else
            {
                result = result + (11 + Math.Abs(speed));
            }
            return(result);
        }
Exemplo n.º 4
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.º 5
0
 public short[] GetCompressedPath(short startCellId, short destinationCellId)
 {
     return(PathingUtils.GetCompressedPath(Find(startCellId, destinationCellId)).ToArray());
 }