示例#1
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);
        }