Beispiel #1
0
        public static ListValue PartList(this IShipconstruct vessel, string partType, SharedObjects sharedObj)
        {
            var list = new ListValue();
            var partList = vessel.Parts.ToList();

            switch (partType.ToUpper())
            {
                case "RESOURCES":
                    list = AggregateResourceValue.PartsToList(partList, sharedObj);
                    break;

                case "PARTS":
                    list = PartValueFactory.Construct(partList, sharedObj);
                    break;

                case "ENGINES":
                    list = EngineValue.PartsToList(partList, sharedObj);
                    break;

                case "SENSORS":
                    list = SensorValue.PartsToList(partList, sharedObj);
                    break;

                case "ELEMENTS":
                    list = ElementValue.PartsToList(partList, sharedObj);
                    break;

                case "DOCKINGPORTS":
                    list = DockingPortValue.PartsToList(partList, sharedObj);
                    break;
            }
            return list;
        }
Beispiel #2
0
        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.Waypoints;

            // 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;
        }
Beispiel #3
0
 public override object GetSuffix(string suffixName)
 {
     switch (suffixName)
     {
         case "NAME":
             return Part.name;
         case "STAGE":
             return Part.inverseStage;
         case "UID":
             return Part.uid;
         case "RESOURCES":
             var resources = new ListValue();
             foreach (PartResource resource in Part.Resources)
             {
                 resources.Add(new ResourceValue(resource));
             }
             return resources;
         case "MODULES":
             var modules = new ListValue();
             foreach (var module in Part.Modules)
             {
                 modules.Add(module.GetType());
             }
             return modules;
     }
     return base.GetSuffix(suffixName);
 }
Beispiel #4
0
        public override void Execute(SharedObjects shared)
        {
            string listType = shared.Cpu.PopValue().ToString();
            ListValue list = new ListValue();

            switch (listType)
            {
                case "bodies":
                    foreach (var body in FlightGlobals.fetch.bodies)
                    {
                        list.Add(new BodyTarget(body, shared.Vessel));
                    }
                    break;
                case "targets":
                    foreach (var vessel in FlightGlobals.Vessels)
                    {
                        if (vessel == shared.Vessel) continue;
                        list.Add(new VesselTarget(vessel, shared.Vessel));
                    }
                    break;
                case "resources":
                case "parts":
                case "engines":
                case "sensors":
                case "elements":
                    list = VesselUtils.PartList(shared.Vessel, listType);
                    break;
            }

            shared.Cpu.PushStack(list);
        }
Beispiel #5
0
        public override void Evaluate()
        {
            var name = new Term(RegexMatch.Groups[2].Value);
            var type = new Term(RegexMatch.Groups[1].Value);
            var list = new ListValue();

            switch (type.Text.ToUpper())
            {
                case "BODIES":
                    foreach (var body in FlightGlobals.fetch.bodies)
                    {
                        list.Add(new BodyTarget(body, Vessel));
                    }
                    break;
                case "TARGETS":
                    foreach (var vessel in FlightGlobals.Vessels)
                    {
                        if (vessel == Vessel) continue;
                        list.Add(new VesselTarget(vessel, ParentContext));
                    }
                    break;
            }

            if (list.Empty())
            {
                list = Vessel.PartList(type.Text);
            }

            FindOrCreateVariable(name.Text).Value = list;

            State = ExecutionState.DONE;
        }
Beispiel #6
0
 public ListValue<Node> GetAllNodes(SharedObjects shared)
 {
     var vessel = shared.Vessel;
     if (vessel.patchedConicSolver == null || vessel.patchedConicSolver.maneuverNodes.Count == 0)
         return new ListValue<Node>();
     var ret = new ListValue<Node>(vessel.patchedConicSolver.maneuverNodes.Select(e => Node.FromExisting(vessel, e, shared)));
     return ret;
 }
Beispiel #7
0
 public static ListValue PartsToList(IEnumerable<Part> parts)
 {
     var toReturn = new ListValue();
     foreach (var part in parts)
     {
         toReturn.Add(new PartValue(part));
     }
     return toReturn;
 }
