protected override bool VesselMeetsCondition(Vessel vessel) { List <Part> parts = vessel.Parts; double count = 0; foreach (var part in parts) { PartModuleList modules = part.Modules; foreach (var module in modules) { if (module.moduleName == "ModuleInventoryPart") { ModuleInventoryPart inv = (ModuleInventoryPart)module; DictionaryValueList <int, StoredPart> storedParts = inv.storedParts; for (int i = 0; i < storedParts.Count; i++) { if (storedParts[i].partName == partName) { count += storedParts[i].quantity; } } } } } return(count >= partCount); }
public void clearDecalModule() { Log.dbg("clearDecalModule start"); PartModuleList modules = part.Modules; PartModule pm; for (int i = 0; i < part.Modules.Count; i++) { pm = part.Modules[i]; if (pm is FlagDecal) { if (((FlagDecal)pm).textureQuadName == textureQuadName) { Log.dbg("clearDecalModule flagDecal found"); part.Modules.Remove(pm); Destroy(pm); Log.dbg("clearDecalModule flagDecal marked for destroy"); break; } } } if (HighLogic.LoadedSceneIsEditor) { Log.dbg("clearDecalModule LoadedSceneIsEditor"); GameEvents.onEditorPartEvent.Fire(ConstructionEventType.PartTweaked, part); GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship); } else if (HighLogic.LoadedSceneIsFlight) { Log.dbg("clearDecalModule LoadedSceneIsFlight"); GameEvents.onVesselWasModified.Fire(vessel); } Log.dbg("clearDecalModule complete"); }
public void FindCapacitors() { activeVessel = FlightGlobals.ActiveVessel; partCount = activeVessel.parts.Count; //Debug.Log("NFE: Capacitor Manager: Finding Capcitors"); List <DischargeCapacitor> unsortedCapacitorList = new List <DischargeCapacitor>(); // Get all parts List <Part> allParts = FlightGlobals.ActiveVessel.parts; foreach (Part pt in allParts) { PartModuleList modules = pt.Modules; for (int i = 0; i < modules.Count; i++) { PartModule curModule = modules.GetModule(i); if (curModule.ClassName == "DischargeCapacitor") { unsortedCapacitorList.Add(curModule.GetComponent <DischargeCapacitor>()); } } } //sort capacitorList = unsortedCapacitorList.OrderByDescending(x => x.dischargeActual).ToList(); capacitorList = unsortedCapacitorList; // Debug.Log("NFE: Capacitor Manager: Found " + capacitorList.Count() + " capacitors"); }
// Finds a list of all fission containers List <FissionContainer> FindFissionContainers() { List <FissionContainer> fissionContainers = new List <FissionContainer>(); List <Part> allParts = this.vessel.parts; foreach (Part pt in allParts) { PartModuleList pml = pt.Modules; for (int i = 0; i < pml.Count; i++) { PartModule curModule = pml.GetModule(i); FissionContainer candidate = curModule.GetComponent <FissionContainer>(); if (candidate != null) { fissionContainers.Add(candidate); } } } if (fissionContainers.Count == 0) { ScreenMessages.PostScreenMessage(new ScreenMessage("No nuclear fuel containers attached to this ship.", 4f, ScreenMessageStyle.UPPER_CENTER)); } return(fissionContainers); }
private void onVesselLoaded(Vessel vessel) { List <Part> parts = vessel.Parts; float biggestAttachNode = 0.0f; foreach (Part part in parts) { List <AttachNode> attachNodes = part.attachNodes; foreach (AttachNode attachNode in attachNodes) { biggestAttachNode = Math.Max(biggestAttachNode, attachNode.size); } PartModuleList modules = part.Modules; foreach (PartModule module in modules) { string moduleName = module.moduleName; BaseEventList events = module.Events; foreach (BaseEvent kspevent in events) { float unfocusedRangeBuffed = (kspevent.unfocusedRange + biggestAttachNode) * Config.pawRangeCoef; kspevent.unfocusedRange = unfocusedRangeBuffed; } } } }
internal static double CalculateOtherPower(Vessel vessel) { double otherPower = 0; List <ModuleGenerator> powerModules = vessel.FindPartModulesImplementing <ModuleGenerator> (); for (int i = 0; i < powerModules.Count; i++) { // Find standard RTGs ModuleGenerator powerModule = powerModules [i]; if (powerModule.generatorIsActive || powerModule.isAlwaysActive) { for (int j = 0; j < powerModule.resHandler.outputResources.Count; ++j) { var resource = powerModule.resHandler.outputResources [j]; if (resource.name == "ElectricCharge") { otherPower += resource.rate * powerModule.efficiency; } } } } for (int i = 0; i < vessel.parts.Count; i++) { var part = vessel.parts [i]; // Search for other generators PartModuleList modules = part.Modules; for (int j = 0; j < modules.Count; j++) { var module = modules [j]; // Near future fission reactors if (module.moduleName == "FissionGenerator") { otherPower += double.Parse(module.Fields.GetValue("CurrentGeneration").ToString()); } } // USI reactors ModuleResourceConverter converterModule = part.FindModuleImplementing <ModuleResourceConverter> (); if (converterModule != null) { if (converterModule.ModuleIsActive() && converterModule.ConverterName == "Reactor") { for (int j = 0; j < converterModule.outputList.Count; ++j) { var resource = converterModule.outputList [j]; if (resource.ResourceName == "ElectricCharge") { otherPower += resource.Ratio * converterModule.GetEfficiencyMultiplier(); } } } } } return(otherPower); } // So many ifs.....
public void SetGlobalVariables(List <string> variables, PartModuleList modules) { foreach (PartModule mod in modules) { if (Global_Variables.ContainsKey(mod.moduleName)) { variables.AddUnique(mod.moduleName); } } }
public static bool PMListContains(this PartModuleList list, string moduleName) { for (int i = 0; i < list.Count; ++i) { if (list[i] != null && list[i].GetType().Name == moduleName) { return(true); } } return(false); }
private double CalculateFuelCellPower() { double fuelCellPower = 0; bool hasHydrogen = false; bool hasOxygen = false; for (int i = 0; i < this.vessel.parts.Count; ++i) { var part_i = this.vessel.parts[i]; PartResourceList resources = part_i.Resources; for (int j = 0; j < resources.Count; ++j) { var resource = resources[j]; if (resource.resourceName == "Hydrogen" && resource.maxAmount > 0) { hasHydrogen = true; } if (resource.resourceName == "Oxygen" && resource.maxAmount > 0) { hasOxygen = true; } } } if (hasHydrogen && hasOxygen) { for (int i = 0; i < this.vessel.parts.Count; ++i) { var part_i = this.vessel.parts[i]; PartModuleList modules = part_i.Modules; PartResourceList resources = part_i.Resources; for (int j = 0; j < modules.Count; ++j) { var module = modules[j]; if (module.moduleName == "ProcessController") { for (int k = 0; k < resources.Count; ++k) { var resource = resources[k]; if (resource.resourceName == "_FuelCell") { fuelCellPower += resource.amount * 0.5; } } } } } } fuelCellProd = fuelCellPower; return(fuelCellPower); }
//These are all multiplied in case multiple modules exist on one part (this one takes a PartModuleList instead) public double GetModuleVariable(PartModuleList modules) { double value = 1.0; foreach (PartModule mod in modules) { if (Module_Variables.ContainsKey(mod.moduleName)) { value *= Module_Variables[mod.moduleName]; } } return(value); }
public int SizeOfDifference(PartModuleList modules) { int size = 0; for (int i = 0, modulesCount = modules.Count; i < modulesCount; i++) { if (!Values.Contains(modules[i].ClassName)) { size++; } } return(size); }
public static bool ContainsRegex( this PartModuleList partModuleList, string pattern, RegexOptions regexOptions = RegexOptions.IgnoreCase | RegexOptions.CultureInvariant ) { foreach (var partModule in partModuleList) { if (Regex.IsMatch(input: partModule.moduleName, pattern: pattern, options: regexOptions)) { return(true); } } return(false); }
// Finds vVariablePowerEngines on the ship private void SetupVariableEngines() { allVariableEngines = new List <VariablePowerEngine>(); for (int j = 0; j < this.vessel.parts.Count; j++) { PartModuleList pml = this.vessel.parts[j].Modules; for (int i = 0; i < pml.Count; i++) { PartModule curModule = pml.GetModule(i); VariablePowerEngine candidate = curModule.GetComponent <VariablePowerEngine>(); if (candidate != null && candidate != this && !allVariableEngines.Contains(candidate)) { allVariableEngines.Add(candidate); } } } }
// Finds multiengine and ModuleEnginesFX private void LoadEngineModules() { engines = new List <ModuleEnginesFX>(); PartModuleList modules = part.Modules; foreach (PartModule mod in part.Modules) { if (mod.moduleName == "ModuleEnginesFX") { engines.Add((ModuleEnginesFX)mod); //Utils.Log("VariableIspEngine: " + ((ModuleEnginesFX)mod).runningEffectName); } if (mod.moduleName == "MultiModeEngine") { multiEngine = mod.GetComponent <MultiModeEngine>(); } } }
public override void OnStart(PartModule.StartState state) { Actions["ActivateTransmitterAction"].guiName = Events["ActivateTransmitter"].guiName = String.Format("Activate Transmitter"); Actions["DeactivateTransmitterAction"].guiName = Events["DeactivateTransmitter"].guiName = String.Format("Deactivate Transmitter"); if (state == StartState.Editor) { return; } this.part.force_activate(); anim = part.FindModelAnimators(animName).FirstOrDefault(); if (anim != null) { anim [animName].layer = 1; if (!IsEnabled) { anim [animName].normalizedTime = 1f; anim [animName].speed = -1f; } else { anim [animName].normalizedTime = 0f; anim [animName].speed = 1f; } anim.Play(); } List <Part> vesselparts = vessel.parts; for (int i = 0; i < vesselparts.Count; ++i) { Part cPart = vesselparts.ElementAt(i); PartModuleList pml = cPart.Modules; for (int j = 0; j < pml.Count; ++j) { var curSolarPan = pml.GetModule(j) as ModuleDeployableSolarPanel; if (curSolarPan != null) { //curSolarPan.powerCurve = PluginHelper.getSatFloatCurve(); } } } }
//These are all multiplied in case multiple modules exist on one part (this one takes a PartModuleList instead) public double GetModuleVariable(PartModuleList modules, out bool hasResourceMult) { double value = 1.0; hasResourceMult = true; foreach (PartModule mod in modules) { if (mod.moduleName == "ModuleTagNoResourceCostMult") { hasResourceMult = false; } if (Module_Variables.ContainsKey(mod.moduleName)) { value *= Module_Variables[mod.moduleName]; } } return(value); }
private Part findCargoBay() { //if (this.VPI.getModules().ContainsKey("LCARS_ShuttleBay") && this.VPI.getModules().ContainsKey("LCARS_CargoBay")) if (this.VPI.getModules().ContainsKey("LCARS_CargoBay")) { foreach (Part p in this.TargetShipSelected.Parts) { PartModuleList pML = p.Modules; foreach (PartModule pm in pML) { if (pm.moduleName == "LCARS_CargoBay") { return(p); } } } } return(null); }
bool CheckPartResources(MSSRB_Part part, bool max = true) { // Check the nextPart's resources and Modules // Check for the correct propellant and that it has the MSSRB_Fuel_Segment module // If so, add it to the segments list and accumulate some values for the motor // then update the propellant value amount in the fuel segment PartResourceList prl = part.Resources; PartModuleList pml = part.Modules; if (prl.Contains(ModSegSRBs.Propellant) && pml.Contains <MSSRB_Fuel_Segment>()) { Log.Info("CheckPartResources, " + ModSegSRBs.Propellant + " found, " + " MSSRB_Fuel_Segment found"); MSSRB_Fuel_Segment moduleFuelSegment = pml["MSSRB_Fuel_Segment"] as MSSRB_Fuel_Segment; if (max) { totalFuelMass += moduleFuelSegment.MaxSolidFuel(); // prl[ModSegSRBs.Propellant].maxAmount; } else { totalFuelMass += prl[ModSegSRBs.Propellant].amount; } totalMaxThrust += moduleFuelSegment.GetMaxThrust(); prl[ModSegSRBs.Propellant].amount = moduleFuelSegment.MaxSolidFuel(); prl[ModSegSRBs.BurnablePropellant].amount = 0; prl[ModSegSRBs.Propellant].maxAmount = prl[ModSegSRBs.BurnablePropellant].maxAmount = moduleFuelSegment.MaxSolidFuel(); Log.Info("totalMaxThrust: " + totalMaxThrust + ", totalFuelMass: " + totalFuelMass); return(true); } else { Log.Info("CheckPartResources, no Propellant found"); return(false); } }
private void SetupVariableEngines() { allVariableEngines = new List <VariableISPEngine>(); List <Part> allParts = this.vessel.parts; foreach (Part pt in allParts) { PartModuleList pml = pt.Modules; for (int i = 0; i < pml.Count; i++) { PartModule curModule = pml.GetModule(i); VariableISPEngine candidate = curModule.GetComponent <VariableISPEngine>(); if (candidate != null && candidate != this && !allVariableEngines.Contains(candidate)) { allVariableEngines.Add(candidate); } } } }
// Finds all reactors on ship public void FindReactors() { //Debug.Log("NFT: Reactor UI: Finding reactors"); reactorList = new List <FissionGenerator>(); // Get all parts List <Part> allParts = FlightGlobals.ActiveVessel.parts; foreach (Part pt in allParts) { PartModuleList modules = pt.Modules; for (int i = 0; i < modules.Count; i++) { PartModule curModule = modules.GetModule(i); if (curModule.ClassName == "FissionGenerator") { reactorList.Add(curModule.GetComponent <FissionGenerator>()); } } } //Debug.Log("NFT: Reactor UI: Found " + reactorList.Count() + " reactors"); }
List <Part> getModulePartParent(string moduleToFind, PartModule pm) { List <Part> lastPart = new List <Part>(); List <Part> plist = this.vessel.parts; if (plist != null) { for (int i = plist.Count - 1; i >= 0; --i) { PartModuleList pmoduleList = plist[i].Modules; for (int i1 = pmoduleList.Count - 1; i1 >= 0; --i1) { if (pmoduleList[i1].moduleName == moduleToFind) { lastPart.Add(plist[i]); } } } } return(lastPart); }
// Gets all attached radiators private void SetupRadiators() { Debug.Log("NFPP: Fission Reactor: begin radiator check...."); radiators = new List <FissionRadiator>(); // Get attached radiators Part[] children = this.part.FindChildParts <Part>(); // Debug.Log("NFPP: Reactor has " + children.Length.ToString()+" children"); foreach (Part pt in children) { PartModuleList modules = pt.Modules; for (int i = 0; i < modules.Count; i++) { PartModule curModule = modules.GetModule(i); FissionRadiator candidate = curModule.GetComponent <FissionRadiator>(); if (candidate != null) { radiators.Add(candidate); } } } Debug.Log("NFPP: Fission Reactor: Completed radiator check"); }
public static Part getModulePartParent(PartModule pm) { Part lastPart = null; List <Part> plist = getPartList(pm); if (plist != null) { for (int i = plist.Count - 1; i >= 0; --i) { PartModuleList pmoduleList = plist[i].Modules; for (int i1 = pmoduleList.Count - 1; i1 >= 0; --i1) { if (pmoduleList[i1].moduleName == Constants.MODNAME) { lastPart = plist[i]; break; } } } } return(lastPart); }
//return index count of specific partmodule type only, not of entire part.modules list. Used in save routine public static int PartModuleModuleToIndex(PartModule pm, PartModuleList pmList) { try { List<PartModule> pmListThisType = new List<PartModule>(); foreach (PartModule pm2 in pmList) { if (pm2.GetType().Name == pm.GetType().Name) { pmListThisType.Add(pm2); } } return pmListThisType.IndexOf(pm); } catch { Debug.Log("AGX SavePMIndex Fail, using default"); return 0; } }
public void Start() { Log.Info("Start"); part.RestoreVariant(); #if false SetThrustCurve(grainName, null); #endif Events["TriggerEngineFailureEvent"].active = HighLogic.CurrentGame.Parameters.CustomParams <MSSRB_1>().devMode; Actions["TriggerEngineFailureAction"].active = HighLogic.CurrentGame.Parameters.CustomParams <MSSRB_1>().devMode; #if false foreach (var e in Events) { Log.Info("Event: " + e.name + ", guiName = " + e.guiName); } foreach (var a in Actions) { Log.Info("Action: " + a.name + ", guiName: " + a.guiName); } foreach (var f in Fields) { Log.Info("Field: " + f.name + ", guiName: " + f.guiName); } #endif Fields["independentThrottle"].guiActive = Fields["independentThrottle"].guiActiveEditor = false; Fields["thrustPercentage"].guiActive = Fields["thrustPercentage"].guiActiveEditor = false; origAtmosphereCurve = atmosphereCurve; PartResourceDefinition prd = PartResourceLibrary.Instance.GetDefinition(ModSegSRBs.Propellant); density = prd.density; densityInverse = 1.0 / prd.density; fuelFlowMultiplier = densityInverse * Planetarium.fetch.fixedDeltaTime; phl = PartHighlighter.CreatePartHighlighter(); if (phl) { highlightID = phl.CreateHighlightList(); } if (highlightID >= 0) { UpdateHighlightColors(); } PartModuleList pml = part.Modules; if (pml.Contains("MSSRB_Fuel_Segment")) { MSSRB_Fuel_Segment moduleFuelSegment = pml["MSSRB_Fuel_Segment"] as MSSRB_Fuel_Segment; part.segmentWidth = moduleFuelSegment.part.segmentWidth; } else { Log.Info("MSSRB_Engine, missing MSSRB_Fuel_Segment"); } foreach (var p in propellants) { if (p.name == ModSegSRBs.BurnablePropellant) { break; } burnablePropIndx++; } foreach (var p in propellants) { if (p.name == ModSegSRBs.Propellant) { break; } propIndx++; } ModSegSRBs.GetExtraInfo(part.baseVariant, ref part.segmentHeight, ref part.segmentWidth); switch (HighLogic.LoadedScene) { case GameScenes.EDITOR: GameEvents.onEditorPartPicked.Add(onEditorPartPicked); GameEvents.onEditorPartPlaced.Add(onEditorPartPlaced); GameEvents.onEditorPartDeleted.Add(onEditorPartDeleted); GameEvents.onVariantApplied.Add(onEditorVariantApplied); ScheduleSegmentUpdate("Start"); break; case GameScenes.FLIGHT: failureChance = HighLogic.CurrentGame.Parameters.CustomParams <MSSRB_1>().failureChance; if (this.vessel.situation <= Vessel.Situations.PRELAUNCH) { UpdateSegments(); foreach (var s in segments) { /* PartModuleList */ pml = s.part.Modules; MSSRB_Fuel_Segment moduleFuelSegment = pml["MSSRB_Fuel_Segment"] as MSSRB_Fuel_Segment; PartResourceList prl = s.part.Resources; if (prl.Contains(ModSegSRBs.Propellant)) { //Log.Info("Segment: " + s.part.partInfo.title + " contains Propellant"); prl[ModSegSRBs.Propellant].amount = moduleFuelSegment.MaxSolidFuel(); } if (prl.Contains(ModSegSRBs.BurnablePropellant)) { prl[ModSegSRBs.BurnablePropellant].amount = 0; //prl[ModSegSRBs.BurnablePropellant].amount = moduleFuelSegment.MaxSolidFuel(); //Log.Info("Segment: " + s.part.partInfo.title + " contains BurnablePropellant"); } } } break; } // switch }
/// <summary> /// Calculate available power from generators and reactors /// </summary> /// <returns></returns> private double GetAvailablePower_Other() { double otherPower = 0; // Go through all parts and get power from generators and reactors for (int i = 0; i < vessel.parts.Count; ++i) { var part = vessel.parts[i]; // Standard RTG ModuleGenerator powerModule = part.FindModuleImplementing <ModuleGenerator>(); if (powerModule != null) { if (powerModule.generatorIsActive || powerModule.isAlwaysActive) { // Go through resources and get EC power for (int j = 0; j < powerModule.resHandler.outputResources.Count; ++j) { var resource = powerModule.resHandler.outputResources[j]; if (resource.name == "ElectricCharge") { otherPower += resource.rate * powerModule.efficiency; } } } } // Other generators PartModuleList modules = part.Modules; for (int j = 0; j < modules.Count; ++j) { var module = modules[j]; // Near future fission reactors if (module.moduleName == "FissionGenerator") { otherPower += double.Parse(module.Fields.GetValue("CurrentGeneration").ToString()); } // KSP Interstellar generators if ((module.moduleName == "ThermalElectricEffectGenerator") || (module.moduleName == "IntegratedThermalElectricPowerGenerator") || (module.moduleName == "ThermalElectricPowerGenerator") || (module.moduleName == "IntegratedChargedParticlesPowerGenerator") || (module.moduleName == "ChargedParticlesPowerGenerator") || (module.moduleName == "FNGenerator")) { if (bool.Parse(module.Fields.GetValue("IsEnabled").ToString())) { //otherPower += double.Parse(module.Fields.GetValue("maxElectricdtps").ToString()); // Doesn't work as expected string maxPowerStr = module.Fields.GetValue("MaxPowerStr").ToString(); double maxPower = 0; if (maxPowerStr.Contains("GW")) { maxPower = double.Parse(maxPowerStr.Replace(" GW", "")) * 1000000; } else if (maxPowerStr.Contains("MW")) { maxPower = double.Parse(maxPowerStr.Replace(" MW", "")) * 1000; } else { maxPower = double.Parse(maxPowerStr.Replace(" KW", "")); } otherPower += maxPower; } } } // WBI reactors, USI reactors and MKS Power Pack ModuleResourceConverter converterModule = part.FindModuleImplementing <ModuleResourceConverter>(); if (converterModule != null) { if (converterModule.ModuleIsActive() && ((converterModule.ConverterName == "Nuclear Reactor") || (converterModule.ConverterName == "Reactor") || (converterModule.ConverterName == "Generator"))) { for (int j = 0; j < converterModule.outputList.Count; ++j) { var resource = converterModule.outputList[j]; if (resource.ResourceName == "ElectricCharge") { otherPower += resource.Ratio * converterModule.GetEfficiencyMultiplier(); } } } } } return(otherPower); }
bool CheckPartResources(MSSRB_Part part) { // Check the nextPart's resources and Modules // Check for the correct propellant and that it has the MSSRB_Fuel_Segment module // If so, add it to the segments list and accumulate some values for the motor // then update the propellant value amount in the fuel segment PartResourceList prl = part.Resources; PartModuleList pml = part.Modules; if (prl.Contains(ModSegSRBs.Propellant) && pml.Contains <MSSRB_Fuel_Segment>()) { Log.Info("CheckPartResources, Part: " + part.partInfo.title + ", " + ModSegSRBs.Propellant + " found, " + " MSSRB_Fuel_Segment found"); MSSRB_Fuel_Segment moduleFuelSegment = pml["MSSRB_Fuel_Segment"] as MSSRB_Fuel_Segment; segments.Add(new Segment(part, moduleFuelSegment.part.segmentHeight)); totalFuelMass += moduleFuelSegment.MaxSolidFuel(); // prl[ModSegSRBs.Propellant].maxAmount; totalMaxThrust += moduleFuelSegment.GetMaxThrust(); Log.Info("CheckPartResources, moduleFuelSegment.part.segmentHeight: " + moduleFuelSegment.part.segmentHeight); totalSegmentHeight += moduleFuelSegment.part.segmentHeight; Log.Info("CheckPartResources, totalFuelMass: " + totalFuelMass + ", totalMaxThrust: " + totalMaxThrust + ", totalSegmentHeight: " + totalSegmentHeight); if (totalSegmentHeight > 0) { invTotalSegmentHeight = 1 / totalSegmentHeight; } else { invTotalSegmentHeight = 0; } moduleFuelSegment.baseEngine = this; if (CoM == null && HighLogic.LoadedSceneIsEditor) { prl[ModSegSRBs.Propellant].amount = prl[ModSegSRBs.Propellant].maxAmount = 0; prl[ModSegSRBs.BurnablePropellant].amount = prl[ModSegSRBs.BurnablePropellant].maxAmount = moduleFuelSegment.MaxSolidFuel(); Log.Info("(2) Propellant Setting part.amount = 0, BurnablePropellant maxAmount set to: " + prl[ModSegSRBs.BurnablePropellant].maxAmount); } else { prl[ModSegSRBs.Propellant].amount = prl[ModSegSRBs.Propellant].maxAmount = moduleFuelSegment.MaxSolidFuel(); prl[ModSegSRBs.BurnablePropellant].amount = prl[ModSegSRBs.BurnablePropellant].maxAmount = 0; } Log.Info("totalMaxThrust: " + totalMaxThrust + ", totalFuelMass: " + totalFuelMass); // Set the baseEngine in the segment ends here, do it in a loop // because there can be either one or two ends foreach (var p in pml) { if (p is MSSRB_SegmentEnds) { MSSRB_SegmentEnds mssrb = p as MSSRB_SegmentEnds; mssrb.baseEngine = this; mssrb.maxThrust = this.maxThrust; mssrb.atmosphereCurve = this.atmosphereCurve; } } return(true); } else { Log.Info("CheckPartResources, no Propellant found"); return(false); } }
void Start() { nonThrustMotor = true; attNode = this.part.FindAttachNode(attachNode); activated = false; #if true base.Events["Activate"].active = false; base.Events["Activate"].guiActive = false; base.Events["Shutdown"].active = false; base.Events["Shutdown"].guiActive = false; base.Fields["independentThrottle"].guiActive = false; base.Fields["independentThrottle"].guiActiveEditor = false; base.Fields["independentThrottlePercentage"].guiActive = false; base.Fields["independentThrottlePercentage"].guiActiveEditor = false; base.Fields["thrustPercentage"].guiActive = false; base.Fields["thrustPercentage"].guiActiveEditor = false; Actions["ToggleThrottle"].active = false; Actions["ToggleThrottle"].activeEditor = false; foreach (var e in Events) { Log.Info("Event: " + e.name + ", guiName = " + e.GUIName); } foreach (var a in Actions) { Log.Info("Action: " + a.name + ", guiName: " + a.guiName); } #endif if (HighLogic.LoadedSceneIsFlight) { PartModuleList pml = part.Modules; if (pml.Contains <MSSRB_Fuel_Segment>()) { thisSegment = pml.GetModule <MSSRB_Fuel_Segment>(); } if (attNode != null && attNode.attachedPart != null) { pml = attNode.attachedPart.Modules; if (pml != null) { if (pml.Contains <MSSRB_Fuel_Segment>()) { attachedSegment = pml.GetModule <MSSRB_Fuel_Segment>(); } if (pml.Contains <MSSRB_Endcap>()) { attachedEndCap = pml.GetModule <MSSRB_Endcap>(); } if (pml.Contains <MSSRB_Engine>()) { attachedMotor = pml.GetModule <MSSRB_Engine>(); } } } } }
private double CalculateOtherPower() { double otherPower = 0; for (int i = 0; i < this.vessel.parts.Count; ++i) { var part = this.vessel.parts[i]; // Find standard RTGs ModuleGenerator powerModule = part.FindModuleImplementing <ModuleGenerator>(); if (powerModule != null) { if (powerModule.generatorIsActive || powerModule.isAlwaysActive) { for (int j = 0; j < powerModule.resHandler.outputResources.Count; ++j) { var resource = powerModule.resHandler.outputResources[j]; if (resource.name == "ElectricCharge") { otherPower += resource.rate * powerModule.efficiency; } } } } // Search for other generators PartModuleList modules = part.Modules; for (int j = 0; j < modules.Count; ++j) { var module = modules[j]; // Near future fission reactors if (module.moduleName == "FissionGenerator") { otherPower += double.Parse(module.Fields.GetValue("CurrentGeneration").ToString()); } // KSP Interstellar generators if (module.moduleName == "FNGenerator") { string maxPowerStr = module.Fields.GetValue("MaxPowerStr").ToString(); double maxPower = 0; if (maxPowerStr.Contains("GW")) { maxPower = double.Parse(maxPowerStr.Replace(" GW", "")) * 1000000; } else if (maxPowerStr.Contains("MW")) { maxPower = double.Parse(maxPowerStr.Replace(" MW", "")) * 1000; } else { maxPower = double.Parse(maxPowerStr.Replace(" KW", "")); } otherPower += maxPower; } } // WBI reactors, USI reactors and MKS Power Pack ModuleResourceConverter converterModule = part.FindModuleImplementing <ModuleResourceConverter>(); if (converterModule != null) { if (converterModule.ModuleIsActive() && ((converterModule.ConverterName == "Nuclear Reactor") || (converterModule.ConverterName == "Reactor") || (converterModule.ConverterName == "Generator"))) { for (int j = 0; j < converterModule.outputList.Count; ++j) { var resource = converterModule.outputList[j]; if (resource.ResourceName == "ElectricCharge") { otherPower += resource.Ratio * converterModule.GetEfficiencyMultiplier(); } } } } } return(otherPower); } // So many ifs.....
//These are all multiplied in case multiple modules exist on one part (this one takes a PartModuleList instead) public double GetModuleVariable(PartModuleList modules) { double value = 1.0; foreach (PartModule mod in modules) { if (Module_Variables.ContainsKey(mod.moduleName)) value *= Module_Variables[mod.moduleName]; } return value; }
public override void OnFixedUpdate() { activeCount++; if (IsEnabled) { List <Part> vesselparts = vessel.parts; float electrical_current_available = 0; for (int i = 0; i < vesselparts.Count; ++i) { Part cPart = vesselparts.ElementAt(i); PartModuleList pml = cPart.Modules; for (int j = 0; j < pml.Count; ++j) { var curFNGen = pml.GetModule(j) as FNGenerator; var curMwRec = pml.GetModule(j) as MicrowavePowerReceiver; var curSolarPan = pml.GetModule(j) as ModuleDeployableSolarPanel; if (curFNGen != null) { float consumeMJ = curFNGen.getMaxPowerOutput() * TimeWarp.fixedDeltaTime; float cvalue = consumeFNResource(consumeMJ, FNResourceManager.FNRESOURCE_MEGAJOULES); electrical_current_available = cvalue * 1000 / TimeWarp.fixedDeltaTime; nuclear = true; } else if (curMwRec != null && nuclear == false) { //electrical_current_available = curMwRec.powerInput; part.RequestResource("ElectricCharge", electrical_current_available * TimeWarp.fixedDeltaTime); microwave = true; } else if (curSolarPan != null && nuclear == false && microwave == false) { electrical_current_available += curSolarPan.flowRate; part.RequestResource("ElectricCharge", electrical_current_available * TimeWarp.fixedDeltaTime); solar = true; } } } inputPower = electrical_current_available; } else { inputPower = 0; } if (activeCount % 1000 == 9) { ConfigNode config = PluginHelper.getPluginSaveFile(); string genType = "undefined"; //float inputPowerFixedAlt = (float) ((double)inputPower * (Math.Pow(FlightGlobals.Bodies[0].GetAltitude(vessel.transform.position), 2)) / PluginHelper.FIXED_SAT_ALTITUDE / PluginHelper.FIXED_SAT_ALTITUDE); float inputPowerFixedAlt = 0; if (nuclear == true) { inputPowerFixedAlt = inputPower; //print ("warp: nuclear inputPower " + inputPowerFixedAlt); genType = "nuclear"; } else if (microwave == true) { inputPowerFixedAlt = inputPower; //print ("warp: relay inputPower " + inputPowerFixedAlt); genType = "relay"; } else if (solar == true) { //inputPowerFixedAlt = inputPower / PluginHelper.getSatFloatCurve ().Evaluate ((float)FlightGlobals.Bodies [0].GetAltitude (vessel.transform.position)); //print ("warp: solar inputPower " + inputPowerFixedAlt); genType = "solar"; } if (genType != "undefined") { string vesselIDSolar = vessel.id.ToString(); string outputPower = inputPowerFixedAlt.ToString("0.000"); if (!config.HasValue(vesselIDSolar)) { config.AddValue(vesselIDSolar, outputPower); } else { config.SetValue(vesselIDSolar, outputPower); } if (!config.HasValue(vesselIDSolar + "type")) { config.AddValue(vesselIDSolar + "type", genType); } else { config.SetValue(vesselIDSolar + "type", genType); } config.Save(PluginHelper.getPluginSaveFilePath()); } } }
internal void scanVessel() { List <ProtoCrewMember> VesselCrew = this.vessel.GetVesselCrew(); this.VPIT.vesselCrew = VesselCrew; List <Part> vesselParts = this.vessel.Parts; this.VPIT.vesselParts = vesselParts; this.VPIT.vesselResourceGenerators = new Dictionary <int, ModuleGenerator>() { }; //ModuleGenerator[] MG_list = UnityEngine.Object.FindObjectsOfType<ModuleGenerator>(); List <ModuleGenerator> MG_list = this.VPIT.vessel.FindPartModulesImplementing <ModuleGenerator>(); int i = 0; foreach (ModuleGenerator MG in MG_list) { List <ModuleGenerator.GeneratorResource> MG_GR = MG.outputList; if (!this.VPIT.vesselResourceGenerators.ContainsKey(i)) { this.VPIT.vesselResourceGenerators.Add(i, MG); } i++; } this.VPIT.vesselPartModules = new Dictionary <string, PartModule>() { }; this.VPIT.vesselPartResources = new Dictionary <string, PartResource>() { }; this.VPIT.AveragePartTemperature = 0f; this.VPIT.AveragePartTemperatureMax = 0f; foreach (Part p in this.VPIT.vesselParts) { this.VPIT.AveragePartTemperature += p.temperature; this.VPIT.AveragePartTemperatureMax += p.maxTemp; this.VPIT.vesselResourceMass += p.GetResourceMass(); PartModuleList pML = p.Modules; foreach (PartModule pm in pML) { if (!this.VPIT.vesselPartModules.ContainsKey(pm.moduleName)) { this.VPIT.vesselPartModules.Add(pm.moduleName, pm); } } PartResourceList pRL = p.Resources; foreach (PartResource pr in pRL) { if (!this.VPIT.vesselPartResources.ContainsKey(pr.resourceName)) { this.VPIT.vesselPartResources.Add(pr.resourceName, pr); } } } this.VPIT.heat_percentage = this.VPIT.AveragePartTemperature / (this.VPIT.AveragePartTemperatureMax / 100); this.VPIT.hullintegrity_percentage = 100 - this.VPIT.heat_percentage; this.VPIT.vesselWetMass = this.vessel.GetTotalMass(); this.VPIT.vesselDryMass += this.VPIT.vesselWetMass - this.VPIT.vesselResourceMass; //UnityEngine.Debug.Log("VesselPartsInventory: print_Modules vesselResourceMass=" + this.VPIT.vesselResourceMass + " vesselWetMass=" + this.VPIT.vesselWetMass + " vesselDryMass=" + this.VPIT.vesselDryMass); }