public override void OnUpdate() { Events["ActivateMagnetometer"].active = !IsEnabled; Events["DeactivateMagnetometer"].active = IsEnabled; Fields["Bmag"].guiActive = IsEnabled; Fields["Brad"].guiActive = IsEnabled; Fields["Bthe"].guiActive = IsEnabled; Fields["ParticleFlux"].guiActive = IsEnabled; float lat = (float)vessel.mainBody.GetLatitude(this.vessel.GetWorldPos3D()); float Bmagf = VanAllen.getBeltMagneticFieldMag(vessel.mainBody.flightGlobalsIndex, (float)vessel.altitude, lat); float Bradf = VanAllen.getBeltMagneticFieldRadial(vessel.mainBody.flightGlobalsIndex, (float)vessel.altitude, lat); float Bthef = VanAllen.getBeltMagneticFieldAzimuthal(vessel.mainBody.flightGlobalsIndex, (float)vessel.altitude, lat); float flux = VanAllen.getBeltAntiparticles(vessel.mainBody.flightGlobalsIndex, (float)vessel.altitude, lat); Bmag = Bmagf.ToString("E") + "T"; Brad = Bradf.ToString("E") + "T"; Bthe = Bthef.ToString("E") + "T"; ParticleFlux = flux.ToString("E"); }
public static double getRadiationDose(Vessel vessel, double rad_hardness) { double radiation_level = 0; CelestialBody cur_ref_body = FlightGlobals.ActiveVessel.mainBody; CelestialBody crefkerbin = FlightGlobals.fetch.bodies[1]; ORSPlanetaryResourcePixel res_pixel = ORSPlanetaryResourceMapData.getResourceAvailability(vessel.mainBody.flightGlobalsIndex, "Thorium", 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 rad = VanAllen.getRadiationLevel(cur_ref_body.flightGlobalsIndex, (float)FlightGlobals.ship_altitude, (float)FlightGlobals.ship_latitude); double divisor = Math.Pow(cur_ref_body.Radius / crefkerbin.Radius, 2.0); double mag_field_strength = VanAllen.getBeltMagneticFieldMag(cur_ref_body.flightGlobalsIndex, (float)FlightGlobals.ship_altitude, (float)FlightGlobals.ship_latitude); // if (cur_ref_body.flightGlobalsIndex == PluginHelper.REF_BODY_KERBOL) { // rad = rad * 1e6; //} double rad_level = 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; 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; } //rad = VanAllen.getBeltAntiparticles (cur_ref_body.flightGlobalsIndex, (float) (Vector3d.Distance(FlightGlobals.ship_position,cur_ref_body.transform.position)-cur_ref_body.Radius), 0.0f); //rad = VanAllen.getRadiationLevel(cur_ref_body.flightGlobalsIndex, (Vector3d.Distance(FlightGlobals.ship_position, cur_ref_body.transform.position) - cur_ref_body.Radius), 0.0); mag_field_strength += VanAllen.getBeltMagneticFieldMag(cur_ref_body.flightGlobalsIndex, (float)(Vector3d.Distance(FlightGlobals.ship_position, cur_ref_body.transform.position) - cur_ref_body.Radius), (float)FlightGlobals.ship_latitude); //rad_level += rad; } if (cur_ref_body.flightGlobalsIndex != PluginHelper.REF_BODY_KERBOL) { solar_radiation = solar_radiation * Math.Exp(-73840.56456662708394321273809886 * mag_field_strength) * Math.Exp(-vessel.atmDensity * 4.5); } radiation_level = (Math.Pow(rad_level / 3e-5, 3.0) * 3.2 + ground_rad + solar_radiation) / rad_hardness; return(radiation_level); }