protected void OnGUI() { string resourcename = FNResourceManager.FNRESOURCE_MEGAJOULES; Vessel vessel = FlightGlobals.ActiveVessel; ORSResourceManager mega_manager = null; if (vessel != null) { if (FNResourceOvermanager.getResourceOvermanagerForResource(resourcename).hasManagerForVessel(vessel) && !hide_button) { mega_manager = FNResourceOvermanager.getResourceOvermanagerForResource(resourcename).getManagerForVessel(vessel); if (mega_manager.getPartModule() != null) { mega_manager.OnGUI(); GUILayout.BeginArea(button_position); if (GUILayout.Button(guibuttontexture)) { mega_manager.showWindow(); } GUILayout.EndArea(); } } } }
protected void OnGUI() { string resourcename = FNResourceManager.FNRESOURCE_MEGAJOULES; Vessel vessel = FlightGlobals.ActiveVessel; ORSResourceManager mega_manager = null; if (vessel == null) { return; } if (FNResourceOvermanager.getResourceOvermanagerForResource(resourcename).hasManagerForVessel(vessel) && !hide_button) { mega_manager = FNResourceOvermanager.getResourceOvermanagerForResource(resourcename).getManagerForVessel(vessel); if (mega_manager.getPartModule() != null) { mega_manager.OnGUI(); if (show_window) { mega_manager.showWindow(); } } } }
public virtual ORSResourceManager createManagerForVessel(PartModule pm) { ORSResourceManager megamanager = new ORSResourceManager(pm, resource_name); managers.Add(pm.vessel, megamanager); return(megamanager); }
public double GetOverproduction(String resourcename) { ORSResourceManager manager = getManagerForVessel(resourcename); if (manager == null) { return(0); } return(manager.getOverproduction()); }
public double getAvailableResourceSupply(String resourcename) { ORSResourceManager manager = getManagerForVessel(resourcename); if (manager == null) { return(0); } return(Math.Max(manager.StableResourceSupply - manager.CurrentHighPriorityResourceDemand, 0)); }
public double getDemandStableSupply(String resourcename) { ORSResourceManager manager = getManagerForVessel(resourcename); if (manager == null) { return(0); } return(manager.getDemandStableSupply()); }
public double getResourceAvailability(String resourcename) { ORSResourceManager manager = getManagerForVessel(resourcename); if (manager == null) { return(0); } return(manager.getResourceAvailability()); }
public double getResourceBarRatio(String resourcename) { ORSResourceManager manager = getManagerForVessel(resourcename); if (manager == null) { return(0); } return(manager.ResourceBarRatio); }
public double supplyFNResourcePerSecond(double supply, String resourcename) { ORSResourceManager manager = getManagerForVessel(resourcename); if (manager == null) { return(0); } return(manager.powerSupplyPerSecond(this, Math.Max(supply, 0))); }
public double GetRequiredResourceDemand(String resourcename) { ORSResourceManager manager = getManagerForVessel(resourcename); if (manager == null) { return(0); } return(manager.GetRequiredResourceDemand()); }
public double getTotalResourceCapacity(String resourcename) { ORSResourceManager manager = getManagerForVessel(resourcename); if (manager == null) { return(0); } return(manager.getTotalResourceCapacity()); }
public double supplyFNResourceFixedWithMax(double supply, double maxsupply, String resourcename) { ORSResourceManager manager = getManagerForVessel(resourcename); if (manager == null) { return(0); } return(manager.powerSupplyFixedWithMax(this, Math.Max(supply, 0), Math.Max(maxsupply, 0))); }
public double GetCurrentResourceDemand(String resourcename) { ORSResourceManager manager = getManagerForVessel(resourcename); if (manager == null) { return(0); } return(manager.CurrentRresourceDemand); }
public double GetPowerSupply(String resourcename) { ORSResourceManager manager = getManagerForVessel(resourcename); if (manager == null) { return(0); } return(manager.PowerSupply); }
public void RemoveItselfAsManager() { foreach (String resourcename in resources_to_supply) { ORSResourceManager resource_manager = getOvermanagerForResource(resourcename).getManagerForVessel(vessel); if (resource_manager != null && resource_manager.PartModule == this) { resource_manager.UpdatePartModule(null); } } }
public override void OnFixedUpdate() { timeWarpFixedDeltaTime = TimeWarpFixedDeltaTime; try { updateCounter++; if (resources_to_supply == null) { return; } foreach (String resourcename in resources_to_supply) { ORSResourceManager resource_manager = getOvermanagerForResource(resourcename).getManagerForVessel(vessel); if (resource_manager == null) { resource_manager = createResourceManagerForResource(resourcename); Debug.Log("[KSPI] Creating Resource Manager for Vessel " + vessel.GetName() + " (" + resourcename + ")"); } if (resource_manager.PartModule == null || resource_manager.PartModule.vessel != this.vessel || resource_manager.Counter < updateCounter) { resource_manager.UpdatePartModule(this); } if (resource_manager.PartModule == this) { resource_manager.update(updateCounter); } } var priority_manager = getSupplyPriorityManager(this.vessel); if (priority_manager.ProcessingPart == null || priority_manager.ProcessingPart.vessel != this.vessel || priority_manager.Counter < updateCounter) { priority_manager.UpdatePartModule(this); } if (priority_manager.ProcessingPart == this) { priority_manager.UpdateResourceSuppliables(updateCounter, timeWarpFixedDeltaTime); } } catch (Exception e) { Debug.LogError("[KSPI] - Exception in ORSResourceSuppliableModule.OnFixedUpdate " + e.Message); throw; } }
public override void OnStart(PartModule.StartState state) { if (state == StartState.Editor || resources_to_supply == null) { return; } foreach (String resourcename in resources_to_supply) { ORSResourceManager manager = getOvermanagerForResource(resourcename).getManagerForVessel(vessel); if (manager == null) { manager = createResourceManagerForResource(resourcename); print("[KSPI] - Creating Resource Manager for Vessel " + vessel.GetName() + " (" + resourcename + ")"); } } getSupplyPriorityManager(this.vessel).Register(this); }
public double consumeFNResource(double power_fixed, String resourcename) { power_fixed = Math.Max(power_fixed, 0); double fixedDeltaTime = (double)(decimal)Math.Round(TimeWarp.fixedDeltaTime, 7); ORSResourceManager manager = getManagerForVessel(resourcename); if (manager == null) { return(0); } if (!fnresource_supplied.ContainsKey(resourcename)) { fnresource_supplied.Add(resourcename, 0); } double power_taken_fixed = Math.Max(Math.Min(power_fixed, fnresource_supplied[resourcename] * fixedDeltaTime), 0); fnresource_supplied[resourcename] -= power_taken_fixed / fixedDeltaTime; manager.powerDrawFixed(this, power_fixed, power_taken_fixed); return(power_taken_fixed); }
public double managedRequestedPowerSupplyPerSecondMinimumRatio(double requested_power, double maximum_power, double ratio_min, String resourcename, ORSResourceManager manager = null) { if (manager == null) { manager = getManagerForVessel(resourcename); } if (manager == null) { return(0); } return(manager.managedRequestedPowerSupplyPerSecondMinimumRatio(this, requested_power, Math.Max(maximum_power, 0), Math.Max(ratio_min, 0))); }
public double getNeededPowerSupplyPerSecondWithMinimumRatio(double supply, double ratio_min, String resourcename, ORSResourceManager manager = null) { if (manager == null) { manager = getManagerForVessel(resourcename); } if (manager == null) { Debug.LogError("[KSPI] - failed to find resource Manager For Current Vessel"); return(0); } return(manager.getNeededPowerSupplyPerSecondWithMinimumRatio(Math.Max(supply, 0), Math.Max(ratio_min, 0))); }
public void deleteManager(ORSResourceManager manager) { managers.Remove(manager.Vessel); }
public void FixedUpdate() // FixedUpdate is also called when not activated { try { UpdateWasteheatBuffer(); if (!HighLogic.LoadedSceneIsFlight) { return; } if (!active) { base.OnFixedUpdate(); } effectiveRadiatorArea = EffectiveRadiatorArea; var external_temperature = FlightGlobals.getExternalTemperature(part.transform.position); wasteheatManager = getManagerForVessel(FNResourceManager.FNRESOURCE_WASTEHEAT); // get resource bar ratio at start of frame wasteheatRatio = wasteheatManager.ResourceBarRatio; if (Double.IsNaN(wasteheatRatio)) { Debug.LogError("FNRadiator: FixedUpdate Single.IsNaN detected in wasteheatRatio"); return; } var normalized_atmosphere = Math.Min(vessel.atmDensity, 1); maxCurrentTemperature = maxAtmosphereTemperature * Math.Max(normalized_atmosphere, 0) + maxVacuumTemperature * Math.Max(Math.Min(1 - vessel.atmDensity, 1), 0); radiator_temperature_temp_val = external_temperature + Math.Min((maxRadiatorTemperature - external_temperature) * Math.Sqrt(wasteheatRatio), maxCurrentTemperature - external_temperature); var efficiency = 1 - Math.Pow(1 - wasteheatRatio, 400); var delta_temp = Math.Max(radiator_temperature_temp_val - Math.Max(external_temperature * normalized_atmosphere, 2.7), 0); if (radiatorIsEnabled) { if (!CheatOptions.IgnoreMaxTemperature && wasteheatRatio >= 1 && CurrentRadiatorTemperature >= maxRadiatorTemperature) { explode_counter++; if (explode_counter > 25) { part.explode(); } } else { explode_counter = 0; } var thermal_power_dissip_per_second = efficiency * Math.Pow(delta_temp, 4) * GameConstants.stefan_const * effectiveRadiatorArea / 1e6; if (Double.IsNaN(thermal_power_dissip_per_second)) { Debug.LogWarning("FNRadiator: FixedUpdate Single.IsNaN detected in fixed_thermal_power_dissip"); } radiatedThermalPower = canRadiateHeat ? consumeWasteHeatPerSecond(thermal_power_dissip_per_second) : 0; if (Double.IsNaN(radiatedThermalPower)) { Debug.LogError("FNRadiator: FixedUpdate Single.IsNaN detected in radiatedThermalPower after call consumeWasteHeat (" + thermal_power_dissip_per_second + ")"); } instantaneous_rad_temp = Math.Max(radiator_temperature_temp_val, Math.Max(FlightGlobals.getExternalTemperature(vessel.altitude, vessel.mainBody), 2.7)); if (Double.IsNaN(instantaneous_rad_temp)) { Debug.LogError("FNRadiator: FixedUpdate Single.IsNaN detected in instantaneous_rad_temp after reading external temperature"); } CurrentRadiatorTemperature = instantaneous_rad_temp; if (_moduleDeployableRadiator) { _moduleDeployableRadiator.hasPivot = pivotEnabled; } } else { double thermal_power_dissip_per_second = efficiency * Math.Pow(Math.Max(delta_temp - external_temperature, 0), 4) * GameConstants.stefan_const * effectiveRadiatorArea / 0.5e7; radiatedThermalPower = canRadiateHeat ? consumeWasteHeatPerSecond(thermal_power_dissip_per_second) : 0; instantaneous_rad_temp = Math.Max(radiator_temperature_temp_val, Math.Max(FlightGlobals.getExternalTemperature(vessel.altitude, vessel.mainBody), 2.7)); CurrentRadiatorTemperature = instantaneous_rad_temp; } if (vessel.atmDensity > 0) { var pressure = vessel.atmDensity; dynamic_pressure = 0.60205 * pressure * vessel.srf_velocity.sqrMagnitude / 101325; pressure += dynamic_pressure; var splashBonus = Math.Max(part.submergedPortion * 10, 1); var convection_delta_temp = Math.Max(0, CurrentRadiatorTemperature - external_temperature); var conv_power_dissip = efficiency * pressure * convection_delta_temp * effectiveRadiatorArea * 0.001 * convectiveBonus * splashBonus; if (!radiatorIsEnabled) { conv_power_dissip = conv_power_dissip / 2; } convectedThermalPower = canRadiateHeat ? consumeWasteHeatPerSecond(conv_power_dissip) : 0; if (update_count == 6) { DeployMentControl(dynamic_pressure); } } else { convectedThermalPower = 0; if (!radiatorIsEnabled && isAutomated && canRadiateHeat && showControls && update_count == 6) { Debug.Log("[KSPI] - FixedUpdate Automated Deplotment "); Deploy(); } } } catch (Exception e) { Debug.LogError("[KSPI] - FNRadiator.FixedUpdate" + e.Message); } }
protected void OnGUI() { Vessel vessel = FlightGlobals.ActiveVessel; if (vessel == null) { return; } if (FNResourceOvermanager.getResourceOvermanagerForResource(FNResourceManager.FNRESOURCE_MEGAJOULES).hasManagerForVessel(vessel) && !hide_button) { ORSResourceManager mega_manager = FNResourceOvermanager.getResourceOvermanagerForResource(FNResourceManager.FNRESOURCE_MEGAJOULES).getManagerForVessel(vessel); if (mega_manager != null && mega_manager.PartModule != null) { // activate rendering if (show_window) { mega_manager.showWindow(); } // show window mega_manager.OnGUI(); } } if (FNResourceOvermanager.getResourceOvermanagerForResource(FNResourceManager.FNRESOURCE_THERMALPOWER).hasManagerForVessel(vessel) && !hide_button) { ORSResourceManager thermal_manager = FNResourceOvermanager.getResourceOvermanagerForResource(FNResourceManager.FNRESOURCE_THERMALPOWER).getManagerForVessel(vessel); if (thermal_manager != null && thermal_manager.PartModule != null) { // activate rendering if (show_window) { thermal_manager.showWindow(); } // show window thermal_manager.OnGUI(); } } if (FNResourceOvermanager.getResourceOvermanagerForResource(FNResourceManager.FNRESOURCE_CHARGED_PARTICLES).hasManagerForVessel(vessel) && !hide_button) { ORSResourceManager charged_manager = FNResourceOvermanager.getResourceOvermanagerForResource(FNResourceManager.FNRESOURCE_CHARGED_PARTICLES).getManagerForVessel(vessel); if (charged_manager != null && charged_manager.PartModule != null) { // activate rendering if (show_window) { charged_manager.showWindow(); } // show window charged_manager.OnGUI(); } } if (FNResourceOvermanager.getResourceOvermanagerForResource(FNResourceManager.FNRESOURCE_WASTEHEAT).hasManagerForVessel(vessel) && !hide_button) { ORSResourceManager waste_manager = FNResourceOvermanager.getResourceOvermanagerForResource(FNResourceManager.FNRESOURCE_WASTEHEAT).getManagerForVessel(vessel); if (waste_manager != null && waste_manager.PartModule != null) { // activate rendering if (show_window) { waste_manager.showWindow(); } // show window waste_manager.OnGUI(); } } show_window = false; }
public double supplyManagedFNResourcePerSecondWithMinimumRatio(double supply, double ratio_min, String resourcename, ORSResourceManager manager = null) { if (manager == null) { manager = getManagerForVessel(resourcename); } if (manager == null) { return(0); } return(manager.managedPowerSupplyPerSecondWithMinimumRatio(this, Math.Max(supply, 0), Math.Max(ratio_min, 0))); }
public double consumeFNResourcePerSecond(double power_per_second, String resourcename, ORSResourceManager manager = null) { power_per_second = Math.Max(power_per_second, 0); if (manager == null) { manager = getManagerForVessel(resourcename); } if (manager == null) { return(0); } if (!fnresource_supplied.ContainsKey(resourcename)) { fnresource_supplied.Add(resourcename, 0); } double power_taken_per_second = Math.Max(Math.Min(power_per_second, fnresource_supplied[resourcename]), 0); fnresource_supplied[resourcename] -= power_taken_per_second; manager.powerDrawPerSecond(this, power_per_second, power_taken_per_second); return(power_taken_per_second); }