Beispiel #8
0
 public static ListValue PartsToList(IEnumerable<global::Part> parts, SharedObjects shared)
 {
     var list = new ListValue();
     var resources = ProspectResources(parts, shared);
     foreach (var resource in resources)
     {
         list.Add(resource.Value);
     }
     return list;
 }
Beispiel #9
0
        public static ListValue PartsToList(IEnumerable<global::Part> parts)
        {
            var toReturn = new ListValue();

            foreach (var flightParts in parts.GroupBy(p => p.missionID))
            {
                toReturn.Add(new ElementValue(flightParts));
            }
            return toReturn;
        }
Beispiel #10
0
        private ListValue<ActiveResourceValue> GetResourceManifest()
        {
            var resources = shared.Vessel.GetActiveResources();
            var toReturn = new ListValue<ActiveResourceValue>();

            foreach (var resource in resources)
            {
                toReturn.Add(new ActiveResourceValue(resource, shared));
            }

            return toReturn;
        }
Beispiel #11
0
 public static new ListValue PartsToList(IEnumerable<Part> parts)
 {
     var toReturn = new ListValue();
     foreach (var part in parts)
     {
         foreach (PartModule module in part.Modules)
         {
             var engineModule = module as ModuleEngines;
             if (engineModule == null) continue;
             toReturn.Add(new EngineValue(part, engineModule));
         }
     }
     return toReturn;
 }
Beispiel #12
0
 public static new ListValue PartsToList(IEnumerable<Part> parts)
 {
     var toReturn = new ListValue();
     foreach (var part in parts)
     {
         foreach (PartModule module in part.Modules)
         {
             var sensor = module as ModuleEnviroSensor;
             if (sensor == null) continue;
             toReturn.Add(new SensorValue(part, sensor));
         }
     }
     return toReturn;
 }
        public override void Evaluate()
        {
            var name = new Term(RegexMatch.Groups[2].Value);
            var type = new Term(RegexMatch.Groups[1].Value);
            var list = new ListValue();

            var partList = Vessel.Parts.ToList();

            switch (type.Text.ToUpper())
            {
                case "BODIES":
                    foreach (var body in FlightGlobals.fetch.bodies)
                    {
                        list.Add(new BodyTarget(body, Vessel));
                    }
                    break;
                case "TARGETS":
                    foreach (var vessel in FlightGlobals.Vessels)
                    {
                        if (vessel == Vessel) continue;
                        list.Add(new VesselTarget(vessel, ParentContext));
                    }
                    break;
                case "RESOURCES":
                    list = ResourceValue.PartsToList(partList);
                    break;
                case "PARTS":
                    list = PartValue.PartsToList(partList);
                    break;
                case "ENGINES":
                    list = EngineValue.PartsToList(partList);
                    break;
                case "SENSORS":
                    list = SensorValue.PartsToList(partList);
                    break;
                case "ELEMENTS":
                    list = ElementValue.PartsToList(partList);
                    break;
            }

            FindOrCreateVariable(name.Text).Value = list;

            State = ExecutionState.DONE;
        }
