示例#1
0
            public Vertex2D GetExplorationNeighbour(Vertex2D current)
            {
                var currDist = minWaypointDistance(current);
                var finder   = new PathFinder2D <Vertex2D>
                {
                    ConnectionProvider = new GridConnectionProvider()
                    {
                        Grid = provider.Grid, Heuristic = (a, b) => 0
                    },
                    StopCondition = n => minWaypointDistance(n) > WaypointDistance || Vector2.Distance(n.Position, current.Position) > 20
                };

                var path = finder.FindPath(current, new Vertex2D(new Vector2(4856984, 45684984)));

                if (minWaypointDistance(current) > minWaypointDistance(path.Last()))
                {
                    return(null);
                }
                if (path == null)
                {
                    return(null);
                }
                return(path.Last());

                //return provider.GetConnectedNodes(current).OrderBy(o => -minWaypointDistance(o)).FirstOrDefault();
            }
示例#2
0
 private void insertNewWaypoint(Vertex2D pos)
 {
     TW.Data.GetSingleton <ExplorationData>().Waypoints.Add(new Waypoint()
     {
         Position = pos.Position
     });
 }
        private List <Vertex2D> findPathAlongWaypoints(Vertex2D start, Vertex2D end, List <Waypoint> wPath)
        {
            var finder = createPathFinder <Vertex2D>();

            finder.ConnectionProvider = gridConnectionProvider;
            finder.NodeFilter         = (n => isNodeWithinPathRange(n, wPath, WaypointRange));
            return(finder.FindPath(start, end));
        }
示例#4
0
 private float minWaypointDistance(Vertex2D arg)
 {
     //TODO: this should be walk distance, not fly distance
     if (!getWaypoints().Any())
     {
         return(float.MaxValue);
     }
     return(getWaypoints().Min(w => Vector2.Distance(arg.Position, w.Position)));
 }
 private bool isNodeWithinPathRange(Vertex2D vertex2D, List <Waypoint> wPath, float range)
 {
     foreach (var p in wPath)
     {
         if (Vector2.Distance(p.Position, vertex2D.Position) < range)
         {
             return(true);
         }
     }
     return(false);
 }
            public void Simulate()
            {
                if (!first)
                {
                    return;
                }
                //first = false;
                grid = TW.Data.GetSingleton <NavigableGrid2DData>().Grid;
                if (grid == null)
                {
                    return;
                }



                var gridConnectionProvider = new GridConnectionProvider()
                {
                    Grid = grid
                };

                p.ConnectionProvider = gridConnectionProvider;


                var start = gridConnectionProvider.GetVertex(Data.Start / grid.NodeSize);
                var goal  = gridConnectionProvider.GetVertex(Data.End / grid.NodeSize);


                TW.Graphics.LineManager3D.AddCenteredBox(new Vector3(start.Position.X + 0.5f, 0, start.Position.Y + 0.5f) * grid.NodeSize, grid.NodeSize * 0.5f, new Color4(0, 1, 0));
                TW.Graphics.LineManager3D.AddCenteredBox(new Vector3(goal.Position.X + 0.5f, 0, goal.Position.Y + 0.5f) * grid.NodeSize, grid.NodeSize * 0.5f, new Color4(1, 0, 0));


                var      path = p.FindPath(start, goal);
                Vertex2D prev = null;

                //viz.Render();

                if (path == null)
                {
                    return;
                }
                foreach (var node in path)
                {
                    if (prev != null)
                    {
                        TW.Graphics.LineManager3D.AddLine(
                            new Vector3(prev.Position.X + 0.5f, 0, prev.Position.Y + 0.5f) * grid.NodeSize,
                            new Vector3(node.Position.X + 0.5f, 0, node.Position.Y + 0.5f) * grid.NodeSize,
                            new Color4(1, 0, 0));
                    }
                    prev = node;
                }
            }
 private Waypoint findClosestWaypoint(Vertex2D end)
 {
     return(getWaypoints().OrderBy(w => Vector2.Distance(w.Position, end.Position)).FirstOrDefault());
 }
示例#8
0
 private void moveGoblinTo(Goblin modelObject, Vertex2D nextPos)
 {
     modelObject.Goal = new Vector3(nextPos.Position.X, 0, nextPos.Position.Y);
 }