public static bool Prefix(DieselLocoSimulation __instance, float delta) { var engineTemp = __instance.engineTemp.value; var state = ExtraState.Instance(__instance); SimulateFanThermostats(engineTemp, state); var energyInKJ = RawPowerInWatts(__instance) * delta / __instance.timeMult / 1000; var heating = energyInKJ / WaterHeatCapacity / CoolantCapacity; if (__instance.engineOn) { __instance.engineTemp.AddNextValue(heating); } var airflowFraction = state.runningFans == 1 ? 0.75f : state.runningFans == 2 ? 1f : 0.01f; var airflow = airflowFraction * CoolingAirflow; var temperatureDelta = __instance.engineTemp.value - AmbientTemperature; var cooling = airflow * temperatureDelta * Main.settings.dieselCoolingMultiplier * delta / __instance.timeMult; __instance.engineTemp.AddNextValue(-cooling); // Main.DebugLog(TrainCar.Resolve(__instance.gameObject), () => $"power={RawPowerInWatts(__instance)} W, heating={heating / delta * __instance.timeMult} *C/s, cooling={cooling / delta * __instance.timeMult} *C/s, engineTemp={engineTemp}, nextTemp={__instance.engineTemp.nextValue}, runningFans={state.runningFans}"); return(false); }
public static bool Prefix(LocoControllerDiesel __instance, ref float __result) { var state = ExtraState.Instance(__instance.sim); __result = state.tractiveEffort; return(false); }
public static bool Prefix(DieselLocoSimulation __instance) { // var loco = TrainCar.Resolve(__instance.gameObject); if (PausePhysicsHandler.PhysicsHandlingInProcess) { return(false); } var throttleVelo = __instance.throttleToTargetDiff.value; var nextRPM = Mathf.SmoothDamp( current: __instance.engineRPM.value, target: TargetRPM(__instance.throttle.value), currentVelocity: ref throttleVelo, smoothTime: 1f, maxSpeed: 1f); __instance.throttleToTargetDiff.SetNextValue(throttleVelo); __instance.engineRPM.SetNextValue(nextRPM); // Main.DebugLog(loco, $"{loco.ID}: throttle={__instance.throttle.value}, RPM={__instance.engineRPM.value}, velo={throttleVelo}"); var state = ExtraState.Instance(__instance); state.CheckTransition(); var speedMetersPerSecond = __instance.speed.value / 3.6f; var powerOutput = (state.InTransition() || __instance.throttle.value == 0f) ? 0f : EngineMaxPower *TransmissionEfficiency *OutputPower(__instance.engineRPM.value); var target = powerOutput / Mathf.Max(1f, speedMetersPerSecond); state.tractiveEffort = Mathf.SmoothDamp( state.tractiveEffort, target, ref state.tractiveEffortVelo, 0.5f); // Main.DebugLog(loco, () => $"engineRPM={__instance.engineRPM.value}, speed={speedMetersPerSecond}, target={target}, TE={state.tractiveEffort}"); return(false); }
public static bool Prefix(ShunterLocoSimulation __instance, float delta) { var heating = Mathf.Lerp(0.025f, 1f, __instance.engineRPM.value) * 12f; if (__instance.engineOn) { __instance.engineTemp.AddNextValue(heating * delta); } var fanRunning = ExtraState.Instance(__instance).UpdateFan(); var thermostatOpen = __instance.engineTemp.value >= ThermostatTemp; var airflow = !thermostatOpen ? NoRadiatorSpeedEquivalent : fanRunning && __instance.speed.value < CoolingFanSpeedEquivalent ? CoolingFanSpeedEquivalent : __instance.speed.value; var temperatureDelta = __instance.engineTemp.value - AmbientTemperature; var cooling = airflow / CoolingFanSpeedEquivalent * temperatureDelta * Main.settings.shunterTemperatureMultiplier; __instance.engineTemp.AddNextValue(-cooling * delta); //Main.DebugLog(car, () => $"{car.ID}: RPM={__instance.engineRPM.value}, temp={__instance.engineTemp.value}, nextTemp={__instance.engineTemp.nextValue}, heating={heating}, airflow={airflow}, cooling={cooling}"); return(false); }
public static bool IsFanRunning(ShunterLocoSimulation sim) { return(ExtraState.Instance(sim).fanRunning); }