Пример #1
0
        public BotAction GetNextAction()
        {
            BotAction        act            = CurrentAction;
            List <BotAction> KnownBotAcions = GetPossibleActions(MaxThinkAboutDistance, MaxSupportedZChange);

            lock (KnownBotAcions)
            {
                if (KnownBotAcions.Count > 0)
                {
                    act = KnownBotAcions[0];// (BotAction)FindBestUsage(KnownBotAcions);
                }
                if (act == null)
                {
                    SimRegion R = Actor.GetSimRegion();
                    if (R == null)
                    {
                        return(new CommandAction(Actor, "anim shrug"));
                    }
                    Vector3d v3d =
                        R.LocalToGlobal(new Vector3(MyRandom.Next(250) + 5, MyRandom.Next(250) + 5,
                                                    Actor.SimPosition.Z));
                    Actor.Debug("MoveToLocation: " + Actor.DistanceVectorString(v3d));
                    SimPosition WP = SimWaypointImpl.CreateGlobal(v3d);
                    act = new MoveToLocation(Actor, WP);
                }
                return(act);
            }
        }
Пример #2
0
        private SimPosition GetSimV(string[] tokens, int start, out int argsUsed, SimPosition offset)
        {
            // not enough args
            if (tokens.Length < start)
            {
                argsUsed = 0;
                return(offset);
            }
            if (start > 0)
            {
                tokens = Parser.SplitOff(tokens, start);
                start  = 0;
            }
            int    maxArgs = 0;
            string first   = tokens[0];

            argsUsed = 1;
            if (first == "last")
            {
                return(offset);
            }
            if (first.EndsWith("s"))
            {
                first = first.Substring(0, first.Length - 1);
            }
            if (first == "forward")
            {
                return(SimOffsetPosition.WithOrientation(offset, new Vector3(0, 1, 0)));
            }
            if (first.EndsWith("ward"))
            {
                first = first.Substring(0, first.Length - 4);
            }
            if (first == "west")
            {
                return(new SimOffsetPosition(offset, new Vector3(-1, 0, 0)));
            }
            if (first == "east")
            {
                return(new SimOffsetPosition(offset, new Vector3(1, 0, 0)));
            }
            if (first == "north")
            {
                return(new SimOffsetPosition(offset, new Vector3(0, 1, 0)));
            }
            if (first == "south")
            {
                return(new SimOffsetPosition(offset, new Vector3(0, -1, 0)));
            }
            if (first == "left")
            {
                return(SimOffsetPosition.WithOrientation(offset, new Vector3(-1, 0, 0)));
            }
            if (first == "right")
            {
                return(SimOffsetPosition.WithOrientation(offset, new Vector3(1, 0, 0)));
            }
            if (first == "back")
            {
                return(SimOffsetPosition.WithOrientation(offset, new Vector3(0, -1, 0)));
            }
            if (first.Contains("/"))
            {
                argsUsed = 1;
                int uu;
                return(GetSimV(first.Split(new char[] { '/' }), 0, out uu, offset));
            }
            bool relative = false;

            for (int st = start; st < tokens.Length; st++)
            {
                if (maxArgs > 2)
                {
                    break;
                }
                string str = tokens[st];
                double doublke;
                if (double.TryParse(str, out doublke))
                {
                    maxArgs++;
                }
                else
                {
                    break;
                }
            }
            Vector3 rel = offset.SimPosition;
            Vector3 target;

            first = tokens[start];
            // Polar coords
            if (first.Contains("*"))
            {
                return(GetPolarRelative(offset, first, out argsUsed));
            }

            if (RelTryParse(first, out target.X, rel.X) &&
                RelTryParse(tokens[start + 1], out target.Y, rel.Y))
            {
                argsUsed = 2;
                target.Z = rel.Z;
                if (tokens.Length > start + 1)
                {
                    RelTryParse(tokens[start + 2], out target.Z, rel.Z);
                    argsUsed = 3;
                }
                if (target.X > 512 || target.Y > 512)
                {
                    // Globals
                    return(SimWaypointImpl.CreateGlobal(target.X, target.Y, target.Z));
                }
                return(SimWaypointImpl.CreateLocal(target, offset.PathStore));
            }
            argsUsed = 0;
            return(null);
        }
