Beispiel #1
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 #2
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 #3
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 #4
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 #5
0
 public static ListValue PartsToList(IEnumerable<Part> parts)
 {
     var toReturn = new ListValue();
     foreach (var part in parts)
     {
         toReturn.Add(new PartValue(part));
     }
     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 #7
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 #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;
 }
Beispiel #13
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 #14
0
 public void AddResource(PartResource resource)
 {
     amount   += resource.amount;
     capacity += resource.maxAmount;
     parts.Add(new PartValue(resource.part, shared));
 }
Beispiel #15
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 #16
0
        public ListValue GetCrew() {
            var crew = new ListValue();

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

            return crew;
        }
Beispiel #17
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 #18
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 #19
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 #20
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;
 }
Beispiel #21
0
        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);
        }
Beispiel #22
0
        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 #23
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;
        }
Beispiel #24
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 #25
0
        private void ConstructPart(global::Part part, PartValue parent, DecouplerValue decoupler)
        {
            if (part.State == PartStates.DEAD || part.transform == null)
            {
                return;
            }

            // Modules can be in any order, so to enforce some sort of priority for parts which are multiple types,
            // gather all potential modules and then select from those valid.
            IEngineStatus      engine    = null;
            ModuleRCS          rcs       = null;
            PartValue          separator = null;
            ModuleEnviroSensor sensor    = null;

            foreach (var module in part.Modules)
            {
                if (module is IEngineStatus)
                {
                    engine = module as IEngineStatus;
                }
                else if (module is ModuleRCS)
                {
                    rcs = module as ModuleRCS;
                }
                else if (module is IStageSeparator)
                {
                    var dock = module as ModuleDockingNode;
                    if (dock != null)
                    {
                        var port = new DockingPortValue(Shared, part, parent, decoupler, dock);
                        separator = port;
                        dockingPorts.Add(port);
                        if (!module.StagingEnabled())
                        {
                            continue;
                        }
                        decoupler = port;
                        decouplers.Add(decoupler);
                    }
                    // ignore anything with staging disabled and continue the search
                    // this can e.g. be heat shield or some sensor with integrated decoupler
                    else
                    {
                        if (!module.StagingEnabled())
                        {
                            continue;
                        }
                        if (module is LaunchClamp)
                        {
                            separator = decoupler = new LaunchClampValue(Shared, part, parent, decoupler);
                        }
                        else if (module is ModuleDecouple || module is ModuleAnchoredDecoupler)
                        {
                            separator = decoupler = new DecouplerValue(Shared, part, parent, decoupler);
                        }
                        else // ModuleServiceModule ?
                        {
                            continue; // rather continue the search
                        }
                        decouplers.Add(decoupler);
                    }
                    // ignore leftover decouplers
                    if (decoupler == null || decoupler.Part.inverseStage >= StageManager.CurrentStage)
                    {
                        continue;
                    }
                    // check if we just created closer decoupler (see StageValues.CreatePartSet)
                    if (nextDecoupler == null || decoupler.Part.inverseStage > nextDecoupler.Part.inverseStage)
                    {
                        nextDecoupler = decoupler;
                    }
                }
                else if (module is ModuleEnviroSensor)
                {
                    sensor = module as ModuleEnviroSensor;
                }
            }

            // Select part value in priority order
            PartValue self;

            if (engine != null)
            {
                self = new EngineValue(Shared, part, parent, decoupler);
            }
            else if (rcs != null)
            {
                self = new RCSValue(Shared, part, parent, decoupler, rcs);
            }
            else if (separator != null)
            {
                self = separator;
            }
            else if (sensor != null)
            {
                self = new SensorValue(Shared, part, parent, decoupler, sensor);
            }
            else
            {
                self = new PartValue(Shared, part, parent, decoupler);
            }

            if (rootPart == null)
            {
                rootPart = self;
            }
            partCache[part] = self;
            allParts.Add(self);
            foreach (var child in part.children)
            {
                ConstructPart(child, self, decoupler);
            }
            self.Children.IsReadOnly = true;
        }