コード例 #1
0
        public override void OnUpdate()
        {
            ORSPlanetaryResourceMapData.updatePlanetaryResourceMap();
            if (resourceInfo == null)
                if (ORSPlanetaryResourceMapData.getPlanetaryResourceMapData.ContainsKey(resourceName))
                    resourceInfo = ORSPlanetaryResourceMapData.getPlanetaryResourceMapData[resourceName];
            Events["DisplayResource"].active = Events["DisplayResource"].guiActive = !ORSPlanetaryResourceMapData.resourceIsDisplayed(resourceName) && mapViewAvailable;
            Events["DisplayResource"].guiName = "Display " + resourceName + " hotspots";
            Events["HideResource"].active = Events["HideResource"].guiActive = ORSPlanetaryResourceMapData.resourceIsDisplayed(resourceName) && mapViewAvailable;
            Events["HideResource"].guiName = "Hide " + resourceName + " hotspots";
            Fields["Ab"].guiName = resourceName + " abundance";
            if (resourceInfo != null)
            {
                if (resourceInfo.getResourceScale() == 1)
                {
                    Ab = (abundance * 100.0).ToString("0.00") + "%";
                }
                else
                {
                    Ab = (abundance * 1000000.0).ToString("0.0") + "ppm";
                }
            }
            else
                Ab = "Broken:(";

        }
コード例 #2
0
 public override void OnUpdate()
 {
     ORSPlanetaryResourceMapData.updatePlanetaryResourceMap();
     if (resourceInfo == null)
     {
         if (ORSPlanetaryResourceMapData.getPlanetaryResourceMapData.ContainsKey(resourceName))
         {
             resourceInfo = ORSPlanetaryResourceMapData.getPlanetaryResourceMapData[resourceName];
         }
     }
     Events["DisplayResource"].active  = Events["DisplayResource"].guiActive = !ORSPlanetaryResourceMapData.resourceIsDisplayed(resourceName) && mapViewAvailable;
     Events["DisplayResource"].guiName = "Display " + resourceName + " hotspots";
     Events["HideResource"].active     = Events["HideResource"].guiActive = ORSPlanetaryResourceMapData.resourceIsDisplayed(resourceName) && mapViewAvailable;
     Events["HideResource"].guiName    = "Hide " + resourceName + " hotspots";
     Fields["Ab"].guiName = resourceName + " abundance";
     if (resourceInfo != null)
     {
         if (resourceInfo.getResourceScale() == 1)
         {
             Ab = (abundance * 100.0).ToString("0.00") + "%";
         }
         else
         {
             Ab = (abundance * 1000000.0).ToString("0.0") + "ppm";
         }
     }
     else
     {
         Ab = "Broken:(";
     }
 }
コード例 #3
0
        public override void OnUpdate()
        {
            if (!isActive)
            {
                Ab = "off";
                return;
            }

            ORSPlanetaryResourceMapData.updatePlanetaryResourceMap();
            if (resourceInfo == null)
                if (ORSPlanetaryResourceMapData.getPlaneteryResourceMapData.ContainsKey(resourceName))
                    resourceInfo = ORSPlanetaryResourceMapData.getPlaneteryResourceMapData[resourceName];
            vessel.GetHeightFromTerrain();
            if (vessel.heightFromTerrain > maxAltitude)
            {
                Ab = "Too High";
                return;
            }

            Fields["Ab"].guiName = resourceName + " abundance";
            if (resourceInfo != null)
            {
                if (resourceInfo.getResourceScale() == 1)
                {
                    Ab = (abundance*100.0).ToString("0.00") + "%";
                }
                else
                {
                    Ab = (abundance*1000000.0).ToString("0.0") + "ppm";
                }
            }
            else
                Ab = "Broken:(";
        }
コード例 #4
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);
     }
 }
コード例 #5
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);
            }
        }
コード例 #6
0
        protected static double getPixelAbundanceValue(int pix_x, int pix_y, ORSPlanetaryResourceInfo resource_info)
        {
            Texture2D map              = resource_info.getResourceMap();
            Color     pix_color        = map.GetPixel(pix_x, pix_y);
            double    resource_val     = 0;
            double    scale_factor     = resource_info.getScaleFactor();
            double    scale_multiplier = resource_info.getScaleMultiplier();

            if (resource_info.getResourceScale() == ORSPlanetaryResourceInfo.LOG_SCALE)
            {
                resource_val = Math.Pow(scale_factor, pix_color.grayscale * 255.0) / 1000000 * scale_multiplier;
            }
            else if (resource_info.getResourceScale() == ORSPlanetaryResourceInfo.LINEAR_SCALE)
            {
                resource_val = pix_color.grayscale * scale_multiplier;
            }
            return(resource_val);
        }
コード例 #7
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);
            }
        }
