public PathRequest(IPathRequester pathRequester, PathfindingMarker startMarker, PathfindingMarker endMarker, float maxJumpHeight) { this.pathRequester = pathRequester; this.startMarker = startMarker; this.endMarker = endMarker; this.maxJumpHeight = maxJumpHeight; }
public void RequestPath(IPathRequester pathRequester, Vector3 startPoint, Vector3 endPoint, float maxJumpHeight) { PathfindingMarker startMarker = _grid.FindNearestMarker(startPoint); PathfindingMarker endMarker = _grid.FindNearestMarker(endPoint); Logging.Log($"Trying to move from {startMarker.name} to {endMarker.name}!"); RequestPath(pathRequester, startMarker, endMarker, maxJumpHeight); }
public Node(PathfindingMarker newMarker, float newG = float.MaxValue, float newH = float.MaxValue) { marker = newMarker; H = newG; G = newH; parentNode = null; childNodes = new List <Node>(); }
private void RequestPath(PathfindingMarker destinationMarker) { EndAllPathfinders(); workInProgressPath = new List <PathfindingMarker> [1]; CurrentPathfinders = new IPathfinder[1]; pathfindingManager.RequestPath(this, transform.position, destinationMarker, highestReachableRelativeAltitude); }
private IEnumerable <Node> TurnAvailableConnectedMarkersIntoNodes(PathfindingMarker marker) { IEnumerable <PathfindingMarker> availableConnectedMarkers = marker.GetAvailableConnectedMarkers(_pathRequest.maxJumpHeight); if (availableConnectedMarkers == null) { return(null); } return(from currMarker in availableConnectedMarkers select GetOrAddMarkerToDictionary(currMarker)); }
private Node GetOrAddMarkerToDictionary(PathfindingMarker marker) { Node node = GetNodeFromMarker(marker); if (node != null) { return(node); } node = new Node(marker); AddToMarkerNodeDictionary(marker, node); return(node); }
private void FindPathsViaCoroutines() { int pathRequestsCount = _pathRequests.Count; if (pathRequestsCount != 0) { Logging.Log($"Searching for {pathRequestsCount} paths"); foreach (PathRequest pathRequest in _pathRequests) { const int defaultIndex = 0; var newPathfinder = AStarMarkerPathFinder.CreateInstance(pathRequest, pathfindingChecksPerFramePerFinder, defaultIndex); pathRequest.pathRequester.CurrentPathfinders = new IPathfinder[] { newPathfinder }; StartPathfinderCoroutine(newPathfinder); } _pathRequests.Clear(); } int multiPathRequestsCount = _multiPathRequests.Count; if (multiPathRequestsCount != 0) { Logging.Log($"Searching for {multiPathRequestsCount} multiPaths"); foreach (MultiPathRequest multiPathRequest in _multiPathRequests) { int requestAmount = multiPathRequest.markers.Count - 1; Logging.Log($"Multipath has {requestAmount} number of requests"); IPathRequester pathRequester = multiPathRequest.pathRequester; for (var index = 0; index < requestAmount; index++) { PathfindingMarker currStartMarker = multiPathRequest.markers[index]; PathfindingMarker currEndMarker = multiPathRequest.markers[index + 1]; var newPathRequest = new PathRequest(pathRequester, currStartMarker, currEndMarker, multiPathRequest.maxJumpHeight); var newPathfinder = AStarMarkerPathFinder.CreateInstance(newPathRequest, pathfindingChecksPerFramePerFinder, index); pathRequester.CurrentPathfinders[index] = newPathfinder; StartPathfinderCoroutine(newPathfinder); } } } _multiPathRequests.Clear(); }
public void RequestMultiPath(IPathRequester pathRequester, Vector3 startPoint, IEnumerable <Vector3> listOfPoints, float maxJumpHeight) { PathfindingMarker startMarker = _grid.FindNearestMarker(startPoint); if (startMarker == null) { Logging.LogWarning("Request MultiPath marker is null!"); return; } List <PathfindingMarker> listOfMarkersToGoThrough = listOfPoints.Select(point => _grid.FindNearestMarker(point)).ToList(); RequestMultiPath(pathRequester, startMarker, listOfMarkersToGoThrough, maxJumpHeight); }
protected PathfindingMarker InstantiateMarker(string markerName, Vector3 markerPos, Transform parent) { var newMarker = PathfindingMarker.CreateInstance(markerName, grid, markerPos, parent, creationHeightAboveFloor); GameObject newGObj = newMarker.gameObject; var boxCollider = newGObj.AddComponent <BoxCollider>(); boxCollider.size = grid.minimumOpenAreaAroundMarkers / 2; boxCollider.isTrigger = true; newGObj.layer = markerLayerMask.GetLayerInt(); return(newMarker); }
public override PathfindingMarker RequestPathToRandomLocationWithinDistance(float distance) { // This is dumb (I get a random point, and then ask for a marker near that point, then get that marker's position and request a path to that position, // which in turn looks for the marker near that position) // Logically I would create a separate 'RequestPath' that takes in a PathfindingMarker (and that's easy), // BUT... I am fully planning on creating a separate non-marker-based pathfinding system at some point in the near-future, // therefore I don't want to create marker-based functions in the AiController directly. PathfindingMarker randomMarker = grid.FindRandomMarkerWithinDistance(transform.position, distance); RequestPath(randomMarker.transform.position); return(null); }
private void InstantiateMarker(string markerName, Vector3 markerPos, Vector3 markerSize) { // var newMarker = PathfindingMarker.CreateInstance(markerName, ref grid); var newMarker = PathfindingMarker.CreateInstance(markerName + " " + grid.markers.Count, ref grid); newMarker.transform.position = markerPos; newMarker.transform.SetParent(gridTransform); var newMarkerCollider = newMarker.gameObject.AddComponent <BoxCollider>(); newMarkerCollider.size = markerSize; // newMarkerCollider.isTrigger = true; Logging.Log(""); Logging.Log(""); Logging.Log(""); Logging.Log(""); Logging.Log("INSTANTIATED MARKER #" + (grid.markers.Count - 1) + " at position " + markerPos.ToString("F4") + ", with size " + markerSize.ToString("F4")); Logging.Log(""); Logging.Log(""); Logging.Log(""); Logging.Log(""); }
// ReSharper disable once SuggestBaseTypeForParameter private Node GetNodeFromMarker(PathfindingMarker marker) { _markerNodeDictionary.TryGetValue(marker, out Node node); return(node); }
protected void GetNextMarkerInPath() { currentMarker = currentPath.Dequeue(); // Logging.Log($"Current marker is now {currentMarker.name}"); }
public void RequestPath(IPathRequester pathRequester, PathfindingMarker startMarker, PathfindingMarker endMarker, float maxJumpHeight) { _pathRequests.Add(new PathRequest(pathRequester, startMarker, endMarker, maxJumpHeight)); }
// ReSharper disable once SuggestBaseTypeForParameter private void AddToMarkerNodeDictionary(PathfindingMarker marker, Node node) { _markerNodeDictionary.Add(marker, node); }
public void RequestPath(IPathRequester pathRequester, Vector3 startPoint, PathfindingMarker endMarker, float maxJumpHeight) { PathfindingMarker startMarker = _grid.FindNearestMarker(startPoint); RequestPath(pathRequester, startMarker, endMarker, maxJumpHeight); }
public void RequestMultiPath(IPathRequester pathRequester, PathfindingMarker startMarker, List <PathfindingMarker> listOfMarkers, float maxJumpHeight) { _multiPathRequests.Add(new MultiPathRequest(pathRequester, listOfMarkers, maxJumpHeight)); }