예제 #1
0
파일: Moving.cs 프로젝트: Bia10/boogiebot
        public MoveResult move()
        {
            if (GiveUpIfUnsafe) // fixme
            {
                //if (!pather.IsItSafeAt(Me.Target, Me.Location))
                //    return MoveResult.Unsafe;
            }
            if (PathTimeout.IsReady)
            {
                MoveAlong = null;
            }
            BoogieCore.Log(LogType.System, "[Mover] MoveAlong = {0}", MoveAlong);
            if (MoveAlong == null)
            {
                Location from = new Location(Me.Location);
                mover.Stop();
                Path path = world.CreatePath(from, target, (float)4.5, PPather.radar); //fixme
                PathTimeout.Reset();
                BoogieCore.Log(LogType.System, "[Mover (New)] PathCount = {0}", path.Count());
                if (path == null || path.Count() == 0)
                {
                    //Context.Log("EasyMover: Can not create path . giving up");
                    mover.MoveRandom();
                    Thread.Sleep(200);
                    mover.Stop();
                    return(MoveResult.CantFindPath);
                }
                else
                {
                    //Context.Log("Save path to " + pathfile);
                    //path.Save(pathfile);
                    MoveAlong = new MoveAlonger(pather, path);
                }
            }

            if (MoveAlong != null)
            {
                Location from = new Location(Me.Location);
                BoogieCore.Log(LogType.System, "[Mover ] PathCount = {0}", MoveAlong.path.Count());

                if (MoveAlong.path.Count() == 0 || from.GetDistanceTo(target) < (float)5.0)
                {
                    BoogieCore.Log(LogType.System, "[Mover] Count = 0 or Dist < 5.0");
                    MoveAlong = null;
                    mover.Stop();
                    return(MoveResult.GotThere);
                }
                else if (!MoveAlong.MoveAlong())
                {
                    BoogieCore.Log(LogType.System, "[Mover] Stuck!!");
                    MoveAlong = null; // got stuck!
                    if (GiveUpIfStuck)
                    {
                        return(MoveResult.Stuck);
                    }
                }
            }
            return(MoveResult.Moving);
        }
예제 #2
0
        public MoveResult move(double howClose)
        {
            if (GiveUpIfUnsafe)
            {
                if (!pather.IsItSafeAt(Me.Target, Me.Location))
                {
                    return(MoveResult.Unsafe);
                }
            }
            if (PathTimeout.IsReady)
            {
                MoveAlong = null;
            }
            if (MoveAlong == null)
            {
                Location from = new Location(Me.Location);
                mover.Stop();
                Path path = world.CreatePath(from, target, (float)howClose, PPather.radar);
                PathTimeout.Reset();
                if (path == null || path.Count() == 0)
                {
                    PPather.WriteLine("EasyMover: Can not create path . giving up");
                    mover.MoveRandom();
                    Thread.Sleep(200);
                    mover.Stop();
                    return(MoveResult.CantFindPath);
                }
                else
                {
                    //PPather.WriteLine("Save path to " + pathfile);
                    //path.Save(pathfile);
                    MoveAlong = new MoveAlonger(pather, path);
                }
            }

            if (MoveAlong != null)
            {
                Location from = new Location(Me.Location);

                if (MoveAlong.path.Count() == 0 || from.GetDistanceTo(target) < howClose)
                {
                    //PPather.WriteLine("Move along used up");
                    MoveAlong = null;
                    mover.Stop();
                    return(MoveResult.GotThere);
                }
                else if (!MoveAlong.MoveAlong())
                {
                    MoveAlong = null;                     // got stuck!
                    if (GiveUpIfStuck)
                    {
                        return(MoveResult.Stuck);
                    }
                }
            }
            return(MoveResult.Moving);
        }
예제 #3
0
파일: PPather.cs 프로젝트: Bia10/boogiebot
        public bool Approach(BoogieBot.Common.Object monster, bool AbortIfUnsafe, int timeout)
        {
            BoogieCore.Log(LogType.System, "[Approach] 1");
            Coordinate loc    = monster.GetCoordinates();
            float      DistTo = loc.DistanceTo(BoogieCore.world.getPlayerObject().GetCoordinates());

            BoogieCore.Log(LogType.System, "[Approach] Distance to object: {0}", DistTo);
            if (DistTo < 4.5f &&
                Math.Abs(loc.O) < PI / 8)
            {
                mover.Stop();
                return(true);
            }

            GSpellTimer   approachTimeout = new GSpellTimer(timeout, false);
            StuckDetecter sd              = new StuckDetecter(this, 1, 2);
            GSpellTimer   t               = new GSpellTimer(0);
            bool          doJump          = random.Next(4) == 0;
            EasyMover     em              = null;
            GSpellTimer   NewTargetUpdate = new GSpellTimer(1000);


            BoogieCore.Log(LogType.System, "[Approach] 2");
            do
            {
                BoogieCore.Log(LogType.System, "[Approach] 3");
                UpdateMyPos();
                BoogieCore.Log(LogType.System, "[Approach] 4");
                // Check for stuck
                if (sd.checkStuck())
                {
                    BoogieCore.Log(LogType.System, "[Approach] 5");
                    BoogieCore.Log(LogType.System, "Major stuck on approach. Giving up");
                    mover.Stop();
                    return(false);
                }
                double distance = monster.GetCoordinates().DistanceTo(BoogieCore.world.getPlayerObject().GetCoordinates());
                BoogieCore.Log(LogType.System, "[Approach] 6 - Dist = {0}", distance);
                bool moved;

                if (distance < 8)
                {
                    loc = monster.GetCoordinates();
                    BoogieCore.Log(LogType.System, "[Approach] 7");
                    moved = mover.moveTowardsFacing(loc, 4.5f, loc);
                    BoogieCore.Log(LogType.System, "[Approach] 8 {0}", moved);
                }
                else
                {
                    BoogieCore.Log(LogType.System, "[Approach] 9");
                    if (em == null)
                    {
                        loc = monster.GetCoordinates();
                        em  = new EasyMover(this, new Location(loc), false, AbortIfUnsafe);
                    }
                    BoogieCore.Log(LogType.System, "[Approach] 10");
                    EasyMover.MoveResult mr = em.move();
                    BoogieCore.Log(LogType.System, "[Approach] 11 {0}", mr);
                    moved = true;
                    if (mr != EasyMover.MoveResult.Moving)
                    {
                        moved = false;
                    }
                    BoogieCore.Log(LogType.System, "[Approach] 12");
                }
                BoogieCore.Log(LogType.System, "[Approach] 13");

                if (!moved)
                {
                    mover.Stop();
                    return(true);
                }
            } while (!approachTimeout.IsReadySlow);
            mover.Stop();
            BoogieCore.Log(LogType.System, "Approach timed out");
            return(false);
        }
