private CellTransition calculatePath(LiMap.Cell cell, Cell lastCell, HashSet <LiMap.Cell> visited, int depth) { if (visited.Contains(cell) || depth > Constant.PathMaxDepth) { return(null); } visited.Add(cell); Cell resultCell = new Cell(); resultCell.Pos = cell.Pos; resultCell.DirIn = cell.Pos - lastCell.Pos; CellTransition max = null; foreach (LiMap.Transition transition in cell.Transitions) { TileDir dir = transition.ToCell.Pos - cell.Pos; resultCell.DirOut = dir; CellTransition newTransition = calculatePath(transition.ToCell, resultCell, visited, depth + 1); if (null != newTransition) { newTransition.TransitionPriority = cellTransitionPriority(lastCell, resultCell, newTransition.Cell, transition.Weight); int checkDepth = transition.isCheckpoint ? 0 : 3; if (null == max || newTransition.Priority(checkDepth) > max.Priority(checkDepth)) { max = newTransition; } } } List <TileDir> dirOuts = new List <TileDir>(); foreach (TileDir dir in cell.Dirs) { if (dir != resultCell.DirIn.Negative()) { dirOuts.Add(dir); } } resultCell.DirOuts = dirOuts.ToArray(); resultCell.DirOut = null; if (0 != dirOuts.Count) { if (null != max) { resultCell.DirOut = max.Cell.Pos - cell.Pos; } } CellTransition result = new CellTransition(resultCell, max, cellPriority(resultCell)); visited.Remove(cell); return(result); }
public double NextPriority(int depth) { return((null != Next) ? Next.Priority(depth) : 0); }