/// <summary> /// 清理 /// </summary> public static void Clear() { g_Map = null; g_Result.Clear(); g_Result = null; g_DirArray = null; }
/// <summary> /// 在一个扇区内进行流程寻路算法 /// </summary> /// <param name="start"></param> /// <param name="end"></param> /// <param name="map"></param> /// <param name="lSector">指定扇区内</param> /// <returns></returns> public static List <IntVector2> GetRoadInSector(MapTile start, MapTile end, List <ushort> lSector) { bool ret = false; openSet.Clear(); closedSet.Clear(); openSet.Add(start); start.integrationValue = 0; while (openSet.Count > 0 && ret == false) { MapTile currentNode = openSet[0]; MapTileSearchResult result = TileHelp.GetNeighboursExpansionSearch(currentNode, lSector); for (int i = 0; i < result.Count; i++) { MapTile neighbour = result.Get(i); if (!openSet.Contains(neighbour)) { openSet.Add(neighbour); // if true, there is a higher node here if (neighbour == end) { ret = true; break; } } } closedSet.Add(currentNode); openSet.Remove(currentNode); } // 得到路径了,回溯路径 List <IntVector2> l = GetRoadList(start, end); // reset for (int i = 0; i < openSet.Count; i++) { openSet[i].integrationValue = TileHelp.tileResetIntegrationValue; } for (int i = 0; i < closedSet.Count; i++) { closedSet[i].integrationValue = TileHelp.tileResetIntegrationValue; } return(l); }
/// <summary> /// 使用流程寻路算法计算start点到扇区的各个gate,并保存的way point的cost中。 /// </summary> /// <param name="start">sector中的起点</param> /// <param name="sector">指定的扇区</param> /// <param name="map">指定地图</param> public static void CalcSectorWayPointCost(PathNode start) { openSet.Clear(); closedSet.Clear(); openSet.Add(start.tileConnection); start.tileConnection.integrationValue = 0; while (openSet.Count > 0) { MapTile currentNode = openSet[0]; MapTileSearchResult result = TileHelp.GetAllNeighboursInSectorFlowFieldSearch(currentNode); for (int i = 0; i < result.Count; i++) { MapTile neighbour = result.Get(i); if (!openSet.Contains(neighbour)) { openSet.Add(neighbour); // if true, there is a higher node here if (neighbour.hasPathNodeConnection) { PathNode neighbourSectorNode = g_map.GetWayPointPathNode(0, neighbour); if (neighbourSectorNode != null) { List <IntVector2> l = GetRoadList(start.tileConnection, neighbour); PathNode.LinkSectorNode(start, neighbourSectorNode, neighbour.integrationValue / 10, l); } } } } closedSet.Add(currentNode); openSet.Remove(currentNode); } // reset for (int i = 0; i < openSet.Count; i++) { openSet[i].integrationValue = TileHelp.tileResetIntegrationValue; } for (int i = 0; i < closedSet.Count; i++) { closedSet[i].integrationValue = TileHelp.tileResetIntegrationValue; } }
public static void Init(Map map) { g_Map = map; g_Result = new MapTileSearchResult(); }