示例#1
0
        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;
        }
示例#2
0
        public void cleanPath(Path path)
        {
            return;
            /* if (path.waypoints.size() < 2) return;
             int startSize = path.waypoints.size();
             CORE_WARNING("Cleaning path.. Current size is %d", startSize);

             int dirX = 0, dirY = 0;
             auto prevPoint = path.waypoints.begin();
             for (auto i = path.waypoints.begin() + 1; i != path.waypoints.end(); i++)
             {
                 if (((*i).X - (*prevPoint).X == dirX) &&
                    ((*i).Y - (*prevPoint).Y == dirY))
                 {
                     path.waypoints.erase(prevPoint);
                     CORE_WARNING("Erased a waypoint");
                 }
                 else
                 {
                     dirX = ((*i).X - (*prevPoint).X);
                     dirY = ((*i).Y - (*prevPoint).Y);
                 }

                 prevPoint = i;
             }

             CORE_WARNING("Done cleaning. New size is %d", path.waypoints.size());
             if (startSize != path.waypoints.size())
                 CORE_WARNING("Removed %d nodes", startSize - path.waypoints.size());*/
        }