public override void CalculatePerformance(double airRatio, double commandedThrottle, double flowMult, double ispMult)
{
// set base bits
base.CalculatePerformance(airRatio, commandedThrottle, flowMult, ispMult);
M0 = mach;
// Calculate Isp (before the shutdown check, so it displays even then)
Isp = atmosphereCurve.Evaluate((float)(p0 * 0.001d * PhysicsGlobals.KpaToAtmospheres)) * ispMult;
// if we're not combusting, don't combust and start cooling off
combusting = running;
statusString = "Nominal";
// ullage check first, overwrite if bad pressure or no propellants
if (!ullage)
{
combusting = false;
statusString = "Vapor in feed line";
}
// check fuel flow fraction
if (ffFraction <= 0d)
{
combusting = false;
statusString = "No propellants";
}
// check pressure
if (!pressure)
{
combusting = false;
statusString = "Lack of pressure";
}
if (disableUnderwater && underwater)
{
combusting = false;
statusString = "Underwater";
}
// check flow mult
double fuelFlowMult = FlowMult();
if (fuelFlowMult < flowMultMin)
{
combusting = false;
statusString = "Airflow outside specs";
}
if (commandedThrottle <= 0d)
combusting = false;
if (!combusting)
{
double declinePow = Math.Pow(tempDeclineRate, TimeWarp.fixedDeltaTime);
chamberTemp = Math.Max(Math.Max(t0, partTemperature), chamberTemp * declinePow);
fxPower = 0f;
}
else
{
// get current flow, and thus thrust.
fuelFlow = scale * flowMult * maxFlow * commandedThrottle * thrustRatio;
if (varyThrust > 0d && fuelFlow > 0d && HighLogic.LoadedSceneIsFlight)
fuelFlow *= (1d + (Mathf.PerlinNoise(Time.time, 0f) * 2d - 1d) * varyThrust);
fxPower = (float)(fuelFlow * maxFlowRecip * ispMult); // FX is proportional to fuel flow and Isp mult.
// apply fuel flow multiplier
double ffMult = fuelFlow * fuelFlowMult;
fuelFlow = ffMult;
if(atmCurveIsp != null)
Isp *= atmCurveIsp.Evaluate((float)(rho * (1d / 1.225d)));
if (velCurveIsp != null)
Isp *= velCurveIsp.Evaluate((float)mach);
double exhaustVelocity = Isp * 9.80665d;
SFC = 3600d / Isp;
thrust = ffMult * exhaustVelocity; // either way, thrust is base * mult * EV
// Calculate chamber temperature as ratio
double desiredTempRatio = Math.Max(tempMin, fxPower);
double machTemp = MachTemp() * 0.05d;
desiredTempRatio = desiredTempRatio * (1d + machTemp) + machTemp;
// set temp based on desired
double desiredTemp = desiredTempRatio * chamberNominalTemp;
if (Math.Abs(desiredTemp - chamberTemp) < 1d)
chamberTemp = desiredTemp;
else
{
double lerpVal = UtilMath.Clamp01(tempLerpRate * TimeWarp.fixedDeltaTime);
chamberTemp = UtilMath.LerpUnclamped(chamberTemp, desiredTemp, lerpVal);
}
}
fxThrottle = combusting ? (float)throttle : 0f;
}