Esempio n. 1
0
 private void PrintPathToConsole(NetworkPathAlgorithm npa)
 {
     foreach (WayPoint wp in npa.Path)
     {
         Console.Write("" + wp);
     }
 }
Esempio n. 2
0
        public bool FindPath(Mobile mob, WayPoint start, WayPoint goal, out List <WayPoint> path)
        {
            NetworkPathAlgorithm npa = new NetworkPathAlgorithm();
            // Initial search
            NetworkPathState result = npa.FindPath(mob, start, goal, DEPTH, new List <WayPoint>());

            // Unable to find a path at all
            if (result == NetworkPathState.Failure || result == NetworkPathState.ExceededDepth)
            {
                path = null;
                return(false);
            }

            if (mob is PathTester && ((BaseCreature)mob).Debug)
            {
                //PrintPathToConsole(npa);
                Console.WriteLine("Path found, looking for better paths...");

                /*
                 * Console.Write("Path: ");
                 * foreach (WayPoint wp in npa.Path)
                 *      Console.Write(""+wp);
                 * Console.WriteLine("");
                 * Console.Write("Branches List: ");
                 * foreach (WayPoint wp in npa.Branches)
                 *      Console.Write(""+wp);
                 * Console.WriteLine("");
                 */
            }

            // If there were branches we didn't take its time to explore them
            int i = 0;

            while (i < npa.Branches.Count)
            {
                NetworkPathAlgorithm npa2      = new NetworkPathAlgorithm();
                List <WayPoint>      forcelist = new List <WayPoint>();
                forcelist.Add(npa.Branches[i]);
                if (mob is PathTester && ((BaseCreature)mob).Debug)
                {
                    Console.WriteLine("Considering alternate path from WayPoint: " + npa.Branches[i] + " X:" + npa.Branches[i].Location.X + " Y:" + npa.Branches[i].Location.Y + " Z:" + npa.Branches[i].Location.Z);
                }
                result = npa2.FindPath(mob, start, goal, npa.Path.Count + (int)(npa.Path.Count * 0.2), forcelist);

                if (result == NetworkPathState.Success)
                {
                    //PrintPathToConsole(npa2);
                    if (mob is PathTester && ((BaseCreature)mob).Debug)
                    {
                        Console.WriteLine("Evaluation: " + npa2.Evaluate() + " vs " + npa.Evaluate());
                    }
                    // If new path is better then select this path
                    if (npa2.Evaluate() < npa.Evaluate())
                    {
                        if (mob is PathTester && ((BaseCreature)mob).Debug)
                        {
                            Console.WriteLine("Better path found!");
                        }
                        npa = npa2;
                    }
                }

                i++;
            }

            path = npa.Path;
            return(true);
        }