public static RadiationDose GetRadiationDose(this Vessel vessel)
        {
            CelestialBody cur_ref_body = vessel.mainBody;
            CelestialBody crefkerbin = FlightGlobals.fetch.bodies[PluginHelper.REF_BODY_KERBIN];

            ORSPlanetaryResourcePixel res_pixel = ORSPlanetaryResourceMapData.getResourceAvailability(vessel.mainBody.flightGlobalsIndex, InterstellarResourcesConfiguration.Instance.ThoriumTetraflouride, cur_ref_body.GetLatitude(vessel.transform.position), cur_ref_body.GetLongitude(vessel.transform.position));
            double ground_rad = Math.Sqrt(res_pixel.getAmount() * 9e6) / 24 / 365.25 / Math.Max(vessel.altitude / 870, 1);
            
            double proton_rad = cur_ref_body.GetProtonRadiationLevel(FlightGlobals.ship_altitude, FlightGlobals.ship_latitude);
            double electron_rad = cur_ref_body.GetElectronRadiationLevel(FlightGlobals.ship_altitude, FlightGlobals.ship_latitude);
            double divisor = Math.Pow(cur_ref_body.Radius / crefkerbin.Radius, 2.0);
            double proton_rad_level = proton_rad / divisor;
            double electron_rad_level = electron_rad / divisor;

            double inv_square_mult = Math.Pow(Vector3d.Distance(FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBIN].transform.position, FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBOL].transform.position), 2) / Math.Pow(Vector3d.Distance(vessel.transform.position, FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBOL].transform.position), 2);
            double solar_radiation = 0.19 * inv_square_mult;
            double mag_field_strength = cur_ref_body.GetBeltMagneticFieldMagnitude(FlightGlobals.ship_altitude, FlightGlobals.ship_latitude);
            while (cur_ref_body.referenceBody != null)
            {
                CelestialBody old_ref_body = cur_ref_body;
                cur_ref_body = cur_ref_body.referenceBody;
                if (cur_ref_body == old_ref_body)break;
                mag_field_strength += cur_ref_body.GetBeltMagneticFieldMagnitude(Vector3d.Distance(FlightGlobals.ship_position, cur_ref_body.transform.position) - cur_ref_body.Radius, FlightGlobals.ship_latitude);
            }
            if (vessel.mainBody != FlightGlobals.fetch.bodies[PluginHelper.REF_BODY_KERBOL])
                solar_radiation = solar_radiation * Math.Exp(-73840.5645666 * mag_field_strength) * Math.Exp(-vessel.atmDensity * 4.5);
            RadiationDose dose = new RadiationDose(Math.Pow(electron_rad_level / 3e-5, 3.0) * 3.2, ground_rad, solar_radiation + Math.Pow(proton_rad_level / 3e-5, 3.0) * 3.2, 0.0);
            return dose;
        }
        public static RadiationDose GetRadiationDose(this Vessel vessel)
        {
            CelestialBody cur_ref_body = vessel.mainBody;
            CelestialBody crefkerbin   = FlightGlobals.fetch.bodies[PluginHelper.REF_BODY_KERBIN];

            ORSPlanetaryResourcePixel res_pixel = ORSPlanetaryResourceMapData.getResourceAvailability(
                vessel.mainBody.flightGlobalsIndex,
                InterstellarResourcesConfiguration.Instance.ThoriumTetraflouride,
                cur_ref_body.GetLatitude(vessel.transform.position),
                cur_ref_body.GetLongitude(vessel.transform.position));

            double ground_rad = Math.Sqrt(res_pixel.getAmount() * 9e6) / 24 / 365.25 / Math.Max(vessel.altitude / 870, 1);

            double proton_rad         = cur_ref_body.GetProtonRadiationLevel(FlightGlobals.ship_altitude, FlightGlobals.ship_latitude);
            double electron_rad       = cur_ref_body.GetElectronRadiationLevel(FlightGlobals.ship_altitude, FlightGlobals.ship_latitude);
            double divisor            = Math.Pow(cur_ref_body.Radius / crefkerbin.Radius, 2.0);
            double proton_rad_level   = proton_rad / divisor;
            double electron_rad_level = electron_rad / divisor;

            double inv_square_mult    = Math.Pow(Vector3d.Distance(FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBIN].transform.position, FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBOL].transform.position), 2) / Math.Pow(Vector3d.Distance(vessel.transform.position, FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBOL].transform.position), 2);
            double solar_radiation    = 0.19 * inv_square_mult;
            double mag_field_strength = cur_ref_body.GetBeltMagneticFieldMagnitude(FlightGlobals.ship_altitude, FlightGlobals.ship_latitude);

            while (cur_ref_body.referenceBody != null)
            {
                CelestialBody old_ref_body = cur_ref_body;
                cur_ref_body = cur_ref_body.referenceBody;
                if (cur_ref_body == old_ref_body)
                {
                    break;
                }
                mag_field_strength += cur_ref_body.GetBeltMagneticFieldMagnitude(Vector3d.Distance(FlightGlobals.ship_position, cur_ref_body.transform.position) - cur_ref_body.Radius, FlightGlobals.ship_latitude);
            }
            if (vessel.mainBody != FlightGlobals.fetch.bodies[PluginHelper.REF_BODY_KERBOL])
            {
                solar_radiation = solar_radiation * Math.Exp(-73840.5645666 * mag_field_strength) * Math.Exp(-vessel.atmDensity * 4.5);
            }
            RadiationDose dose = new RadiationDose(Math.Pow(electron_rad_level / 3e-5, 3.0) * 3.2, ground_rad, solar_radiation + Math.Pow(proton_rad_level / 3e-5, 3.0) * 3.2, 0.0);

            return(dose);
        }
