public override void OnStart(StartState state) { base.OnStart(state); radiator = this.part.FindModuleImplementing <ModuleActiveRadiator>(); radiator.isEnabled = isDeployed && isCooling; radiator.enabled = isDeployed && isCooling; emitter = this.part.GetComponentInChildren <KSPParticleEmitter>(); if (emitter != null) { emitter.emit = isDeployed && isCooling; emitter.enabled = isDeployed && isCooling; } UpdateStatus(); if (isOpenCycle) { this.Events["ToggleOpenCycle"].guiName = "Open Cycle Off"; } else { this.Events["ToggleOpenCycle"].guiName = "Open Cycle On"; } }
private ModuleActiveRadiator GetShieldState() { ModuleActiveRadiator ShieldState = null; ShieldState = part.FindModuleImplementing <ModuleActiveRadiator>(); return(ShieldState); }
internal Radiator(Part part) { this.part = part; activeRadiator = part.InternalPart.Module <ModuleActiveRadiator> (); deployableRadiator = part.InternalPart.Module <ModuleDeployableRadiator> (); if (activeRadiator == null && deployableRadiator == null) { throw new ArgumentException("Part is not a radiator"); } }
public override void OnStart(StartState state) { base.OnStart(state); radiator = this.part.FindModuleImplementing <ModuleActiveRadiator>(); radiator.isEnabled = isCooling; radiator.enabled = isCooling; UpdateStatus(); }
void Process_radiator(ModuleActiveRadiator radiator) { // note: IsCooling is not valid in the editor, for deployable radiators, // we will have to check if the related deploy module is deployed // we use PlannerController instead foreach (ModuleResource res in radiator.resHandler.inputResources) { Resource(res.name).Consume(res.rate, "radiator"); } }
public override void OnStart(StartState state) { base.OnStart(state); if (HighLogic.LoadedSceneIsFlight) { shieldState = GetShieldState(); shieldCheck = ShieldControl(); hpTracker = GetHP(); CheckShieldState(); calcSurfaceArea(); hp = hpTracker.Hitpoints; hpCheck = hp; } }
public override void OnStart(StartState state) { base.OnStart(state); //ModuleActiveRadiator activeRadiator = this.part.FindModuleImplementing <ModuleActiveRadiator>(); //Get the resource definition for electric charge. electricChargeDef = definitions["ElectricCharge"]; //Set cooling mode. For now, default is closed. coolingCycleMode = CoolingCycleModes.closed; Events["ToggleCoolingMode"].guiName = "Cooling Mode (closed)"; //Dig into the proto part and find the coolant resource nodes. getCoolantNodes(); //Load the sound effects LoadSoundFX(); }
public override void OnStart(StartState state) { base.OnStart(state); radiator = this.part.FindModuleImplementing<ModuleActiveRadiator>(); radiator.isEnabled = isDeployed && isCooling; radiator.enabled = isDeployed && isCooling; emitter = this.part.GetComponentInChildren<KSPParticleEmitter>(); if (emitter != null) { emitter.emit = isDeployed && isCooling; emitter.enabled = isDeployed && isCooling; } UpdateStatus(); if (isOpenCycle) this.Events["ToggleOpenCycle"].guiName = "Open Cycle Off"; else this.Events["ToggleOpenCycle"].guiName = "Open Cycle On"; }
public override void OnStart(StartState state) { base.OnStart(state); radiator = this.part.FindModuleImplementing <ModuleActiveRadiator>(); radiator.isEnabled = isDeployed && isCooling; radiator.enabled = isDeployed && isCooling; emitter = this.part.GetComponentInChildren <KSPParticleEmitter>(); if (emitter != null) { emitter.emit = isDeployed && isCooling; emitter.enabled = isDeployed && isCooling; } UpdateStatus(); if (isOpenCycle) { this.Events["ToggleOpenCycle"].guiName = "Open Cycle Off"; } else { this.Events["ToggleOpenCycle"].guiName = "Open Cycle On"; } if (isDeployed == false && this.part.Resources.Contains("Water")) { this.part.Resources["Water"].amount = 0; } if (fixedUpdateHelper == null) { fixedUpdateHelper = this.part.gameObject.AddComponent <FixedUpdateHelper>(); fixedUpdateHelper.onFixedUpdateDelegate = OnUpdateFixed; } fixedUpdateHelper.enabled = true; }
public static ec_data analyze_ec(List<Part> parts, environment_data env, crew_data crew, food_data food, oxygen_data oxygen, signal_data signal) { // store data ec_data ec = new ec_data(); // calculate climate cost ec.consumed = (double)crew.count * env.temp_diff * Settings.ElectricChargePerSecond; // scan the parts foreach(Part p in parts) { // accumulate EC storage ec.storage += Lib.GetResourceAmount(p, "ElectricCharge"); // remember if we already considered a resource converter module // rationale: we assume only the first module in a converter is active bool first_converter = true; // for each module foreach(PartModule m in p.Modules) { // command if (m.moduleName == "ModuleCommand") { ModuleCommand mm = (ModuleCommand)m; foreach(ModuleResource res in mm.inputResources) { if (res.name == "ElectricCharge") { ec.consumed += res.rate; } } } // solar panel else if (m.moduleName == "ModuleDeployableSolarPanel") { ModuleDeployableSolarPanel mm = (ModuleDeployableSolarPanel)m; double solar_k = (mm.useCurve ? mm.powerCurve.Evaluate((float)env.sun_dist) : env.sun_flux / Sim.SolarFluxAtHome()); double generated = mm.chargeRate * solar_k * env.atmo_factor; ec.generated_sunlight += generated; ec.best_ec_generator = Math.Max(ec.best_ec_generator, generated); } // generator else if (m.moduleName == "ModuleGenerator") { // skip launch clamps, that include a generator if (p.partInfo.name == "launchClamp1") continue; ModuleGenerator mm = (ModuleGenerator)m; foreach(ModuleResource res in mm.inputList) { if (res.name == "ElectricCharge") { ec.consumed += res.rate; } } foreach(ModuleResource res in mm.outputList) { if (res.name == "ElectricCharge") { ec.generated_shadow += res.rate; ec.generated_sunlight += res.rate; ec.best_ec_generator = Math.Max(ec.best_ec_generator, res.rate); } } } // converter // note: only electric charge is considered for resource converters // note: we only consider the first resource converter in a part, and ignore the rest else if (m.moduleName == "ModuleResourceConverter" && first_converter) { ModuleResourceConverter mm = (ModuleResourceConverter)m; foreach(ResourceRatio rr in mm.inputList) { if (rr.ResourceName == "ElectricCharge") { ec.consumed += rr.Ratio; } } foreach(ResourceRatio rr in mm.outputList) { if (rr.ResourceName == "ElectricCharge") { ec.generated_shadow += rr.Ratio; ec.generated_sunlight += rr.Ratio; ec.best_ec_generator = Math.Max(ec.best_ec_generator, rr.Ratio); } } first_converter = false; } // harvester // note: only electric charge is considered for resource harvesters else if (m.moduleName == "ModuleResourceHarvester") { ModuleResourceHarvester mm = (ModuleResourceHarvester)m; foreach(ResourceRatio rr in mm.inputList) { if (rr.ResourceName == "ElectricCharge") { ec.consumed += rr.Ratio; } } } // active radiators else if (m.moduleName == "ModuleActiveRadiator") { ModuleActiveRadiator mm = (ModuleActiveRadiator)m; if (mm.IsCooling) { foreach(var rr in mm.inputResources) { if (rr.name == "ElectricCharge") { ec.consumed += rr.rate; } } } } // wheels else if (m.moduleName == "ModuleWheelMotor") { ModuleWheelMotor mm = (ModuleWheelMotor)m; if (mm.motorEnabled && mm.inputResource.name == "ElectricCharge") { ec.consumed += mm.inputResource.rate; } } else if (m.moduleName == "ModuleWheelMotorSteering") { ModuleWheelMotorSteering mm = (ModuleWheelMotorSteering)m; if (mm.motorEnabled && mm.inputResource.name == "ElectricCharge") { ec.consumed += mm.inputResource.rate; } } // SCANsat support else if (m.moduleName == "SCANsat" || m.moduleName == "ModuleSCANresourceScanner") { // include it in ec consumption, if deployed if (SCANsat.isDeployed(p, m)) ec.consumed += Lib.ReflectionValue<float>(m, "power"); } // NearFutureSolar support // note: assume half the components are in sunlight, and average inclination is half else if (m.moduleName == "ModuleCurvedSolarPanel") { // get total rate double tot_rate = Lib.ReflectionValue<float>(m, "TotalEnergyRate"); // get number of components int components = p.FindModelTransforms(Lib.ReflectionValue<string>(m, "PanelTransformName")).Length; // approximate output // 0.7071: average clamped cosine ec.generated_sunlight += 0.7071 * tot_rate; } } } // include cost from greenhouses artificial lighting ec.consumed += food.greenhouse_cost; // include cost from scrubbers ec.consumed += oxygen.scrubber_cost; // include relay cost for the best relay antenna ec.consumed += signal.relay_cost; // finally, calculate life expectancy of ec ec.life_expectancy_sunlight = ec.storage / Math.Max(ec.consumed - ec.generated_sunlight, 0.0); ec.life_expectancy_shadow = ec.storage / Math.Max(ec.consumed - ec.generated_shadow, 0.0); // return data return ec; }
public override void OnStart(StartState state) { String[] resources_to_supply = { FNResourceManager.FNRESOURCE_WASTEHEAT }; this.resources_to_supply = resources_to_supply; base.OnStart(state); radiatedThermalPower = 0; convectedThermalPower = 0; CurrentRadiatorTemperature = 0; update_count = 0; explode_counter = 0; DetermineGenerationType(); maxRadiatorTemperature = (float)MaxRadiatorTemperature; if (hasSurfaceAreaUpgradeTechReq) { part.emissiveConstant = 1.6; } radiatorType = RadiatorType; effectiveRadiatorArea = EffectiveRadiatorArea; deployRadiatorEvent = Events["DeployRadiator"]; retractRadiatorEvent = Events["RetractRadiator"]; thermalPowerConvStrField = Fields["thermalPowerConvStr"]; radiatorIsEnabledField = Fields["radiatorIsEnabled"]; isAutomatedField = Fields["isAutomated"]; pivotEnabledField = Fields["pivotEnabled"]; Actions["DeployRadiatorAction"].guiName = Events["DeployRadiator"].guiName = "Deploy Radiator"; Actions["ToggleRadiatorAction"].guiName = String.Format("Toggle Radiator"); Actions["RetractRadiatorAction"].guiName = "Retract Radiator"; Events["RetractRadiator"].guiName = "Retract Radiator"; // calculate WasteHeat Capacity partBaseWasteheat = part.mass * 1e+6 * wasteHeatMultiplier; wasteheatPowerResource = part.Resources[FNResourceManager.FNRESOURCE_WASTEHEAT]; var myAttachedEngine = part.FindModuleImplementing <ModuleEngines>(); if (myAttachedEngine == null) { partMass = part.mass; Fields["partMass"].guiActiveEditor = true; Fields["partMass"].guiActive = true; Fields["convectiveBonus"].guiActiveEditor = true; } if (!String.IsNullOrEmpty(thermalAnim)) { heatStates = SetUpAnimation(thermalAnim, this.part); if (heatStates != null) { SetHeatAnimationRatio(0); } } deployAnim = part.FindModelAnimators(animName).FirstOrDefault(); if (deployAnim != null) { deployAnim[animName].layer = 1; deployAnim[animName].speed = 0; deployAnim[animName].normalizedTime = radiatorIsEnabled ? 1 : 0; } _moduleDeployableRadiator = part.FindModuleImplementing <ModuleDeployableRadiator>(); _moduleActiveRadiator = part.FindModuleImplementing <ModuleActiveRadiator>(); if (_moduleActiveRadiator != null) { _moduleActiveRadiator.Events["Activate"].guiActive = false; _moduleActiveRadiator.Events["Shutdown"].guiActive = false; } BaseField radiatorfield = Fields["radiatorIsEnabled"]; radiatorfield.guiActive = showControls; radiatorfield.guiActiveEditor = showControls; radiatorfield.OnValueModified += radiatorIsEnabled_OnValueModified; BaseField automatedfield = Fields["isAutomated"]; automatedfield.guiActive = showControls; automatedfield.guiActiveEditor = showControls; BaseField pivotfield = Fields["pivotEnabled"]; pivotfield.guiActive = showControls; pivotfield.guiActiveEditor = showControls; _maxEnergyTransfer = radiatorArea * 1000 * Math.Pow(1 + ((int)CurrentGenerationType), 1.5); if (_moduleActiveRadiator != null) { _moduleActiveRadiator.maxEnergyTransfer = _maxEnergyTransfer; } if (state == StartState.Editor) { return; } int depth = 0; star = FlightGlobals.currentMainBody; while (depth < 10 && star != null && star.GetTemperature(0) < 2000) { star = star.referenceBody; depth++; } if (star == null) { star = FlightGlobals.Bodies[0]; } if (ResearchAndDevelopment.Instance != null) { upgradeCostStr = ResearchAndDevelopment.Instance.Science + "/" + upgradeCost.ToString("0") + " Science"; } renderArray = part.FindModelComponents <Renderer>().ToArray(); if (radiatorInit == false) { radiatorInit = true; } part.maxTemp = maxRadiatorTemperature; radiatorTempStr = maxRadiatorTemperature + "K"; maxVacuumTemperature = String.IsNullOrEmpty(surfaceAreaUpgradeTechReq) ? Math.Min((float)PluginHelper.RadiatorTemperatureMk3, maxRadiatorTemperature) : Math.Min(maxVacuumTemperature, maxRadiatorTemperature); maxAtmosphereTemperature = String.IsNullOrEmpty(surfaceAreaUpgradeTechReq) ? Math.Min((float)PluginHelper.RadiatorTemperatureMk3, maxRadiatorTemperature) : Math.Min(maxAtmosphereTemperature, maxRadiatorTemperature); }
private void OnWindow(int window_id) { try { GUILayout.BeginVertical(); // Get all modules of the selected part: var part_title = ""; Part part = null; KRnDModule rnd_module = null; List <ModuleEngines> engine_modules = null; ModuleRCS rcs_module = null; ModuleReactionWheel reaction_wheel_module = null; ModuleDeployableSolarPanel solar_panel_module = null; ModuleWheelBase landing_leg_module = null; PartResource electric_charge_resource = null; ModuleGenerator generator_module = null; PartModule fission_generator = null; List <ModuleResourceConverter> converter_modules = null; ModuleParachute parachute_module = null; ModuleDataTransmitter antenna_module = null; ModuleScienceLab science_lab = null; List <PartResource> fuel_resources = null; ModuleResourceHarvester harvester_module = null; ModuleActiveRadiator radiator_module = null; ELConverter el_converter = null; if (selectedPart != null) { foreach (var a_part in PartLoader.LoadedPartsList) { if (a_part.partPrefab.name == selectedPart.name) { part = a_part.partPrefab; part_title = a_part.title; break; } } if (part) { antenna_module = PartStats.GetModuleDataTransmitter(part); science_lab = PartStats.GetModuleScienceLab(part); rnd_module = PartStats.GetKRnDModule(part); engine_modules = PartStats.GetModuleEnginesList(part); rcs_module = PartStats.GetModuleRCS(part); reaction_wheel_module = PartStats.GetModuleReactionWheel(part); solar_panel_module = PartStats.GetModuleDeployableSolarPanel(part); landing_leg_module = PartStats.GetModuleWheelBase(part); electric_charge_resource = PartStats.GetElectricCharge(part); generator_module = PartStats.GetModuleGenerator(part); fission_generator = PartStats.GetFissionGenerator(part); converter_modules = PartStats.GetModuleResourceConverterList(part); parachute_module = PartStats.GetModuleParachute(part); fuel_resources = PartStats.GetFuelResources(part); harvester_module = PartStats.GetModuleResourceHarvester(part); radiator_module = PartStats.GetModuleActiveRadiator(part); el_converter = PartStats.GetModuleElConverter(part); } } if (!part) { // No part selected: GUILayout.BeginArea(new Rect(10, 5, _windowStyle.fixedWidth, 20)); GUILayout.Label("<b>Kerbal R&D: Select a part to improve</b>", _labelStyle); GUILayout.EndArea(); GUILayout.EndVertical(); GUI.DragWindow(); return; } if (!rnd_module) { // Invalid part selected: GUILayout.BeginArea(new Rect(10, 5, _windowStyle.fixedWidth, 20)); GUILayout.Label("<b>Kerbal R&D: Select a different part to improve</b>", _labelStyle); GUILayout.EndArea(); GUILayout.EndVertical(); GUI.DragWindow(); return; } // Get stats of the current version of the selected part: if (!KRnD.upgrades.TryGetValue(part.name, out var current_upgrade)) { current_upgrade = new PartUpgrades(); } var current_info = BuildPartInfoString(part, current_upgrade); // Create a copy of the part-stats which we can use to mock an upgrade further below: var next_upgrade = current_upgrade.Clone(); // Title: GUILayout.BeginArea(new Rect(10, 5, _windowStyle.fixedWidth, 20)); var version = rnd_module.GetVersion(); if (version != "") { version = " - " + version; } GUILayout.Label("<b>" + part_title + version + "</b>", _labelStyle); GUILayout.EndArea(); // List with upgrade-options: float options_width = 100; var options_height = _windowStyle.fixedHeight - 30 - 30 - 20; GUILayout.BeginArea(new Rect(10, 30 + 20, options_width, options_height)); GUILayout.BeginVertical(); var options = new List <string> { "Dry Mass", "Max Temp" }; if (engine_modules != null || rcs_module) { options.Add("ISP Vac"); options.Add("ISP Atm"); options.Add("Fuel Flow"); } if (antenna_module != null) { options.Add("Antenna Power"); } if (antenna_module != null && antenna_module.antennaType != AntennaType.INTERNAL) { options.Add("Packet Size"); } if (science_lab != null) { options.Add("Data Storage"); } if (reaction_wheel_module != null) { options.Add("Torque"); } if (solar_panel_module != null) { options.Add("Charge Rate"); } if (landing_leg_module != null) { options.Add("Crash Tolerance"); } if (electric_charge_resource != null) { options.Add("Battery"); } //if (fuel_resources != null) options.Add("Fuel Pressure"); if (generator_module || fission_generator) { options.Add("Generator"); } if (converter_modules != null) { options.Add("Converter"); } if (parachute_module) { options.Add("Parachute"); } if (harvester_module) { options.Add("Harvester"); } if (radiator_module) { options.Add("Radiator"); } if (el_converter) { options.Add("EL Converter"); } if (_selectedUpgradeOption >= options.Count) { _selectedUpgradeOption = 0; } _selectedUpgradeOption = GUILayout.SelectionGrid(_selectedUpgradeOption, options.ToArray(), 1, _buttonStyle); GUILayout.EndVertical(); GUILayout.EndArea(); var selected_upgrade_option = options.ToArray()[_selectedUpgradeOption]; int current_upgrade_level; int next_upgrade_level; int science_cost; float current_improvement_factor; float next_improvement_factor; UpgradeConstants u_constants; if (!KRnD.originalStats.TryGetValue(part.name, out var original_stats)) { throw new Exception("no original-stats for part '" + part.name + "'"); } //Func<PartUpgrades, int> improve_function; if (selected_upgrade_option == "ISP Vac") { //improve_function = KRnD.ImproveIspVac; current_upgrade_level = current_upgrade.ispVac; next_upgrade_level = ++next_upgrade.ispVac; u_constants = ValueConstants.GetData(StringConstants.ISP_VAC); current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.ispVac); next_improvement_factor = u_constants.CalculateImprovementFactor(next_upgrade.ispVac); science_cost = u_constants.CalculateScienceCost(0, next_upgrade.ispVac); } else if (selected_upgrade_option == "ISP Atm") { //improve_function = KRnD.ImproveIspAtm; current_upgrade_level = current_upgrade.ispAtm; next_upgrade_level = ++next_upgrade.ispAtm; u_constants = ValueConstants.GetData(StringConstants.ISP_ATM); current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.ispAtm); next_improvement_factor = u_constants.CalculateImprovementFactor(next_upgrade.ispAtm); science_cost = u_constants.CalculateScienceCost(0, next_upgrade.ispAtm); } else if (selected_upgrade_option == "Fuel Flow") { //improve_function = KRnD.ImproveFuelFlow; current_upgrade_level = current_upgrade.fuelFlow; next_upgrade_level = ++next_upgrade.fuelFlow; u_constants = ValueConstants.GetData(StringConstants.FUEL_FLOW); current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.fuelFlow); next_improvement_factor = u_constants.CalculateImprovementFactor(next_upgrade.fuelFlow); science_cost = u_constants.CalculateScienceCost(0, next_upgrade.fuelFlow); } else if (selected_upgrade_option == "Dry Mass") { //improve_function = KRnD.ImproveDryMass; current_upgrade_level = current_upgrade.dryMass; next_upgrade_level = ++next_upgrade.dryMass; u_constants = ValueConstants.GetData(StringConstants.DRY_MASS); current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.dryMass); next_improvement_factor = u_constants.CalculateImprovementFactor(next_upgrade.dryMass); science_cost = u_constants.CalculateScienceCost(original_stats.dryMass, next_upgrade.dryMass); } else if (selected_upgrade_option == "Torque") { //improve_function = KRnD.ImproveTorque; current_upgrade_level = current_upgrade.torqueStrength; next_upgrade_level = ++next_upgrade.torqueStrength; u_constants = ValueConstants.GetData(StringConstants.TORQUE); current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.torqueStrength); next_improvement_factor = u_constants.CalculateImprovementFactor(next_upgrade.torqueStrength); science_cost = u_constants.CalculateScienceCost(original_stats.torqueStrength, next_upgrade.torqueStrength); } else if (selected_upgrade_option == "Antenna Power") { //improve_function = KRnD.ImproveAntennaPower; current_upgrade_level = current_upgrade.antennaPower; next_upgrade_level = ++next_upgrade.antennaPower; u_constants = ValueConstants.GetData(StringConstants.ANTENNA_POWER); current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.antennaPower); next_improvement_factor = u_constants.CalculateImprovementFactor(next_upgrade.antennaPower); science_cost = u_constants.CalculateScienceCost((float)original_stats.antennaPower, next_upgrade.antennaPower); } else if (selected_upgrade_option == "Packet Size") { //improve_function = KRnD.ImprovePacketSize; current_upgrade_level = current_upgrade.packetSize; next_upgrade_level = ++next_upgrade.packetSize; u_constants = ValueConstants.GetData(StringConstants.PACKET_SIZE); current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.packetSize); next_improvement_factor = u_constants.CalculateImprovementFactor(next_upgrade.packetSize); science_cost = u_constants.CalculateScienceCost(original_stats.packetSize, next_upgrade.packetSize); } else if (selected_upgrade_option == "Data Storage") { //improve_function = KRnD.ImproveDataStorage; current_upgrade_level = current_upgrade.dataStorage; next_upgrade_level = ++next_upgrade.dataStorage; u_constants = ValueConstants.GetData(StringConstants.DATA_STORAGE); current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.dataStorage); next_improvement_factor = u_constants.CalculateImprovementFactor(next_upgrade.dataStorage); science_cost = u_constants.CalculateScienceCost(original_stats.dataStorage, next_upgrade.dataStorage); } else if (selected_upgrade_option == "Harvester") { //improve_function = KRnD.ImproveResourceHarvester; current_upgrade_level = current_upgrade.resourceHarvester; next_upgrade_level = ++next_upgrade.resourceHarvester; u_constants = ValueConstants.GetData(StringConstants.RESOURCE_HARVESTER); current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.resourceHarvester); next_improvement_factor = u_constants.CalculateImprovementFactor(next_upgrade.resourceHarvester); science_cost = u_constants.CalculateScienceCost(original_stats.resourceHarvester, next_upgrade.resourceHarvester); } else if (selected_upgrade_option == "Radiator") { //improve_function = KRnD.ImproveActiveRadiator; current_upgrade_level = current_upgrade.maxEnergyTransfer; next_upgrade_level = ++next_upgrade.maxEnergyTransfer; u_constants = ValueConstants.GetData(StringConstants.ENERGY_TRANSFER); current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.maxEnergyTransfer); next_improvement_factor = u_constants.CalculateImprovementFactor(next_upgrade.maxEnergyTransfer); science_cost = u_constants.CalculateScienceCost((float)original_stats.maxEnergyTransfer, next_upgrade.maxEnergyTransfer); } else if (selected_upgrade_option == "Charge Rate") { //improve_function = KRnD.ImproveChargeRate; current_upgrade_level = current_upgrade.efficiencyMult; next_upgrade_level = ++next_upgrade.efficiencyMult; u_constants = ValueConstants.GetData(StringConstants.CHARGE_RATE); current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.efficiencyMult); next_improvement_factor = u_constants.CalculateImprovementFactor(next_upgrade.efficiencyMult); science_cost = u_constants.CalculateScienceCost(original_stats.efficiencyMult, next_upgrade.efficiencyMult); } else if (selected_upgrade_option == "Crash Tolerance") { //improve_function = KRnD.ImproveCrashTolerance; current_upgrade_level = current_upgrade.crashTolerance; next_upgrade_level = ++next_upgrade.crashTolerance; u_constants = ValueConstants.GetData(StringConstants.CRASH_TOLERANCE); current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.crashTolerance); next_improvement_factor = u_constants.CalculateImprovementFactor(next_upgrade.crashTolerance); science_cost = u_constants.CalculateScienceCost(original_stats.crashTolerance, next_upgrade.crashTolerance); } else if (selected_upgrade_option == "Battery") { //improve_function = KRnD.ImproveBatteryCharge; current_upgrade_level = current_upgrade.batteryCharge; next_upgrade_level = ++next_upgrade.batteryCharge; u_constants = ValueConstants.GetData(StringConstants.BATTERY_CHARGE); current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.batteryCharge); next_improvement_factor = u_constants.CalculateImprovementFactor(next_upgrade.batteryCharge); science_cost = u_constants.CalculateScienceCost((float)original_stats.batteryCharge, next_upgrade.batteryCharge); } else if (selected_upgrade_option == "Fuel Pressure") { //improve_function = KRnD.ImproveFuelCapacity; current_upgrade_level = current_upgrade.fuelCapacity; next_upgrade_level = ++next_upgrade.fuelCapacity; u_constants = ValueConstants.GetData(StringConstants.FUEL_CAPACITY); current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.fuelCapacity); next_improvement_factor = u_constants.CalculateImprovementFactor(next_upgrade.fuelCapacity); science_cost = u_constants.CalculateScienceCost((float)original_stats.fuelCapacitiesSum, next_upgrade.fuelCapacity); } else if (selected_upgrade_option == "Generator") { //improve_function = KRnD.ImproveGeneratorEfficiency; current_upgrade_level = current_upgrade.generatorEfficiency; next_upgrade_level = ++next_upgrade.generatorEfficiency; u_constants = ValueConstants.GetData(StringConstants.GENERATOR_EFFICIENCY); current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.generatorEfficiency); next_improvement_factor = u_constants.CalculateImprovementFactor(next_upgrade.generatorEfficiency); science_cost = u_constants.CalculateScienceCost(0, next_upgrade.generatorEfficiency); } else if (selected_upgrade_option == "Converter") { //improve_function = KRnD.ImproveConverterEfficiency; current_upgrade_level = current_upgrade.converterEfficiency; next_upgrade_level = ++next_upgrade.converterEfficiency; u_constants = ValueConstants.GetData(StringConstants.CONVERTER_EFFICIENCY); current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.converterEfficiency); next_improvement_factor = u_constants.CalculateImprovementFactor(next_upgrade.converterEfficiency); science_cost = u_constants.CalculateScienceCost(0, next_upgrade.converterEfficiency); } else if (selected_upgrade_option == "Parachute") { //improve_function = KRnD.ImproveParachuteStrength; current_upgrade_level = current_upgrade.parachuteStrength; next_upgrade_level = ++next_upgrade.parachuteStrength; u_constants = ValueConstants.GetData(StringConstants.PARACHUTE_STRENGTH); current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.parachuteStrength); next_improvement_factor = u_constants.CalculateImprovementFactor(next_upgrade.parachuteStrength); science_cost = u_constants.CalculateScienceCost((float)original_stats.chuteMaxTemp, next_upgrade.parachuteStrength); } else if (selected_upgrade_option == "Max Temp") { //improve_function = KRnD.ImproveMaxTemperature; current_upgrade_level = current_upgrade.maxTemperature; next_upgrade_level = ++next_upgrade.maxTemperature; u_constants = ValueConstants.GetData(StringConstants.MAX_TEMPERATURE); current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.maxTemperature); next_improvement_factor = u_constants.CalculateImprovementFactor(next_upgrade.maxTemperature); science_cost = u_constants.CalculateScienceCost((float)original_stats.intMaxTemp, next_upgrade.maxTemperature); } else if (selected_upgrade_option == "EL Converter") { //improve_function = KRnD.ImproveMaxTemperature; current_upgrade_level = current_upgrade.elConverter; next_upgrade_level = ++next_upgrade.elConverter; u_constants = ValueConstants.GetData(StringConstants.EL_CONVERTER); current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.elConverter); next_improvement_factor = u_constants.CalculateImprovementFactor(next_upgrade.elConverter); science_cost = u_constants.CalculateScienceCost((float)original_stats.ELConverter, next_upgrade.elConverter); } else { throw new Exception("unexpected option '" + selected_upgrade_option + "'"); } var new_info = BuildPartInfoString(part, next_upgrade); // Calculate part-info if the selected stat was upgraded. new_info = HighlightChanges(current_info, new_info); // Current stats: GUILayout.BeginArea(new Rect(10 + options_width + 10, 30, _windowStyle.fixedWidth, 20)); GUILayout.Label("<color=#FFFFFF><b>Current:</b> " + current_upgrade_level + " (" + current_improvement_factor.ToString("+0.##%;-0.##%;-") + ")</color>", _labelStyle); GUILayout.EndArea(); var area_width = (_windowStyle.fixedWidth - 20 - options_width) / 2; var area_height = options_height; GUILayout.BeginArea(new Rect(10 + options_width, 30 + 20, area_width, area_height)); _scrollPos = GUILayout.BeginScrollView(_scrollPos, _scrollStyle, GUILayout.Width(area_width), GUILayout.Height(area_height)); GUILayout.Label(current_info, _labelStyleSmall); GUILayout.EndScrollView(); GUILayout.EndArea(); // Next stats: GUILayout.BeginArea(new Rect(10 + options_width + area_width + 10, 30, _windowStyle.fixedWidth, 20)); GUILayout.Label("<color=#FFFFFF><b>Next upgrade:</b> " + next_upgrade_level + " (" + next_improvement_factor.ToString("+0.##%;-0.##%;-") + ")</color>", _labelStyle); GUILayout.EndArea(); GUILayout.BeginArea(new Rect(10 + options_width + area_width, 30 + 20, area_width, area_height)); _scrollPos = GUILayout.BeginScrollView(_scrollPos, _scrollStyle, GUILayout.Width(area_width), GUILayout.Height(area_height)); GUILayout.Label(new_info, _labelStyleSmall); GUILayout.EndScrollView(); GUILayout.EndArea(); // Bottom-line (display only if the upgrade would have an effect): if (Math.Abs(current_improvement_factor - next_improvement_factor) > float.Epsilon) { GUILayout.BeginArea(new Rect(10, _windowStyle.fixedHeight - 25, _windowStyle.fixedWidth, 30)); float current_science = 0; if (ResearchAndDevelopment.Instance != null) { current_science = ResearchAndDevelopment.Instance.Science; } var color = "FF0000"; if (current_science >= science_cost) { color = "00FF00"; } GUILayout.Label("<b>Science: <color=#" + color + ">" + science_cost + " / " + Math.Floor(current_science) + "</color></b>", _labelStyle); GUILayout.EndArea(); if (current_science >= science_cost && ResearchAndDevelopment.Instance != null && u_constants != null /*&& improve_function != null*/) { GUILayout.BeginArea(new Rect(_windowStyle.fixedWidth - 110, _windowStyle.fixedHeight - 30, 100, 30)); if (GUILayout.Button("Research", _buttonStyle)) { //upgrade_function(part); try { if (!KRnD.upgrades.TryGetValue(part.name, out var store)) { store = new PartUpgrades(); KRnD.upgrades.Add(part.name, store); } u_constants.upgradeFunction(store); //improve_function(store); KRnD.UpdateGlobalParts(); KRnD.UpdateEditorVessel(); } catch (Exception e) { Debug.LogError("[KRnD] UpgradeIspVac(): " + e); } ResearchAndDevelopment.Instance.AddScience(-science_cost, TransactionReasons.RnDTechResearch); } GUILayout.EndArea(); } } GUILayout.EndVertical(); GUI.DragWindow(); } catch (Exception e) { Debug.LogError("[KRnD] GenerateWindow(): " + e); } }
public override bool Initialize(PartModule pm) { base.Initialize(pm); radiator = (ModuleActiveRadiator)pm; return(true); }
public override void OnStart(StartState state) { String[] resourcesToSupply = { ResourceManager.FNRESOURCE_WASTEHEAT }; this.resources_to_supply = resourcesToSupply; base.OnStart(state); radiatedThermalPower = 0; convectedThermalPower = 0; CurrentRadiatorTemperature = 0; update_count = 0; radiator_deploy_delay = 0; explode_counter = 0; DetermineGenerationType(); kspShader = Shader.Find(kspShaderLocation); maxRadiatorTemperature = (float)MaxRadiatorTemperature; if (hasSurfaceAreaUpgradeTechReq) { part.emissiveConstant = 1.6; } radiatorType = RadiatorType; effectiveRadiatorArea = EffectiveRadiatorArea; stefanArea = PhysicsGlobals.StefanBoltzmanConstant * effectiveRadiatorArea * 1e-6; deployRadiatorEvent = Events["DeployRadiator"]; retractRadiatorEvent = Events["RetractRadiator"]; thermalPowerConvStrField = Fields["thermalPowerConvStr"]; radiatorIsEnabledField = Fields["radiatorIsEnabled"]; isAutomatedField = Fields["isAutomated"]; pivotEnabledField = Fields["pivotEnabled"]; var preventDeplyField = Fields["preventShieldedDeploy"]; preventDeplyField.guiActive = isDeployable; preventDeplyField.guiActiveEditor = isDeployable; Actions["DeployRadiatorAction"].guiName = Events["DeployRadiator"].guiName = "Deploy Radiator"; Actions["ToggleRadiatorAction"].guiName = String.Format("Toggle Radiator"); Actions["RetractRadiatorAction"].guiName = "Retract Radiator"; Events["RetractRadiator"].guiName = "Retract Radiator"; var myAttachedEngine = part.FindModuleImplementing <ModuleEngines>(); if (myAttachedEngine == null) { partMass = part.mass; Fields["partMass"].guiActiveEditor = true; Fields["partMass"].guiActive = true; Fields["convectiveBonus"].guiActiveEditor = true; } if (!String.IsNullOrEmpty(thermalAnim)) { heatStates = PluginHelper.SetUpAnimation(thermalAnim, this.part); if (heatStates != null) { SetHeatAnimationRatio(0); } } deployAnimation = part.FindModelAnimators(animName).FirstOrDefault(); if (deployAnimation != null) { deployAnimation[animName].layer = 1; deployAnimation[animName].speed = 0; deployAnimation[animName].normalizedTime = radiatorIsEnabled ? 1 : 0; } _moduleActiveRadiator = part.FindModuleImplementing <ModuleActiveRadiator>(); if (_moduleActiveRadiator != null) { _moduleActiveRadiator.Events["Activate"].guiActive = false; _moduleActiveRadiator.Events["Shutdown"].guiActive = false; } _moduleDeployableRadiator = part.FindModuleImplementing <ModuleDeployableRadiator>(); if (_moduleDeployableRadiator != null) { radiatorState = _moduleDeployableRadiator.deployState; } var radiatorfield = Fields["radiatorIsEnabled"]; radiatorfield.guiActive = showControls; radiatorfield.guiActiveEditor = showControls; radiatorfield.OnValueModified += radiatorIsEnabled_OnValueModified; var automatedfield = Fields["isAutomated"]; automatedfield.guiActive = showControls; automatedfield.guiActiveEditor = showControls; var pivotfield = Fields["pivotEnabled"]; pivotfield.guiActive = showControls; pivotfield.guiActiveEditor = showControls; if (_moduleActiveRadiator != null) { var generationValue = 1 + ((int)CurrentGenerationType); _maxEnergyTransfer = radiatorArea * 2500 * Math.Pow(generationValue, 1.5); _moduleActiveRadiator.maxEnergyTransfer = _maxEnergyTransfer; _moduleActiveRadiator.overcoolFactor = 0.20 + ((int)CurrentGenerationType * 0.025); } if (state == StartState.Editor) { return; } if (ResearchAndDevelopment.Instance != null) { upgradeCostStr = ResearchAndDevelopment.Instance.Science + "/" + upgradeCost.ToString("0") + " Science"; } renderArray = part.FindModelComponents <Renderer>().ToArray(); if (radiatorInit == false) { radiatorInit = true; } part.maxTemp = maxRadiatorTemperature; radiatorTempStr = maxRadiatorTemperature + "K"; maxVacuumTemperature = String.IsNullOrEmpty(surfaceAreaUpgradeTechReq) ? Math.Min((float)PluginHelper.RadiatorTemperatureMk3, maxRadiatorTemperature) : Math.Min(maxVacuumTemperature, maxRadiatorTemperature); maxAtmosphereTemperature = String.IsNullOrEmpty(surfaceAreaUpgradeTechReq) ? Math.Min((float)PluginHelper.RadiatorTemperatureMk3, maxRadiatorTemperature) : Math.Min(maxAtmosphereTemperature, maxRadiatorTemperature); resourceBuffers = new ResourceBuffers(); resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceManager.FNRESOURCE_WASTEHEAT, wasteHeatMultiplier, 2.0e+6)); resourceBuffers.UpdateVariable(ResourceManager.FNRESOURCE_WASTEHEAT, this.part.mass); resourceBuffers.Init(this.part); }
public override void OnStart(StartState state) { radiatedThermalPower = 0; convectedThermalPower = 0; CurrentRadiatorTemperature = 0; directionrotate = 1; update_count = 0; explode_counter = 0; DetermineGenerationType(); if (hasSurfaceAreaUpgradeTechReq) { part.emissiveConstant = 1.6; } radiatorType = RadiatorType; effectiveRadiatorArea = EffectiveRadiatorArea; deployRadiatorEvent = Events["DeployRadiator"]; retractRadiatorEvent = Events["RetractRadiator"]; Actions["DeployRadiatorAction"].guiName = Events["DeployRadiator"].guiName = "Deploy Radiator"; Actions["ToggleRadiatorAction"].guiName = String.Format("Toggle Radiator"); Actions["RetractRadiatorAction"].guiName = "Retract Radiator"; Events["RetractRadiator"].guiName = "Retract Radiator"; doLegacyGraphics = (part.name.StartsWith("circradiator") || part.name.StartsWith("RadialRadiator") || (part.name.StartsWith("LargeFlatRadiator"))); // calculate WasteHeat Capacity var wasteheatPowerResource = part.Resources.FirstOrDefault(r => r.resourceName == FNResourceManager.FNRESOURCE_WASTEHEAT); if (wasteheatPowerResource != null) { var ratio = Math.Min(1.0, Math.Max(0.0, wasteheatPowerResource.amount / wasteheatPowerResource.maxAmount)); wasteheatPowerResource.maxAmount = part.mass * 1.0e+5 * wasteHeatMultiplier; wasteheatPowerResource.amount = wasteheatPowerResource.maxAmount * ratio; } var myAttachedEngine = this.part.FindModuleImplementing <ModuleEngines>(); if (myAttachedEngine == null) { Fields["partMass"].guiActiveEditor = true; Fields["convectiveBonus"].guiActiveEditor = true; } if (!String.IsNullOrEmpty(thermalAnim)) { heatStates = SetUpAnimation(thermalAnim, this.part); } SetHeatAnimationRatio(0); deployAnim = part.FindModelAnimators(animName).FirstOrDefault(); if (deployAnim != null) { deployAnim[animName].layer = 1; deployAnim[animName].speed = 0; if (radiatorIsEnabled) { deployAnim[animName].normalizedTime = 1; } else { deployAnim[animName].normalizedTime = 0; } } _moduleDeployableRadiator = part.FindModuleImplementing <ModuleDeployableRadiator>(); _moduleActiveRadiator = part.FindModuleImplementing <ModuleActiveRadiator>(); if (_moduleActiveRadiator != null) { _moduleActiveRadiator.Events["Activate"].guiActive = false; _moduleActiveRadiator.Events["Shutdown"].guiActive = false; } BaseField radiatorfield = Fields["radiatorIsEnabled"]; radiatorfield.OnValueModified += radiatorIsEnabled_OnValueModified; if (_moduleDeployableRadiator == null && _moduleActiveRadiator != null && state != StartState.Editor) { if (radiatorIsEnabled) { Deploy(); } else { Retract(); } } _maxEnergyTransfer = radiatorArea * 1000 * (1 + ((int)CurrentGenerationType * 2)); if (state == StartState.Editor) { return; } int depth = 0; star = FlightGlobals.currentMainBody; while (depth < 10 && star != null && star.GetTemperature(0) < 2000) { star = star.referenceBody; depth++; } if (star == null) { star = FlightGlobals.Bodies[0]; } // find all thermal sources list_of_thermal_sources = vessel.FindPartModulesImplementing <IThermalSource>().Where(tc => tc.IsThermalSource).ToList(); if (ResearchAndDevelopment.Instance != null) { upgradeCostStr = ResearchAndDevelopment.Instance.Science + "/" + upgradeCost.ToString("0") + " Science"; } if (state == PartModule.StartState.Docked) { base.OnStart(state); return; } // add to static list of all radiators FNRadiator.list_of_all_radiators.Add(this); renderArray = part.FindModelComponents <Renderer>().ToArray(); //if (isDeployable) // UnityEngine.Debug.Log("[KSPI] - OnStart.Start isDeployable"); //else // radiatorIsEnabled = true; if (radiatorInit == false) { radiatorInit = true; } part.maxTemp = MaxRadiatorTemperature; radiatorTempStr = MaxRadiatorTemperature + "K"; }
public override void OnStart(StartState state) { radiatedThermalPower = 0; convectedThermalPower = 0; current_rad_temp = 0; directionrotate = 1; last_draw_update = 0; update_count = 0; hasrequiredupgrade = false; explode_counter = 0; DetermineGenerationType(); if (hasSurfaceAreaUpgradeTechReq) { part.emissiveConstant = 1.6; } radiatorType = RadiatorType; UpdateEnableAutomation(); effectiveRadiatorArea = EffectiveRadiatorArea; //attachedParts = part.attachNodes.Where(a => a.attachedPart != null).Select(m => m.attachedPart).ToList(); Actions["DeployRadiatorAction"].guiName = Events["DeployRadiator"].guiName = "Deploy Radiator"; Actions["RetractRadiatorAction"].guiName = Events["RetractRadiator"].guiName = "Retract Radiator"; Actions["ToggleRadiatorAction"].guiName = String.Format("Toggle Radiator"); var wasteheatPowerResource = part.Resources.list.FirstOrDefault(r => r.resourceName == FNResourceManager.FNRESOURCE_WASTEHEAT); // calculate WasteHeat Capacity if (wasteheatPowerResource != null) { var ratio = Math.Min(1, Math.Max(0, wasteheatPowerResource.amount / wasteheatPowerResource.maxAmount)); wasteheatPowerResource.maxAmount = part.mass * 1.0e+5 * wasteHeatMultiplier; wasteheatPowerResource.amount = wasteheatPowerResource.maxAmount * ratio; } var myAttachedEngine = this.part.FindModuleImplementing <ModuleEngines>(); if (myAttachedEngine == null) { Fields["partMass"].guiActiveEditor = true; Fields["convectiveBonus"].guiActiveEditor = true; } if (!String.IsNullOrEmpty(thermalAnim)) { heatStates = SetUpAnimation(thermalAnim, this.part); } SetHeatAnimationRatio(0); deployAnim = part.FindModelAnimators(animName).FirstOrDefault(); if (deployAnim != null) { deployAnim[animName].layer = 1; deployAnim[animName].speed = 0; if (radiatorIsEnabled) { deployAnim[animName].normalizedTime = 1; } else { deployAnim[animName].normalizedTime = 0; } } _moduleDeployableRadiator = part.FindModuleImplementing <ModuleDeployableRadiator>(); _moduleActiveRadiator = part.FindModuleImplementing <ModuleActiveRadiator>(); _maxEnergyTransfer = radiatorArea * 1000 * (1 + ((int)CurrentGenerationType * 2)); if (state == StartState.Editor) { if (hasTechsRequiredToUpgrade()) { isupgraded = true; hasrequiredupgrade = true; } return; } // find all thermal sources list_of_thermal_sources = vessel.FindPartModulesImplementing <IThermalSource>().Where(tc => tc.IsThermalSource).ToList(); if (ResearchAndDevelopment.Instance != null) { upgradeCostStr = ResearchAndDevelopment.Instance.Science + "/" + upgradeCost.ToString("0") + " Science"; } if (state == PartModule.StartState.Docked) { base.OnStart(state); return; } // add to static list of all radiators FNRadiator.list_of_all_radiators.Add(this); array = part.FindModelComponents <Renderer>(); if (isDeployable) { UnityEngine.Debug.Log("[KSPI] - OnStart.Start isDeployable"); pivot = part.FindModelTransform("suntransform"); if (pivot != null) { original_eulers = pivot.transform.localEulerAngles; } } else { radiatorIsEnabled = true; } UnityEngine.Debug.Log("[KSPI] - OnStart.Start I"); if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER) { //if(PluginHelper.hasTech(upgradeTechReq)) // hasrequiredupgrade = true; } else { hasrequiredupgrade = true; } if (radiatorInit == false) { radiatorInit = true; } part.maxTemp = RadiatorTemperature; radiatorTempStr = RadiatorTemperature + "K"; UnityEngine.Debug.Log("[KSPI] - OnStart.Start J"); }
public override void OnStart(StartState state) { String[] resourcesToSupply = { ResourceManager.FNRESOURCE_WASTEHEAT }; this.resources_to_supply = resourcesToSupply; base.OnStart(state); radiatedThermalPower = 0; convectedThermalPower = 0; CurrentRadiatorTemperature = 0; radiator_deploy_delay = 0; DetermineGenerationType(); isGraphene = !String.IsNullOrEmpty(surfaceAreaUpgradeTechReq); maximumRadiatorTempInSpace = (float)RadiatorProperties.RadiatorTemperatureMk6; maxSpaceTempBonus = maximumRadiatorTempInSpace - maximumRadiatorTempAtOneAtmosphere; temperatureRange = maximumRadiatorTempInSpace - drapperPoint; kspShader = Shader.Find(kspShaderLocation); maxRadiatorTemperature = (float)MaxRadiatorTemperature; part.heatConvectiveConstant = convectiveBonus; if (hasSurfaceAreaUpgradeTechReq) { part.emissiveConstant = 1.6; } radiatorType = RadiatorType; effectiveRadiatorArea = EffectiveRadiatorArea; stefanArea = PhysicsGlobals.StefanBoltzmanConstant * effectiveRadiatorArea * 1e-6; startWithCircradiator = part.name.StartsWith("circradiator"); startWithRadialRadiator = part.name.StartsWith("RadialRadiator"); startWithLargeFlatRadiator = part.name.StartsWith("LargeFlatRadiator"); deployRadiatorEvent = Events["DeployRadiator"]; retractRadiatorEvent = Events["RetractRadiator"]; thermalPowerConvStrField = Fields["thermalPowerConvStr"]; radiatorIsEnabledField = Fields["radiatorIsEnabled"]; isAutomatedField = Fields["isAutomated"]; pivotEnabledField = Fields["pivotEnabled"]; var preventDeplyField = Fields["preventShieldedDeploy"]; preventDeplyField.guiActive = isDeployable; preventDeplyField.guiActiveEditor = isDeployable; Actions["DeployRadiatorAction"].guiName = Events["DeployRadiator"].guiName = "Deploy Radiator"; Actions["ToggleRadiatorAction"].guiName = String.Format("Toggle Radiator"); Actions["RetractRadiatorAction"].guiName = "Retract Radiator"; Events["RetractRadiator"].guiName = "Retract Radiator"; var myAttachedEngine = part.FindModuleImplementing <ModuleEngines>(); if (myAttachedEngine == null) { partMass = part.mass; Fields["partMass"].guiActiveEditor = true; Fields["partMass"].guiActive = true; Fields["convectiveBonus"].guiActiveEditor = true; } if (!String.IsNullOrEmpty(thermalAnim)) { heatStates = PluginHelper.SetUpAnimation(thermalAnim, this.part); if (heatStates != null) { SetHeatAnimationRatio(0); } } deployAnimation = part.FindModelAnimators(animName).FirstOrDefault(); if (deployAnimation != null) { deployAnimation[animName].layer = 1; deployAnimation[animName].speed = 0; deployAnimation[animName].normalizedTime = radiatorIsEnabled ? 1 : 0; } _moduleActiveRadiator = part.FindModuleImplementing <ModuleActiveRadiator>(); if (_moduleActiveRadiator != null) { _moduleActiveRadiator.Events["Activate"].guiActive = false; _moduleActiveRadiator.Events["Shutdown"].guiActive = false; } _moduleDeployableRadiator = part.FindModuleImplementing <ModuleDeployableRadiator>(); if (_moduleDeployableRadiator != null) { radiatorState = _moduleDeployableRadiator.deployState; } var radiatorfield = Fields["radiatorIsEnabled"]; radiatorfield.guiActive = showControls; radiatorfield.guiActiveEditor = showControls; radiatorfield.OnValueModified += radiatorIsEnabled_OnValueModified; var automatedfield = Fields["isAutomated"]; automatedfield.guiActive = showControls; automatedfield.guiActiveEditor = showControls; var pivotfield = Fields["pivotEnabled"]; pivotfield.guiActive = showControls; pivotfield.guiActiveEditor = showControls; if (_moduleActiveRadiator != null) { _maxEnergyTransfer = radiatorArea * PhysicsGlobals.StefanBoltzmanConstant * Math.Pow(MaxRadiatorTemperature, 4) * 0.001; _moduleActiveRadiator.maxEnergyTransfer = _maxEnergyTransfer; _moduleActiveRadiator.overcoolFactor = 0.20 + ((int)CurrentGenerationType * 0.025); if (radiatorIsEnabled) { _moduleActiveRadiator.Activate(); } else { _moduleActiveRadiator.Shutdown(); } } if (state == StartState.Editor) { return; } if (isAutomated && !isDeployable) { ActivateRadiator(); } for (var i = 0; i < 20; i++) { radTempQueue.Enqueue(currentRadTemp); } InitializeTemperatureColorChannels(); ApplyColorHeat(); if (ResearchAndDevelopment.Instance != null) { upgradeCostStr = ResearchAndDevelopment.Instance.Science + "/" + upgradeCost.ToString("0") + " Science"; } renderArray = part.FindModelComponents <Renderer>().ToArray(); if (radiatorInit == false) { radiatorInit = true; } radiatorTempStr = maxRadiatorTemperature + "K"; maxVacuumTemperature = isGraphene ? Math.Min(maxVacuumTemperature, maxRadiatorTemperature) : Math.Min(RadiatorProperties.RadiatorTemperatureMk4, maxRadiatorTemperature); maxAtmosphereTemperature = isGraphene ? Math.Min(maxAtmosphereTemperature, maxRadiatorTemperature) : Math.Min(RadiatorProperties.RadiatorTemperatureMk3, maxRadiatorTemperature); UpdateMaxCurrentTemperature(); if (keepMaxPartTempEqualToMaxRadiatorTemp) { var partSkinTemperature = Math.Min(part.skinTemperature, maxCurrentRadiatorTemperature * 0.99); if (double.IsNaN(partSkinTemperature) == false) { part.skinTemperature = partSkinTemperature; } var partTemperature = Math.Min(part.temperature, maxCurrentRadiatorTemperature * 0.99); if (double.IsNaN(partTemperature) == false) { part.temperature = partTemperature; } if (double.IsNaN(maxCurrentRadiatorTemperature) == false) { part.skinMaxTemp = maxCurrentRadiatorTemperature; part.maxTemp = maxCurrentRadiatorTemperature; } } if (maintainResourceBuffers) { resourceBuffers = new ResourceBuffers(); resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceManager.FNRESOURCE_WASTEHEAT, wasteHeatMultiplier, 2.0e+6)); resourceBuffers.UpdateVariable(ResourceManager.FNRESOURCE_WASTEHEAT, this.part.mass); resourceBuffers.Init(this.part); } }
public PartStats(Part part) { this.mass = part.mass; if (part.partInfo.variant != null) { kRnDVariants = KRnD.getVariants(part); currentVariant = part.partInfo.variant.Name; currentVariantMass = part.partInfo.variant.Mass; variantBaseMass = part.baseVariant.Mass; } if (kRnDVariants != null) { hasVariants = true; } else { currentVariantMass = 0; variantBaseMass = 0; hasVariants = false; } this.skinMaxTemp = part.skinMaxTemp; this.intMaxTemp = part.maxTemp; // There should only be one or the other, engines or RCS: List <ModuleEngines> engineModules = KRnD.getEngineModules(part); ModuleRCS rcsModule = KRnD.getRcsModule(part); if (engineModules != null) { this.maxFuelFlows = new List <float>(); this.atmosphereCurves = new List <FloatCurve>(); for (int i = 0; i < engineModules.Count; i++) { ModuleEngines engineModule = engineModules[i]; this.maxFuelFlows.Add(engineModule.maxFuelFlow); FloatCurve atmosphereCurve = new FloatCurve(); for (int i5 = 0; i5 < engineModule.atmosphereCurve.Curve.length; i5++) { Keyframe frame = engineModule.atmosphereCurve.Curve[i5]; atmosphereCurve.Add(frame.time, frame.value); } this.atmosphereCurves.Add(atmosphereCurve); } } else if (rcsModule) { this.maxFuelFlows = new List <float>(); this.atmosphereCurves = new List <FloatCurve>(); this.maxFuelFlows.Add(rcsModule.thrusterPower); FloatCurve atmosphereCurve = new FloatCurve(); for (int i = 0; i < rcsModule.atmosphereCurve.Curve.length; i++) { Keyframe frame = rcsModule.atmosphereCurve.Curve[i]; atmosphereCurve.Add(frame.time, frame.value); } this.atmosphereCurves.Add(atmosphereCurve); } ModuleReactionWheel reactionWheel = KRnD.getReactionWheelModule(part); if (reactionWheel) { this.torque = reactionWheel.RollTorque; // There is also pitch- and yaw-torque, but they should all be the same } // WIP //ModuleDataTransmitter dataTransmitter = KRnD.getDataTransmitterModule(part); //if (dataTransmitter) //{ // this.antPower = dataTransmitter.antennaPower; //} ModuleResourceHarvester resourceHarvester = KRnD.getResourceHarvesterModule(part); if (resourceHarvester) { this.harvester = resourceHarvester.Efficiency; } ModuleActiveRadiator activeRadiator = KRnD.getActiveRadiatorModule(part); if (activeRadiator) { this.radiatorEfficiency = activeRadiator.maxEnergyTransfer; } ModuleDeployableSolarPanel solarPanel = KRnD.getSolarPanelModule(part); if (solarPanel) { this.chargeRate = solarPanel.chargeRate; } ModuleWheelBase landingLeg = KRnD.getLandingLegModule(part); if (landingLeg) { this.crashTolerance = part.crashTolerance; // Every part has a crash tolerance, but we only want to improve landing legs. } PartResource electricCharge = KRnD.getChargeResource(part); if (electricCharge != null) { this.batteryCharge = electricCharge.maxAmount; } ModuleGenerator generator = KRnD.getGeneratorModule(part); if (generator != null) { generatorEfficiency = new Dictionary <String, double>(); for (int i = 0; i < generator.resHandler.outputResources.Count; i++) { ModuleResource outputResource = generator.resHandler.outputResources[i]; generatorEfficiency.Add(outputResource.name, outputResource.rate); } } PartModule fissionGenerator = KRnD.getFissionGeneratorModule(part); if (fissionGenerator != null) { fissionPowerGeneration = KRnD.getGenericModuleValue(fissionGenerator, "PowerGeneration"); } // There might be different converter-modules in the same part with different names (eg for Fuel, Monopropellant, etc): List <ModuleResourceConverter> converterList = KRnD.getConverterModules(part); if (converterList != null) { converterEfficiency = new Dictionary <String, Dictionary <String, double> >(); for (int i = 0; i < converterList.Count; i++) { ModuleResourceConverter converter = converterList[i]; Dictionary <String, double> thisConverterEfficiency = new Dictionary <String, double>(); for (int i2 = 0; i2 < converter.outputList.Count; i2++) { ResourceRatio resourceRatio = converter.outputList[i2]; thisConverterEfficiency.Add(resourceRatio.ResourceName, resourceRatio.Ratio); } converterEfficiency.Add(converter.ConverterName, thisConverterEfficiency); } } ModuleParachute parachute = KRnD.getParachuteModule(part); if (parachute) { this.chuteMaxTemp = parachute.chuteMaxTemp; } ModuleProceduralFairing fairing = KRnD.getFairingModule(part); if (fairing) { this.fairingAreaMass = fairing.UnitAreaMass; } List <PartResource> fuelResources = KRnD.getFuelResources(part); if (fuelResources != null) { fuelCapacities = new Dictionary <string, double>(); fuelCapacitiesSum = 0; for (int i = 0; i < fuelResources.Count; i++) { PartResource fuelResource = fuelResources[i]; fuelCapacities.Add(fuelResource.resourceName, fuelResource.maxAmount); fuelCapacitiesSum += fuelResource.maxAmount; } } }