Exemplo n.º 1
0
        public override void Execute(SharedObjects shared)
        {
            string pointName = PopValueAssert(shared).ToString();

            AssertArgBottomAndConsume(shared);

            WaypointManager wpm = WaypointManager.Instance();

            if (wpm == null) // When zero waypoints exist, there might not even be a waypoint manager.
            {
                ReturnValue = null;
                // I don't like returning null here without the user being able to test for that, but
                // we don't have another way to communicate "no such waypoint".  We really need to address
                // that problem once and for all.
                return;
            }

            string   baseName;
            int      index;
            bool     hasGreek = WaypointValue.GreekToInteger(pointName, out index, out baseName);
            Waypoint point    = wpm.AllWaypoints().FirstOrDefault(
                p => String.Equals(p.name, baseName, StringComparison.CurrentCultureIgnoreCase) && (!hasGreek || p.index == index));

            ReturnValue = new WaypointValue(point, shared);
        }
Exemplo n.º 2
0
        public override void Execute(SharedObjects shared)
        {
            string pointName = PopValueAssert(shared).ToString();

            AssertArgBottomAndConsume(shared);

            WaypointManager wpm = WaypointManager.Instance();

            // If no contracts have been generated with waypoints in them,
            // then sometimes the stock game's waypoint manager doesn't even
            // exist yet either.  (The base game seems not to instance one until the
            // first time a contract with a waypoint is created).
            if (wpm == null)
            {
                throw new KOSInvalidArgumentException("waypoint", "\"" + pointName + "\"", "no waypoints exist");
            }

            // If this name has a greek letter in it's spelling like "alpha", "beta", etc, then it
            // is probably part of a waypoint cluster.
            // Waypoint clusters are actually 1 waypoint with an array of "children" by index number.
            // where the waypoint's name is just the base part with the "alpha", "beta", etc suffix removed.
            string baseName;
            int    index;
            bool   hasGreek = WaypointValue.GreekToInteger(pointName, out index, out baseName);

            Waypoint point = null;

            if (hasGreek) // Attempt to find it as part of a waypoint cluster.
            {
                point = wpm.Waypoints.FirstOrDefault(
                    p => string.Equals(p.name, baseName, StringComparison.CurrentCultureIgnoreCase) && (!hasGreek || p.index == index));
                if (point != null) // Will be null if this name is not really a waypoint cluster.
                {
                    pointName = baseName;
                }
            }
            if (point == null) // Either it had no greek letter, or it did but wasn't a waypoint cluster.  Try it as a vanilla waypoint:
            {
                point = wpm.Waypoints.FirstOrDefault(
                    p => string.Equals(p.name, pointName, StringComparison.CurrentCultureIgnoreCase) && (!hasGreek || p.index == index));
            }

            // If it's still null at this point then give up - we can't find such a waypoint name:
            if (point == null)
            {
                throw new KOSInvalidArgumentException("waypoint", "\"" + pointName + "\"", "no such waypoint");
            }

            ReturnValue = WaypointValue.CreateWaypointValueWithCheck(point, shared, false);
        }
Exemplo n.º 3
0
        public override void Execute(SharedObjects shared)
        {
            string pointName = PopValueAssert(shared).ToString();

            AssertArgBottomAndConsume(shared);

            WaypointManager wpm = WaypointManager.Instance();

            // If no contracts have been generated with waypoints in them,
            // then sometimes the stock game's waypoint manager doesn't even
            // exist yet either.  (The base game seems not to instance one until the
            // first time a contract with a waypoint is created).
            if (wpm == null)
            {
                throw new KOSInvalidArgumentException("waypoint", "\"" + pointName + "\"", "no waypoints exist");
            }

            string baseName;
            int    index;
            bool   hasGreek = WaypointValue.GreekToInteger(pointName, out index, out baseName);

            if (hasGreek)
            {
                pointName = baseName;
            }
            Waypoint point = wpm.Waypoints.FirstOrDefault(
                p => string.Equals(p.name, pointName, StringComparison.CurrentCultureIgnoreCase) && (!hasGreek || p.index == index));

            // We can't communicate the concept of a lookup fail to the script in a way it can catch (can't do
            // nulls), so bomb out here:
            if (point == null)
            {
                throw new KOSInvalidArgumentException("waypoint", "\"" + pointName + "\"", "no such waypoint");
            }

            ReturnValue = new WaypointValue(point, shared);
        }