Esempio n. 3
0
        public override void OnUpdate()
        {
            Fields["radiationLevel"].guiActive  = true;
            Fields["radiationLevel2"].guiActive = vessel.isEVA;
            double rad_level_yr = radiation_level * 24 * 365.25;

            if (radiation_level >= 1000)
            {
                radiationLevel = (radiation_level / 1000).ToString("0.00") + " Sv/h";
            }
            else
            {
                if (radiation_level >= 1)
                {
                    radiationLevel = radiation_level.ToString("0.00") + " mSv/hr";
                }
                else
                {
                    if (radiation_level >= 0.001)
                    {
                        radiationLevel = (radiation_level * 1000.0).ToString("0.00") + " uSv/h";
                    }
                    else
                    {
                        radiationLevel = (radiation_level * 1000000.0).ToString("0.00") + " nSv/h";
                    }
                }
            }


            if (rad_level_yr >= 1e9)
            {
                radiationLevel = radiationLevel + " " + (rad_level_yr / 1e9).ToString("0.00") + " MSv/yr";
            }
            else
            {
                if (rad_level_yr >= 1e6)
                {
                    radiationLevel = radiationLevel + " " + (rad_level_yr / 1e6).ToString("0.00") + " KSv/yr";
                }
                else
                {
                    if (rad_level_yr >= 1e3)
                    {
                        radiationLevel = radiationLevel + " " + (rad_level_yr / 1e3).ToString("0.00") + " Sv/yr";
                    }
                    else
                    {
                        radiationLevel = radiationLevel + " " + (rad_level_yr).ToString("0.00") + " mSv/yr";
                    }
                }
            }

            if (VanAllen.crew_rad_exposure.ContainsKey(vessel.vesselName))
            {
                double tot_rad_exp = VanAllen.crew_rad_exposure[vessel.vesselName];
                if (tot_rad_exp >= 1000)
                {
                    radiationLevel2 = (tot_rad_exp / 1000).ToString("0.00") + " Sv";
                }
                else
                {
                    if (tot_rad_exp >= 1)
                    {
                        radiationLevel2 = tot_rad_exp.ToString("0.00") + " mSv";
                    }
                    else
                    {
                        if (tot_rad_exp >= 0.001)
                        {
                            radiationLevel2 = (tot_rad_exp * 1000.0).ToString("0.00") + " uSv";
                        }
                        else
                        {
                            if (tot_rad_exp >= 1e-6)
                            {
                                radiationLevel2 = (tot_rad_exp * 1000000.0).ToString("0.00") + " nSv";
                            }
                            else
                            {
                                radiationLevel2 = (tot_rad_exp * 1000000000.0).ToString("0.00") + " pSv";
                            }
                        }
                    }
                }
            }

            if (rad_level_yr <= 50)
            {
                radiationStatus = "Safe.";
            }
            else
            {
                if (rad_level_yr <= 200)
                {
                    radiationStatus = "Elevated.";
                }
                else if (rad_level_yr <= 2000)
                {
                    radiationStatus = "High.";
                }
                else if (radiation_level <= 100)
                {
                    radiationStatus = "Dangerous.";
                }
                else
                {
                    radiationStatus = "Deadly.";
                }
            }

            RadiationDose dose = vessel.GetRadiationDose().GetDoseWithMaterialShielding(1.0 / rad_hardness);

            radiation_level = dose.TotalDose;
            double rad_level_sec = radiation_level / 3600.0;
            List <ProtoCrewMember> crew_members = part.protoModuleCrew;

            if (!vessel.isEVA)
            {
                foreach (ProtoCrewMember crewmember in crew_members)
                {
                    if (VanAllen.crew_rad_exposure.ContainsKey(crewmember.name))
                    {
                        double current_rad = VanAllen.crew_rad_exposure[crewmember.name];
                        VanAllen.crew_rad_exposure[crewmember.name] = Math.Max(current_rad + rad_level_sec * TimeWarp.deltaTime - (50.0 / 31557600.0 * TimeWarp.fixedDeltaTime), 0);
                    }
                    else
                    {
                        VanAllen.crew_rad_exposure.Add(crewmember.name, Math.Max(rad_level_sec * TimeWarp.deltaTime - (50.0 / 31557600.0 * TimeWarp.fixedDeltaTime), 0));
                    }
                }
            }
            else
            {
                if (VanAllen.crew_rad_exposure.ContainsKey(vessel.vesselName))
                {
                    double current_rad = VanAllen.crew_rad_exposure[vessel.vesselName];
                    VanAllen.crew_rad_exposure[vessel.vesselName] = Math.Max(current_rad + rad_level_sec * TimeWarp.deltaTime - (50.0 / 31557600.0 * TimeWarp.fixedDeltaTime), 0);
                }
                else
                {
                    VanAllen.crew_rad_exposure.Add(vessel.vesselName, Math.Max(rad_level_sec * TimeWarp.deltaTime - (50.0 / 31557600.0 * TimeWarp.fixedDeltaTime), 0));
                }
            }
        }