Ejemplo n.º 1
0
        public override void OnFixedUpdate()
        {
            CelestialBody             body      = vessel.mainBody;
            ORSPlanetaryResourcePixel res_pixel = ORSPlanetaryResourceMapData.getResourceAvailability(vessel.mainBody.flightGlobalsIndex, resourceName, body.GetLatitude(vessel.transform.position), body.GetLongitude(vessel.transform.position));

            abundance = res_pixel.getAmount();
        }
        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";
            }
        }
Ejemplo n.º 3
0
 public static ORSPlanetaryResourcePixel getResourceAvailabilityByRealResourceName(int body, string resourcename, double lat, double lng)
 {
     if (body != current_body)
     {
         loadPlanetaryResourceData(body);
     }
     try{
         ORSPlanetaryResourceInfo resource_info = body_resource_maps.Where(ri => ri.Value.getResourceName() == resourcename).FirstOrDefault().Value;
         return(getResourceAvailability(body, resource_info.getName(), lat, lng));
     }catch (Exception ex) {
         ORSPlanetaryResourcePixel resource_pixel = new ORSPlanetaryResourcePixel(resourcename, 0, body);
         return(resource_pixel);
     }
 }
Ejemplo n.º 4
0
        public static ORSPlanetaryResourcePixel getResourceAvailability(int body, string resourcename, double lat, double lng)
        {
            if (body != current_body)
            {
                loadPlanetaryResourceData(body);
            }
            int lng_s = ((int)Math.Ceiling(Math.Abs(lng / 180)) % 2);

            lng = lng % 180;
            if (lng_s == 0)
            {
                lng = (180 * Math.Sign(lng) - lng) * (-1);
            }
            int lat_s = ((int)Math.Ceiling(Math.Abs(lat / 90)) % 2);

            lat = lat % 90;
            if (lat_s == 0)
            {
                lat = (90 * Math.Sign(lat) - lat) * (-1);
            }
            if (body_resource_maps.ContainsKey(resourcename))
            {
                ORSPlanetaryResourceInfo resource_info = body_resource_maps[resourcename];
                Texture2D map      = resource_info.getResourceMap();
                double    len_x    = map.width;
                double    len_y    = map.height;
                double    origin_x = map.width / 2.0;
                double    origin_y = map.height / 2.0;

                double map_x = (lng * len_x / 2 / 180 + origin_x);
                double map_y = (lat * len_y / 2 / 90 + origin_y);

                int pix_x = (int)Math.Round(map_x);
                int pix_y = (int)Math.Round(map_y);

                double resource_val = getPixelAbundanceValue(pix_x, pix_y, resource_info);

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

                return(resource_pixel);
            }
            else
            {
                ORSPlanetaryResourcePixel resource_pixel = new ORSPlanetaryResourcePixel(resourcename, 0, body);
                return(resource_pixel);
            }
        }
Ejemplo n.º 5
0
        public static ORSPlanetaryResourcePixel getResourceAvailability(int body, string resourcename, double lat, double lng)
        {
            if (body != current_body)
            {
                loadPlanetaryResourceData(body);
            }

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

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

                return(resource_pixel);
            }
            else
            {
                ORSPlanetaryResourcePixel resource_pixel = new ORSPlanetaryResourcePixel(resourcename, 0, body);
                return(resource_pixel);
            }
        }
        public static ORSPlanetaryResourcePixel getResourceAvailability(int body, string resourcename, double lat, double lng)
        {
            if (body != current_body)
            {
                loadPlanetaryResourceData(body);
            }
            int lng_s = ((int)Math.Ceiling(Math.Abs(lng / 180)) % 2);
            lng = lng % 180;
            if (lng_s == 0)
            {
                lng = (180 * Math.Sign(lng) - lng) * (-1);
            }
            int lat_s = ((int)Math.Ceiling(Math.Abs(lat / 90)) % 2);
            lat = lat % 90;
            if (lat_s == 0)
            {
                lat = (90 * Math.Sign(lat) - lat) * (-1);
            }
            if (body_resource_maps.ContainsKey(resourcename))
            {
                ORSPlanetaryResourceInfo resource_info = body_resource_maps[resourcename];
                Texture2D map = resource_info.getResourceMap();
                double len_x = map.width;
                double len_y = map.height;
                double origin_x = map.width / 2.0;
                double origin_y = map.height / 2.0;

                double map_x = (lng * len_x / 2 / 180 + origin_x);
                double map_y = (lat * len_y / 2 / 90 + origin_y);

                int pix_x = (int)Math.Round(map_x);
                int pix_y = (int)Math.Round(map_y);

                double resource_val = getPixelAbundanceValue(pix_x, pix_y, resource_info);

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

                return resource_pixel;
            }
            else
            {
                ORSPlanetaryResourcePixel resource_pixel = new ORSPlanetaryResourcePixel(resourcename, 0, body);
                return resource_pixel;
            }
        }
 public static ORSPlanetaryResourcePixel getResourceAvailabilityByRealResourceName(int body, string resourcename, double lat, double lng)
 {
     if (body != current_body)
     {
         loadPlanetaryResourceData(body);
     }
     try
     {
         ORSPlanetaryResourceInfo resource_info = body_resource_maps.Where(ri => ri.Value.getResourceName() == resourcename).FirstOrDefault().Value;
         return getResourceAvailability(body, resource_info.getName(), lat, lng);
     }
     catch (Exception ex)
     {
         ORSPlanetaryResourcePixel resource_pixel = new ORSPlanetaryResourcePixel(resourcename, 0, body);
         return resource_pixel;
     }
 }
Ejemplo n.º 8
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;
         }
     }
 }
        public static ORSPlanetaryResourcePixel getResourceAvailability(int body, string resourcename, double lat, double lng) 
        {
            if (body != current_body) loadPlanetaryResourceData(body);

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

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

                return resource_pixel;
            }
            else 
            {
                ORSPlanetaryResourcePixel resource_pixel = new ORSPlanetaryResourcePixel(resourcename, 0, body);
                return resource_pixel;
            }
        }