public UllageSet(ModuleEnginesRF eng) { log.dbg("Ullage constructor called on " + eng.part.name); engine = eng; ullageSim = new UllageSimulator(engine.part.name); if (engine.vessel != null) { module = engine.vessel.GetComponent <UllageModule>(); } else { module = null; } tanks = new List <Part>(); rfTanks = new Dictionary <Part, Tanks.ModuleFuelTanks>(); // set engine fields pressureFed = engine.pressureFed; ullageEnabled = engine.ullage; // create orientaiton SetThrustAxis(engine.thrustAxis); if (HighLogic.LoadedSceneIsFlight || HighLogic.LoadedSceneIsEditor) { SetTanks(); // fill tank lists, find pressurization, etc. } }
public UllageSet(ModuleEnginesRF eng) { MonoBehaviour.print("*U* Ullage constructor called on " + eng.part.name); engine = eng; ullageSim = new UllageSimulator(engine.part.name); module = engine.vessel?.GetComponent <UllageModule>(); // set engine fields ullageEnabled = engine.ullage; // create orientaiton SetThrustAxis(engine.thrustAxis); if (HighLogic.LoadedSceneIsFlight || HighLogic.LoadedSceneIsEditor) { SetTanks(); // fill tank lists, find pressurization, etc. } }
/// <summary> /// Initializes this module. Loads custom curve data from persistence if necessary, and updates the engine module with the currently loaded curve. /// </summary> private void initialize() { if (initialized) { return; } initialized = true; ROELog.debug("Initializing..."); if (currentCurve == null) { ROELog.debug("currentCurve is null"); if (!string.IsNullOrEmpty(customCurveData)) { ROELog.debug("Using customCurveData"); //load currentCurve from customCurveData currentCurve = new FloatCurve(); currentCurve.loadSingleLine(customCurveData); savedCurve = currentCurve.ToStringSingleLine(); thrustCurveName = part.partInfo.title + " Custom"; } else if (usePresetCurve && !string.IsNullOrEmpty(presetCurveName)) { ROELog.debug("Using presetCurve: " + presetCurveName); //load currentCurve from PresetCurve data loadPresetCurve(presetCurveName); thrustCurveName = presetCurveName; customCurveData = ""; } else { ROELog.debug("Using curve from existing Engine Module"); //init to the curve that exists in the engine already ModuleEnginesRF pm = part.Modules.GetModule <ModuleEnginesRF>(); usePresetCurve = true; thrustCurveName = part.partInfo.title + " Curve"; currentCurve = new FloatCurve(); currentCurve.loadSingleLine(pm.thrustCurve.ToStringSingleLine()); savedCurve = currentCurve.ToStringSingleLine(); } } updateEngineCurve(); }
//TODO should be expanded to search the entire vessel during flight (respecting stage/flow setup) //TODO should be expanded to search the entire ShipConstruct in the editor, respecting stage flow private float getEnginePropellantMass(ModuleEnginesRF engine) { float fuelMass = 0; if (engine.propellants != null && engine.propellants.Count > 0) { int len = engine.propellants.Count; for (int i = 0; i < len; i++) { string propName = engine.propellants[0].name; PartResource pr = part.Resources[propName]; if (pr != null) { fuelMass += (float)(pr.info.density * pr.amount); } } } return(fuelMass); }
private void updateStats() { ModuleEnginesRF[] engines = part.GetComponents <ModuleEnginesRF>(); if (engines == null || engines.Length < 1 || engineModuleIndex < 0 || engineModuleIndex >= engines.Length) { //no valid engine module; set UI values to default/0, and disable UI fields return; } ModuleEnginesRF engine = engines[engineModuleIndex]; //derivation of fuel mass flow from isp and thrust, from expression of thrust from ISP (t = g * i * m) //t = thrust(kn), g = g0(m/s), i = isp(s), m = massflowrate(t/s) //t = g * i * m //basic definition //t = m * i * g //commutative re-arrangement //t/i/g = m //isolate mass flow float fuelMass = getEnginePropellantMass(engine); float ispValue = engine.atmosphereCurve.Evaluate(0); float delta = engine.maxThrust - engine.minThrust; float limiter = engine.thrustPercentage * 0.01f; float thrust = engine.minThrust + limiter * delta; float massFlow = thrust / ispValue / 9.81f;//m = t/i/g float burnTime = (fuelMass / massFlow); this.ispGuiDisplay = ispValue.ToString(); this.thrustGuiDisplay = thrust.ToString(); this.burnTimeGuiDisplay = burnTime.ToString(); this.fuelFlowGuiDisplay = (engine.maxThrust / ispValue).ToString(); //old code from SSTUModularBooster //if (engineModule != null) //{ // string prop = engineModule.propellants[0].name; // PartResource res = part.Resources[prop]; // double propMass = res.info.density * res.amount; // float delta = engineModule.maxThrust - engineModule.minThrust; // float limiter = engineModule.thrustPercentage * 0.01f; // guiThrust = engineModule.minThrust + delta * limiter; // float limit = guiThrust / engineModule.maxThrust; // guiBurnTime = (float)(propMass / engineModule.maxFuelFlow) / limit; //} }
public UllageSet(ModuleEnginesRF eng) { engine = eng; ullageSim = new UllageSimulator(); if (engine.vessel != null) module = engine.vessel.GetComponent<UllageModule>(); else module = null; tanks = new List<Part>(); rfTanks = new Dictionary<Part, Tanks.ModuleFuelTanks>(); // set engine fields pressureFed = engine.pressureFed; ullageEnabled = engine.ullage; // create orientaiton SetThrustAxis(engine.thrustAxis); if (HighLogic.LoadedSceneIsFlight || HighLogic.LoadedSceneIsEditor) SetTanks(); // fill tank lists, find pressurization, etc. }
public void Reset() { ullageSets.Clear(); tanks.Clear(); for (int i = partCount - 1; i >= 0; --i) { Part part = vessel.Parts[i]; for (int j = part.Modules.Count - 1; j >= 0; --j) { PartModule m = part.Modules[j]; if (m is Tanks.ModuleFuelTanks) { Tanks.ModuleFuelTanks tank = m as Tanks.ModuleFuelTanks; if (!tanks.Contains(tank)) { tanks.Add(tank); } } else if (m is ModuleEnginesRF) { ModuleEnginesRF engine = m as ModuleEnginesRF; if (engine.ullageSet == null) // just in case { engine.ullageSet = new UllageSet(engine); } else { engine.ullageSet.SetTanks(); engine.ullageSet.SetModule(this); } ullageSets.Add(engine.ullageSet); } } } }