Example #1
0
        public Path CreatePath(Location fromLoc, Location toLoc,
                               float howClose,
                               ILocationHeuristics locationHeuristics)
        {
            GSpellTimer t    = new GSpellTimer(0);
            Spot        from = FindClosestSpot(fromLoc, MinStepLength);
            Spot        to   = FindClosestSpot(toLoc, MinStepLength);

            if (from == null)
            {
                from = AddAndConnectSpot(new Spot(fromLoc));
            }
            if (to == null)
            {
                to = AddAndConnectSpot(new Spot(toLoc));
            }

            Path rawPath = CreatePath(from, to, to.location, howClose, true, locationHeuristics);


            if (rawPath != null && paint != null)
            {
                Location prev = null;
                for (int i = 0; i < rawPath.Count(); i++)
                {
                    Location l = rawPath.Get(i);
                    paint.AddBigMarker(l.X, l.Y, l.Z);
                    if (prev != null)
                    {
                        paint.PaintPath(l.X, l.Y, l.Z + 3, prev.X, prev.Y, prev.Z + 3);
                    }
                    prev = l;
                }
            }
            PPather.WriteLine("CreatePath took " + -t.TicksLeft);
            if (rawPath == null)
            {
                return(null);
            }
            else
            {
                Location last = rawPath.GetLast();
                if (last.GetDistanceTo(toLoc) > 1.0)
                {
                    rawPath.AddLast(toLoc);
                }
            }
            return(rawPath);
        }
Example #2
0
        public Path CreatePath(Location fromLoc, Location toLoc,
                               float howClose,
                               ILocationHeuristics locationHeuristics)
        {
            System.DateTime t    = System.DateTime.Now;
            Spot            from = FindClosestSpot(fromLoc, MinStepLength);
            Spot            to   = FindClosestSpot(toLoc, MinStepLength);

            if (from == null)
            {
                from = AddAndConnectSpot(new Spot(fromLoc));
            }
            if (to == null)
            {
                to = AddAndConnectSpot(new Spot(toLoc));
            }

            Path rawPath = CreatePath(from, to, to.location, howClose, true, locationHeuristics);


            if (rawPath != null && paint != null)
            {
                Location prev = null;
                for (int i = 0; i < rawPath.Count; i++)
                {
                    Location l = rawPath.Get(i);
                    paint.AddBigMarker(l.X, l.Y, l.Z);
                    if (prev != null)
                    {
                        paint.PaintPath(l.X, l.Y, l.Z + 3, prev.X, prev.Y, prev.Z + 3);
                    }
                    prev = l;
                }
            }
            Console.WriteLine("CreatePath took {0}", System.DateTime.Now.Subtract(t).Seconds);
            if (rawPath == null)
            {
                return(null);
            }
            else
            {
                Location last = rawPath.GetLast();
                if (last.GetDistanceTo(toLoc) > 1.0)
                {
                    rawPath.AddLast(toLoc);
                }
            }
            return(rawPath);
        }