private static void SetPathfinderDelegates(NewPathFinder pf, PathDataLog pathData) { if (pathData.tpMoveCardinal >= 0) { NewPathFinder.GetPawnPathCostSettings = (p) => new NewPathFinder.PawnPathCostSettings { moveTicksCardinal = pathData.tpMoveCardinal, moveTicksDiagonal = pathData.tpMoveDiagonal, area = pathData.allowedArea, avoidGrid = pathData.avoidGrid }; } NewPathFinder.GetPathCostForBuilding = (building, parms) => { if (building is Building_DoorIndex) { var fakeEdificeVal = pathData.fakeEdificeGrid[((Building_DoorIndex)building).edificeIndex]; switch (fakeEdificeVal) { case PathDataLog.Edifice_Impassible: //shouldn't happen, but might as well check case PathDataLog.Edifice_NonTraversableDoor: return(-1); default: return(fakeEdificeVal); } } if (building is Building_KnownArmedTrap) { return(800); } throw new Exception("Unknown Building"); }; }
static void Main() { InitGameData(); Console.WriteLine("-----"); var sw = new Stopwatch(); foreach (var file in Directory.GetFiles(pathDirectory, "*.xml")) //var file = Path.Combine(pathDirectory, "Darcie - 1215368.xml"); { GC.Collect(); Console.WriteLine(Path.GetFileNameWithoutExtension(file)); var pathData = PathDataLog.LoadFromFile(file); var pf = new NewPathFinder(MapBuilder.MapFromPathData(pathData)); var dest = new LocalTargetInfo(pathData.dest.CenterCell); var tp = new TraverseParms() { canBash = pathData.tpCanBash, maxDanger = pathData.tpMaxDanger, mode = pathData.tpMode }; SetPathfinderDelegates(pf, pathData); sw.Start(); //for (int i = 0; i < 4; i++) { var path = pf.FindPath(pathData.start, dest, tp, pathData.peMode); path.Dispose(); } sw.Stop(); Console.WriteLine(); } //Console.WriteLine($"pathmax: {true}, weight: {true}, pops: {pf.debug_openCellsPopped}, pathcost: {path.TotalCost}, elapsed: {sw.ElapsedTicks}"); Console.WriteLine($"\nAll Done!\nElapsed pathfinding time: {sw.ElapsedMilliseconds}ms"); Console.Read(); }
public static Map MapFromPathData(PathDataLog data) { var map = new Map(); Find.Maps.Clear(); Find.Maps.Add(map); map.info.Size = data.mapSize; map.cellIndices = new CellIndices(map); map.temperatureCache = new TemperatureCache(map); map.regionLinkDatabase = new RegionLinkDatabase(); map.regionGrid = new RegionGrid(map); map.regionMaker = new RegionMaker(map); map.regionAndRoomUpdater = new RegionAndRoomUpdater(map); map.pathGrid = new PathGrid(map); map.regionDirtyer = new RegionDirtyer(map); map.edificeGrid = new EdificeGrid(map); map.pawnPathPool = new PawnPathPool(map); map.thingGrid = new ThingGrid(map); map.mapTemperature = new MapTemperature(map); map.mapConditionManager = new MapConditionManager(map); map.autoBuildRoofAreaSetter = new AutoBuildRoofAreaSetter(map); map.roofGrid = new RoofGrid(map); map.mapPawns = new MapPawns(map); map.reachability = new Reachability(map); map.areaManager = new AreaManager(map); map.pathGrid.pathGrid = data.pathGrid.ToArray(); var edificeAry = map.edificeGrid.InnerArray; for (int i = 0; i < data.fakeEdificeGrid.CellsCount; i++) { Building building = null; switch (data.fakeEdificeGrid[i]) { case PathDataLog.Edifice_None: continue; case PathDataLog.Edifice_Impassible: building = new Building() { def = impassible }; break; case PathDataLog.Edifice_KnownArmedTrap: building = new Building_KnownArmedTrap(); break; default: building = new Building_DoorIndex(i); break; } edificeAry[i] = SetupNewBuilding(building, i); map.thingGrid.Register(edificeAry[i]); } //Do this here for more consistent profiling times map.regionAndRoomUpdater.RebuildDirtyRegionsAndRooms(); return(map); }