public override void OnUpdate() { float lat = (float)vessel.mainBody.GetLatitude(this.vessel.GetWorldPos3D()); float flux = VanAllen.getBeltAntiparticles(vessel.mainBody.flightGlobalsIndex, (float)vessel.altitude, lat); ParticleFlux = flux.ToString("E"); collectionRate = (collection_rate_d * collectionMultiplier).ToString("0.00") + " mg/day"; }
public override void OnFixedUpdate() { drawCount++; float lat = (float)vessel.mainBody.GetLatitude(this.vessel.GetWorldPos3D()); float flux = VanAllen.getBeltAntiparticles(vessel.mainBody.flightGlobalsIndex, (float)vessel.altitude, lat); //part.RequestResource("Antimatter", -flux * TimeWarp.fixedDeltaTime); ORSHelper.fixedRequestResource(part, "Antimatter", -flux * collectionMultiplier * TimeWarp.fixedDeltaTime); last_active_time = (float)Planetarium.GetUniversalTime(); collection_rate_d = flux * collectionMultiplier * 86400; }
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); }
public override void OnStart(PartModule.StartState state) { if (state == StartState.Editor) { return; } this.part.force_activate(); double now = Planetarium.GetUniversalTime(); double time_diff = now - last_active_time; if (last_active_time != 0 && vessel.orbit.eccentricity < 1) { double lat = vessel.mainBody.GetLatitude(vessel.transform.position); double vessel_avg_alt = (vessel.orbit.ApR + vessel.orbit.PeR) / 2.0f; double vessel_inclination = vessel.orbit.inclination; float flux = (VanAllen.getBeltAntiparticles(vessel.mainBody.flightGlobalsIndex, (float)vessel_avg_alt, (float)vessel_inclination) + VanAllen.getBeltAntiparticles(vessel.mainBody.flightGlobalsIndex, (float)vessel_avg_alt, 0.0f)) / 2.0f; //vessel.orbit. double antimatter_to_add = time_diff * flux; //part.RequestResource("Antimatter", -antimatter_to_add); ORSHelper.fixedRequestResource(part, "Antimatter", -antimatter_to_add); } }
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."; } } /* * 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; * } * solar_radiation = solar_radiation * Math.Exp(-73840.56456662708394321273809886 * mag_field_strength); * radiation_level = (Math.Pow(rad_level / 3e-5, 3.0) * 3.2 + ground_rad + solar_radiation) / rad_hardness; * //print(radiation_level); */ radiation_level = VanAllen.getRadiationDose(vessel, rad_hardness); 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)); } } }