Пример #3
0
        public SimPosition GetVector(string[] args, out int argsUsed, SimPosition offset)
        {
            argsUsed = 0;
            if (args.Length == 0)
            {
                return(offset ?? TheSimAvatar);
            }
            //if (args.Length >= 2)
            {
                SimPosition R = GetSimV(args, 0, out argsUsed, offset);
                if (R != null)
                {
                    return(R);
                }
            }
            UUID uuid = UUID.Zero;

            if (UUID.TryParse(args[0], out uuid))
            {
                SimObject O = null;
                O = GetSimObjectFromUUID(uuid);
                if (O != null)
                {
                    argsUsed = 1;
                    return(O);
                }
            }

            List <SimObject> prim = GetSingleArg(args, out argsUsed);

            if (prim.Count == 1)
            {
                return(prim[0]);
            }


            argsUsed = 0;
            string destination = String.Empty;

            // Handle multi-word sim names by combining the arguments
            foreach (string arg in args)
            {
                destination += arg + " ";
            }
            int consume = args.Length;

            destination = destination.Trim();

            string[] tokens = destination.Split(new char[] { '/' });
            float    x, y = 128;

            if (!float.TryParse(tokens[0], out x))
            {
                x = 128;
            }
            else
            {
                argsUsed++;
            }
            string sim = tokens[argsUsed];

            //TODO use the GetSimV code
            argsUsed += 1;
            float z = -1;

            if (tokens.Length > argsUsed + 1)
            {
                if (!float.TryParse(tokens[argsUsed], out x) ||
                    !float.TryParse(tokens[argsUsed + 1], out y))
                {
                    return(null);
                }
                argsUsed += 2;
                if (tokens.Length > argsUsed)
                {
                    if (float.TryParse(tokens[argsUsed], out z))
                    {
                        argsUsed += 1;
                    }
                    else
                    {
                        z = -1;
                    }
                }
                // test for global
                if (x > 512 || y > 512)
                {
                    float.TryParse(tokens[argsUsed], out z);
                    return(SimWaypointImpl.CreateGlobal(x, y, z));
                }
            }
            SimRegion region = SimRegion.GetRegion(sim, client);

            if (region == null)
            {
                return(null);
            }
            if (z == -1)
            {
                z = region.AverageHieght;
            }

            Vector3 v3 = new Vector3(x, y, z);

            return(SimWaypointImpl.CreateLocal(v3, region.GetPathStore(v3)));
        }
Пример #4
0
        private SimPosition GetPolarRelative(SimPosition offset, string first, out int argsUsed)
        {
            Vector3 rel  = offset.SimPosition;
            int     star = first.IndexOf("*");

            if (star < 0)
            {
                argsUsed = 0;
                return(offset);
            }

            // -180*5 == *-5
            // -180*5
            // +90*5
            // +180* == -180* == -0*-1
            // +0*5 == -0*5 == *5
            //
            bool   relative;
            double rotate;
            double dist = 1.0;

            if (star == 0)
            {
                relative = true;
                rotate   = 0.0;
                float f;
                if (RelTryParse(first.Substring(1), out f, 0))
                {
                    dist = f;
                }
            }
            else
            {
                string arg = first.Substring(0, star);
                relative = true;
                if (arg.StartsWith("A"))
                {
                    relative = false;
                    arg      = arg.Substring(1);
                }

                float f;
                float offsetZ = (float)(GetZHeading(offset.SimRotation) * 180 / Math.PI);
                if (!RelTryParse(arg, out f, offsetZ))
                {
                    argsUsed = 0;
                    return(offset);
                }
                rotate = f;
                string firstSubstring = first.Substring(star + 1);
                if (firstSubstring.Length == 0)
                {
                    dist = 1.0;
                }
                else if (RelTryParse(firstSubstring, out f, 0))
                {
                    dist = f;
                }
                else
                {
                    argsUsed = 0;
                    return(offset);
                }
            }

            Vector3 v3 = Vector3.Transform(Vector3.UnitX, Matrix4.CreateFromQuaternion(offset.SimRotation));

            v3.X     = (float)(Math.Sin(rotate * (Math.PI / 180)) * dist) + rel.X;
            v3.Y     = (float)(Math.Cos(rotate * (Math.PI / 180)) * dist) + rel.Y;
            v3.Z     = rel.Z;
            argsUsed = 1;
            return(SimWaypointImpl.CreateLocal(v3, offset.PathStore));
        }