public override void OnUpdate() { Events["ActivateScoop"].active = !scoopIsEnabled; Events["DisableScoop"].active = scoopIsEnabled; Events["ToggleResource"].active = scoopIsEnabled; Fields["resflow"].guiActive = scoopIsEnabled; Fields["currentresourceStr"].guiActive = scoopIsEnabled; Fields["resourceStoragename"].guiActive = scoopIsEnabled; double resourcePercentage = AtmosphericResourceHandler.GetAtmosphericResourceContent(vessel.mainBody, currentresource) * 100; string resourceDisplayName = AtmosphericResourceHandler.GetAtmosphericResourceDisplayName(vessel.mainBody, currentresource); if (resourceDisplayName != null) { currentresourceStr = resourceDisplayName + "(" + resourcePercentage + "%)"; } UpdateResourceFlow(); }
private void ScoopAtmosphere(double deltaTimeInSeconds, bool offlineCollecting) { string currentResourceName = AtmosphericResourceHandler.GetAtmosphericResourceName(vessel.mainBody, currentresource); string resourceDisplayName = AtmosphericResourceHandler.GetAtmosphericResourceDisplayName(vessel.mainBody, currentresource); if (currentResourceName == null) { resflowf = 0; recievedPower = Localizer.Format("#LOC_KSPIE_ISRUScoop_error"); //"error" densityFractionOfUpperAthmosphere = Localizer.Format("#LOC_KSPIE_ISRUScoop_error"); //"error" return; } // map ors resource to kspi resource if (PluginHelper.OrsResourceMappings == null || !PluginHelper.OrsResourceMappings.TryGetValue(currentResourceName, out resourceStoragename)) { resourceStoragename = currentResourceName; } else if (!PartResourceLibrary.Instance.resourceDefinitions.Contains(resourceStoragename)) { resourceStoragename = currentResourceName; } var definition = PartResourceLibrary.Instance.GetDefinition(resourceStoragename); if (definition == null) { return; } double resourceDensity = definition.density; double maxAltitudeAtmosphere = PluginHelper.getMaxAtmosphericAltitude(vessel.mainBody); double upperAtmosphereFraction = Math.Max(0, (vessel.altitude - maxAltitudeAtmosphere) / Math.Max(0.000001, maxAltitudeAtmosphere * PluginHelper.MaxAtmosphericAltitudeMult - maxAltitudeAtmosphere)); double upperAtmosphereDensity = 1 - upperAtmosphereFraction; double airDensity = part.vessel.atmDensity + (PluginHelper.MinAtmosphericAirDensity * upperAtmosphereDensity); atmosphericDensity = airDensity.ToString("0.00000000"); var hydrogenTax = 0.4 * Math.Sin(upperAtmosphereFraction * Math.PI * 0.5); var heliumTax = 0.2 * Math.Sin(upperAtmosphereFraction * Math.PI); double resourceFraction = (1.0 - hydrogenTax - heliumTax) * AtmosphericResourceHandler.GetAtmosphericResourceContent(vessel.mainBody, currentresource); // increase density hydrogen if (resourceDisplayName == ResourceSettings.Config.HydrogenGas) { resourceFraction += hydrogenTax; } else if (resourceDisplayName == ResourceSettings.Config.Helium4Gas) { resourceFraction += heliumTax; } densityFractionOfUpperAthmosphere = upperAtmosphereDensity.ToString("P3"); rescourcePercentage = resourceFraction * 100; if (resourceFraction <= 0 || vessel.altitude > (PluginHelper.getMaxAtmosphericAltitude(vessel.mainBody) * PluginHelper.MaxAtmosphericAltitudeMult)) { resflowf = 0; recievedPower = Localizer.Format("#LOC_KSPIE_ISRUScoop_off"); //"off" densityFractionOfUpperAthmosphere = Localizer.Format("#LOC_KSPIE_ISRUScoop_toohigh"); //"too high" rescourcePercentage = 0; return; } double airspeed = part.vessel.srf_velocity.magnitude + 40.0; double air = airspeed * airDensity * 0.001 * scoopair / resourceDensity; double scoopedAtm = air * resourceFraction; double powerRequirementsInMegawatt = 40.0 * scoopair * PluginHelper.PowerConsumptionMultiplier * powerReqMult; if (scoopedAtm > 0 && part.GetResourceSpareCapacity(resourceStoragename) > 0) { // Determine available power, using EC if below 2 MW required double powerReceivedInMegawatt = consumeMegawatts(powerRequirementsInMegawatt, true, false, powerRequirementsInMegawatt < 2.0); last_power_percentage = offlineCollecting ? last_power_percentage : powerReceivedInMegawatt / powerRequirementsInMegawatt; } else { last_power_percentage = 0; powerRequirementsInMegawatt = 0; } recievedPower = PluginHelper.getFormattedPowerString(last_power_percentage * powerRequirementsInMegawatt) + " / " + PluginHelper.getFormattedPowerString(powerRequirementsInMegawatt); double resourceChange = scoopedAtm * last_power_percentage * deltaTimeInSeconds; if (offlineCollecting) { string format = resourceChange > 100 ? "0" : "0.00"; ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_KSPIE_ISRUScoop_CollectedMsg") + " " + resourceChange.ToString(format) + " " + resourceStoragename, 10.0f, ScreenMessageStyle.LOWER_CENTER);//Atmospheric Scoop collected } resflowf = part.RequestResource(resourceStoragename, -resourceChange); resflowf = -resflowf / TimeWarp.fixedDeltaTime; UpdateResourceFlow(); }