public override void OnUpdate()
        {
            //double resource_abundance = 0;
            bool resource_available = false;

            if (vessel.Landed)
            {
                ORSPlanetaryResourcePixel current_resource_abundance_pixel = ORSPlanetaryResourceMapData.getResourceAvailabilityByRealResourceName(vessel.mainBody.flightGlobalsIndex, resourceName, vessel.latitude, vessel.longitude);
                resource_abundance = (float)current_resource_abundance_pixel.getAmount();
            }
            else if (vessel.checkSplashed())
            {
                resource_abundance = (float)ORSOceanicResourceHandler.getOceanicResourceContent(vessel.mainBody.flightGlobalsIndex, resourceName);
            }

            if (resource_abundance > 0)
            {
                resource_available = true;
            }

            Events["startResourceExtraction"].active = !IsEnabled && resource_available;
            Events["stopResourceExtration"].active   = IsEnabled;

            if (IsEnabled)
            {
                Fields["powerStr"].guiActive     = true;
                Fields["resourceRate"].guiActive = true;
                statusTitle = "Active";

                double power_required = 0;
                if (vessel.Landed)
                {
                    power_required = powerConsumptionLand;
                }
                else if (vessel.Splashed)
                {
                    power_required = powerConsumptionOcean;
                }

                powerStr = (power_required * electrical_power_ratio).ToString("0.000") + " MW / " + power_required.ToString("0.000") + " MW";
                double resource_density       = PartResourceLibrary.Instance.GetDefinition(resourceName).density;
                double resource_rate_per_hour = extraction_rate_d * resource_density * 3600;
                resourceRate = formatMassStr(resource_rate_per_hour);
            }
            else
            {
                Fields["powerStr"].guiActive     = false;
                Fields["resourceRate"].guiActive = false;
                statusTitle = "Offline";
            }
        }
示例#2
0
 public void FixedUpdate()
 {
     if (IsEnabled && HighLogic.LoadedSceneIsFlight)
     {
         double power_requirements = 0;
         double extraction_time    = 0;
         if (vessel.Landed)
         {
             power_requirements = powerConsumptionLand;
             extraction_time    = extractionRateLandPerTon;
         }
         else if (vessel.Splashed)
         {
             power_requirements = powerConsumptionOcean;
             extraction_time    = extractionRateOceanPerTon;
         }
         else
         {
             IsEnabled = false;
             return;
         }
         double electrical_power_provided = 0;
         if (resourceManaged)
         {
             electrical_power_provided = consumeFNResource(power_requirements * TimeWarp.fixedDeltaTime, resourceToUse);
         }
         else
         {
             electrical_power_provided = part.RequestResource(resourceToUse, power_requirements * TimeWarp.fixedDeltaTime);
         }
         if (power_requirements > 0)
         {
             electrical_power_ratio = electrical_power_provided / TimeWarp.fixedDeltaTime / power_requirements;
         }
         else
         {
             if (power_requirements < 0)
             {
                 IsEnabled = false;
                 return;
             }
             else
             {
                 electrical_power_ratio = 1;
             }
         }
         double resource_abundance = 0;
         if (vessel.Landed)
         {
             ORSPlanetaryResourcePixel current_resource_abundance_pixel = ORSPlanetaryResourceMapData.getResourceAvailabilityByRealResourceName(vessel.mainBody.flightGlobalsIndex, resourceName, vessel.latitude, vessel.longitude);
             resource_abundance = current_resource_abundance_pixel.getAmount();
         }
         else if (vessel.Splashed)
         {
             resource_abundance = ORSOceanicResourceHandler.getOceanicResourceContent(vessel.mainBody.flightGlobalsIndex, resourceName);
         }
         double extraction_rate = resource_abundance * extraction_time * electrical_power_ratio;
         if (resource_abundance > 0)
         {
             double resource_density = PartResourceLibrary.Instance.GetDefinition(resourceName).density;
             //extraction_rate_d = -part.RequestResource(resourceName, -extraction_rate / resource_density * TimeWarp.fixedDeltaTime) / TimeWarp.fixedDeltaTime;
             extraction_rate_d = -ORSHelper.fixedRequestResource(part, resourceName, -extraction_rate / resource_density * TimeWarp.fixedDeltaTime) / TimeWarp.fixedDeltaTime;
         }
         else
         {
             IsEnabled = false;
         }
     }
 }