Example #1
0
        public EntrancePoint AddEntrance(Id <AbstractNode> abstractNodeId, Position relativePosition)
        {
            var entrancePoint = new EntrancePoint(abstractNodeId, relativePosition);

            EntrancePoints.Add(entrancePoint);
            return(entrancePoint);
        }
Example #2
0
 public void UpdatePathsForLocalEntrance(EntrancePoint srcEntrancePoint)
 {
     foreach (var entrancePoint in EntrancePoints)
     {
         ComputePathBetweenEntrances(srcEntrancePoint, entrancePoint);
     }
 }
Example #3
0
        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;
        }
Example #4
0
 /// <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);
 }
Example #5
0
 private int GetEntrancePointLevel(EntrancePoint entrancePoint)
 {
     return(AbstractGraph.GetNodeInfo(entrancePoint.AbstractNodeId).Level);
 }