/// <summary> /// Function that will return a path between two points on separate graphs /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <returns></returns> public Dictionary<int, List<UndirEdge>> FindPath(GraphLocatable from, GraphLocatable to) { var path = new Dictionary<int, List<UndirEdge>>(); // Detect if we are chaing floors if (from.Floor != to.Floor) { // Floor change // Find the stairs on current floor var stairsFromFloor = Rooms.Find(x => x.IsStairs && x.Floor == from.Floor); var stairsTargetFloor = Rooms.Find(x => x.IsStairs && x.Floor == to.Floor); if(stairsFromFloor == null || stairsTargetFloor == null) throw new Exception("Couldnt locate any stairs to transition"); int fromFloor = from.Floor; int toFloor = to.Floor; var fromFloorGraph = _floorGraphs[fromFloor]; var toFloorGraph = _floorGraphs[toFloor]; var pathFromFloor = fromFloorGraph.FindPath(from.ToPointString(), stairsFromFloor.Position.ToPointString()); var pathToFloor = toFloorGraph.FindPath(stairsTargetFloor.Position.ToPointString(), to.ToPointString()); path.Add(fromFloor,pathFromFloor); path.Add(toFloor,pathToFloor); } else { // Same floor navigation path.Add(from.Floor, _floorGraphs[from.Floor].FindPath(from.ToPointString(), to.ToPointString())); } return path; }
/// <summary> /// Function that will return a path between two points on separate graphs /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <returns></returns> public Dictionary <int, List <UndirEdge> > FindPath(GraphLocatable from, GraphLocatable to) { var path = new Dictionary <int, List <UndirEdge> >(); // Detect if we are chaing floors if (from.Floor != to.Floor) { // Floor change // Find the stairs on current floor var stairsFromFloor = Rooms.Find(x => x.IsStairs && x.Floor == from.Floor); var stairsTargetFloor = Rooms.Find(x => x.IsStairs && x.Floor == to.Floor); if (stairsFromFloor == null || stairsTargetFloor == null) { throw new Exception("Couldnt locate any stairs to transition"); } int fromFloor = from.Floor; int toFloor = to.Floor; var fromFloorGraph = FloorGraphs[fromFloor]; var toFloorGraph = FloorGraphs[toFloor]; var pathFromFloor = fromFloorGraph.FindPath(from.ToPointString(), stairsFromFloor.Position.ToPointString()); var pathToFloor = toFloorGraph.FindPath(stairsTargetFloor.Position.ToPointString(), to.ToPointString()); path.Add(fromFloor, pathFromFloor); path.Add(toFloor, pathToFloor); } else { // Same floor navigation path.Add(from.Floor, FloorGraphs[from.Floor].FindPath(from.ToPointString(), to.ToPointString())); } return(path); }