public static double getRadiationLevel(int refBody, double altitude, double lat) { lat = lat / 180 * Math.PI; CelestialBody crefbody = FlightGlobals.fetch.bodies[refBody]; CelestialBody crefkerbin = FlightGlobals.fetch.bodies[1]; double atmosphere = FlightGlobals.getStaticPressure(altitude, crefbody); double atmosphere_height = PluginHelper.getMaxAtmosphericAltitude(crefbody); double atmosphere_scaling = Math.Exp(-atmosphere); double mp = crefbody.Mass; double rp = crefbody.Radius; double rt = crefbody.rotationPeriod; double relmp = mp / crefkerbin.Mass; double relrp = rp / crefkerbin.Radius; double relrt = rt / crefkerbin.rotationPeriod; double peakbelt = 1.5 * crefkerbin.Radius * relrp; double peakbelt2 = 6 * crefkerbin.Radius * relrp; double altituded = altitude; double a = peakbelt / Math.Sqrt(2); double b = peakbelt2 / Math.Sqrt(2); double beltparticles = Math.Sqrt(2 / Math.PI) * Math.Pow(altituded, 2) * Math.Exp(-Math.Pow(altituded, 2) / (2.0 * Math.Pow(a, 2))) / (Math.Pow(a, 3)) + 0.9 * Math.Sqrt(2 / Math.PI) * Math.Pow(altituded, 2) * Math.Exp(-Math.Pow(altituded, 2) / (2.0 * Math.Pow(b, 2))) / (Math.Pow(b, 3)); beltparticles = beltparticles * relrp / relrt * 50.0; if (crefbody.flightGlobalsIndex == 0) { beltparticles = beltparticles / 1000; } beltparticles = beltparticles * Math.Abs(Math.Cos(lat)) * getSpecialMagneticFieldScaling(refBody) * atmosphere_scaling; return(beltparticles); }
protected override void pluginSpecificImpl() { if (resource_name == FNRESOURCE_CHARGED_PARTICLES) { flow_type = FNRESOURCE_FLOWTYPE_EVEN; } if (String.Equals(this.resource_name, FNResourceManager.FNRESOURCE_WASTEHEAT)) // passive dissip of waste heat - a little bit of this { double vessel_mass = my_vessel.GetTotalMass(); double passive_dissip = passive_temp_p4 * GameConstants.stefan_const * vessel_mass * 2.0; internl_power_extract += passive_dissip * TimeWarp.fixedDeltaTime; if (my_vessel.altitude <= PluginHelper.getMaxAtmosphericAltitude(my_vessel.mainBody)) // passive convection - a lot of this { double pressure = FlightGlobals.getStaticPressure(my_vessel.transform.position); double delta_temp = 20; double conv_power_dissip = pressure * delta_temp * vessel_mass * 2.0 * GameConstants.rad_const_h / 1e6 * TimeWarp.fixedDeltaTime; internl_power_extract += conv_power_dissip; } if (internl_power_extract < 0 && PluginHelper.isThermalDissipationDisabled()) // set buildup/dissip of waste heat to 0 if waste heat is disabled { internl_power_extract = 0; } } }
public override void OnFixedUpdate() { if (scoopIsEnabled) { string atmospheric_resource_name = ORSAtmosphericResourceHandler.getAtmosphericResourceName(vessel.mainBody.flightGlobalsIndex, currentresource); if (atmospheric_resource_name != null) { double resourcedensity = PartResourceLibrary.Instance.GetDefinition(atmospheric_resource_name).density; double respcent = ORSAtmosphericResourceHandler.getAtmosphericResourceContent(vessel.mainBody.flightGlobalsIndex, currentresource); //double resourcedensity = PartResourceLibrary.Instance.GetDefinition(PluginHelper.atomspheric_resources_tocollect[currentresource]).density; //double respcent = PluginHelper.getAtmosphereResourceContent(vessel.mainBody.flightGlobalsIndex, currentresource); double airdensity = part.vessel.atmDensity / 1000; double powerrequirements = scoopair / 0.15f * 6f; double airspeed = part.vessel.srf_velocity.magnitude + 40.0; double air = airspeed * airdensity * scoopair / resourcedensity; if (respcent > 0 && vessel.altitude <= PluginHelper.getMaxAtmosphericAltitude(vessel.mainBody)) { double scoopedAtm = air * respcent; float powerreceived = Math.Max(consumeFNResource(powerrequirements * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_MEGAJOULES), 0); float powerpcnt = (float)(powerreceived / powerrequirements / TimeWarp.fixedDeltaTime); //resflowf = (float)part.RequestResource(atmospheric_resource_name, -scoopedAtm * powerpcnt * TimeWarp.fixedDeltaTime); resflowf = (float)ORSHelper.fixedRequestResource(part, atmospheric_resource_name, -scoopedAtm * powerpcnt * TimeWarp.fixedDeltaTime); resflowf = -resflowf / TimeWarp.fixedDeltaTime; } } else { } } }
private void Window(int windowID) { bold_label = new GUIStyle(GUI.skin.label); bold_label.fontStyle = FontStyle.Bold; if (GUI.Button(new Rect(windowPosition.width - 20, 2, 18, 18), "x")) { render_window = false; } GUILayout.BeginVertical(); if (vessel.altitude < PluginHelper.getMaxAtmosphericAltitude(vessel.mainBody)) { if (analysis_count > analysis_length) { GUILayout.BeginHorizontal(); GUILayout.Label("Gas", bold_label, GUILayout.Width(150)); GUILayout.Label("Abundance", bold_label, GUILayout.Width(150)); GUILayout.EndHorizontal(); GUILayout.Space(5); foreach (ORSAtmosphericResource atmospheric_resource in ORSAtmosphericResourceHandler.getAtmosphericCompositionForBody(vessel.mainBody.flightGlobalsIndex)) { GUILayout.BeginHorizontal(); GUILayout.Label(atmospheric_resource.getDisplayName(), GUILayout.Width(150)); string resource_abundance_str; if (atmospheric_resource.getResourceAbundance() > 0.001) { resource_abundance_str = (atmospheric_resource.getResourceAbundance() * 100.0).ToString() + "%"; } else { if (atmospheric_resource.getResourceAbundance() > 0.000001) { resource_abundance_str = (atmospheric_resource.getResourceAbundance() * 1e6).ToString() + " ppm"; } else { resource_abundance_str = (atmospheric_resource.getResourceAbundance() * 1e9).ToString() + " ppb"; } } GUILayout.Label(resource_abundance_str, GUILayout.Width(150)); GUILayout.EndHorizontal(); } } else { double percent_analysed = (double)analysis_count / analysis_length * 100; GUILayout.BeginHorizontal(); GUILayout.Label("Analysing...", GUILayout.Width(150)); GUILayout.Label(percent_analysed.ToString("0.00") + "%", GUILayout.Width(150)); GUILayout.EndHorizontal(); } } else { GUILayout.Label("--No Atmosphere to Sample--", GUILayout.ExpandWidth(true)); analysis_count = 0; } GUILayout.EndVertical(); GUI.DragWindow(); }
public void ActivateWarpDrive() { if (IsEnabled) { return; } Vessel vess = this.part.vessel; //float atmosphere_height = vess.mainBody.maxAtmosphereAltitude; if (vess.altitude <= PluginHelper.getMaxAtmosphericAltitude(vess.mainBody) && vess.mainBody.flightGlobalsIndex != 0) { ScreenMessages.PostScreenMessage("Cannot activate warp drive within the atmosphere!", 5.0f, ScreenMessageStyle.UPPER_CENTER); return; } var resources = new List <PartResource>(); part.GetConnectedResources(PartResourceLibrary.Instance.GetDefinition("ExoticMatter").id, PartResourceLibrary.Instance.GetDefinition("ExoticMatter").resourceFlowMode, resources); float electrical_current_available = 0; for (int i = 0; i < resources.Count; ++i) { electrical_current_available += (float)resources.ElementAt(i).amount; } if (electrical_current_available < megajoules_required * warp_factors[selected_factor]) { ScreenMessages.PostScreenMessage("Warp drive charging!", 5.0f, ScreenMessageStyle.UPPER_CENTER); return; } part.RequestResource("ExoticMatter", megajoules_required * warp_factors[selected_factor]); warp_sound.Play(); warp_sound.loop = true; //Orbit planetOrbit = vessel.orbit.referenceBody.orbit; Vector3d heading = part.transform.up; double temp1 = heading.y; heading.y = heading.z; heading.z = temp1; Vector3d position = vessel.orbit.pos; heading = heading * GameConstants.warpspeed * warp_factors[selected_factor]; heading_act = heading; serialisedwarpvector = ConfigNode.WriteVector(heading); vessel.GoOnRails(); vessel.orbit.UpdateFromStateVectors(position, vessel.orbit.vel + heading, vessel.orbit.referenceBody, Planetarium.GetUniversalTime()); vessel.GoOffRails(); IsEnabled = true; }
public static float getBeltAntiparticles(int refBody, float altitude, float lat) { lat = (float)(lat / 180 * Math.PI); CelestialBody crefbody = FlightGlobals.fetch.bodies[refBody]; CelestialBody crefkerbin = FlightGlobals.fetch.bodies[1]; double atmosphere_height = PluginHelper.getMaxAtmosphericAltitude(crefbody); if (altitude <= atmosphere_height && crefbody.flightGlobalsIndex != 0) { return(0); } double mp = crefbody.Mass; double rp = crefbody.Radius; double rt = crefbody.rotationPeriod; double relmp = mp / crefkerbin.Mass; double relrp = rp / crefkerbin.Radius; double relrt = rt / crefkerbin.rotationPeriod; double peakbelt = 1.5 * crefkerbin.Radius * relrp; double altituded = ((double)altitude); double a = peakbelt / Math.Sqrt(2); double beltparticles = Math.Sqrt(2 / Math.PI) * Math.Pow(altituded, 2) * Math.Exp(-Math.Pow(altituded, 2) / (2.0 * Math.Pow(a, 2))) / (Math.Pow(a, 3)); beltparticles = beltparticles * relmp * relrp / relrt * 50.0; if (crefbody.flightGlobalsIndex == 0) { beltparticles = beltparticles / 1000; } beltparticles = beltparticles * Math.Abs(Math.Cos(lat)) * getSpecialMagneticFieldScaling(refBody); return((float)beltparticles); }
public override void OnUpdate() { bool inAtmos = false; if (vessel.altitude <= PluginHelper.getMaxAtmosphericAltitude(vessel.mainBody)) { telescopeIsEnabled = false; inAtmos = true; } Events["beginOberservations"].active = !inAtmos && !telescopeIsEnabled; Events["stopOberservations"].active = telescopeIsEnabled; Fields["sciencePerDay"].guiActive = telescopeIsEnabled; performPcnt = (perform_factor_d * 100).ToString("0.0") + "%"; sciencePerDay = (science_rate * 86400).ToString("0.00") + " Science/Day"; double current_au = Vector3d.Distance(vessel.transform.position, FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBOL].transform.position) / Vector3d.Distance(FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBIN].transform.position, FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBOL].transform.position); if (vessel.FindPartModulesImplementing <ScienceModule>().Count > 0 || vessel.FindPartModulesImplementing <ComputerCore>().Count > 0) { List <ComputerCore> cores = vessel.FindPartModulesImplementing <ComputerCore>(); List <ScienceModule> science_labs = vessel.FindPartModulesImplementing <ScienceModule>(); bool upgraded_core = false; bool crewed_lab = false; foreach (ComputerCore core in cores) { upgraded_core = upgraded_core ? upgraded_core : core.isupgraded; } foreach (ScienceModule science_lab in science_labs) { crewed_lab = crewed_lab ? crewed_lab : (science_lab.part.protoModuleCrew.Count > 0); } if (current_au >= 548 && !inAtmos && (crewed_lab || upgraded_core)) { if (vessel.orbit.eccentricity < 0.8) { Events["beginOberservations2"].active = true; if (telescopeIsEnabled && dpo) { gLensStr = "Ongoing."; } else { gLensStr = "Available."; } } else { Events["beginOberservations2"].active = false; gLensStr = "Eccentricity: " + vessel.orbit.eccentricity.ToString("0.0") + "; < 0.8 Required"; } } else { Events["beginOberservations2"].active = false; gLensStr = current_au.ToString("0.0") + " AU; Required 548 AU"; } } else { Events["beginOberservations2"].active = false; gLensStr = "Science Lab/Computer Core required"; } if (helium_time_scale <= 0) { performPcnt = "Helium Coolant Deprived."; } }
public override void OnFixedUpdate() { base.OnFixedUpdate(); if (autoVacuum) // checking to see if set to automode { if (vessel.altitude > PluginHelper.getMaxAtmosphericAltitude(vessel.mainBody) && isupgraded) { previousfuelmode = fuel_mode; // save the previous fuelmode for reentry into an atmosphere fuel_mode = 0; // set to vacuum plasma } else if (isupgraded) { if (previousfuelmode == 0) { fuel_mode = 1; // since alt is false, set the fuel mode to a normal fuel, if vacuum mode was the previous mode } else { fuel_mode = previousfuelmode; // set to previous fuel mode if it wasn't vacuum plasma } } else { fuel_mode = 0; // exception to handle the change in index for unupgraded engines } } List <Part> vessel_parts = vessel.parts; int engines = 0; foreach (Part vessel_part in vessel_parts) { foreach (PartModule vessel_part_module in vessel_part.Modules) { var curEngine2 = vessel_part_module as ElectricEngineController; if (curEngine2 != null) { var curEngine3 = curEngine2.part.Modules["ModuleEngines"] as ModuleEngines; if (curEngine3.isOperational) { engines++; } } } } if (engines <= 0) { engines = 1; } var curEngine = this.part.Modules["ModuleEngines"] as ModuleEngines; evaluateMaxThrust(); if (final_thrust_store <= 0) { final_thrust_store = initial_thrust; } float thrust_per_engine = final_thrust_store / engines; float power_per_engine = Math.Min(0.5f * curEngine.currentThrottle * thrust_per_engine * curEngine.atmosphereCurve.Evaluate(0) / 1000.0f * 9.81f, maxPower); //print (power_per_engine); float power_received = consumeFNResource(power_per_engine * TimeWarp.fixedDeltaTime / thrust_efficiency, FNResourceManager.FNRESOURCE_MEGAJOULES) / TimeWarp.fixedDeltaTime; electrical_consumption_f = power_received; float heat_to_produce = power_received * (1.0f - thrust_efficiency); heat_production_f = supplyFNResource(heat_to_produce * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_WASTEHEAT) / TimeWarp.fixedDeltaTime; float thrust_ratio; if (power_per_engine > 0) { thrust_ratio = power_received / power_per_engine; thrust_ratio = Mathf.Min(thrust_ratio, 1); } else { thrust_ratio = 1; if (curEngine.currentThrottle * thrust_per_engine > 0.0001f && !curEngine.flameout) { shutdown_counter++; if (shutdown_counter > 2) { curEngine.Events ["Shutdown"].Invoke(); ScreenMessages.PostScreenMessage("Engines shutdown due to lack of Electrical Power (Megajoules)!", 5.0f, ScreenMessageStyle.UPPER_CENTER); shutdown_counter = 0; foreach (FXGroup fx_group in part.fxGroups) { fx_group.setActive(false); } } } else { shutdown_counter = 0; } } //float thrust_to_use = thrust_per_engine; float thrust_to_use = thrust_efficiency * 2000.0f * power_received / (curEngine.atmosphereCurve.Evaluate(0) * 9.81f * curEngine.currentThrottle); float temp_to_part_set = Mathf.Min(curEngine.currentThrottle * part.maxTemp * 0.8f, 1); //curEngine.maxThrust = Mathf.Max(thrust_to_use*thrust_ratio,0.00001f); if (curEngine.currentThrottle > 0) { if (!float.IsNaN(thrust_to_use) && !float.IsInfinity(thrust_to_use)) { curEngine.maxThrust = Mathf.Max(thrust_to_use, 0.00001f); } else { curEngine.maxThrust = 0.00001f; } } if (thrust_to_use * thrust_ratio <= 0.0001f && curEngine.currentThrottle * thrust_per_engine > 0.0001f && !curEngine.flameout) { shutdown_counter++; if (shutdown_counter > 2) { curEngine.Events ["Shutdown"].Invoke(); ScreenMessages.PostScreenMessage("Engines shutdown due to lack of Electrical Power (Megajoules)!", 5.0f, ScreenMessageStyle.UPPER_CENTER); shutdown_counter = 0; foreach (FXGroup fx_group in part.fxGroups) { fx_group.setActive(false); } } } else { shutdown_counter = 0; } if (isupgraded) { float vacuum_plasma_needed = 0; float vacuum_plasma_current = 0; List <PartResource> vacuum_resources = new List <PartResource>(); part.GetConnectedResources(PartResourceLibrary.Instance.GetDefinition("VacuumPlasma").id, PartResourceLibrary.Instance.GetDefinition("VacuumPlasma").resourceFlowMode, vacuum_resources); foreach (PartResource partresource in vacuum_resources) { vacuum_plasma_needed += (float)(partresource.maxAmount - partresource.amount); vacuum_plasma_current += (float)partresource.amount; } if (vessel.altitude < PluginHelper.getMaxAtmosphericAltitude(vessel.mainBody)) { part.RequestResource("VacuumPlasma", vacuum_plasma_current); } else { part.RequestResource("VacuumPlasma", -vacuum_plasma_needed); } } }
public override void OnFixedUpdate() { float atmosphere_height = vessel.mainBody.maxAtmosphereAltitude; float vessel_height = (float)vessel.mainBody.GetAltitude(vessel.transform.position); float conv_power_dissip = 0; if (vessel.altitude <= PluginHelper.getMaxAtmosphericAltitude(vessel.mainBody)) { float pressure = (float)FlightGlobals.getStaticPressure(vessel.transform.position); float dynamic_pressure = (float)(0.5 * pressure * 1.2041 * vessel.srf_velocity.sqrMagnitude / 101325.0); pressure += dynamic_pressure; float low_temp = FlightGlobals.getExternalTemperature(vessel.transform.position); float delta_temp = Mathf.Max(0, radiatorTemp - low_temp); conv_power_dissip = pressure * delta_temp * radiatorArea * rad_const_h / 1e6f * TimeWarp.fixedDeltaTime * convectiveBonus; if (!radiatorIsEnabled) { conv_power_dissip = conv_power_dissip / 2.0f; } convectedThermalPower = consumeFNResource(conv_power_dissip, FNResourceManager.FNRESOURCE_WASTEHEAT) / TimeWarp.fixedDeltaTime; if (radiatorIsEnabled && dynamic_pressure > 1.4854428818159388107574636072046e-3 && isDeployable) { part.deactivate(); //part.breakingForce = 1; //part.breakingTorque = 1; part.decouple(1); } } if (radiatorIsEnabled) { if (getResourceBarRatio(FNResourceManager.FNRESOURCE_WASTEHEAT) >= 1 && current_rad_temp >= radiatorTemp) { explode_counter++; if (explode_counter > 25) { part.explode(); } } else { explode_counter = 0; } double radiator_temperature_temp_val = radiatorTemp * Math.Pow(getResourceBarRatio(FNResourceManager.FNRESOURCE_WASTEHEAT), 0.25); if (FNReactor.hasActiveReactors(vessel)) { radiator_temperature_temp_val = Math.Min(FNReactor.getTemperatureofColdestReactor(vessel) / 1.01, radiator_temperature_temp_val); } double thermal_power_dissip = (GameConstants.stefan_const * radiatorArea * Math.Pow(radiator_temperature_temp_val, 4) / 1e6) * TimeWarp.fixedDeltaTime; radiatedThermalPower = consumeFNResource(thermal_power_dissip, FNResourceManager.FNRESOURCE_WASTEHEAT) / TimeWarp.fixedDeltaTime; double instantaneous_rad_temp = (Math.Min(Math.Pow(radiatedThermalPower * 1e6 / (GameConstants.stefan_const * radiatorArea), 0.25), radiatorTemp)); instantaneous_rad_temp = Math.Max(instantaneous_rad_temp, Math.Max(FlightGlobals.getExternalTemperature((float)vessel.altitude, vessel.mainBody) + 273.16, 2.7)); if (current_rad_temp <= 0) { current_rad_temp = instantaneous_rad_temp; } else { current_rad_temp = instantaneous_rad_temp * alpha + (1.0 - alpha) * instantaneous_rad_temp; } if (isDeployable) { Vector3 pivrot = pivot.rotation.eulerAngles; pivot.Rotate(Vector3.up * 5f * TimeWarp.fixedDeltaTime * directionrotate); Vector3 sunpos = FlightGlobals.Bodies[0].transform.position; Vector3 flatVectorToTarget = sunpos - transform.position; flatVectorToTarget = flatVectorToTarget.normalized; float dot = Mathf.Asin(Vector3.Dot(pivot.transform.right, flatVectorToTarget)) / Mathf.PI * 180.0f; float anglediff = -dot; oldangle = dot; //print (dot); directionrotate = anglediff / 5 / TimeWarp.fixedDeltaTime; directionrotate = Mathf.Min(3, directionrotate); directionrotate = Mathf.Max(-3, directionrotate); part.maximum_drag = 0.8f; part.minimum_drag = 0.8f; } } else { if (isDeployable) { pivot.transform.localEulerAngles = original_eulers; } double radiator_temperature_temp_val = radiatorTemp * Math.Pow(getResourceBarRatio(FNResourceManager.FNRESOURCE_WASTEHEAT), 0.25); if (FNReactor.hasActiveReactors(vessel)) { radiator_temperature_temp_val = Math.Min(FNReactor.getTemperatureofColdestReactor(vessel) / 1.01, radiator_temperature_temp_val); } double thermal_power_dissip = (GameConstants.stefan_const * radiatorArea * Math.Pow(radiator_temperature_temp_val, 4) / 1e7) * TimeWarp.fixedDeltaTime; radiatedThermalPower = consumeFNResource(thermal_power_dissip, FNResourceManager.FNRESOURCE_WASTEHEAT) / TimeWarp.fixedDeltaTime; double instantaneous_rad_temp = (Math.Min(Math.Pow(radiatedThermalPower * 1e7 / (GameConstants.stefan_const * radiatorArea), 0.25), radiatorTemp)); instantaneous_rad_temp = Math.Max(instantaneous_rad_temp, Math.Max(FlightGlobals.getExternalTemperature((float)vessel.altitude, vessel.mainBody) + 273.16, 2.7)); if (current_rad_temp <= 0) { current_rad_temp = instantaneous_rad_temp; } else { current_rad_temp = instantaneous_rad_temp * alpha + (1.0 - alpha) * instantaneous_rad_temp; } part.maximum_drag = 0.2f; part.minimum_drag = 0.2f; } }