private static void RadiationLevels(CelestialBody body, out string inner, out string outer, out string pause) { // TODO cache this information in RadiationBody double rad = PreferencesStorm.Instance.externRadiation; var rbSun = Radiation.Info(FlightGlobals.Bodies[0]); rad += rbSun.radiation_pause; var rb = Radiation.Info(body); if (rb.inner_visible) inner = rb.model.has_inner ? "~" + Lib.HumanReadableRadiation(Math.Max(0, rad + rb.radiation_inner) / 3600.0) : "n/a"; else inner = "unknown"; if (rb.outer_visible) outer = rb.model.has_outer ? "~" + Lib.HumanReadableRadiation(Math.Max(0, rad + rb.radiation_outer) / 3600.0) : "n/a"; else outer = "unknown"; if (rb.pause_visible) pause = rb.model.has_pause ? "~" + Lib.HumanReadableRadiation(Math.Max(0, rad + rb.radiation_pause) / 3600.0) : "n/a"; else pause = "unknown"; }
private static void RadiationLevels(CelestialBody body, out string inner, out string outer, out string pause, out double activity, out double cycle) { // TODO cache this information somewhere var rb = Radiation.Info(body); double rad = Settings.ExternRadiation / 3600.0; var rbSun = Radiation.Info(Lib.GetParentSun(body)); rad += rbSun.radiation_pause; if (rb.inner_visible) { inner = rb.model.has_inner ? "~" + Lib.HumanReadableRadiation(Math.Max(0, rad + rb.radiation_inner)) : "n/a"; } else { inner = "unknown"; } if (rb.outer_visible) { outer = rb.model.has_outer ? "~" + Lib.HumanReadableRadiation(Math.Max(0, rad + rb.radiation_outer)) : "n/a"; } else { outer = "unknown"; } if (rb.pause_visible) { pause = rb.model.has_pause ? "∆" + Lib.HumanReadableRadiation(Math.Abs(rb.radiation_pause)) : "n/a"; } else { pause = "unknown"; } activity = -1; cycle = rb.solar_cycle; if (cycle > 0) { activity = rb.SolarActivity(); } }
public static bool IsAvailableOnBody(this VirtualBiome virtualBiome, CelestialBody body) { switch (virtualBiome) { case VirtualBiome.InnerBelt: if (!Radiation.Info(body).model.has_inner) { return(false); } break; case VirtualBiome.OuterBelt: if (!Radiation.Info(body).model.has_outer) { return(false); } break; case VirtualBiome.Magnetosphere: if (!Radiation.Info(body).model.has_pause) { return(false); } break; case VirtualBiome.Interstellar: if (!Lib.IsSun(body)) { return(false); } break; case VirtualBiome.Reentry: if (!body.atmosphere) { return(false); } break; } return(true); }
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; } }