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 static double getPixelAbundanceValue(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];
         return(resource_info.getLatLongAbundanceValue(lat, lng));
     }
     else
     {
         return(0);
     }
 }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        public static void loadPlanetaryResourceData(int body)
        {
            string celestial_body_name = FlightGlobals.Bodies[body].bodyName;

            UrlDir.UrlConfig[] configs = GameDatabase.Instance.GetConfigs("ORSX_PLANETARY_RESOURCE");
            Debug.Log("[ORS] Loading Planetary Resource Data. Length: " + configs.Length);
            foreach (ORSX_ResourceAbundanceMarker 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("[ORSX] Loading Planetary Resource Data for " + celestial_body_name);
                    Texture2D map = GameDatabase.Instance.GetTexture(planetary_resource_config_node.GetValue("mapUrl"),
                                                                     false);
                    if (map == null)
                    {
                        continue;
                    }

                    //Texture managing addons can cause a texture to be able to load (ie map != null)
                    //but not be readable, at least not by GetPixel,
                    //which is called repeatedly at the end of the load method (in the getPixelAbundanceValue method)
                    //This tests the texture once to make sure it works properly before allowing it to continue
                    try
                    {
                        map.GetPixel(1, 1);
                    }
                    catch (UnityException e)
                    {
                        Debug.Log("Stop Doing Dumb Things With Your Map Textures: " + e);
                        continue;
                    }

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

                    if (body_resource_maps.ContainsKey(resource_gui_name))
                    {
                        continue;                                                    // skip duplicates
                    }
                    var resource_info = new ORSX_PlanetaryResourceInfo(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("ORSX/resource_point"); //Rename to whatever folder ORSX will be in; put default resource point texture there
                        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);
                    var 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;
                                var    angles = new Vector2d(theta, phi);
                                abundance_points_list.Add(angles);
                            }
                        }
                    }

                    body_abudnance_angles.Add(resource_gui_name, abundance_points_list.ToArray());
                    Debug.Log("[ORSX] " + abundance_points_list.Count + " high value " + resource_gui_name +
                              " locations detected");
                }
            }
        }
Exemplo n.º 5
0
        public static void loadPlanetaryResourceData(int body)
        {
            string celestial_body_name = FlightGlobals.Bodies[body].bodyName;
            UrlDir.UrlConfig[] configs = GameDatabase.Instance.GetConfigs("ORSX_PLANETARY_RESOURCE");
            Debug.Log("[ORS] Loading Planetary Resource Data. Length: " + configs.Length);
            foreach (ORSX_ResourceAbundanceMarker 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("[ORSX] Loading Planetary Resource Data for " + celestial_body_name);
                    Texture2D map = GameDatabase.Instance.GetTexture(planetary_resource_config_node.GetValue("mapUrl"),
                        false);
                    if (map == null) continue;

                    //Texture managing addons can cause a texture to be able to load (ie map != null)
                    //but not be readable, at least not by GetPixel,
                    //which is called repeatedly at the end of the load method (in the getPixelAbundanceValue method)
                    //This tests the texture once to make sure it works properly before allowing it to continue
                    try
                    {
                        map.GetPixel(1, 1);
                    }
                    catch (UnityException e)
                    {
                        Debug.Log("Stop Doing Dumb Things With Your Map Textures: " + e);
                        continue;
                    }

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

                    if (body_resource_maps.ContainsKey(resource_gui_name)) continue; // skip duplicates

                    var resource_info = new ORSX_PlanetaryResourceInfo(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("ORSX/resource_point"); //Rename to whatever folder ORSX will be in; put default resource point texture there
                        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);
                    var 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;
                                var angles = new Vector2d(theta, phi);
                                abundance_points_list.Add(angles);
                            }
                        }
                    }

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