public static Path getPath(Vector2 from, Vector2 to, float boxSize) { Path path = new Path(); PathJob job = new PathJob(); if ((System.DateTime.Now - g_Clock).Milliseconds > 4000 && (successes + oot + empties) > 0) Logger.LogCoreInfo("Pathfinding successrate: " + (((float)successes / (float)(successes + oot + empties)) * (100.0f))); if (debugOutput) Logger.LogCoreInfo("Recording this minion movement."); if (chart == null) Logger.LogCoreError("Tried to find a path without setting the map."); if (getMesh() == null) Logger.LogCoreError("Can't start pathfinding without initialising the AIMesh"); job.start = job.fromPositionToGrid(from); // Save start in grid info job.destination = job.fromPositionToGrid(to); // Save destination in grid info if (debugOutput) { Logger.LogCoreInfo("Going from (" + job.start.X + ", " + job.start.Y + ") to (" + job.destination.X + ", " + job.destination.Y); } job.insertObstructions(chart, getMesh()); // Ready the map. job.addToOpenList(job.start, null); // Let's start at the start. int tries; for (tries = 0; job.openList.Count != 0; tries++) // Go through the open list while it's not empty { if (debugOutput) Logger.LogCoreInfo("Going through openlist. Tries: " + tries + " | Objects on list: " + job.openList.Count); if (tries == MAX_PATHFIND_TRIES) { path.error = PathError.PATH_ERROR_OUT_OF_TRIES; oot++; //CORE_WARNING("PATH_ERROR_OUT_OF_TRIES"); path.waypoints = job.reconstructUnfinishedPath(); job.cleanPath(path); job.cleanLists(); return path; } else if (job.traverseOpenList(tries == 0)) { path.error = PathError.PATH_ERROR_NONE; successes++; //CORE_INFO("We finished a path."); path.waypoints = job.reconstructPath(); job.cleanPath(path); job.cleanLists(); return path; } } if (debugOutput) Logger.LogCoreInfo("Going through openlist. Tries: " + tries + " | Objects on list: " + job.openList.Count); //CORE_WARNING("PATH_ERROR_OPENLIST_EMPTY"); path.error = PathError.PATH_ERROR_OPENLIST_EMPTY; empties++; path.waypoints.Add(from); job.cleanPath(path); job.cleanLists(); return path; }
public static Path getPath(Vector2 from, Vector2 to, float boxSize) { Path path = new Path(); PathJob job = new PathJob(); if ((System.DateTime.Now - g_Clock).Milliseconds > 4000 && (successes + oot + empties) > 0) { Logger.LogCoreInfo("Pathfinding successrate: " + (((float)successes / (float)(successes + oot + empties)) * (100.0f))); } if (debugOutput) { Logger.LogCoreInfo("Recording this minion movement."); } if (chart == null) { Logger.LogCoreError("Tried to find a path without setting the map."); } if (getMesh() == null) { Logger.LogCoreError("Can't start pathfinding without initialising the AIMesh"); } job.start = job.fromPositionToGrid(from); // Save start in grid info job.destination = job.fromPositionToGrid(to); // Save destination in grid info if (debugOutput) { Logger.LogCoreInfo("Going from (" + job.start.X + ", " + job.start.Y + ") to (" + job.destination.X + ", " + job.destination.Y); } job.insertObstructions(chart, getMesh()); // Ready the map. job.addToOpenList(job.start, null); // Let's start at the start. int tries; for (tries = 0; job.openList.Count != 0; tries++) // Go through the open list while it's not empty { if (debugOutput) { Logger.LogCoreInfo("Going through openlist. Tries: " + tries + " | Objects on list: " + job.openList.Count); } if (tries == MAX_PATHFIND_TRIES) { path.error = PathError.PATH_ERROR_OUT_OF_TRIES; oot++; //CORE_WARNING("PATH_ERROR_OUT_OF_TRIES"); path.waypoints = job.reconstructUnfinishedPath(); job.cleanPath(path); job.cleanLists(); return(path); } else if (job.traverseOpenList(tries == 0)) { path.error = PathError.PATH_ERROR_NONE; successes++; //CORE_INFO("We finished a path."); path.waypoints = job.reconstructPath(); job.cleanPath(path); job.cleanLists(); return(path); } } if (debugOutput) { Logger.LogCoreInfo("Going through openlist. Tries: " + tries + " | Objects on list: " + job.openList.Count); } //CORE_WARNING("PATH_ERROR_OPENLIST_EMPTY"); path.error = PathError.PATH_ERROR_OPENLIST_EMPTY; empties++; path.waypoints.Add(from); job.cleanPath(path); job.cleanLists(); return(path); }