public static void AddPotential(PotentialPath potential_path, int parent_cell, NavType parent_nav_type, int cost, int underwater_cost, int transition_id, PotentialList potentials, PathGrid path_grid, ref Cell cell_data) { cell_data.cost = cost; cell_data.underwaterCost = (byte)Math.Min(underwater_cost, 255); cell_data.parent = parent_cell; cell_data.navType = potential_path.navType; cell_data.parentNavType = parent_nav_type; cell_data.transitionId = transition_id; potentials.Add(cost, potential_path); path_grid.SetCell(potential_path, ref cell_data); }
public static void AddPotentials(PotentialScratchPad potential_scratch_pad, PotentialPath potential, int cost, int underwater_cost, ref PathFinderAbilities abilities, PathFinderQuery query, int max_links_per_cell, NavGrid.Link[] links, PotentialList potentials, PathGrid path_grid, int parent_cell, NavType parent_nav_type) { int num = 0; NavGrid.Link[] linksWithCorrectNavType = potential_scratch_pad.linksWithCorrectNavType; int num2 = potential.cell * max_links_per_cell; NavGrid.Link link = links[num2]; for (int link2 = link.link; link2 != InvalidHandle; link2 = link.link) { if (link.startNavType == potential.navType && (parent_cell != link2 || parent_nav_type != link.startNavType)) { linksWithCorrectNavType[num++] = link; } num2++; link = links[num2]; } int num4 = 0; PotentialScratchPad.PathGridCellData[] linksInCellRange = potential_scratch_pad.linksInCellRange; for (int i = 0; i < num; i++) { NavGrid.Link link3 = linksWithCorrectNavType[i]; int link4 = link3.link; bool is_cell_in_range = false; Cell cell = path_grid.GetCell(link4, link3.endNavType, out is_cell_in_range); if (is_cell_in_range) { int num5 = cost + link3.cost; bool flag = cell.cost == -1; bool flag2 = num5 < cell.cost; if (flag || flag2) { linksInCellRange[num4++] = new PotentialScratchPad.PathGridCellData { pathGridCell = cell, link = link3 }; } } } for (int j = 0; j < num4; j++) { PotentialScratchPad.PathGridCellData pathGridCellData = linksInCellRange[j]; NavGrid.Link link5 = pathGridCellData.link; int link6 = link5.link; pathGridCellData.isSubmerged = IsSubmerged(link6); linksInCellRange[j] = pathGridCellData; } for (int k = 0; k < num4; k++) { PotentialScratchPad.PathGridCellData pathGridCellData2 = linksInCellRange[k]; NavGrid.Link link7 = pathGridCellData2.link; int link8 = link7.link; Cell cell_data = pathGridCellData2.pathGridCell; int num7 = cost + link7.cost; PotentialPath path = potential; path.cell = link8; path.navType = link7.endNavType; int underwater_cost2; if (pathGridCellData2.isSubmerged) { underwater_cost2 = underwater_cost + 1; int submergedPathCostPenalty = abilities.GetSubmergedPathCostPenalty(path, link7); num7 += submergedPathCostPenalty; } else { underwater_cost2 = 0; } PotentialPath.Flags flags = path.flags; bool flag3 = abilities.TraversePath(ref path, potential.cell, potential.navType, num7, link7.transitionId, underwater_cost2); if (path.flags != flags) { KProfiler.AddEvent("NavChange"); } if (flag3) { AddPotential(path, potential.cell, potential.navType, num7, underwater_cost2, link7.transitionId, potentials, path_grid, ref cell_data); } } }
private static void FindPaths(NavGrid nav_grid, ref PathFinderAbilities abilities, PotentialPath potential_path, PathFinderQuery query, PotentialList potentials, ref int result_cell, ref NavType result_nav_type) { potentials.Clear(); PathGrid.ResetUpdate(); PathGrid.BeginUpdate(potential_path.cell, false); bool is_cell_in_range; Cell cell_data = PathGrid.GetCell(potential_path, out is_cell_in_range); AddPotential(potential_path, Grid.InvalidCell, NavType.NumNavTypes, 0, 0, -1, potentials, PathGrid, ref cell_data); int num = 2147483647; while (potentials.Count > 0) { KeyValuePair <int, PotentialPath> keyValuePair = potentials.Next(); cell_data = PathGrid.GetCell(keyValuePair.Value, out is_cell_in_range); if (cell_data.cost != keyValuePair.Key) { continue; } int num2; if (cell_data.navType != NavType.Tube) { PotentialPath value = keyValuePair.Value; if (query.IsMatch(value.cell, cell_data.parent, cell_data.cost)) { num2 = ((cell_data.cost < num) ? 1 : 0); goto IL_00cc; } } num2 = 0; goto IL_00cc; IL_00cc: if (num2 != 0) { PotentialPath value2 = keyValuePair.Value; result_cell = value2.cell; num = cell_data.cost; result_nav_type = cell_data.navType; break; } AddPotentials(nav_grid.potentialScratchPad, keyValuePair.Value, cell_data.cost, cell_data.underwaterCost, ref abilities, query, nav_grid.maxLinksPerCell, nav_grid.Links, potentials, PathGrid, cell_data.parent, cell_data.parentNavType); } PathGrid.EndUpdate(true); }