Exemplo n.º 1
0
 public override void OnUpdate()
 {
     if (HighLogic.LoadedSceneIsFlight)
     {
         double resource_abundance = 0;
         bool   resource_available = false;
         if (vessel.Landed)
         {
             ORSPlanetaryResourcePixel current_resource_abundance_pixel = ORSPlanetaryResourceMapData.getResourceAvailabilityByRealResourceName(vessel.mainBody.flightGlobalsIndex, resourceName, vessel.latitude, vessel.longitude);
             resource_abundance = current_resource_abundance_pixel.getAmount();
         }
         else if (vessel.Splashed)
         {
             resource_abundance = ORSOceanicResourceHandler.getOceanicResourceContent(vessel.mainBody.flightGlobalsIndex, resourceName);
         }
         if (resource_abundance > 0)
         {
             resource_available = true;
         }
         Events["startResourceExtraction"].active = !IsEnabled && resource_available;
         Events["stopResourceExtration"].active   = IsEnabled;
         if (IsEnabled)
         {
             Fields["powerStr"].guiActive     = true;
             Fields["resourceRate"].guiActive = true;
             statusTitle = "Active";
             double power_required = 0;
             if (vessel.Landed)
             {
                 power_required = powerConsumptionLand;
             }
             else if (vessel.Splashed)
             {
                 power_required = powerConsumptionOcean;
             }
             powerStr = (power_required * electrical_power_ratio).ToString("0.000") + " MW / " + power_required.ToString("0.000") + " MW";
             double resource_density       = PartResourceLibrary.Instance.GetDefinition(resourceName).density;
             double resource_rate_per_hour = extraction_rate_d * resource_density * 3600;
             resourceRate = formatMassStr(resource_rate_per_hour);
         }
         else
         {
             Fields["powerStr"].guiActive     = false;
             Fields["resourceRate"].guiActive = false;
             statusTitle = "Offline";
         }
     }
 }
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public override void OnFixedUpdate()
        {
            if (IsEnabled)
            {
                double power_requirements = 0;
                double extraction_time    = 0;
                if (vessel.Landed)
                {
                    power_requirements = powerConsumptionLand;
                    extraction_time    = extractionRateLandPerTon;
                }
                else if (vessel.Splashed)
                {
                    power_requirements = powerConsumptionOcean;
                    extraction_time    = extractionRateOceanPerTon;
                }
                else
                {
                    IsEnabled = false;
                    return;
                }

                /** RAILS **/
                if (Time.timeSinceLevelLoad < 1.0f || !FlightGlobals.ready)
                {
                    return;
                }

                if (lastUpdateTime == 0.0f)
                {
                    // Just started running
                    lastUpdateTime = Planetarium.GetUniversalTime();
                    return;
                }

                double deltaTime = Math.Min(Planetarium.GetUniversalTime() - lastUpdateTime, Utilities.MaxDeltaTime);
                lastUpdateTime += deltaTime;
                /** RAILS **/


                double electrical_power_provided = 0;
                double desiredPower = power_requirements * TimeWarp.fixedDeltaTime;
                double maxPower     = power_requirements * Math.Max(Utilities.ElectricityMaxDeltaTime, TimeWarp.fixedDeltaTime);

                var powerRequested = Math.Min(desiredPower, maxPower);


                if (resourceManaged)
                {
                    electrical_power_provided = consumeFNResource(powerRequested, resourceToUse);
                }
                else
                {
                    electrical_power_provided = part.RequestResource(resourceToUse, powerRequested);
                }
                if (power_requirements > 0)
                {
                    electrical_power_ratio = electrical_power_provided / desiredPower;
                }
                else
                {
                    if (power_requirements < 0)
                    {
                        IsEnabled = false;
                        return;
                    }
                    else
                    {
                        electrical_power_ratio = 1;
                    }
                }
                double resource_abundance = 0;
                if (vessel.Landed)
                {
                    ORSPlanetaryResourcePixel current_resource_abundance_pixel = ORSPlanetaryResourceMapData.getResourceAvailabilityByRealResourceName(vessel.mainBody.flightGlobalsIndex, resourceName, vessel.latitude, vessel.longitude);
                    resource_abundance = current_resource_abundance_pixel.getAmount();
                }
                else if (vessel.Splashed)
                {
                    resource_abundance = ORSOceanicResourceHandler.getOceanicResourceContent(vessel.mainBody.flightGlobalsIndex, resourceName);
                }
                double extraction_rate = resource_abundance * extraction_time * electrical_power_ratio;
                if (resource_abundance > 0)
                {
                    double resource_density = PartResourceLibrary.Instance.GetDefinition(resourceName).density;
                    extraction_rate_d = -ORSHelper.fixedRequestResource(part, resourceName, -extraction_rate / resource_density * deltaTime) / deltaTime;
                }
                else
                {
                    IsEnabled = false;
                }
            }
        }
Exemplo n.º 5
0
        public override void OnUpdate()
        {
            Fields["radiationLevel"].guiActive = true;
            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";
                    }
                }
            }

            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);

            if (cur_ref_body.flightGlobalsIndex == PluginHelper.REF_BODY_KERBOL)
            {
                rad = rad * 1e6;
            }

            double rad_level = rad / divisor;

            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);
                if (cur_ref_body.flightGlobalsIndex == PluginHelper.REF_BODY_KERBOL)
                {
                    rad = rad * 1e6;
                }
                rad_level += rad;
            }

            radiation_level = (Math.Pow(rad_level / 3e-5, 3.0) * 5.2 + ground_rad) / rad_hardness;
            //print(radiation_level);

            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] = current_rad + radiation_level * TimeWarp.deltaTime;
                    }
                    else
                    {
                        VanAllen.crew_rad_exposure.Add(crewmember.name, radiation_level * TimeWarp.deltaTime);
                    }
                }
            }
            else
            {
                if (VanAllen.crew_rad_exposure.ContainsKey(vessel.vesselName))
                {
                    double current_rad = VanAllen.crew_rad_exposure[vessel.vesselName];
                    VanAllen.crew_rad_exposure[vessel.vesselName] = current_rad + radiation_level * TimeWarp.deltaTime;
                }
                else
                {
                    VanAllen.crew_rad_exposure.Add(vessel.vesselName, radiation_level * TimeWarp.deltaTime);
                }
            }
        }