/// <summary> /// Consumes electric charge and return whether boiloff happens /// </summary> /// <returns></returns> public bool ConsumeCharge() { bool boiloff = false; if (CoolingEnabled && IsCoolable()) { double chargeRequest = finalCoolingCost * TimeWarp.fixedDeltaTime; vessel.GetConnectedResourceTotals(PartResourceLibrary.Instance.GetDefinition("ElectricCharge").id, out double currentEC, out double maxEC); // only use EC if there is more then minResToLeave left double consumedEC = 0; if (currentEC > (chargeRequest + minResToLeave)) { consumedEC = part.RequestResource("ElectricCharge", chargeRequest); } double tolerance = 0.0001; if (consumedEC >= (chargeRequest - tolerance)) { boiloff = false; BoiloffStatus = Localizer.Format("#LOC_CryoTanks_ModuleCryoTank_Field_BoiloffStatus_Insulated"); CoolingStatus = Localizer.Format("#LOC_CryoTanks_ModuleCryoTank_Field_CoolingStatus_Cooling", finalCoolingCost.ToString("F2")); } else { boiloff = true; BoiloffStatus = BoiloffUtils.FormatRate(GetTotalBoiloffRate() * fuelAmount * fluxScale); CoolingStatus = Localizer.Format("#LOC_CryoTanks_ModuleCryoTank_Field_CoolingStatus_Uncooled"); } } return(boiloff); }
/// <summary> /// Sets the boiloff state /// </summary> /// <param name="state">Whether boiloff is occuring or not</param> /// <return>The total cost of the boiloff</return> public double SetBoiloffState(bool isBoiling) { if (CoolingEnabled && IsCoolable()) { if (isBoiling) { BoiloffOccuring = true; BoiloffStatus = BoiloffUtils.FormatRate(GetTotalBoiloffRate() * fuelAmount * fluxScale); CoolingStatus = Localizer.Format("#LOC_CryoTanks_ModuleCryoTank_Field_CoolingStatus_Uncooled"); } else { BoiloffOccuring = false; BoiloffStatus = String.Format("Insulated"); CoolingStatus = Localizer.Format("#LOC_CryoTanks_ModuleCryoTank_Field_CoolingStatus_Cooling", finalCoolingCost.ToString("F2")); } return((double)finalCoolingCost); } return(0d); }
protected void FixedUpdate() { if (HighLogic.LoadedSceneIsFlight && HasAnyBoiloffResource) { fluxScale = CalculateRadiativeEffects(); fuelAmount = GetTotalResouceAmount(); // If we have no fuel, no need to do any calculations if (fuelAmount == 0.0) { BoiloffStatus = Localizer.Format("#LOC_CryoTanks_ModuleCryoTank_Field_BoiloffStatus_NoFuel"); CoolingStatus = Localizer.Format("#LOC_CryoTanks_ModuleCryoTank_Field_CoolingStatus_NoFuel"); currentCoolingCost = 0.0; return; } // If the tank is not coolable we must boil off if (!IsCoolable()) { BoiloffOccuring = true; BoiloffStatus = BoiloffUtils.FormatRate(GetTotalBoiloffRate() * fuelAmount * fluxScale); currentCoolingCost = 0.0; } // else check for available power else { if (!CoolingEnabled) { BoiloffOccuring = true; BoiloffStatus = BoiloffUtils.FormatRate(GetTotalBoiloffRate() * fuelAmount * fluxScale); CoolingStatus = Localizer.Format("#LOC_CryoTanks_ModuleCryoTank_Field_CoolingStatus_Disabled"); currentCoolingCost = 0.0; } else { BoiloffOccuring = ConsumeCharge(); currentCoolingCost = finalCoolingCost; } } if (BoiloffOccuring) { DoBoiloff(); } if (part.vessel.missionTime > 0.0) { } } if (HighLogic.LoadedSceneIsFlight && DebugMode) { D_Albedo = String.Format("{0:F4}", Albedo); D_Emiss = String.Format("{0:F4}", part.emissiveConstant); D_InPlanet = String.Format("{0:F4}", planetFlux); D_InSolar = String.Format("{0:F4}", solarFlux * Albedo); D_NetRad = String.Format("{0:F4}", fluxScale); } if (HighLogic.LoadedSceneIsEditor && HasAnyBoiloffResource) { currentCoolingCost = GetTotalCoolingCost() * GetTotalMaxResouceAmount() / 1000d; } }