コード例 #1
0
        private void Load(ConfigNode node)
        {
            msg_signal      = Lib.ConfigValue(node, "msg_signal", false);
            msg_belt        = Lib.ConfigValue(node, "msg_belt", false);
            cfg_ec          = Lib.ConfigValue(node, "cfg_ec", PreferencesMessages.Instance.ec);
            cfg_supply      = Lib.ConfigValue(node, "cfg_supply", PreferencesMessages.Instance.supply);
            cfg_signal      = Lib.ConfigValue(node, "cfg_signal", PreferencesMessages.Instance.signal);
            cfg_malfunction = Lib.ConfigValue(node, "cfg_malfunction", PreferencesMessages.Instance.malfunction);
            cfg_storm       = Lib.ConfigValue(node, "cfg_storm", PreferencesMessages.Instance.storm);
            cfg_script      = Lib.ConfigValue(node, "cfg_script", PreferencesMessages.Instance.script);
            cfg_highlights  = Lib.ConfigValue(node, "cfg_highlights", PreferencesReliability.Instance.highlights);
            cfg_showlink    = Lib.ConfigValue(node, "cfg_showlink", true);
            cfg_show        = Lib.ConfigValue(node, "cfg_show", true);

            deviceTransmit = Lib.ConfigValue(node, "deviceTransmit", true);

            solarPanelsAverageExposure = Lib.ConfigValue(node, "solarPanelsAverageExposure", -1.0);
            scienceTransmitted         = Lib.ConfigValue(node, "scienceTransmitted", 0.0);

            stormData   = new StormData(node.GetNode("StormData"));
            habitatInfo = new VesselHabitatInfo(node.GetNode("SunShielding"));
            computer    = new Computer(node.GetNode("computer"));

            supplies = new Dictionary <string, SupplyData>();
            foreach (var supply_node in node.GetNode("supplies").GetNodes())
            {
                supplies.Add(DB.From_safe_key(supply_node.name), new SupplyData(supply_node));
            }

            scansat_id = new List <uint>();
            foreach (string s in node.GetValues("scansat_id"))
            {
                scansat_id.Add(Lib.Parse.ToUInt(s));
            }

            ConfigNode partsNode = new ConfigNode();

            if (node.TryGetNode("parts", ref partsNode))
            {
                foreach (ConfigNode partDataNode in partsNode.GetNodes())
                {
                    PartData partData;
                    if (parts.TryGetValue(Lib.Parse.ToUInt(partDataNode.name), out partData))
                    {
                        partData.Load(partDataNode);
                    }
                }
            }

            filesTransmitted = new List <File>();
            vesselSituations = new VesselSituations(this);
        }
コード例 #2
0
        public static void Update(CelestialBody body, double elapsed_s)
        {
            // do nothing if storms are disabled
            if (!Features.SpaceWeather)
            {
                return;
            }

            StormData bd = DB.Storm(body.name);

            CreateStorm(bd, body, body.orbit.semiMajorAxis);

            // send messages

            if (Body_is_relevant(body))
            {
                switch (bd.storm_state)
                {
                case 2:
                    if (bd.msg_storm < 2)
                    {
                        Message.Post(Severity.danger, Lib.BuildString("The coronal mass ejection hit <b>", body.name, "</b> system"),
                                     Lib.BuildString("Storm duration: ", Lib.HumanReadableDuration(bd.displayed_duration)));
                    }
                    break;

                case 1:
                    if (bd.msg_storm < 1 && bd.display_warning)
                    {
                        var tti = bd.storm_time - Planetarium.GetUniversalTime();
                        Message.Post(Severity.warning, Lib.BuildString("Our observatories report a coronal mass ejection directed toward <b>", body.name, "</b> system"),
                                     Lib.BuildString("Time to impact: ", Lib.HumanReadableDuration(tti)));
                    }
                    break;

                case 0:
                    if (bd.msg_storm == 2)
                    {
                        Message.Post(Severity.relax, Lib.BuildString("The solar storm at <b>", body.name, "</b> system is over"));
                    }
                    break;
                }
            }

            bd.msg_storm = bd.storm_state;
        }
コード例 #3
0
        private void FieldsDefaultInit()
        {
            msg_signal      = false;
            msg_belt        = false;
            cfg_ec          = PreferencesMessages.Instance.ec;
            cfg_supply      = PreferencesMessages.Instance.supply;
            cfg_signal      = PreferencesMessages.Instance.signal;
            cfg_malfunction = PreferencesMessages.Instance.malfunction;
            cfg_storm       = PreferencesMessages.Instance.storm;
            cfg_script      = PreferencesMessages.Instance.script;
            cfg_highlights  = PreferencesReliability.Instance.highlights;
            cfg_showlink    = true;
            deviceTransmit  = true;

            stormData        = new StormData(null);
            habitatInfo      = new VesselHabitatInfo(null);
            computer         = new Computer(null);
            supplies         = new Dictionary <string, SupplyData>();
            scansat_id       = new List <uint>();
            filesTransmitted = new List <File>();
            vesselSituations = new VesselSituations(this);
        }
コード例 #4
0
        internal static void CreateStorm(StormData bd, CelestialBody body, double distanceToSun)
        {
            // do nothing if storms are disabled
            if (!Features.SpaceWeather)
            {
                return;
            }

            var now = Planetarium.GetUniversalTime();

            if (bd.storm_generation < now)
            {
                var sun         = Lib.GetParentSun(body);
                var avgDuration = PreferencesRadiation.Instance.AvgStormDuration;

                // retry after 3 * average storm duration + jitter (to avoid recalc spikes)
                bd.storm_generation = now + avgDuration * 3 + avgDuration * Lib.RandomDouble();

                var rb       = Radiation.Info(sun);
                var activity = rb.solar_cycle > 0 ? rb.SolarActivity() : 1.0;

                if (Lib.RandomDouble() < activity * PreferencesRadiation.Instance.stormFrequency)
                {
                    // storm duration depends on current solar activity
                    bd.storm_duration = avgDuration / 2.0 + avgDuration * activity * 2;

                    // if further out, the storm lasts longer (but is weaker)
                    bd.storm_duration /= Storm_frequency(distanceToSun);

                    // set a start time to give enough time for warning
                    bd.storm_time = now + Time_to_impact(distanceToSun);

                    // delay next storm generation by duration of this one
                    bd.storm_generation += bd.storm_duration;

                    // add a random error to the estimated storm duration if we don't observe the sun too well
                    var error = bd.storm_duration * 3 * Lib.RandomDouble() * (1 - sun_observation_quality);
                    bd.displayed_duration = bd.storm_duration + error;

                    // show warning message only if you're lucky...
                    bd.display_warning = Lib.RandomFloat() < sun_observation_quality;


#if DEBUG_RADIATION
                    Lib.Log("Storm on " + body + " will start in " + Lib.HumanReadableDuration(bd.storm_time - now) + " and last for " + Lib.HumanReadableDuration(bd.storm_duration));
                }
                else
                {
                    Lib.Log("No storm on " + body + ", will retry in " + Lib.HumanReadableDuration(bd.storm_generation - now));
#endif
                }
            }

            if (bd.storm_time + bd.storm_duration < now)
            {
                // storm is over
                bd.Reset();
            }
            else if (bd.storm_time < now && bd.storm_time + bd.storm_duration > now)
            {
                // storm in progress
                bd.storm_state = 2;
            }
            else if (bd.storm_time > now)
            {
                // storm incoming
                bd.storm_state = 1;
            }
        }