コード例 #8
0
        public static void loadPlanetaryResourceData(int body)
        {
            string celestial_body_name = FlightGlobals.Bodies[body].bodyName;
            UrlDir.UrlConfig[] configs = GameDatabase.Instance.GetConfigs("PLANETARY_RESOURCE_DEFINITION");
            Debug.Log("[ORS] Loading Planetary Resource Data. Length: " + configs.Length);
            foreach (ORSResourceAbundanceMarker abundance_marker in abundance_markers)
            {
                removeAbundanceSphere(abundance_marker.getPlanetarySphere());
                removeAbundanceSphere(abundance_marker.getScaledSphere());
            }
            sphere = null;
            sphere_texture = null;
            body_resource_maps.Clear();
            body_abudnance_angles.Clear();
            map_body = -1;
            current_body = body;
            foreach (UrlDir.UrlConfig config in configs)
            {
                ConfigNode planetary_resource_config_node = config.config;
                if (planetary_resource_config_node.GetValue("celestialBodyName") == celestial_body_name && planetary_resource_config_node != null)
                {
                    Debug.Log("[ORS] Loading Planetary Resource Data for " + celestial_body_name);
                    string resource_gui_name = planetary_resource_config_node.GetValue("name");
                    if (body_resource_maps.ContainsKey(resource_gui_name))
                        continue;
                    Texture2D map = GameDatabase.Instance.GetTexture(planetary_resource_config_node.GetValue("mapUrl"), false);
                    try
                    {
                        map.GetPixel(1, 1);
                    }
                    catch (UnityException e)
                    {
                        Debug.Log("Stop Doing Dumb Things With Your Map Textures: " + e);
                        continue;
                    }
                    if (map == null)
                    {
                        continue;
                    }
                    ORSPlanetaryResourceInfo resource_info = new ORSPlanetaryResourceInfo(resource_gui_name, map, body);
                    if (planetary_resource_config_node.HasValue("resourceName"))
                    {
                        string resource_name = planetary_resource_config_node.GetValue("resourceName");
                        resource_info.setResourceName(resource_name);
                    }
                    if (planetary_resource_config_node.HasValue("resourceScale"))
                    {
                        string resource_scale = planetary_resource_config_node.GetValue("resourceScale");
                        resource_info.setResourceScale(resource_scale);
                    }
                    if (planetary_resource_config_node.HasValue("scaleFactor"))
                    {
                        string scale_factorstr = planetary_resource_config_node.GetValue("scaleFactor");
                        double scale_factor = double.Parse(scale_factorstr);
                        resource_info.setScaleFactor(scale_factor);
                    }
                    if (planetary_resource_config_node.HasValue("scaleMultiplier"))
                    {
                        string scale_multstr = planetary_resource_config_node.GetValue("scaleMultiplier");
                        double scale_mult = double.Parse(scale_multstr);
                        resource_info.setScaleMultiplier(scale_mult);
                    }
                    if (planetary_resource_config_node.HasValue("displayTexture"))
                    {
                        string tex_path = planetary_resource_config_node.GetValue("displayTexture");
                        resource_info.setDisplayTexture(tex_path);
                    }
                    else
                    {
                        string tex_path = planetary_resource_config_node.GetValue("WarpPlugin/resource_point");
                        resource_info.setDisplayTexture(tex_path);
                    }
                    if (planetary_resource_config_node.HasValue("displayThreshold"))
                    {
                        string display_threshold_str = planetary_resource_config_node.GetValue("displayThreshold");
                        double display_threshold = double.Parse(display_threshold_str);
                        resource_info.setDisplayThreshold(display_threshold);
                    }
                    body_resource_maps.Add(resource_gui_name, resource_info);
                    List<Vector2d> abundance_points_list = new List<Vector2d>();

                    for (int i = 0; i < map.height; ++i)
                    {
                        for (int j = 0; j < map.width; ++j)
                        {
                            if (getPixelAbundanceValue(j, i, resource_info) >= resource_info.getDisplayThreshold())
                            {
                                //high value location, mark it
                                double theta = (j - map.width / 2) * 2.0 * 180.0 / map.width;
                                double phi = (i - map.height / 2) * 2.0 * 90.0 / map.height;
                                Vector2d angles = new Vector2d(theta, phi);
                                //body_abudnance_angles.Add(resource_gui_name, angles);
                                abundance_points_list.Add(angles);
                            }
                        }
                    }

                    body_abudnance_angles.Add(resource_gui_name, abundance_points_list.ToArray());
                    Debug.Log("[ORS] " + abundance_points_list.Count + " high value " + resource_gui_name + " locations detected");
                }
            }
        }
