Exemplo n.º 1
0
        public static ORSX_PlanetaryResourcePixel getResourceAvailability(int body, string resourcename, double lat,
                                                                          double lng)
        {
            if (body != current_body)
            {
                loadPlanetaryResourceData(body);
            }

            if (body_resource_maps.ContainsKey(resourcename))
            {
                ORSX_PlanetaryResourceInfo resource_info = body_resource_maps[resourcename];
                double resource_val = resource_info.getLatLongAbundanceValue(lat, lng);

                var resource_pixel = new ORSX_PlanetaryResourcePixel(resource_info.getName(), resource_val,
                                                                     resource_info.getBody());
                resource_pixel.setResourceName(resource_info.getResourceName());

                return(resource_pixel);
            }
            else
            {
                var resource_pixel = new ORSX_PlanetaryResourcePixel(resourcename, 0, body);
                return(resource_pixel);
            }
        }
Exemplo n.º 2
0
        public override void OnFixedUpdate()
        {
            CelestialBody body = vessel.mainBody;
            ORSX_PlanetaryResourcePixel res_pixel =
                ORSX_PlanetaryResourceMapData.getResourceAvailability(vessel.mainBody.flightGlobalsIndex, resourceName,
                                                                      body.GetLatitude(vessel.transform.position), body.GetLongitude(vessel.transform.position));

            abundance = res_pixel.getAmount();
        }
 public override void OnUpdate()
 {
     if (HighLogic.LoadedSceneIsFlight)
     {
         double resource_abundance = 0;
         bool   resource_available = false;
         if (vessel.Landed)
         {
             ORSX_PlanetaryResourcePixel current_resource_abundance_pixel = ORSX_PlanetaryResourceMapData.getResourceAvailabilityByRealResourceName(vessel.mainBody.flightGlobalsIndex, resourceName, vessel.latitude, vessel.longitude);
             resource_abundance = current_resource_abundance_pixel.getAmount();
         }
         else if (vessel.Splashed)
         {
             resource_abundance = ORSX_OceanicResourceHandler.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";
         }
     }
 }
Exemplo n.º 4
0
        public static ORSX_PlanetaryResourcePixel getResourceAvailabilityByRealResourceName(int body, string resourcename,
                                                                                            double lat, double lng)
        {
            if (body != current_body)
            {
                loadPlanetaryResourceData(body);
            }

            try
            {
                ORSX_PlanetaryResourceInfo resource_info =
                    body_resource_maps.Where(ri => ri.Value.getResourceName() == resourcename).FirstOrDefault().Value;
                return(getResourceAvailability(body, resource_info.getName(), lat, lng));
            }
            catch (Exception ex)
            {
                var resource_pixel = new ORSX_PlanetaryResourcePixel(resourcename, 0, body);
                return(resource_pixel);
            }
        }
        public override void OnFixedUpdate()
        {
            if (IsEnabled)
            {
                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;
                }

                /** 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 electrical_power_provided = 0;
                double desiredPower = power_requirements * TimeWarp.fixedDeltaTime;
                double maxPower     = power_requirements * Math.Max(Utilities.ElectricityMaxDeltaTime, TimeWarp.fixedDeltaTime);

                var powerRequested = Math.Min(desiredPower, maxPower);


                electrical_power_provided = part.RequestResource(resourceToUse, powerRequested);
                if (power_requirements > 0)
                {
                    electrical_power_ratio = electrical_power_provided / desiredPower;
                }
                else
                {
                    if (power_requirements < 0)
                    {
                        IsEnabled = false;
                        return;
                    }
                    else
                    {
                        electrical_power_ratio = 1;
                    }
                }
                double resource_abundance = 0;
                if (vessel.Landed)
                {
                    ORSX_PlanetaryResourcePixel current_resource_abundance_pixel = ORSX_PlanetaryResourceMapData.getResourceAvailabilityByRealResourceName(vessel.mainBody.flightGlobalsIndex, resourceName, vessel.latitude, vessel.longitude);
                    resource_abundance = current_resource_abundance_pixel.getAmount();
                }
                else if (vessel.Splashed)
                {
                    resource_abundance = ORSX_OceanicResourceHandler.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 = -ORSX_Helper.fixedRequestResource(part, resourceName, -extraction_rate / resource_density * deltaTime) / deltaTime;
                }
                else
                {
                    IsEnabled = false;
                }
            }
        }