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); }
public override void Execute(SharedObjects shared) { AssertArgBottomAndConsume(shared); // no args // ReSharper disable SuggestUseVarKeywordEvident ListValue <WaypointValue> returnList = new ListValue <WaypointValue>(); // ReSharper enable SuggestUseVarKeywordEvident WaypointManager wpm = WaypointManager.Instance(); if (wpm == null) { ReturnValue = returnList; // When no waypoints exist, there isn't even a waypoint manager at all. return; } List <Waypoint> points = wpm.AllWaypoints(); // If the code below gets used in more places it may be worth moving into a factory method // akin to how PartValueFactory makes a ListValue<PartValue> from a List<Part>. // But for now, this is the only place it's done: foreach (Waypoint point in points) { returnList.Add(new WaypointValue(point, shared)); } ReturnValue = returnList; }
public override void Execute(SharedObjects shared) { string pointName = shared.Cpu.PopValue().ToString(); WaypointManager wpm = WaypointManager.Instance(); if (wpm == null) { shared.Cpu.PushStack(null); // When no waypoints exist, there isn't even a waypoint manager. // 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; } Waypoint point = wpm.AllWaypoints().FirstOrDefault(p => String.Equals(p.name, pointName, StringComparison.CurrentCultureIgnoreCase)); shared.Cpu.PushStack(new WaypointValue(point, shared)); }
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.AllWaypoints().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); }