public EntrancePoint AddEntrance(Id <AbstractNode> abstractNodeId, Position relativePosition) { var entrancePoint = new EntrancePoint(abstractNodeId, relativePosition); EntrancePoints.Add(entrancePoint); return(entrancePoint); }
private void ComputePathBetweenEntrances(EntrancePoint e1, EntrancePoint e2) { if (e1.AbstractNodeId == e2.AbstractNodeId) { return; } var tuple = Tuple.Create(e1.AbstractNodeId, e2.AbstractNodeId); var invtuple = Tuple.Create(e2.AbstractNodeId, e1.AbstractNodeId); if (_distanceCalculated.ContainsKey(tuple)) { return; } var startNodeId = Id <ConcreteNode> .From(GetEntrancePositionIndex(e1)); var targetNodeId = Id <ConcreteNode> .From(GetEntrancePositionIndex(e2)); var search = new AStar <ConcreteNode>(SubConcreteMap, startNodeId, targetNodeId); var path = search.FindPath(); if (path.PathCost != -1) { // Yeah, we are supposing reaching A - B is the same like reaching B - A. Which // depending on the game this is NOT necessarily true (e.g climbing, downstepping a mountain) _distances[tuple] = _distances[invtuple] = path.PathCost; _cachedPaths[tuple] = new List <Id <ConcreteNode> >(path.PathNodes); path.PathNodes.Reverse(); _cachedPaths[invtuple] = path.PathNodes; } _distanceCalculated[tuple] = _distanceCalculated[invtuple] = true; }
public void UpdatePathsForLocalEntrance(EntrancePoint srcEntrancePoint) { foreach (var entrancePoint in EntrancePoints) { ComputePathBetweenEntrances(srcEntrancePoint, entrancePoint); } }
private int GetEntrancePointLevel(EntrancePoint entrancePoint) { return HierarchicalMap.AbstractGraph.GetNodeInfo(entrancePoint.AbsNodeId).Level; }
/// <summary> /// Gets the index of the entrance point inside this cluster /// </summary> private int GetEntrancePositionIndex(EntrancePoint entrancePoint) { return(entrancePoint.RelativePosition.Y * Size.Width + entrancePoint.RelativePosition.X); }
private int GetEntrancePointLevel(EntrancePoint entrancePoint) { return(AbstractGraph.GetNodeInfo(entrancePoint.AbstractNodeId).Level); }
private void ComputePathBetweenEntrances(EntrancePoint e1, EntrancePoint e2) { var start = GetEntrancePositionIndex(e1); var target = GetEntrancePositionIndex(e2); var startIdx = e1.EntranceLocalIdx; var targetIdx = e2.EntranceLocalIdx; var tuple = Tuple.Create(startIdx, targetIdx); var invtuple = Tuple.Create(targetIdx, startIdx); // If a path already existed, or both are the same node, just return if (this.DistanceCalculated.ContainsKey(tuple) || startIdx == targetIdx) return; var search = new AStar(); var path = search.FindPath(SubConcreteMap, start, target); // TODO: Store the path as well, not only the cost. This will make everything faster! if (path.PathCost != -1) { // Yeah, we are supposing reaching A - B is the same like reaching B - A. Which // depending on the game this is NOT necessarily true (e.g climbing, downstepping a mountain) Distances[tuple] = Distances[invtuple] = path.PathCost; CachedPaths[tuple] = CachedPaths[invtuple] = path.PathNodes; } this.DistanceCalculated[tuple] = this.DistanceCalculated[invtuple] = true; }
/// <summary> /// Gets the index of the entrance point inside this cluster /// </summary> private int GetEntrancePositionIndex(EntrancePoint entrancePoint) { return entrancePoint.RelativePos.Y * Size.Width + entrancePoint.RelativePos.X; }
/// <summary> /// Adds an entrance point to the cluster and returns the entrance index assigned for the point /// </summary> public int AddEntrance(int abstractNodeId, Position relativePosition) { var entranceLocalIdx = EntrancePoints.Count; var localEntrance = new EntrancePoint( abstractNodeId, EntrancePoints.Count, relativePosition); EntrancePoints.Add(localEntrance); return entranceLocalIdx; }
/// <summary> /// Tells whether a path exists inside the cluster between localIdx1 and localIdx2 /// </summary> public bool AreConnected(EntrancePoint point1, EntrancePoint point2) { return Distances.ContainsKey(Tuple.Create(point1.EntranceLocalIdx, point2.EntranceLocalIdx)); }