public Dictionary <AvailablePart, int> GetExperimentalParts() { var devPartsOnShip = new Dictionary <AvailablePart, int>(); if (ResearchAndDevelopment.Instance == null) { return(devPartsOnShip); } foreach (ConfigNode pNode in ShipNode.GetNodes("PART")) { string partName = Utilities.GetPartNameFromNode(pNode); if (Utilities.PartIsExperimental(partName)) { AvailablePart partInfoByName = PartLoader.getPartInfoByName(partName); if (!devPartsOnShip.ContainsKey(partInfoByName)) { devPartsOnShip.Add(partInfoByName, 1); } else { ++devPartsOnShip[partInfoByName]; } } } return(devPartsOnShip); }
////Generate fully random science experiment contract parameter //internal static DMCollectScience fetchScienceContract(Contract.ContractPrestige p, List<CelestialBody> cR, List<CelestialBody> cUR) //{ // DMScienceContainer scienceContainer; // CelestialBody body; // ExperimentSituations targetSituation; // List<ExperimentSituations> situations; // ScienceExperiment exp; // ScienceSubject sub; // AvailablePart aPart; // string name; // string biome = ""; // //Choose a random science experiment from our list generated at startup // scienceContainer = DMUtils.availableScience["All"].ElementAt(rand.Next(0, DMUtils.availableScience["All"].Count)).Value; // name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == scienceContainer).Key; // DMUtils.DebugLog("Checking Contract Requirements"); // //Determine if the science part is available if applicable // if (scienceContainer.sciPart != "None") // { // DMUtils.DebugLog("Checking For Part {0} Now", scienceContainer.sciPart); // aPart = PartLoader.getPartInfoByName(scienceContainer.sciPart); // if (aPart == null) // return null; // if (!ResearchAndDevelopment.PartModelPurchased(aPart)) // return null; // DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name); // } // //Select a random Celestial Body based on contract prestige levels // body = DMUtils.nextTargetBody(p, cR, cUR); // if (body == null) // return null; // //Make sure our experiment is OK // exp = scienceContainer.exp; // if (exp == null) // return null; // //Choose an acceptable experimental situation for a given science experiment // if ((situations = DMUtils.availableSituations(exp, scienceContainer.sitMask, body)).Count == 0) // return null; // else // { // DMUtils.DebugLog("Acceptable Situations Found"); // targetSituation = situations[rand.Next(0, situations.Count)]; // DMUtils.DebugLog("Experimental Situation: {0}", targetSituation); // } // //Build a list of acceptable biomes if applicable, choose one with remaining science // if (DMUtils.biomeRelevant(targetSituation, scienceContainer.bioMask) && targetSituation != ExperimentSituations.SrfSplashed) // { // DMUtils.DebugLog("Checking For Biome Usage"); // List<string> bList = DMUtils.fetchBiome(body, exp, targetSituation); // if (bList.Count == 0) // { // DMUtils.DebugLog("Planet All Tapped Out; No Remaining Science Here"); // return null; // } // int i = rand.Next(0, 2); // if (i == 0) // { // biome = bList[rand.Next(0, bList.Count)]; // DMUtils.DebugLog("Acceptable Biome Found: {0}", biome); // } // } // //Make sure that our chosen science subject has science remaining to be gathered // if ((sub = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}{3}", exp.id, body.name, targetSituation, biome.Replace(" ", "")))) != null) // { // if (sub.scientificValue < 0.4f) // return null; // } // return new DMCollectScience(body, targetSituation, biome, name, 0); //} ////Generate random experiment for a given celestial body //internal static DMCollectScience fetchScienceContract(CelestialBody body) //{ // DMScienceContainer scienceContainer; // ExperimentSituations targetSituation; // List<ExperimentSituations> situations; // ScienceExperiment exp; // ScienceSubject sub; // AvailablePart aPart; // string name; // string biome = ""; // //Choose a random science experiment from our list generated at startup // scienceContainer = DMUtils.availableScience["All"].ElementAt(rand.Next(0, DMUtils.availableScience.Count)).Value; // name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == scienceContainer).Key; // DMUtils.DebugLog("Checking Contract Requirements"); // //Determine if the science part is available if applicable // if (scienceContainer.sciPart != "None") // { // DMUtils.DebugLog("Checking For Part {0} Now", scienceContainer.sciPart); // aPart = PartLoader.getPartInfoByName(scienceContainer.sciPart); // if (aPart == null) // return null; // if (!ResearchAndDevelopment.PartModelPurchased(aPart)) // return null; // DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name); // } // //Make sure our experiment is OK // exp = scienceContainer.exp; // if (exp == null) // return null; // //Choose an acceptable experimental situation for a given science experiment // if ((situations = DMUtils.availableSituations(exp, scienceContainer.sitMask, body)).Count == 0) // return null; // else // { // DMUtils.DebugLog("Acceptable Situations Found"); // targetSituation = situations[rand.Next(0, situations.Count)]; // DMUtils.DebugLog("Experimental Situation: {0}", targetSituation); // } // //Build a list of acceptable biomes if applicable, choose one with remaining science // if (DMUtils.biomeRelevant(targetSituation, scienceContainer.bioMask) && targetSituation != ExperimentSituations.SrfSplashed) // { // DMUtils.DebugLog("Checking For Biome Usage"); // List<string> bList = DMUtils.fetchBiome(body, exp, targetSituation); // if (bList.Count == 0) // { // DMUtils.DebugLog("Planet All Tapped Out; No Remaining Science Here"); // return null; // } // int i = rand.Next(0, 2); // if (i == 0) // { // biome = bList[rand.Next(0, bList.Count)]; // DMUtils.DebugLog("Acceptable Biome Found: {0}", biome); // } // } // //Make sure that our chosen science subject has science remaining to be gathered // if ((sub = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}{3}", exp.id, body.name, targetSituation, biome.Replace(" ", "")))) != null) // { // if (sub.scientificValue < 0.4f) // return null; // } // return new DMCollectScience(body, targetSituation, biome, name, 0); //} ////Generate experiment for a given Celestial Body and experimental situation //internal static DMCollectScience fetchScienceContract(CelestialBody body, ExperimentSituations targetSituation) //{ // DMScienceContainer scienceContainer; // ScienceExperiment exp; // ScienceSubject sub; // AvailablePart aPart; // string name; // string biome = ""; // //Choose a random science experiment from our list generated at startup // scienceContainer = DMUtils.availableScience["All"].ElementAt(rand.Next(0, DMUtils.availableScience.Count)).Value; // name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == scienceContainer).Key; // DMUtils.DebugLog("Checking Contract Requirements"); // //Determine if the science part is available if applicable // if (scienceContainer.sciPart != "None") // { // DMUtils.DebugLog("Checking For Part {0} Now", scienceContainer.sciPart); // aPart = PartLoader.getPartInfoByName(scienceContainer.sciPart); // if (aPart == null) // return null; // if (!ResearchAndDevelopment.PartModelPurchased(aPart)) // return null; // DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name); // } // //Make sure our experiment is OK // exp = scienceContainer.exp; // if (exp == null) // return null; // //Make sure that the experiment can be conducted in this situation // if (((ExperimentSituations)exp.situationMask & targetSituation) != targetSituation) // return null; // //Build a list of acceptable biomes if applicable, choose one with remaining science // if (DMUtils.biomeRelevant(targetSituation, scienceContainer.bioMask) && targetSituation != ExperimentSituations.SrfSplashed) // { // DMUtils.DebugLog("Checking For Biome Usage"); // List<string> bList = DMUtils.fetchBiome(body, exp, targetSituation); // if (bList.Count == 0) // { // DMUtils.DebugLog("Planet All Tapped Out; No Remaining Science Here"); // return null; // } // int i = rand.Next(0, 2); // if (i == 0) // { // biome = bList[rand.Next(0, bList.Count)]; // DMUtils.DebugLog("Acceptable Biome Found: {0}", biome); // } // } // //Make sure that our chosen science subject has science remaining to be gathered // if ((sub = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}{3}", exp.id, body.name, targetSituation, biome.Replace(" ", "")))) != null) // { // if (sub.scientificValue < 0.4f) // return null; // } // return new DMCollectScience(body, targetSituation, biome, name, 0); //} ////Generate random experiment for a given celestial body //internal static DMCollectScience fetchScienceContract(CelestialBody body, ScienceExperiment exp) //{ // DMScienceContainer scienceContainer; // ExperimentSituations targetSituation; // List<ExperimentSituations> situations; // ScienceSubject sub; // AvailablePart aPart; // string name; // string biome = ""; // //Choose science container based on a given science experiment // scienceContainer = DMUtils.availableScience["All"].FirstOrDefault(e => e.Value.exp == exp).Value; // name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == scienceContainer).Key; // DMUtils.DebugLog("Checking Contract Requirements"); // //Determine if the science part is available if applicable // if (scienceContainer.sciPart != "None") // { // DMUtils.DebugLog("Checking For Part {0} Now", scienceContainer.sciPart); // aPart = PartLoader.getPartInfoByName(scienceContainer.sciPart); // if (aPart == null) // return null; // if (!ResearchAndDevelopment.PartModelPurchased(aPart)) // return null; // DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name); // } // //Make sure our experiment is OK // exp = scienceContainer.exp; // if (exp == null) // return null; // //Choose an acceptable experimental situation for a given science experiment // if ((situations = DMUtils.availableSituations(exp, scienceContainer.sitMask, body)).Count == 0) // return null; // else // { // DMUtils.DebugLog("Acceptable Situations Found"); // targetSituation = situations[rand.Next(0, situations.Count)]; // DMUtils.DebugLog("Experimental Situation: {0}", targetSituation); // } // //Build a list of acceptable biomes if applicable, choose one with remaining science // if (DMUtils.biomeRelevant(targetSituation, scienceContainer.bioMask) && targetSituation != ExperimentSituations.SrfSplashed) // { // DMUtils.DebugLog("Checking For Biome Usage"); // List<string> bList = DMUtils.fetchBiome(body, exp, targetSituation); // if (bList.Count == 0) // { // DMUtils.DebugLog("Planet All Tapped Out; No Remaining Science Here"); // return null; // } // int i = rand.Next(0, 2); // if (i == 0) // { // biome = bList[rand.Next(0, bList.Count)]; // DMUtils.DebugLog("Acceptable Biome Found: {0}", biome); // } // } // //Make sure that our chosen science subject has science remaining to be gathered // if ((sub = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}{3}", exp.id, body.name, targetSituation, biome.Replace(" ", "")))) != null) // { // if (sub.scientificValue < 0.4f) // return null; // } // return new DMCollectScience(body, targetSituation, biome, name, 0); //} //Use for magnetic field survey internal static DMCollectScience fetchScienceContract(CelestialBody Body, ExperimentSituations Situation, DMScienceContainer DMScience) { AvailablePart aPart; string name; //Choose science container based on a given science experiment name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; DMUtils.DebugLog("Checking Contract Requirements"); if (DMScience.exp == null) { return(null); } //Determine if the science part is available if applicable if (DMScience.sciPart != "None") { DMUtils.DebugLog("Checking For Part {0} Now", DMScience.sciPart); aPart = PartLoader.getPartInfoByName(DMScience.sciPart); if (aPart == null) { return(null); } if (!ResearchAndDevelopment.PartModelPurchased(aPart)) { return(null); } DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name); } return(new DMCollectScience(Body, Situation, "", name, 1)); }
public Dictionary <AvailablePart, int> GetLockedParts() { var lockedPartsOnShip = new Dictionary <AvailablePart, int>(); if (ResearchAndDevelopment.Instance == null) { return(lockedPartsOnShip); } foreach (ConfigNode pNode in shipNode.GetNodes("PART")) { string partName = KCT_Utilities.PartNameFromNode(pNode); if (!KCT_Utilities.PartIsUnlocked(partName)) { AvailablePart partInfoByName = PartLoader.getPartInfoByName(partName); if (!lockedPartsOnShip.ContainsKey(partInfoByName)) { lockedPartsOnShip.Add(partInfoByName, 1); } else { ++lockedPartsOnShip[partInfoByName]; } } } return(lockedPartsOnShip); }
public string getRandomAllowedCrewedPartWithSameMass(System.Random rnd, string originalPartName) { List <string> allowedCrewedPartsList = AllowedPartsSettings.Instance .FilterAllowedParts(allowedCrewedParts); AvailablePart originalPart = PartLoader.getPartInfoByName(originalPartName); // we couldn't load the part so just return any random part if (originalPart == null) { return(getRandomAllowedCrewedPart(rnd)); } List <AvailablePart> filteredParts = allowedCrewedPartsList .Select(name => PartLoader.getPartInfoByName(name)) .Where(part => part != null && CalcPercentDifference(originalPart.partPrefab.mass, part.partPrefab.mass) <= maxMassPercentDiff) .ToList(); if (filteredParts.Count == 0) { RescueContractFix.Log($"Could not find part similar in mass to {originalPartName}. " + "Using any random allowed part instead."); int index = rnd.Next(allowedCrewedPartsList.Count); return(allowedCrewedPartsList[index]); } else { int index = rnd.Next(filteredParts.Count); return(filteredParts[index].name); } }
public static float GetCost(Part part) { AvailablePart availablePart = PartLoader.getPartInfoByName(part.name); if (availablePart != null && availablePart.costsFunds) { float cost = availablePart.cost; foreach (PartResource resource in part.Resources) { double unusedAmount = resource.maxAmount - resource.amount; cost -= (float)(unusedAmount * PartResourceLibrary.Instance.GetDefinition(resource.resourceName).unitCost); } foreach (PartModule module in part.Modules) { if (module is IPartCostModifier) { IPartCostModifier costModifier = module as IPartCostModifier; cost = costModifier.GetModuleCost(cost, ModifierStagingSituation.CURRENT); } } foreach (Part child in part.children) { cost += GetCost(child); } return(cost); } else { return(0.0F); } }
public override void OnStart(StartState state) { if (actual_object == null && !string.IsNullOrEmpty(original_part_name) && !string.IsNullOrEmpty(debris_transform_name)) { var info = PartLoader.getPartInfoByName(original_part_name); if (info == null) { this.Log("WARNING: {} part was not found in the database!", original_part_name); return; } actual_object = info.partPrefab.FindModelTransform(debris_transform_name); if (actual_object == null) { this.Log("WARNING: {} part does not have {} transform!", original_part_name, debris_transform_name); return; } var debris_part_model = part.transform.Find("model"); actual_object = Instantiate(actual_object.gameObject).transform; actual_object.parent = debris_part_model; actual_object.localPosition = Vector3.zero; actual_object.localRotation = local_rotation; debris_part_model.localScale = local_scale; debris_part_model.hasChanged = true; part.transform.hasChanged = true; } StartCoroutine(update_drag_cubes()); if (selfDestruct > 0) { StartCoroutine(self_destruct()); } }
private void AddInventoryItems(ProtoCrewMember kerbalPcm) //, System.Reflection.Assembly KIS) { $"{kerbalPcm.name} has {WalkAboutPersistent.AllocatedItems[kerbalPcm.name].Count} items to be assigned".Debug(); #if false var ModuleKISInventoryType = KIS.GetType("KIS.ModuleKISInventory"); "found KIS inventory type".Debug(); var inventory = FlightGlobals.ActiveVessel.GetComponent(ModuleKISInventoryType); #endif var moduleKISInventory = FlightGlobals.ActiveVessel.GetComponent <ModuleKISInventory>(); "obtained modules for the active vessel".Debug(); if (moduleKISInventory != null) { foreach (var itemName in WalkAboutPersistent.AllocatedItems[kerbalPcm.name]) { var part = PartLoader.getPartInfoByName(itemName)?.partPrefab; moduleKISInventory.AddItem(part, 1, -1); //AddItemToInventory(kerbalPcm, itemName, ModuleKISInventoryType, inventory); } } WalkAboutPersistent.AllocatedItems.Remove(kerbalPcm.name); }
public static AvailablePart getPartForExperiment(string type, ExperimentData exp) { AvailablePart ap = null; string[] partsRegistry = null; switch (type) { case OMS_EXPERIMENTS: partsRegistry = omsRegistry; break; case KEMINI_EXPERIMENTS: partsRegistry = getKeminiRegister(); break; } for (int idx = 0, count = partsRegistry.Length; idx < count; idx++) { ap = PartLoader.getPartInfoByName(partsRegistry[idx]); if (ap != null) { NE_ExperimentModule e = ap.partPrefab.GetComponent <NE_ExperimentModule>(); if (e.type == exp.getType()) { break; } } } return(ap); }
private List <string> getPartTitles(List <string> names) { List <string> l = new List <string>(); for (int i = names.Count - 1; i >= 0; i--) { string s = names[i]; if (string.IsNullOrEmpty(s)) { continue; } AvailablePart p = PartLoader.getPartInfoByName(s.Replace('_', '.')); if (p == null) { continue; } if (!ResearchAndDevelopment.PartModelPurchased(p)) { continue; } l.Add(p.title); } return(l); }
public void Start() { // log version Lib.Log("version " + Assembly.GetExecutingAssembly().GetName().Version); // set callbacks GameEvents.onCrewOnEva.Add(this.toEVA); GameEvents.onCrewBoardVessel.Add(this.fromEVA); GameEvents.onVesselRecovered.Add(this.vesselRecovered); GameEvents.onVesselTerminated.Add(this.vesselTerminated); GameEvents.onVesselWillDestroy.Add(this.vesselDestroyed); GameEvents.onPartCouple.Add(this.vesselDock); GameEvents.OnTechnologyResearched.Add(this.techResearched); // add module to EVA vessel part prefab // note: try..catch travesty required to avoid spurious exception, that seem to have no negative effects // note: dummy test for null char required to avoid compiler warning try { PartLoader.getPartInfoByName("kerbalEVA").partPrefab.AddModule("EVA"); } catch (Exception ex) { if (ex.Message.Contains("\0")) { } } try { PartLoader.getPartInfoByName("kerbalEVAfemale").partPrefab.AddModule("EVA"); } catch (Exception ex) { if (ex.Message.Contains("\0")) { } } }
//Use for magnetic field survey internal static DMCollectScience fetchScienceContract(CelestialBody Body, ExperimentSituations Situation, DMScienceContainer DMScience) { AvailablePart aPart; string name; //Choose science container based on a given science experiment name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; if (DMScience.Exp == null) { return(null); } //Determine if the science part is available if applicable if (DMScience.SciPart != "None") { aPart = PartLoader.getPartInfoByName(DMScience.SciPart); if (aPart == null) { return(null); } if (!ResearchAndDevelopment.PartModelPurchased(aPart)) { return(null); } } return(new DMCollectScience(Body, Situation, "", name, 1)); }
public void Awake() { ConfigNode EVA = new ConfigNode("MODULE"); EVA.AddValue("name", "EVACamera"); EVA.AddValue("cameraName", "EVACam"); try { PartLoader.getPartInfoByName("kerbalEVA").partPrefab.AddModule(EVA); } catch {} try { PartLoader.getPartInfoByName("kerbalEVAfemale").partPrefab.AddModule(EVA); } catch {} try { PartLoader.getPartInfoByName("kerbalEVAVintage").partPrefab.AddModule(EVA); } catch { } try { PartLoader.getPartInfoByName("kerbalEVAfemaleVintage").partPrefab.AddModule(EVA); } catch { } }
protected virtual List <KeyValuePair <ModuleDataTransmitter, ProtoPartSnapshot> > GetTransmittersUnloaded(Vessel v) { List <KeyValuePair <ModuleDataTransmitter, ProtoPartSnapshot> > transmitters; if (!Cache.HasVesselObjectsCache(v, "commnet_bg")) { transmitters = new List <KeyValuePair <ModuleDataTransmitter, ProtoPartSnapshot> >(); // find proto transmitters foreach (ProtoPartSnapshot p in v.protoVessel.protoPartSnapshots) { // get part prefab (required for module properties) Part part_prefab = PartLoader.getPartInfoByName(p.partName).partPrefab; foreach (ModuleDataTransmitter t in part_prefab.FindModulesImplementing <ModuleDataTransmitter>()) { transmitters.Add(new KeyValuePair <ModuleDataTransmitter, ProtoPartSnapshot>(t, p)); } } Cache.SetVesselObjectsCache(v, "commnet_bg", transmitters); } else { // cache transmitters transmitters = Cache.VesselObjectsCache <List <KeyValuePair <ModuleDataTransmitter, ProtoPartSnapshot> > >(v, "commnet_bg"); } return(transmitters); }
public override bool MeetRequirements() { AvailablePart ap1 = PartLoader.getPartInfoByName("tarsierSpaceTelescope"); AvailablePart ap2 = PartLoader.getPartInfoByName("tarsierAdvSpaceTelescope"); return(ResearchAndDevelopment.PartTechAvailable(ap1) || ResearchAndDevelopment.PartTechAvailable(ap2)); }
internal static ModuleGroundExpControl GetModuleGroundExpControl(Vessel v) { if (v.loaded) { if (v.parts.Count > 1) { return(null); // deployables are 1-part vessels } foreach (Part part in v.parts) { var result = part.FindModuleImplementing <ModuleGroundExpControl>(); if (result != null) { return(result); } } } else { foreach (ProtoPartSnapshot p in v.protoVessel.protoPartSnapshots) { Part part_prefab = PartLoader.getPartInfoByName(p.partName).partPrefab; var result = part_prefab.FindModuleImplementing <ModuleGroundExpControl>(); if (result != null) { return(result); } } } return(null); }
public void Awake() { EvaDebug.DebugLog("Loaded AddonAddModule."); var parts = new string[] { "kerbalEVA", "kerbalEVAVintage", "kerbalEVAfemale", "kerbalEVAfemaleVintage", "kerbalEVA_RD_Exp", "kerbalEVA_female_Exp", "kerbalEVA_RD_Future", "kerbalEVA_female_Future", "kerbalEVAfemaleFuture", "maleEVA", "femaleEVA", }; foreach (var part in parts) { var EVA = new ConfigNode("MODULE"); EVA.AddValue("name", "EvaModule"); try { PartLoader.getPartInfoByName(part).partPrefab.AddModule(EVA); } catch { } } }
public bool CreateBoM() { string str; craftBoMdirty = false; if (craftConfig != null) { craftBoM = new List <string> (); var partCounts = new Dictionary <string, int> (); str = craftConfig.GetValue("description"); if (!string.IsNullOrEmpty(str)) { craftBoM.Add(Localizer.Format(str)); craftBoM.Add(""); // blank line } foreach (var part in craftConfig.GetNodes("PART")) { string name = part.GetValue("part").Split('_')[0]; if (!partCounts.ContainsKey(name)) { partCounts[name] = 0; } partCounts[name]++; } foreach (var key in partCounts.Keys) { var ap = PartLoader.getPartInfoByName(key); craftBoM.Add($"{partCounts[key]}x {ap.title}"); } return(true); } craftBoM = null; return(false); }
// Runs on PartModule startup. public override void OnStart(StartState state) { // Startup the PartModule stuff first. base.OnStart(state); // Set our state trackers to the opposite of our states, to force first-run updates. // this.startLockedState = !this.startLocked; // Fetch the gimbal module from the part. this.gimbalModule = base.part.getFirstModuleOfType <ModuleGimbal>(); if (this.gimbalModule == null) { return; } //PartLoader.getPartInfoByName(base.part.partInfo.name).partPrefab.Modules /*.OfType<ModuleGimbal>() * .FirstOrDefault() * .gimbalRange*/ #if true ModuleGimbal gimbalPrefab; if (PartLoader.getPartInfoByName(base.part.partInfo.name).partPrefab.tryGetFirstModuleOfType(out gimbalPrefab)) {
/// <summary> Returns true if the experiment is currently active and collecting data </summary> public static bool ExperimentIsRunning(Vessel vessel, string experiment_id) { if (!Features.Science) { return(false); } if (vessel.loaded) { foreach (Experiment e in vessel.FindPartModulesImplementing <Experiment>()) { if (e.enabled && e.experiment_id == experiment_id && (e.State == Experiment.RunningState.Running || e.State == Experiment.RunningState.Forced)) { return(true); } } } else { var PD = new Dictionary <string, Lib.Module_prefab_data>(); foreach (ProtoPartSnapshot p in vessel.protoVessel.protoPartSnapshots) { // get part prefab (required for module properties) Part part_prefab = PartLoader.getPartInfoByName(p.partName).partPrefab; // get all module prefabs var module_prefabs = part_prefab.FindModulesImplementing <PartModule>(); // clear module indexes PD.Clear(); foreach (ProtoPartModuleSnapshot m in p.modules) { // get the module prefab // if the prefab doesn't contain this module, skip it PartModule module_prefab = Lib.ModulePrefab(module_prefabs, m.moduleName, PD); if (!module_prefab) { continue; } // if the module is disabled, skip it // note: this must be done after ModulePrefab is called, so that indexes are right if (!Lib.Proto.GetBool(m, "isEnabled")) { continue; } if (m.moduleName == "Experiment" && ((Experiment)module_prefab).experiment_id == experiment_id) { var state = Lib.Proto.GetEnum(m, "expState", Experiment.RunningState.Stopped); if (state == Experiment.RunningState.Running || state == Experiment.RunningState.Forced) { return(true); } } } } } return(false); }
// Runs on PartModule startup. public override void OnStart(StartState state) { // Startup the PartModule stuff first. base.OnStart(state); // Set our state trackers to the opposite of our states, to force first-run updates. // this.startLockedState = !this.startLocked; // Fetch the gimbal module from the part. this.gimbalModule = base.part.getFirstModuleOfType <ModuleGimbal>(); if (this.gimbalModule == null) { return; } //PartLoader.getPartInfoByName(base.part.partInfo.name).partPrefab.Modules /*.OfType<ModuleGimbal>() * .FirstOrDefault() * .gimbalRange*/ ModuleGimbal gimbalPrefab; if (PartLoader.getPartInfoByName(base.part.partInfo.name).partPrefab.tryGetFirstModuleOfType(out gimbalPrefab)) { // Initialize the gimbal range tweakable and value. TweakableTools.InitializeTweakable <ModuleTweakableGimbal>( this.Fields["gimbalRange"].uiControlCurrent(), ref this.gimbalRange, ref this.gimbalModule.gimbalRange, gimbalPrefab.gimbalRange, this.lowerMult, this.upperMult ); } // If we're in flight mode... if (HighLogic.LoadedSceneIsFlight) { // ...and if our control state and gimbal range don't match... if ( (this.reverseGimbalControl && this.gimbalRange >= 0) || (!this.reverseGimbalControl && this.gimbalRange < 0) ) { // ...toggle the reverse state. this.ToggleGimbalFlip(); // ...and seed our last state. this.reverseControlState = this.reverseGimbalControl; } } if (this.disableStockLimiter) { this.gimbalModule.Fields["gimbalLimiter"].guiActive = false; this.gimbalModule.Fields["gimbalLimiter"].guiActiveEditor = false; } }
public void setReflectionType(Type type) { if (type == Type.STATIC && staticEnvMap == null) { type = Type.NONE; } reflectionType = type; Part[] evas = { PartLoader.getPartInfoByName("kerbalEVA").partPrefab, PartLoader.getPartInfoByName("kerbalEVAfemale").partPrefab }; for (int i = 0; i < 2; ++i) { // Set visor texture and reflection on proto-EVA Kerbal. SkinnedMeshRenderer visor = evas[i].GetComponentsInChildren <SkinnedMeshRenderer>(true) .First(m => m.name == "visor"); Material material = visor.sharedMaterial; bool enableStatic = isVisorReflectionEnabled && reflectionType == Type.STATIC; // We apply visor shader for real reflections later, through TREvaModule since we don't // want corrupted reflections in the main menu. material.shader = enableStatic ? visorShader : transparentSpecularShader; material.SetTexture(Util.CUBE_PROPERTY, enableStatic ? staticEnvMap : null); material.SetColor(Util.REFLECT_COLOR_PROPERTY, visorReflectionColour); } }
public static Part CreatePart(string partname, Vector3 position, Quaternion rotation, Part flagFromPart) { AvailablePart avPart = PartLoader.getPartInfoByName(partname); return(CreatePart(avPart, position, rotation, flagFromPart)); }
public override void OnLoad(ConfigNode node) { base.OnLoad(node); if (node.HasNode("CONTENT")) { contents.Clear(); } foreach (ConfigNode cn in node.GetNodes("CONTENT")) { if (cn.HasValue("name") && cn.HasValue("qty")) { string AvPartName = cn.GetValue("name").ToString(); AvailablePart avPart = null; avPart = PartLoader.getPartInfoByName(AvPartName); int qty = int.Parse(cn.GetValue("qty")); if (avPart != null) { contents.Add(avPart, qty); } else { KAS_Shared.DebugError("Load(Container) - Cannot retrieve " + AvPartName + " from PartLoader !"); } } } }
public STBPrintable(string partName) { this.iconRes = 64; this.apart = PartLoader.getPartInfoByName(partName); this._iconViewer = new KIS_IconViewer(this.apart.partPrefab, this.iconRes); this.icon = this._iconViewer.texture; }
public static List <string> parsePartStringList(string source) { List <string> list = new List <string>(); if (string.IsNullOrEmpty(source)) { return(list); } string[] s = source.Split(','); int l = s.Length; for (int i = 0; i < l; i++) { string p = s[i]; AvailablePart a = PartLoader.getPartInfoByName(p.Replace('_', '.')); if (a == null) { continue; } list.Add(p); } return(list); }
public int CrewCapacity() { if (!Valid || !Complete) { return(0); } var capacity = 0; foreach (ConfigNode p in Blueprint.nodes) { var name_id = p.GetValue("part"); if (string.IsNullOrEmpty(name_id)) { continue; } string name = KSPUtil.GetPartName(name_id); var kit_part = PartLoader.getPartInfoByName(name); if (kit_part == null || kit_part.partPrefab == null) { continue; } capacity += kit_part.partPrefab.CrewCapacity; } return(capacity); }
public override AvailablePart ParseIdentifier(Token token) { // Try to parse more, as part names can have spaces and other weird characters Match m = Regex.Match(expression, @"^((?>\s*[\w\d-\.]+)+).*"); string identifier = m.Groups[1].Value; expression = (expression.Length > identifier.Length ? expression.Substring(identifier.Length) : ""); identifier = token.sval + identifier; // Underscores in part names get replaced with spaces. Nobody knows why. string partName = identifier.Replace('_', '.'); if (identifier.Equals("null", StringComparison.CurrentCultureIgnoreCase)) { return(null); } // Get the part AvailablePart part = PartLoader.getPartInfoByName(partName); if (part == null) { throw new ArgumentException("'" + identifier + "' is not a valid Part."); } return(part); }
private void FindBackgroundModules() { var protoPartSnapshots = vessel.protoVessel.protoPartSnapshots; foreach (var protoPartSnapshot in protoPartSnapshots) { // get the part prefab, so we can get the modules on the part var prefab = PartLoader.getPartInfoByName(protoPartSnapshot.partName).partPrefab; // and get the prefab modules var modulePrefabs = prefab.FindModulesImplementing <IKITModule>(); var protoModuleSnapshots = protoPartSnapshot.modules; var backgroundModules = protoModuleSnapshots.Zip(modulePrefabs, (snapshot, module) => { var backgroundFunctionInfo = BackgroundFunctionInfo.Instance(module); var pm = module as PartModule; System.Diagnostics.Debug.Assert(pm != null, nameof(pm) + " != null"); if (snapshot.moduleName != pm.moduleName) { Debug.Log($"[FindBackgroundModule] Uh oh, order of the prefab modules does not match the proto module order :("); throw new Exception( "[FindBackgroundModule] Uh oh, order of the prefab modules does not match the proto module order :("); } return(new BackgroundModule(backgroundFunctionInfo, vessel, protoPartSnapshot, snapshot, prefab, pm)); }).ToArray(); Debug.Log($"got {backgroundModules}"); } }
private Dictionary <AvailablePart, int> GetControlledParts(bool locked = false, bool experimental = false) { var res = new Dictionary <AvailablePart, int>(); if (ResearchAndDevelopment.Instance == null) { return(res); } foreach (ConfigNode pNode in ShipNode.GetNodes("PART")) { string partName = Utilities.GetPartNameFromNode(pNode); if ((locked && !Utilities.PartIsUnlocked(partName)) || (experimental && Utilities.PartIsExperimental(partName))) { AvailablePart partInfoByName = PartLoader.getPartInfoByName(partName); if (!res.ContainsKey(partInfoByName)) { res.Add(partInfoByName, 1); } else { ++res[partInfoByName]; } } } return(res); }
void Start() { TechName = TechNameTemplate.Replace("<TAG>", animationName.Replace("Offset", "")); actionGUIName = "Enable/disable angled nozzle"; endEventGUIName = "Disable angled nozzle"; startEventGUIName = "Enable angled nozzle"; if (PartLoader.DoesPartExist(TechName)) { techPart = PartLoader.getPartInfoByName(TechName); techPartResearched = PartResearched(techPart); if (!techPartResearched) { if (HighLogic.LoadedScene != GameScenes.LOADING) { Log.Info(TechName + ", not researched yet"); part.RemoveModule(this); } } else { Log.Info("researched"); } } }