예제 #1
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);
        }
예제 #2
0
        public bool checkStuck()
        {
            if (firstStuckCheck)
            {
                oldLocation     = GContext.Main.Me.Location;
                predictedDX     = 0;
                predictedDY     = 0;
                firstStuckCheck = false;
                lastStuckCheck.Reset();
            }
            else
            {
                // update predicted location
                double h;
                double speed;
                h = mover.GetMoveHeading(out speed);

                float dt = (float)-lastStuckCheck.TicksLeft / 1000f;
                float dx = (float)Math.Cos(h) * (float)speed * dt;
                float dy = (float)Math.Sin(h) * (float)speed * dt;
                //PPather.WriteLine("speed: " + speed + " dt: " + dt + " dx: " + dx + " dy : " + dy);
                predictedDX += dx;
                predictedDY += dy;

                lastStuckCheck.Reset();
                if (StuckTimeout.IsReady)
                {
                    // Check stuck
                    GLocation loc    = Me.Location;
                    float     realDX = loc.X - oldLocation.X;
                    float     realDY = loc.Y - oldLocation.Y;
                    //PPather.WriteLine(" dx: " + predictedDX + " dy : " + predictedDY + " Real dx: " + realDX + " dy : " + realDY );

                    float predictDist = (float)Math.Sqrt(predictedDX * predictedDX + predictedDY * predictedDY);
                    float realDist    = (float)Math.Sqrt(realDX * realDX + realDY * realDY);

                    //PPather.WriteLine(" pd " + predictDist + " rd " + realDist);

                    int multiplier = 3;
                    if (GPlayerSelf.Me.IsStealth)
                    {
                        multiplier = 4;
                    }

                    if (predictDist > realDist * multiplier)
                    {
                        // moving a lot slower than predicted
                        // check direction
                        GLocation excpected = new GLocation(loc.X + predictedDX, loc.Y + predictedDY);

                        PPather.WriteLine("I am stuck " + stuckMove);                         //. Jumping to get free");
                        if (stuckMove == 0)
                        {
                            mover.Forwards(false);
                            mover.Forwards(true);
                            mover.StrafeLeft(true);
                            //mover.Jump();
                            //mover.StrafeRight(false);
                        }
                        else if (stuckMove == 1)
                        {
                            mover.Forwards(false);
                            mover.Forwards(true);
                            mover.StrafeLeft(true);
                            //PPather.WriteLine("  strafe left");
                            //mover.Jump();
                            //mover.StrafeLeft(false);
                        }
                        else if (stuckMove == 2)
                        {
                            mover.Forwards(false);
                            mover.Forwards(true);
                            mover.StrafeRight(true);
                            //PPather.WriteLine("  strafe left");
                            //mover.StrafeLeft(true);
                        }
                        else if (stuckMove == 2)
                        {
                            mover.Forwards(false);
                            mover.Forwards(true);
                            mover.StrafeRight(true);
                            //PPather.WriteLine("  strafe left");
                            //mover.StrafeLeft(true);
                        }
                        stuckMove++;
                        if (stuckMove >= abortSensitivity)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        stuckMove = 0;
                    }
                    predictedDX = 0;
                    predictedDY = 0;
                    oldLocation = loc;
                    StuckTimeout.Reset();
                }
            }
            return(false);
        }