public override void OnFixedUpdate() { if (scoopIsEnabled) { string atmospheric_resource_name = ORSAtmosphericResourceHandler.getAtmosphericResourceName(vessel.mainBody.flightGlobalsIndex, currentresource); if (atmospheric_resource_name != null) { double resourcedensity = PartResourceLibrary.Instance.GetDefinition(atmospheric_resource_name).density; double respcent = ORSAtmosphericResourceHandler.getAtmosphericResourceContent(vessel.mainBody.flightGlobalsIndex, currentresource); //double resourcedensity = PartResourceLibrary.Instance.GetDefinition(PluginHelper.atomspheric_resources_tocollect[currentresource]).density; //double respcent = PluginHelper.getAtmosphereResourceContent(vessel.mainBody.flightGlobalsIndex, currentresource); double airdensity = part.vessel.atmDensity / 1000; double powerrequirements = scoopair / 0.15f * 6f; double airspeed = part.vessel.srf_velocity.magnitude + 40.0; double air = airspeed * airdensity * scoopair / resourcedensity; if (respcent > 0 && vessel.altitude <= PluginHelper.getMaxAtmosphericAltitude(vessel.mainBody)) { double scoopedAtm = air * respcent; float powerreceived = Math.Max(consumeFNResource(powerrequirements * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_MEGAJOULES), 0); float powerpcnt = (float)(powerreceived / powerrequirements / TimeWarp.fixedDeltaTime); //resflowf = (float)part.RequestResource(atmospheric_resource_name, -scoopedAtm * powerpcnt * TimeWarp.fixedDeltaTime); resflowf = (float)ORSHelper.fixedRequestResource(part, atmospheric_resource_name, -scoopedAtm * powerpcnt * TimeWarp.fixedDeltaTime); resflowf = -resflowf / TimeWarp.fixedDeltaTime; } } else { } } }
public override void OnFixedUpdate() { if (scoopIsEnabled) { string atmospheric_resource_name = ORSAtmosphericResourceHandler.getAtmosphericResourceName(vessel.mainBody.flightGlobalsIndex, currentresource); if (atmospheric_resource_name != null) { //Common double resourcedensity = PartResourceLibrary.Instance.GetDefinition(atmospheric_resource_name).density; double respcent = ORSAtmosphericResourceHandler.getAtmosphericResourceContent(vessel.mainBody.flightGlobalsIndex, currentresource); double airdensity = part.vessel.atmDensity / 1000; double powerrequirements = scoopair / 0.15f * ecRequirement; double airspeed = part.vessel.srf_velocity.magnitude + 40.0; double air = airspeed * airdensity * scoopair / resourcedensity; if (respcent > 0 && vessel.altitude <= ORSHelper.getMaxAtmosphericAltitude(vessel.mainBody)) { double scoopedAtm = air * respcent; float powerreceived = (float)Math.Max(part.RequestResource("ElectricCharge", powerrequirements * TimeWarp.fixedDeltaTime), 0); float powerpcnt = (float)(powerreceived / powerrequirements / TimeWarp.fixedDeltaTime); resflowf = (float)ORSHelper.fixedRequestResource(part, atmospheric_resource_name, -scoopedAtm * powerpcnt * TimeWarp.fixedDeltaTime); resflowf = -resflowf / TimeWarp.fixedDeltaTime; } } } }
public override void OnFixedUpdate() { if (CollectorIsEnabled) { string atmospheric_resource_name = ORSAtmosphericResourceHandler.getAtmosphericResourceName(vessel.mainBody.flightGlobalsIndex, currentresource); if (atmospheric_resource_name != null) { //range is 10% of the atmosphere var range = ORSHelper.getMaxAtmosphericAltitude(vessel.mainBody) * 1.1; double resourcedensity = PartResourceLibrary.Instance.GetDefinition(atmospheric_resource_name).density; double respcent = ORSAtmosphericResourceHandler.getAtmosphericResourceContent(vessel.mainBody.flightGlobalsIndex, currentresource); //If we're in the narrow band of the upper atmosphere if (vessel.altitude <= range && respcent > 0 && vessel.altitude >= ORSHelper.getMaxAtmosphericAltitude(vessel.mainBody)) { /** RAILS **/ if (Time.timeSinceLevelLoad < 1.0f || !FlightGlobals.ready) { return; } if (lastUpdateTime == 0.0f) { // Just started running lastUpdateTime = Planetarium.GetUniversalTime(); return; } double deltaTime = Math.Min(Planetarium.GetUniversalTime() - lastUpdateTime, Utilities.MaxDeltaTime); lastUpdateTime += deltaTime; /** RAILS **/ double powerrequirements = particleRate / 0.15f * ecRequirement; double desiredPower = powerrequirements * TimeWarp.fixedDeltaTime; double maxPower = powerrequirements * Math.Max(Utilities.ElectricityMaxDeltaTime, TimeWarp.fixedDeltaTime); var powerRequested = Math.Min(desiredPower, maxPower); double particles = particleRate / resourcedensity; double CollectedParticles = particles * respcent; float powerreceived = (float) Math.Max( part.RequestResource("ElectricCharge", powerRequested), 0); float powerpcnt = (float)(powerreceived / desiredPower); resflowf = (float) ORSHelper.fixedRequestResource(part, atmospheric_resource_name, -CollectedParticles * powerpcnt * deltaTime); resflowf = -resflowf / (float)deltaTime; } } } }
public void ToggleResource() { currentresource++; if (ORSAtmosphericResourceHandler.getAtmosphericResourceName(vessel.mainBody.flightGlobalsIndex, currentresource) == null && ORSAtmosphericResourceHandler.getAtmosphericResourceContent(vessel.mainBody.flightGlobalsIndex, currentresource) > 0 && currentresource != 0) { ToggleResource(); } if (currentresource >= ORSAtmosphericResourceHandler.getAtmosphericCompositionForBody(vessel.mainBody.flightGlobalsIndex).Count) { currentresource = 0; } }
private void ScoopAthmosphere(double deltaTimeInSeconds, bool offlineCollecting) { string atmospheric_resource_name = ORSAtmosphericResourceHandler.getAtmosphericResourceName(vessel.mainBody.flightGlobalsIndex, currentresource); if (atmospheric_resource_name == null) { resflowf = 0.0f; return; } double resourcedensity = PartResourceLibrary.Instance.GetDefinition(atmospheric_resource_name).density; double respcent = ORSAtmosphericResourceHandler.getAtmosphericResourceContent(vessel.mainBody.flightGlobalsIndex, currentresource); //double resourcedensity = PartResourceLibrary.Instance.GetDefinition(PluginHelper.atomspheric_resources_tocollect[currentresource]).density; //double respcent = PluginHelper.getAtmosphereResourceContent(vessel.mainBody.flightGlobalsIndex, currentresource); double airdensity = (part.vessel.atmDensity + PluginHelper.MinAtmosphericAirDensity) / 1000.0; double powerrequirements = (scoopair / 0.15f) * 6f * (float)PluginHelper.PowerConsumptionMultiplier; double airspeed = part.vessel.srf_velocity.magnitude + 40.0; double air = airspeed * airdensity * scoopair / resourcedensity; if (respcent == 0 || vessel.altitude > (PluginHelper.getMaxAtmosphericAltitude(vessel.mainBody) * PluginHelper.MaxAtmosphericAltitudeMult)) { resflowf = 0.0f; return; } double scoopedAtm = air * respcent; float powerreceived = Math.Max(consumeFNResource(powerrequirements * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_MEGAJOULES), 0); last_power_percentage = offlineCollecting ? last_power_percentage : (float)(powerreceived / powerrequirements / TimeWarp.fixedDeltaTime); double resourceChange = scoopedAtm * last_power_percentage * deltaTimeInSeconds; if (offlineCollecting) { string numberformat = resourceChange > 100 ? "0" : "0.00"; ScreenMessages.PostScreenMessage("Atmospheric Scoop collected " + resourceChange.ToString(numberformat) + " " + atmospheric_resource_name, 10.0f, ScreenMessageStyle.LOWER_CENTER); } //resflowf = (float)part.RequestResource(atmospheric_resource_name, -scoopedAtm * powerpcnt * TimeWarp.fixedDeltaTime); resflowf = (float)ORSHelper.fixedRequestResource(part, atmospheric_resource_name, -resourceChange); resflowf = -resflowf / TimeWarp.fixedDeltaTime; }
private void ScoopAthmosphere(double deltaTimeInSeconds, bool offlineCollecting) { string ors_atmospheric_resource_name = ORSAtmosphericResourceHandler.getAtmosphericResourceName(vessel.mainBody.flightGlobalsIndex, currentresource); string resourceDisplayName = ORSAtmosphericResourceHandler.getAtmosphericResourceDisplayName(vessel.mainBody.flightGlobalsIndex, currentresource); if (ors_atmospheric_resource_name == null) { resflowf = 0.0f; recievedPower = "error"; densityFractionOfUpperAthmosphere = "error"; return; } // map ors resource to kspi resource if (PluginHelper.OrsResourceMappings == null || !PluginHelper.OrsResourceMappings.TryGetValue(ors_atmospheric_resource_name, out resourceStoragename)) { resourceStoragename = ors_atmospheric_resource_name; } else if (!PartResourceLibrary.Instance.resourceDefinitions.Contains(resourceStoragename)) { resourceStoragename = ors_atmospheric_resource_name; } //double resourcedensity = PartResourceLibrary.Instance.GetDefinition(PluginHelper.atomspheric_resources_tocollect[currentresource]).density; double resourcedensity = PartResourceLibrary.Instance.GetDefinition(resourceStoragename).density; double maxAltitudeAtmosphere = PluginHelper.getMaxAtmosphericAltitude(vessel.mainBody); double upperAtmospherFraction = Math.Max(0, (vessel.altitude - maxAltitudeAtmosphere) / Math.Max(0.000001, maxAltitudeAtmosphere * PluginHelper.MaxAtmosphericAltitudeMult - maxAltitudeAtmosphere)); double upperatmosphereDensity = 1 - upperAtmospherFraction; double airDensity = part.vessel.atmDensity + (PluginHelper.MinAtmosphericAirDensity * upperatmosphereDensity); atmosphericDensity = airDensity.ToString("0.00000000"); var hydrogenTax = 0.4 * Math.Sin(upperAtmospherFraction * Math.PI * 0.5); var heliumTax = 0.2 * Math.Sin(upperAtmospherFraction * Math.PI); double rescourceFraction = (1.0 - hydrogenTax - heliumTax) * ORSAtmosphericResourceHandler.getAtmosphericResourceContent(vessel.mainBody.flightGlobalsIndex, currentresource); // increase density hydrogen if (resourceDisplayName == "Hydrogen") { rescourceFraction += hydrogenTax; } else if (resourceDisplayName == "Helium") { rescourceFraction += heliumTax; } densityFractionOfUpperAthmosphere = (upperatmosphereDensity * 100.0).ToString("0.000") + "%"; rescourcePercentage = (float)rescourceFraction * 100f; if (rescourceFraction <= 0 || vessel.altitude > (PluginHelper.getMaxAtmosphericAltitude(vessel.mainBody) * PluginHelper.MaxAtmosphericAltitudeMult)) { resflowf = 0.0f; recievedPower = "off"; densityFractionOfUpperAthmosphere = "too high"; rescourcePercentage = 0; return; } double airspeed = part.vessel.srf_velocity.magnitude + 40.0; double air = airspeed * (airDensity / 1000) * scoopair / resourcedensity; double scoopedAtm = air * rescourceFraction; double powerrequirementsMW = (scoopair / 0.15f) * 6f * PluginHelper.PowerConsumptionMultiplier * powerReqMult; if (scoopedAtm > 0 && part.GetResourceSpareCapacity(resourceStoragename) > 0) { var powerRequest = powerrequirementsMW * TimeWarp.fixedDeltaTime; // calculate available power double powerreceivedMW = CheatOptions.InfiniteElectricity ? powerRequest : Math.Max(consumeFNResource(powerRequest, FNResourceManager.FNRESOURCE_MEGAJOULES), 0); double normalisedRevievedPowerMW = powerreceivedMW / TimeWarp.fixedDeltaTime; // if power requirement sufficiently low, retreive power from KW source if (powerrequirementsMW < 2 && normalisedRevievedPowerMW <= powerrequirementsMW) { var requiredKW = (powerrequirementsMW - normalisedRevievedPowerMW) * 1000; var recievedKW = ORSHelper.fixedRequestResource(part, FNResourceManager.STOCK_RESOURCE_ELECTRICCHARGE, requiredKW * TimeWarp.fixedDeltaTime); powerreceivedMW += (recievedKW / 1000); } last_power_percentage = offlineCollecting ? last_power_percentage : powerreceivedMW / powerrequirementsMW / TimeWarp.fixedDeltaTime; } else { last_power_percentage = 0; powerrequirementsMW = 0; } recievedPower = powerrequirementsMW < 2 ? (last_power_percentage * powerrequirementsMW * 1000).ToString("0.0") + " KW / " + (powerrequirementsMW * 1000).ToString("0.0") + " KW" : (last_power_percentage * powerrequirementsMW).ToString("0.0") + " MW / " + powerrequirementsMW.ToString("0.0") + " MW"; double resourceChange = scoopedAtm * last_power_percentage * deltaTimeInSeconds; if (offlineCollecting) { string numberformat = resourceChange > 100 ? "0" : "0.00"; ScreenMessages.PostScreenMessage("Atmospheric Scoop collected " + resourceChange.ToString(numberformat) + " " + resourceStoragename, 10.0f, ScreenMessageStyle.LOWER_CENTER); } //resflowf = (float)part.RequestResource(atmospheric_resource_name, -scoopedAtm * powerpcnt * TimeWarp.fixedDeltaTime); resflowf = (float)ORSHelper.fixedRequestResource(part, resourceStoragename, -resourceChange); resflowf = -resflowf / TimeWarp.fixedDeltaTime; UpdateResourceFlow(); }