public static GetResourceDensity ( int type ) : float | ||
type | int | |
return | float |
public void SetResourceConsumptions() { if (this.part.HasModule <MultiModeEngine>()) { string mode = this.part.GetModule <MultiModeEngine>().mode; foreach (ModuleEnginesFX engine in this.part.GetModules <ModuleEnginesFX>()) { if (engine.engineID == mode) { double flowRate = 0d; if (part.vessel != null) { if (engine.throttleLocked) { flowRate = engine.maxThrust * (engine.thrustPercentage / 100f) / (isp * 9.81d); } else { if (part.vessel.Landed) { flowRate = Math.Max(0.000001d, engine.maxThrust * (engine.thrustPercentage / 100f) * FlightInputHandler.state.mainThrottle) / (isp * 9.81d); } else { if (engine.requestedThrust > 0) { flowRate = engine.requestedThrust / (isp * 9.81d); } else { flowRate = engine.maxThrust * (engine.thrustPercentage / 100f) / (isp * 9.81d); } } } } else { flowRate = engine.maxThrust * (engine.thrustPercentage / 100f) / (isp * 9.81d); } float flowMass = 0f; foreach (Propellant propellant in engine.propellants) { flowMass += propellant.ratio * ResourceContainer.GetResourceDensity(propellant.id); } foreach (Propellant propellant in engine.propellants) { if (propellant.name == "ElectricCharge" || propellant.name == "IntakeAir") { continue; } double consumptionRate = propellant.ratio * flowRate / flowMass; resourceConsumptions.Add(propellant.id, consumptionRate); } } } } else if (this.part.HasModule <ModuleEnginesFX>()) { foreach (ModuleEnginesFX engine in part.GetModules <ModuleEnginesFX>()) { double flowRate = 0d; if (part.vessel != null) { if (engine.throttleLocked) { flowRate = engine.maxThrust * (engine.thrustPercentage / 100f) / (isp * 9.81d); } else { if (part.vessel.Landed) { flowRate = Math.Max(0.000001d, engine.maxThrust * (engine.thrustPercentage / 100f) * FlightInputHandler.state.mainThrottle) / (isp * 9.81d); } else { if (engine.requestedThrust > 0) { flowRate = engine.requestedThrust / (isp * 9.81d); } else { flowRate = engine.maxThrust * (engine.thrustPercentage / 100f) / (isp * 9.81d); } } } } else { flowRate = engine.maxThrust * (engine.thrustPercentage / 100f) / (isp * 9.81d); } float flowMass = 0f; foreach (Propellant propellant in engine.propellants) { flowMass += propellant.ratio * ResourceContainer.GetResourceDensity(propellant.id); } foreach (Propellant propellant in engine.propellants) { if (propellant.name == "ElectricCharge" || propellant.name == "IntakeAir") { continue; } double consumptionRate = propellant.ratio * flowRate / flowMass; resourceConsumptions.Add(propellant.id, consumptionRate); } } } else if (this.part.HasModule <ModuleEngines>()) { foreach (ModuleEngines engine in part.GetModules <ModuleEngines>()) { double flowRate = 0d; if (part.vessel != null) { if (engine.throttleLocked) { flowRate = engine.maxThrust * (engine.thrustPercentage / 100f) / (isp * 9.81d); } else { if (part.vessel.Landed) { flowRate = Math.Max(0.000001d, engine.maxThrust * (engine.thrustPercentage / 100f) * FlightInputHandler.state.mainThrottle) / (isp * 9.81d); } else { if (engine.requestedThrust > 0) { flowRate = engine.requestedThrust / (isp * 9.81d); } else { flowRate = engine.maxThrust * (engine.thrustPercentage / 100f) / (isp * 9.81d); } } } } else { flowRate = engine.maxThrust * (engine.thrustPercentage / 100f) / (isp * 9.81d); } float flowMass = 0f; foreach (Propellant propellant in engine.propellants) { flowMass += propellant.ratio * ResourceContainer.GetResourceDensity(propellant.id); } foreach (Propellant propellant in engine.propellants) { if (propellant.name == "ElectricCharge" || propellant.name == "IntakeAir") { continue; } double consumptionRate = propellant.ratio * flowRate / flowMass; resourceConsumptions.Add(propellant.id, consumptionRate); } } } }
public EngineSim(PartSim theEngine, double atmosphere, double velocity, float maxThrust, float minThrust, float thrustPercentage, float requestedThrust, Vector3 vecThrust, float realIsp, FloatCurve atmosphereCurve, FloatCurve velocityCurve, bool throttleLocked, List <Propellant> propellants, bool active, bool correctThrust) { StringBuilder buffer = null; //MonoBehaviour.print("Create EngineSim for " + theEngine.name); //MonoBehaviour.print("maxThrust = " + maxThrust); //MonoBehaviour.print("minThrust = " + minThrust); //MonoBehaviour.print("thrustPercentage = " + thrustPercentage); //MonoBehaviour.print("requestedThrust = " + requestedThrust); //MonoBehaviour.print("velocity = " + velocity); partSim = theEngine; isActive = active; thrust = (maxThrust - minThrust) * (thrustPercentage / 100f) + minThrust; //MonoBehaviour.print("thrust = " + thrust); thrustVec = vecThrust; double flowRate = 0d; if (partSim.hasVessel) { //MonoBehaviour.print("hasVessel is true"); actualThrust = requestedThrust; if (velocityCurve != null) { actualThrust *= velocityCurve.Evaluate((float)velocity); //MonoBehaviour.print("actualThrust at velocity = " + actualThrust); } isp = atmosphereCurve.Evaluate((float)partSim.part.staticPressureAtm); if (isp == 0d) { MonoBehaviour.print("Isp at " + partSim.part.staticPressureAtm + " is zero. Flow rate will be NaN"); } if (correctThrust && realIsp == 0) { float ispsl = atmosphereCurve.Evaluate(0); if (ispsl != 0) { thrust = thrust * isp / ispsl; } else { MonoBehaviour.print("Isp at sea level is zero. Unable to correct thrust."); } //MonoBehaviour.print("corrected thrust = " + thrust); } if (velocityCurve != null) { thrust *= velocityCurve.Evaluate((float)velocity); //MonoBehaviour.print("thrust at velocity = " + thrust); } if (throttleLocked) { //MonoBehaviour.print("throttleLocked is true"); flowRate = thrust / (isp * 9.81d); } else { if (partSim.isLanded) { //MonoBehaviour.print("partSim.isLanded is true, mainThrottle = " + FlightInputHandler.state.mainThrottle); flowRate = Math.Max(0.000001d, thrust * FlightInputHandler.state.mainThrottle) / (isp * 9.81d); } else { if (requestedThrust > 0) { if (velocityCurve != null) { requestedThrust *= velocityCurve.Evaluate((float)velocity); //MonoBehaviour.print("requestedThrust at velocity = " + requestedThrust); } //MonoBehaviour.print("requestedThrust > 0"); flowRate = requestedThrust / (isp * 9.81d); } else { //MonoBehaviour.print("requestedThrust <= 0"); flowRate = thrust / (isp * 9.81d); } } } } else { //MonoBehaviour.print("hasVessel is false"); isp = atmosphereCurve.Evaluate((float)atmosphere); if (isp == 0d) { MonoBehaviour.print("Isp at " + atmosphere + " is zero. Flow rate will be NaN"); } if (correctThrust) { float ispsl = atmosphereCurve.Evaluate(0); if (ispsl != 0) { thrust = thrust * isp / ispsl; } else { MonoBehaviour.print("Isp at sea level is zero. Unable to correct thrust."); } //MonoBehaviour.print("corrected thrust = " + thrust); } if (velocityCurve != null) { thrust *= velocityCurve.Evaluate((float)velocity); //MonoBehaviour.print("thrust at velocity = " + thrust); } flowRate = thrust / (isp * 9.81d); } if (SimManager.logOutput) { buffer = new StringBuilder(1024); buffer.AppendFormat("flowRate = {0:g6}\n", flowRate); } float flowMass = 0f; foreach (Propellant propellant in propellants) { flowMass += propellant.ratio * ResourceContainer.GetResourceDensity(propellant.id); } if (SimManager.logOutput) { buffer.AppendFormat("flowMass = {0:g6}\n", flowMass); } foreach (Propellant propellant in propellants) { if (propellant.name == "ElectricCharge" || propellant.name == "IntakeAir") { continue; } double consumptionRate = propellant.ratio * flowRate / flowMass; if (SimManager.logOutput) { buffer.AppendFormat("Add consumption({0}, {1}:{2:d}) = {3:g6}\n", ResourceContainer.GetResourceName(propellant.id), theEngine.name, theEngine.partId, consumptionRate); } resourceConsumptions.Add(propellant.id, consumptionRate); } if (SimManager.logOutput) { MonoBehaviour.print(buffer); } }