コード例 #9
0
 protected static double getPixelAbundanceValue(int pix_x, int pix_y, ORSPlanetaryResourceInfo resource_info)
 {
     Texture2D map = resource_info.getResourceMap();
     Color pix_color = map.GetPixel(pix_x, pix_y);
     double resource_val = 0;
     double scale_factor = resource_info.getScaleFactor();
     double scale_multiplier = resource_info.getScaleMultiplier();
     if (resource_info.getResourceScale() == ORSPlanetaryResourceInfo.LOG_SCALE)
     {
         resource_val = Math.Pow(scale_factor, pix_color.grayscale * 255.0) / 1000000 * scale_multiplier;
     }
     else if (resource_info.getResourceScale() == ORSPlanetaryResourceInfo.LINEAR_SCALE)
     {
         resource_val = pix_color.grayscale * scale_multiplier;
     }
     return resource_val;
 }
コード例 #10
0
        public static void loadPlanetaryResourceData(int body)
        {
            string celestial_body_name = FlightGlobals.Bodies[body].bodyName;

            UrlDir.UrlConfig[] configs = GameDatabase.Instance.GetConfigs("PLANETARY_RESOURCE_DEFINITION");
            Debug.Log("[ORS] Loading Planetary Resource Data. Length: " + configs.Length);

            foreach (ORSResourceAbundanceMarker abundance_marker in abundance_markers)
            {
                removeAbundanceSphere(abundance_marker.getPlanetarySphere());
                removeAbundanceSphere(abundance_marker.getScaledSphere());
            }

            sphere         = null;
            sphere_texture = null;
            body_resource_maps.Clear();
            body_abudnance_angles.Clear();
            map_body     = -1;
            current_body = body;

            foreach (UrlDir.UrlConfig config in configs)
            {
                ConfigNode planetary_resource_config_node = config.config;
                if (planetary_resource_config_node.GetValue("celestialBodyName") == celestial_body_name && planetary_resource_config_node != null)
                {
                    Debug.Log("[ORS] Loading Planetary Resource Data for " + celestial_body_name);
                    Texture2D map = GameDatabase.Instance.GetTexture(planetary_resource_config_node.GetValue("mapUrl"), false);
                    if (map == null)
                    {
                        continue;
                    }

                    string resource_gui_name = planetary_resource_config_node.GetValue("name");

                    if (body_resource_maps.ContainsKey(resource_gui_name))
                    {
                        continue;                                                    // skip duplicates
                    }
                    ORSPlanetaryResourceInfo resource_info = new ORSPlanetaryResourceInfo(resource_gui_name, map, body);
                    if (planetary_resource_config_node.HasValue("resourceName"))
                    {
                        string resource_name = planetary_resource_config_node.GetValue("resourceName");
                        resource_info.setResourceName(resource_name);
                    }
                    if (planetary_resource_config_node.HasValue("resourceScale"))
                    {
                        string resource_scale = planetary_resource_config_node.GetValue("resourceScale");
                        resource_info.setResourceScale(resource_scale);
                    }
                    if (planetary_resource_config_node.HasValue("scaleFactor"))
                    {
                        string scale_factorstr = planetary_resource_config_node.GetValue("scaleFactor");
                        double scale_factor    = double.Parse(scale_factorstr);
                        resource_info.setScaleFactor(scale_factor);
                    }
                    if (planetary_resource_config_node.HasValue("scaleMultiplier"))
                    {
                        string scale_multstr = planetary_resource_config_node.GetValue("scaleMultiplier");
                        double scale_mult    = double.Parse(scale_multstr);
                        resource_info.setScaleMultiplier(scale_mult);
                    }

                    if (planetary_resource_config_node.HasValue("displayTexture"))
                    {
                        string tex_path = planetary_resource_config_node.GetValue("displayTexture");
                        resource_info.setDisplayTexture(tex_path);
                    }
                    else
                    {
                        string tex_path = planetary_resource_config_node.GetValue("WarpPlugin/ParticleFX/resource_point");
                        resource_info.setDisplayTexture(tex_path);
                    }

                    if (planetary_resource_config_node.HasValue("displayThreshold"))
                    {
                        string display_threshold_str = planetary_resource_config_node.GetValue("displayThreshold");
                        double display_threshold     = double.Parse(display_threshold_str);
                        resource_info.setDisplayThreshold(display_threshold);
                    }
                    body_resource_maps.Add(resource_gui_name, resource_info);
                    List <Vector2d> abundance_points_list = new List <Vector2d>();

                    for (int i = 0; i < map.height; ++i)
                    {
                        for (int j = 0; j < map.width; ++j)
                        {
                            if (resource_info.getPixelAbundanceValue(j, i) >= resource_info.getDisplayThreshold())
                            {
                                //high value location, mark it
                                double   theta  = (j - map.width / 2) * 2.0 * 180.0 / map.width;
                                double   phi    = (i - map.height / 2) * 2.0 * 90.0 / map.height;
                                Vector2d angles = new Vector2d(theta, phi);
                                abundance_points_list.Add(angles);
                            }
                        }
                    }

                    body_abudnance_angles.Add(resource_gui_name, abundance_points_list.ToArray());
                    Debug.Log("[ORS] " + abundance_points_list.Count + " high value " + resource_gui_name + " locations detected");
                }
            }
        }