Beispiel #14
0
        public override void Execute(SharedObjects shared)
        {
            string listType = PopValueAssert(shared).ToString();
            var list = new ListValue();

            switch (listType)
            {
                case "bodies":
                    foreach (CelestialBody cBody in FlightGlobals.fetch.bodies)
                    {                        
                        list.Add(new BodyTarget(cBody, shared));
                    }
                    break;
                case "targets":
                    foreach (var vessel in FlightGlobals.Vessels)
                    {
                        if (vessel == shared.Vessel) continue;
                        list.Add(new VesselTarget(vessel, shared));
                    }
                    break;
                case "resources":
                case "parts":
                case "engines":
                case "sensors":
                case "elements":
                case "dockingports":
                    list = shared.Vessel.PartList(listType, shared);
                    break;
                case "files":
                    list = ListValue.CreateList(shared.VolumeMgr.CurrentVolume.GetFileList());
                    break;
                case "volumes":
                    list = ListValue.CreateList(shared.VolumeMgr.Volumes.Values.ToList());
                    break;
                case "processors":
                    list = ListValue.CreateList(shared.ProcessorMgr.processors.Values.ToList().Select((processor) => PartModuleFieldsFactory.Construct(processor, shared)));
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
            AssertArgBottomAndConsume(shared);

            ReturnValue = list;
        }
Beispiel #15
0
 public static ListValue PartsToList(IEnumerable<Part> parts)
 {
     var list = new ListValue();
     var resources = new Dictionary<string, ResourceValue>();
     foreach (var part in parts)
     {
         foreach (PartResource module in part.Resources)
         {
             ResourceValue resourceAmount;
             if (!resources.TryGetValue(module.resourceName, out resourceAmount))
             {
                 resourceAmount = new ResourceValue(module.resourceName);
             }
             resourceAmount.AddResource(module);
             resources[module.resourceName] = resourceAmount;
         }
     }
     foreach (var resource in resources)
     {
         list.Add(resource.Value);
     }
     return list;
 }
Beispiel #16
0
        public static ListValue PartsToList(IEnumerable <global::Part> parts)
        {
            var list      = new ListValue();
            var resources = new Dictionary <string, ResourceValue>();

            foreach (var part in parts)
            {
                foreach (PartResource module in part.Resources)
                {
                    ResourceValue resourceAmount;
                    if (!resources.TryGetValue(module.resourceName, out resourceAmount))
                    {
                        resourceAmount = new ResourceValue(module.resourceName);
                    }
                    resourceAmount.AddResource(module);
                    resources[module.resourceName] = resourceAmount;
                }
            }
            foreach (var resource in resources)
            {
                list.Add(resource.Value);
            }
            return(list);
        }
Beispiel #17
0
 public override void Execute(SharedObjects shared)
 {
     Structure[] argArray = new Structure[CountRemainingArgs(shared)];
     for (int i = argArray.Length - 1 ; i >= 0 ; --i)
         argArray[i] = PopStructureAssertEncapsulated(shared); // fill array in reverse order because .. stack args.
     AssertArgBottomAndConsume(shared);
     var listValue = new ListValue(argArray.ToList());
     ReturnValue = listValue;
 }
Beispiel #18
0
        public ListValue<ScalarValue> GetRatesList(TimeWarp.Modes warpMode)
        {
            float[] ratesArray = GetRateArrayForMode(warpMode);

            ListValue<ScalarValue> ratesKOSList = new ListValue<ScalarValue>();

            // Have to convert the elements one at a time from (float) to (ScalarDoubleValue):
            foreach (float val in ratesArray)
                ratesKOSList.Add(val);

            return ratesKOSList;
        }
Beispiel #19
0
 private ListValue GetQuicksaveList()
 {
     var ret = new ListValue();
     string path = KSPUtil.GetOrCreatePath("saves/" + HighLogic.SaveFolder);
     var files = Directory.GetFiles(path, "*.sfs");
     foreach (var file in files)
     {
         string name = Path.GetFileNameWithoutExtension(file);
         if (!name.Equals("persistent"))
         {
             ret.Add(new StringValue(name));
         }
     }
     return ret;
 }
Beispiel #20
0
        private ListValue GetModulesInGroup(string groupName)
        {
            var matchGroup = KSPActionGroup.None;
            string upperName = groupName.ToUpper();

            // TODO: later refactor:  put this in a Dictionary lookup instead, and then share it
            // by both this code and the code in ActionGroup.cs:
            if (upperName == "SAS") { matchGroup = KSPActionGroup.SAS; }
            if (upperName == "GEAR") { matchGroup = KSPActionGroup.Gear; }
            if (upperName == "LIGHTS") { matchGroup = KSPActionGroup.Light; }
            if (upperName == "BRAKES") { matchGroup = KSPActionGroup.Brakes; }
            if (upperName == "RCS") { matchGroup = KSPActionGroup.RCS; }
            if (upperName == "ABORT") { matchGroup = KSPActionGroup.Abort; }
            if (upperName == "AG1") { matchGroup = KSPActionGroup.Custom01; }
            if (upperName == "AG2") { matchGroup = KSPActionGroup.Custom02; }
            if (upperName == "AG3") { matchGroup = KSPActionGroup.Custom03; }
            if (upperName == "AG4") { matchGroup = KSPActionGroup.Custom04; }
            if (upperName == "AG5") { matchGroup = KSPActionGroup.Custom05; }
            if (upperName == "AG6") { matchGroup = KSPActionGroup.Custom06; }
            if (upperName == "AG7") { matchGroup = KSPActionGroup.Custom07; }
            if (upperName == "AG8") { matchGroup = KSPActionGroup.Custom08; }
            if (upperName == "AG9") { matchGroup = KSPActionGroup.Custom09; }
            if (upperName == "AG10") { matchGroup = KSPActionGroup.Custom10; }

            ListValue kScriptParts = new ListValue();

            // This is almost identical to the logic in GetPartsInGroup and it might be a nice idea
            // later to merge them somehow:
            //
            if (matchGroup == KSPActionGroup.None) return kScriptParts;

            foreach (global::Part p in Vessel.parts)
                foreach (PartModule pm in p.Modules)
                {
                    if (pm.Actions.Any(a => a.actionGroup.Equals(matchGroup)))
                    {
                        kScriptParts.Add(PartModuleFieldsFactory.Construct(pm, Shared));
                    }
                }

            return kScriptParts;
        }
Beispiel #21
0
        public ListValue GetCrew() {
            var crew = new ListValue();

            foreach (var crewMember in Vessel.GetVesselCrew()) {
                crew.Add(new CrewMember(crewMember, Shared));
            }

            return crew;
        }
Beispiel #22
0
 private ListValue(ListValue toCopy)
 {
     list = new List<object>(toCopy.list);
 }
Beispiel #23
0
        private ListValue GetPartsInGroup(string groupName)
        {
            var matchGroup = KSPActionGroup.None;
            string upperName = groupName.ToUpper();

            // TODO: later refactor:  put this in a Dictionary lookup instead, and then share it
            // by both this code and the code in ActionGroup.cs:
            if (upperName == "SAS") { matchGroup = KSPActionGroup.SAS; }
            if (upperName == "GEAR") { matchGroup = KSPActionGroup.Gear; }
            if (upperName == "LIGHTS") { matchGroup = KSPActionGroup.Light; }
            if (upperName == "BRAKES") { matchGroup = KSPActionGroup.Brakes; }
            if (upperName == "RCS") { matchGroup = KSPActionGroup.RCS; }
            if (upperName == "ABORT") { matchGroup = KSPActionGroup.Abort; }
            if (upperName == "AG1") { matchGroup = KSPActionGroup.Custom01; }
            if (upperName == "AG2") { matchGroup = KSPActionGroup.Custom02; }
            if (upperName == "AG3") { matchGroup = KSPActionGroup.Custom03; }
            if (upperName == "AG4") { matchGroup = KSPActionGroup.Custom04; }
            if (upperName == "AG5") { matchGroup = KSPActionGroup.Custom05; }
            if (upperName == "AG6") { matchGroup = KSPActionGroup.Custom06; }
            if (upperName == "AG7") { matchGroup = KSPActionGroup.Custom07; }
            if (upperName == "AG8") { matchGroup = KSPActionGroup.Custom08; }
            if (upperName == "AG9") { matchGroup = KSPActionGroup.Custom09; }
            if (upperName == "AG10") { matchGroup = KSPActionGroup.Custom10; }

            ListValue kScriptParts = new ListValue();
            if (matchGroup == KSPActionGroup.None) return kScriptParts;

            foreach (global::Part p in Vessel.parts)
            {
                // See if any of the parts' actions are this action group:
                bool hasPartAction = p.Actions.Any(a => a.actionGroup.Equals(matchGroup));
                if (hasPartAction)
                {
                    kScriptParts.Add(PartValueFactory.Construct(p, Shared));
                    continue;
                }

                var modules = p.Modules.Cast<PartModule>();
                bool hasModuleAction = modules.Any(pm => pm.Actions.Any(a => a.actionGroup.Equals(matchGroup)));
                if (hasModuleAction)
                {
                    kScriptParts.Add(PartValueFactory.Construct(p, Shared));
                }
            }
            return kScriptParts;
        }
Beispiel #24
0
 public static ListValue GetAllTemplates()
 {
     ListValue ret = new ListValue();
     var files = GetAllPathStrings();
     foreach (string path in files)
     {
         var template = ShipConstruction.LoadTemplate(path);
         if (template != null)
         {
             ret.Add(new CraftTemplate(path, template));
         }
     }
     return ret;
 }
        private ListValue <PartValue> GetParts()
        {
            var parts = PartValueFactory.Construct(resources.Select(r => r.part), shared);

            return(ListValue <PartValue> .CreateList(parts));
        }
Beispiel #26
0
 public override void Execute(SharedObjects shared)
 {
     var listValue = new ListValue();
     shared.Cpu.PushStack(listValue);
 }
        private ListValue GetModulesInGroup(StringValue groupName)
        {
            var    matchGroup = KSPActionGroup.None;
            string upperName  = groupName.ToUpper();

            // TODO: later refactor:  put this in a Dictionary lookup instead, and then share it
            // by both this code and the code in ActionGroup.cs:
            if (upperName == "SAS")
            {
                matchGroup = KSPActionGroup.SAS;
            }
            if (upperName == "GEAR")
            {
                matchGroup = KSPActionGroup.Gear;
            }
            if (upperName == "LIGHTS")
            {
                matchGroup = KSPActionGroup.Light;
            }
            if (upperName == "BRAKES")
            {
                matchGroup = KSPActionGroup.Brakes;
            }
            if (upperName == "RCS")
            {
                matchGroup = KSPActionGroup.RCS;
            }
            if (upperName == "ABORT")
            {
                matchGroup = KSPActionGroup.Abort;
            }
            if (upperName == "AG1")
            {
                matchGroup = KSPActionGroup.Custom01;
            }
            if (upperName == "AG2")
            {
                matchGroup = KSPActionGroup.Custom02;
            }
            if (upperName == "AG3")
            {
                matchGroup = KSPActionGroup.Custom03;
            }
            if (upperName == "AG4")
            {
                matchGroup = KSPActionGroup.Custom04;
            }
            if (upperName == "AG5")
            {
                matchGroup = KSPActionGroup.Custom05;
            }
            if (upperName == "AG6")
            {
                matchGroup = KSPActionGroup.Custom06;
            }
            if (upperName == "AG7")
            {
                matchGroup = KSPActionGroup.Custom07;
            }
            if (upperName == "AG8")
            {
                matchGroup = KSPActionGroup.Custom08;
            }
            if (upperName == "AG9")
            {
                matchGroup = KSPActionGroup.Custom09;
            }
            if (upperName == "AG10")
            {
                matchGroup = KSPActionGroup.Custom10;
            }

            ListValue kScriptParts = new ListValue();

            // This is almost identical to the logic in GetPartsInGroup and it might be a nice idea
            // later to merge them somehow:
            //
            if (matchGroup == KSPActionGroup.None)
            {
                return(kScriptParts);
            }

            foreach (global::Part p in Vessel.parts)
            {
                foreach (PartModule pm in p.Modules)
                {
                    if (pm.Actions.Any(a => a.actionGroup.Equals(matchGroup)))
                    {
                        kScriptParts.Add(PartModuleFieldsFactory.Construct(pm, Shared));
                    }
                }
            }

            return(kScriptParts);
        }
        private ListValue GetPartsInGroup(StringValue groupName)
        {
            var    matchGroup = KSPActionGroup.None;
            string upperName  = groupName.ToUpper();

            // TODO: later refactor:  put this in a Dictionary lookup instead, and then share it
            // by both this code and the code in ActionGroup.cs:
            if (upperName == "SAS")
            {
                matchGroup = KSPActionGroup.SAS;
            }
            if (upperName == "GEAR")
            {
                matchGroup = KSPActionGroup.Gear;
            }
            if (upperName == "LIGHTS")
            {
                matchGroup = KSPActionGroup.Light;
            }
            if (upperName == "BRAKES")
            {
                matchGroup = KSPActionGroup.Brakes;
            }
            if (upperName == "RCS")
            {
                matchGroup = KSPActionGroup.RCS;
            }
            if (upperName == "ABORT")
            {
                matchGroup = KSPActionGroup.Abort;
            }
            if (upperName == "AG1")
            {
                matchGroup = KSPActionGroup.Custom01;
            }
            if (upperName == "AG2")
            {
                matchGroup = KSPActionGroup.Custom02;
            }
            if (upperName == "AG3")
            {
                matchGroup = KSPActionGroup.Custom03;
            }
            if (upperName == "AG4")
            {
                matchGroup = KSPActionGroup.Custom04;
            }
            if (upperName == "AG5")
            {
                matchGroup = KSPActionGroup.Custom05;
            }
            if (upperName == "AG6")
            {
                matchGroup = KSPActionGroup.Custom06;
            }
            if (upperName == "AG7")
            {
                matchGroup = KSPActionGroup.Custom07;
            }
            if (upperName == "AG8")
            {
                matchGroup = KSPActionGroup.Custom08;
            }
            if (upperName == "AG9")
            {
                matchGroup = KSPActionGroup.Custom09;
            }
            if (upperName == "AG10")
            {
                matchGroup = KSPActionGroup.Custom10;
            }

            ListValue kScriptParts = new ListValue();

            if (matchGroup == KSPActionGroup.None)
            {
                return(kScriptParts);
            }

            foreach (global::Part p in Vessel.parts)
            {
                // See if any of the parts' actions are this action group:
                bool hasPartAction = p.Actions.Any(a => a.actionGroup.Equals(matchGroup));
                if (hasPartAction)
                {
                    kScriptParts.Add(PartValueFactory.Construct(p, Shared));
                    continue;
                }

                var  modules         = p.Modules.Cast <PartModule>();
                bool hasModuleAction = modules.Any(pm => pm.Actions.Any(a => a.actionGroup.Equals(matchGroup)));
                if (hasModuleAction)
                {
                    kScriptParts.Add(PartValueFactory.Construct(p, Shared));
                }
            }
            return(kScriptParts);
        }
Beispiel #29
0
 private ListValue(ListValue toCopy)
 {
     list = new List <object>(toCopy.list);
 }
Beispiel #30
0
        public static ListValue <AggregateResourceValue> FromVessel(Vessel vessel, SharedObjects shared)
        {
            var resources = ProspectResources(vessel.parts, shared);

            return(ListValue <AggregateResourceValue> .CreateList(resources.Values));
        }
Beispiel #31
0
        private ListValue BuildPatchList()
        {
            var list = new ListValue();
            var orb = Orbit;
            int index = 0;
            int highestAllowedIndex = Career.PatchLimit();
            while (index <= highestAllowedIndex)
            {
                if (orb == null || (!orb.activePatch))
                {
                    break;
                }

                list.Add(new OrbitInfo(orb, Shared));
                orb = orb.nextPatch;
                ++index;
            }
            return list;
        }
Beispiel #32
0
        private ListValue<ActiveResourceValue> GetResourceManifest()
        {
            if (resList != null) return resList;
            resList = new ListValue<ActiveResourceValue>();
            CreatePartSet();
            var defs = PartResourceLibrary.Instance.resourceDefinitions;
            foreach (var def in defs)
            {
                resList.Add(new ActiveResourceValue(def, shared, this, partSet));
            }

            return resList;
        }