예제 #4
0
파일: Moving.cs 프로젝트: Bia10/boogiebot
        public bool MoveAlong()
        {
            double     max  = 3.0;
            Coordinate loc  = Me.Location;
            Location   isAt = new Location(loc.X, loc.Y, loc.Z);

            /*
             * while (isAt.GetDistanceTo(current) < max && next != null)
             * {
             *  //Context.Log(current + " - " + next);
             *  path.RemoveFirst();
             *  if (path.Count() == 0)
             *  {
             *      //Context.Log("ya");
             *      //return true; // good in some way
             *  }
             *  else
             *  {
             *      prev = current;
             *      current = path.GetFirst();
             *      next = path.GetSecond();
             *  }
             * }
             */
            bool consume = false;

            do
            {
                bool blocked = false;

                consume = false;
                if (next != null)
                {
                    world.triangleWorld.IsStepBlocked(loc.X, loc.Y, loc.Z, next.X, next.Y, next.Z,
                                                      PathGraph.toonHeight, PathGraph.toonSize, null);
                }
                double d = isAt.GetDistanceTo(current);
                if ((d < max && !blocked) ||
                    d < 1.5)
                {
                    consume = true;
                }

                if (consume)
                {
                    //GContext.Main.Log("Consume spot " + current + " d " + d + " block " + blocked);
                    path.RemoveFirst();
                    if (path.Count() == 0)
                    {
                        break;
                    }
                    else
                    {
                        prev    = current;
                        current = path.GetFirst();
                        next    = path.GetSecond();
                    }
                }
            } while (consume);

            {
                //Context.Log("Move towards " + current);
                Coordinate gto = new Coordinate((float)current.X, (float)current.Y, (float)current.Z);
                Coordinate face;
                if (next != null)
                {
                    face = new Coordinate(next.X, next.Y, next.Z);
                }
                else
                {
                    face = gto;
                }

                if (!mover.moveTowardsFacing(gto, 0.5, face))
                {
                    //Context.Log("Can't move " + current);
                    world.BlacklistStep(prev, current);
                    //world.MarkStuckAt(loc, Me.Heading);
                    mover.MoveRandom();
                    Thread.Sleep(500);
                    mover.Stop();
                    return(false);
                    // hmm, mover does not want to move, must be up or down
                }

                {
                    double h; double speed;
                    h = mover.GetMoveHeading(out speed);
                    float stand_z = 0.0f;
                    int   flags   = 0;
                    float x       = isAt.X + (float)Math.Cos(h) * 1.0f;
                    float y       = isAt.Y + (float)Math.Sin(h) * 1.0f;
                    float z       = isAt.Z;
                    bool  aheadOk = world.triangleWorld.FindStandableAt(x, y,
                                                                        z - 4,
                                                                        z + 6,
                                                                        out stand_z, out flags, 0, 0);
                    if (!aheadOk)
                    {
                        blockCount++;
                        world.MarkStuckAt(isAt, Me.Location.O);

                        if (prev != null)
                        {
                            Coordinate gprev = new Coordinate((float)prev.X, (float)prev.Y, (float)prev.Z);

                            if (!mover.moveTowardsFacing(gprev, 0.5, face))
                            {
                                mover.Stop();
                                return(false);
                            }
                        }
                        if (blockCount > 1)
                        {
                            world.BlacklistStep(prev, current);
                            return(false);
                        }

                        return(true);
                    }
                    else
                    {
                        blockCount = 0;
                    }
                }


                if (sd.checkStuck())
                {
                    //Context.Log("Stuck at " + isAt);
                    world.MarkStuckAt(isAt, (float)Me.Heading);
                    world.BlacklistStep(prev, current);
                    mover.Stop();
                    return(false);
                }
            }
            return(true);
        }