public static int UpdateFuelFlow(UpgradeConstants u_constants, Part part, PartStats original_stats, PartUpgrades upgrades_to_apply) { var upgrade_factor = u_constants.CalculateImprovementFactor(upgrades_to_apply.fuelFlow); var engine_modules = PartStats.GetModuleEnginesList(part); var rcs_module = PartStats.GetModuleRCS(part); if (engine_modules == null && !rcs_module) { return(0); } for (var i = 0; i < original_stats.maxFuelFlows.Count; i++) { var max_fuel_flow = original_stats.maxFuelFlows[i] * upgrade_factor; if (engine_modules != null) { engine_modules[i].maxFuelFlow = max_fuel_flow; } else if (rcs_module) { rcs_module.thrusterPower = max_fuel_flow; // There is only one rcs-module } } return(0); }
public static int UpdateFuelCapacity(UpgradeConstants u_constants, Part part, PartStats original_stats, PartUpgrades upgrades_to_apply) { // Fuel Capacity: var fuel_resources = PartStats.GetFuelResources(part); if (fuel_resources == null || original_stats.fuelCapacities == null) { return(0); } double improvement_factor = u_constants.CalculateImprovementFactor(upgrades_to_apply.fuelCapacity); foreach (var fuel_resource in fuel_resources) { if (!original_stats.fuelCapacities.ContainsKey(fuel_resource.resourceName)) { continue; } var original_capacity = original_stats.fuelCapacities[fuel_resource.resourceName]; var new_capacity = Math.Round(original_capacity * improvement_factor); var percentage_full = fuel_resource.amount / fuel_resource.maxAmount; fuel_resource.maxAmount = new_capacity; fuel_resource.amount = new_capacity * percentage_full; } return(0); }
public static int UpdateElConverter(UpgradeConstants u_constants, Part part, PartStats original_stats, PartUpgrades upgrades_to_apply) { var converter_list = PartStats.GetModuleElConverterList(part); if (converter_list == null) { return(0); } foreach (var converter in converter_list) { converter.Rate = u_constants.CalculateImprovementValue(original_stats.ELConverter, upgrades_to_apply.elConverter); } #if false var el_converter = PartStats.GetModuleElConverter(part); if (el_converter) { el_converter.Rate = u_constants.CalculateImprovementValue(original_stats.ELConverter, upgrades_to_apply.elConverter); } #endif return(0); }
// Updates the given part either to the latest model (updateToLatestModel=TRUE) or to the model defined by its // KRnDModule. public static void UpdatePart(Part part, bool update_to_latest_model) { PartUpgrades upgrades_to_apply; if (update_to_latest_model) { if (upgrades.TryGetValue(SanitizePartName(part.name), out upgrades_to_apply)) { // Apply upgrades from global list: UpdatePart(part, upgrades_to_apply); } else { // No Upgrades found, apply base-stats: upgrades_to_apply = new PartUpgrades(); UpdatePart(part, upgrades_to_apply); } } else { // Extract current upgrades of the part and set those stats: var rnd_module = PartStats.GetKRnDModule(part); if (rnd_module != null && (upgrades_to_apply = rnd_module.GetCurrentUpgrades()) != null) { // Apply upgrades from the RnD-Module: UpdatePart(part, upgrades_to_apply); } else { // No Upgrades found, apply base-stats: upgrades_to_apply = new PartUpgrades(); UpdatePart(part, upgrades_to_apply); } } }
public static int UpdateGeneratorEfficiency(UpgradeConstants u_constants, Part part, PartStats original_stats, PartUpgrades upgrades_to_apply) { var generator = PartStats.GetModuleGenerator(part); if (generator) { foreach (var output_resource in generator.resHandler.outputResources) { if (!original_stats.generatorEfficiency.TryGetValue(output_resource.name, out var original_rate)) { continue; } output_resource.rate = u_constants.CalculateImprovementValue(original_rate, upgrades_to_apply.generatorEfficiency); } } var fission_generator = PartStats.GetFissionGenerator(part); if (fission_generator) { var power_generation = u_constants.CalculateImprovementValue(original_stats.fissionPowerGeneration, upgrades_to_apply.generatorEfficiency); PartStats.SetGenericModuleValue(fission_generator, "PowerGeneration", power_generation); } return(0); }
public static int UpdateConverterEfficiency(UpgradeConstants u_constants, Part part, PartStats original_stats, PartUpgrades upgrades_to_apply) { // Converter Efficiency: var converter_list = PartStats.GetModuleResourceConverterList(part); if (converter_list == null) { return(0); } foreach (var converter in converter_list) { if (!original_stats.converterEfficiency.TryGetValue(converter.ConverterName, out var original_output_resources)) { continue; } // Since KSP 1.2 this can't be done in a foreach anymore, we have to read and write back the entire ResourceRatio-Object: for (var i = 0; i < converter.outputList.Count; i++) { var resource_ratio = converter.outputList[i]; if (!original_output_resources.TryGetValue(resource_ratio.ResourceName, out var original_ratio)) { continue; } resource_ratio.Ratio = u_constants.CalculateImprovementValue(original_ratio, upgrades_to_apply.converterEfficiency); converter.outputList[i] = resource_ratio; } } return(0); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Fetches all fuel resources by going through every part and collecting all resources that are /// listed as a propellant. If the propellent is listed in the NON_FUELS list, then don't /// consider it a real fuel so don't add it.</summary> /// /// <returns> All fuel resources that are not specifically indicated as a non-fuel propellant.</returns> private static List <string> FetchAllFuelResources() { // Create a list of all valid fuel resources: Always use MonoPropellant as fuel (RCS-Thrusters don't have engine modules and are not found with the code below) var fuel_resources = new List <string> { "MonoPropellant" }; foreach (var a_part in PartLoader.LoadedPartsList) { var part = a_part.partPrefab; var engine_modules = PartStats.GetModuleEnginesList(part); if (engine_modules == null) { continue; } foreach (var engine_module in engine_modules) { if (engine_module.propellants == null) { continue; } foreach (var propellant in engine_module.propellants) { // Don't consider a propellant to actually be a fuel if it is specifically part of the non-fuel list. if (StringConstants.NON_FUELS.Contains(propellant.name)) { continue; } //if (propellant.name == "ElectricCharge") continue; // Electric Charge is improved by batteries. //if (propellant.name == "IntakeAir") continue; // This is no real fuel-type. //if (propellant.name == "IntakeAtm") continue; // This is no real fuel-type. if (!fuel_resources.Contains(propellant.name)) { fuel_resources.Add(propellant.name); } } } } #if false var list_string = ""; foreach (var fuel_name in fuel_resources) { if (list_string != "") { list_string += ", "; } list_string += fuel_name; } Debug.Log("[KRnD] found " + KRnD.fuel_resources.Count.ToString() + " propellants: " + listString); #endif return(fuel_resources); }
public static int UpdateChargeRate(UpgradeConstants u_constants, Part part, PartStats original_stats, PartUpgrades upgrades_to_apply) { var solar_panel = PartStats.GetModuleDeployableSolarPanel(part); if (solar_panel) { solar_panel.efficiencyMult = u_constants.CalculateImprovementValue(original_stats.efficiencyMult, upgrades_to_apply.efficiencyMult); } return(0); }
public static int UpdateActiveRadiator(UpgradeConstants u_constants, Part part, PartStats original_stats, PartUpgrades upgrades_to_apply) { var radiator = PartStats.GetModuleActiveRadiator(part); if (radiator) { radiator.maxEnergyTransfer = u_constants.CalculateImprovementValue(original_stats.maxEnergyTransfer, upgrades_to_apply.maxEnergyTransfer); } return(0); }
public static int UpdatePacketSize(UpgradeConstants u_constants, Part part, PartStats original_stats, PartUpgrades upgrades_to_apply) { var antenna = PartStats.GetModuleDataTransmitter(part); if (antenna) { antenna.packetSize = u_constants.CalculateImprovementValue(original_stats.packetSize, upgrades_to_apply.packetSize); } return(0); }
public static int UpdateCrashTolerance(UpgradeConstants u_constants, Part part, PartStats original_stats, PartUpgrades upgrades_to_apply) { var landing_leg = PartStats.GetModuleWheelBase(part); if (landing_leg) { part.crashTolerance = u_constants.CalculateImprovementValue(original_stats.crashTolerance, upgrades_to_apply.crashTolerance); } return(0); }
public static int UpdateParachuteStrength(UpgradeConstants u_constants, Part part, PartStats original_stats, PartUpgrades upgrades_to_apply) { // Parachute Strength: var parachute = PartStats.GetModuleParachute(part); if (parachute) { // The safe deployment-speed is derived from the temperature parachute.chuteMaxTemp = original_stats.chuteMaxTemp * u_constants.CalculateImprovementFactor(upgrades_to_apply.parachuteStrength); } return(0); }
public static int UpdateResourceHarvester(UpgradeConstants u_constants, Part part, PartStats original_stats, PartUpgrades upgrades_to_apply) { // Resource Harvester var harvester = PartStats.GetModuleResourceHarvester(part); if (harvester) { harvester.Efficiency = u_constants.CalculateImprovementValue(original_stats.resourceHarvester, upgrades_to_apply.resourceHarvester); } // TODO: Update surface harvester module too? return(0); }
public static int UpdateDryMass(UpgradeConstants u_constants, Part part, PartStats original_stats, PartUpgrades upgrades_to_apply) { part.prefabMass = part.mass = u_constants.CalculateImprovementValue(original_stats.dryMass, upgrades_to_apply.dryMass); // Dry Mass also improves fairing mass: var fairing_module = PartStats.GetModuleProceduralFairing(part); if (fairing_module) { fairing_module.UnitAreaMass = u_constants.CalculateImprovementValue(original_stats.fairingAreaMass, upgrades_to_apply.dryMass); } return(0); }
public static int UpdateBatteryCharge(UpgradeConstants u_constants, Part part, PartStats original_stats, PartUpgrades upgrades_to_apply) { var electric_charge = PartStats.GetElectricCharge(part); if (electric_charge == null) { return(0); } var max_charge = Math.Round(u_constants.CalculateImprovementValue(original_stats.batteryCharge, upgrades_to_apply.batteryCharge)); var percentage_full = electric_charge.amount / electric_charge.maxAmount; electric_charge.maxAmount = max_charge; electric_charge.amount = max_charge * percentage_full; return(0); }
public static int UpdateTorque(UpgradeConstants u_constants, Part part, PartStats original_stats, PartUpgrades upgrades_to_apply) { var reaction_wheel = PartStats.GetModuleReactionWheel(part); if (!reaction_wheel) { return(0); } var torque = u_constants.CalculateImprovementValue(original_stats.torqueStrength, upgrades_to_apply.torqueStrength); reaction_wheel.PitchTorque = torque; reaction_wheel.YawTorque = torque; reaction_wheel.RollTorque = torque; return(0); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Updates all parts of the given vessel according to their RnD-Module settings (should be executed /// when the vessel is loaded to make sure, that the vessel uses its own, historic upgrades and /// not the global part-upgrades).</summary> /// /// <exception cref="Exception"> Thrown when an exception error condition occurs.</exception> /// /// <param name="vessel"> The vessel.</param> public static void UpdateVessel(Vessel vessel) { try { if (!vessel.isActiveVessel) { return; // Only the currently active vessel matters, the others are not simulated anyway. } if (upgrades == null) { throw new Exception("upgrades-dictionary missing"); } //Debug.Log("[KRnD] updating vessel '" + vessel.vesselName.ToString() + "'"); // Iterate through all parts: foreach (var part in vessel.parts) { // We only have to update parts which have the RnD-Module: var rnd_module = PartStats.GetKRnDModule(part); if (rnd_module == null) { continue; } if (vessel.situation == Vessel.Situations.PRELAUNCH) { // Update the part with the latest model while on the launchpad: UpdatePart(part, true); } else if (rnd_module.upgradeToLatest > 0) { // Flagged by another mod (eg KSTS) to get updated to the latest model (once): //Debug.Log("[KRnD] part '"+ KRnD.sanatizePartName(part.name) + "' of '"+ vessel.vesselName + "' was flagged to be updated to the latest model"); rnd_module.upgradeToLatest = 0; UpdatePart(part, true); } else { // Update this part with its own stats: UpdatePart(part, false); } } } catch (Exception e) { Debug.LogError("[KRnD] updateVesselActive(): " + e); } }
public static int UpdateDataStorage(UpgradeConstants u_constants, Part part, PartStats original_stats, PartUpgrades upgrades_to_apply) { var science_lab = PartStats.GetModuleScienceLab(part); if (science_lab) { science_lab.dataStorage = u_constants.CalculateImprovementValue(original_stats.dataStorage, upgrades_to_apply.dataStorage); } var science_converter = PartStats.GetModuleScienceConverter(part); if (science_converter) { science_converter.scienceCap = u_constants.CalculateImprovementValue(original_stats.scienceCap, upgrades_to_apply.dataStorage); } return(0); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Create a backup of all unmodified parts before we update them. We will later use these backup- /// parts for all calculations of upgraded stats.</summary> /// /// <returns> all part statistics.</returns> private static Dictionary <string, PartStats> FetchAllPartStats() { var original_stats = new Dictionary <string, PartStats>(); foreach (var a_part in PartLoader.LoadedPartsList) { var part = a_part.partPrefab; // Backup this part, if it has the RnD-Module: if (PartStats.GetKRnDModule(part) == null) { continue; } if (!original_stats.ContainsKey(part.name)) { original_stats.Add(part.name, new PartStats(part)); } } return(original_stats); }
// Returns the info-text of the given part with the given upgrades to be displayed in the GUI-comparison. private string BuildPartInfoString(Part part, PartUpgrades upgrades_to_apply = null) { var info = ""; PartUpgrades original_upgrades = null; try { var rnd_module = PartStats.GetKRnDModule(part); if (rnd_module == null || (original_upgrades = rnd_module.GetCurrentUpgrades()) == null) { return(info); } // Upgrade the part to get the correct info, we revert it back to its previous values in the finally block below: KRnD.UpdatePart(part, upgrades_to_apply); var engine_modules = PartStats.GetModuleEnginesList(part); var rcs_module = PartStats.GetModuleRCS(part); var reaction_wheel_module = PartStats.GetModuleReactionWheel(part); var solar_panel_module = PartStats.GetModuleDeployableSolarPanel(part); var landing_leg_module = PartStats.GetModuleWheelBase(part); var electric_charge_resource = PartStats.GetElectricCharge(part); var generator_module = PartStats.GetModuleGenerator(part); var fission_generator = PartStats.GetFissionGenerator(part); var converter_modules = PartStats.GetModuleResourceConverterList(part); var parachute_module = PartStats.GetModuleParachute(part); var fairing_module = PartStats.GetModuleProceduralFairing(part); var fuel_resources = PartStats.GetFuelResources(part); var antenna_module = PartStats.GetModuleDataTransmitter(part); var science_module = PartStats.GetModuleScienceLab(part); var harvester_module = PartStats.GetModuleResourceHarvester(part); var radiator_module = PartStats.GetModuleActiveRadiator(part); var el_converter = PartStats.GetModuleElConverter(part); // Basic stats: info = "<color=#FFFFFF><b>Dry Mass:</b> " + part.mass.ToString("0.#### t") + "\n"; info += "<b>Max Temp.:</b> " + part.maxTemp.ToString("0.#") + "/" + part.skinMaxTemp.ToString("0.#") + " °K\n"; if (landing_leg_module != null) { info += "<b>Crash Tolerance:</b> " + part.crashTolerance.ToString("0.#### m/s") + "\n"; } if (electric_charge_resource != null) { info += "<b>Electric Charge:</b> " + electric_charge_resource.maxAmount + "\n"; } // Fuels: if (fuel_resources != null) { foreach (var fuel_resource in fuel_resources) { // Reformat resource-names like "ElectricCharge" to "Electric Charge": var fuel_name = fuel_resource.resourceName; fuel_name = Regex.Replace(fuel_name, @"([a-z])([A-Z])", "$1 $2"); info += "<b>" + fuel_name + ":</b> " + fuel_resource.maxAmount + "\n"; } } // Module stats: info += "\n"; if (engine_modules != null) { foreach (var engine_module in engine_modules) { info += "<color=#99FF00><b>Engine"; if (engine_modules.Count > 1) { info += " (" + engine_module.engineID + ")"; } info += ":</b></color>\n" + engine_module.GetInfo(); if (engine_modules.Count > 1) { info += "\n"; } } } if (rcs_module) { info += "<color=#99FF00><b>RCS:</b></color>\n" + rcs_module.GetInfo(); } if (reaction_wheel_module) { info += "<color=#99FF00><b>Reaction Wheel:</b></color>\n" + reaction_wheel_module.GetInfo(); } if (solar_panel_module) { info += "<color=#99FF00><b>Solar Panel:</b></color>\n" + KRnD.GetSolarPanelInfo(solar_panel_module); } if (generator_module) { info += "<color=#99FF00><b>Generator:</b></color>\n" + generator_module.GetInfo(); } if (fission_generator) { info += "<color=#99FF00><b>Fission-Generator:</b></color>\n" + fission_generator.GetInfo(); } if (converter_modules != null) { foreach (var converter_module in converter_modules) { info += "<color=#99FF00><b>Converter " + converter_module.ConverterName + ":</b></color>\n" + converter_module.GetInfo() + "\n"; } } if (parachute_module) { info += "<color=#99FF00><b>Parachute:</b></color>\n" + parachute_module.GetInfo(); } if (fairing_module) { info += "<color=#99FF00><b>Fairing:</b></color>\n" + fairing_module.GetInfo(); } if (antenna_module) { info += "<color=#99FF00><b>Antenna:</b></color>\n" + antenna_module.GetInfo(); } if (science_module) { info += "<color=#99FF00><b>Science Lab:</b></color>\n" + science_module.GetInfo(); } if (harvester_module) { info += "<color=#99FF00><b>Harvester:</b></color>\n" + harvester_module.GetInfo(); } if (radiator_module) { info += "<color=#99FF00><b>Radiator:</b></color>\n" + radiator_module.GetInfo(); } if (el_converter) { info += "<color=#99FF00><b>EL Converter:</b></color>\n" + el_converter.GetInfo(); } info += "</color>"; } catch (Exception e) { Debug.LogError("[KRnDGUI] getPartInfo(): " + e); } finally { try { if (original_upgrades != null) { KRnD.UpdatePart(part, original_upgrades); } } catch (Exception e) { Debug.LogError("[KRnDGUI] getPartInfo() restore of part failed: " + e); } } return(info); }
// Updates the global dictionary of available parts with the current set of upgrades (should be // executed for example when a new game starts or an existing game is loaded). public static int UpdateGlobalParts() { var upgrades_applied = 0; try { if (upgrades == null) { throw new Exception("upgrades-dictionary missing"); } foreach (var part in PartLoader.LoadedPartsList) { try { PartUpgrades upgrade; if (!upgrades.TryGetValue(part.name, out upgrade)) { upgrade = new PartUpgrades(); // If there are no upgrades, reset the part. } // Update the part to its latest model: UpdatePart(part.partPrefab, true); // Rebuild the info-screen: var converter_module_number = 0; // There might be multiple modules of this type var engine_module_number = 0; // There might be multiple modules of this type foreach (var info in part.moduleInfos) { if (info.moduleName.ToLower() == "engine") { var engines = PartStats.GetModuleEnginesList(part.partPrefab); if (engines != null && engines.Count > 0) { var engine = engines[engine_module_number]; info.info = engine.GetInfo(); info.primaryInfo = engine.GetPrimaryField(); engine_module_number++; } } else if (info.moduleName.ToLower() == "rcs") { var rcs = PartStats.GetModuleRCS(part.partPrefab); if (rcs) { info.info = rcs.GetInfo(); } } else if (info.moduleName.ToLower() == "reaction wheel") { var reaction_wheel = PartStats.GetModuleReactionWheel(part.partPrefab); if (reaction_wheel) { info.info = reaction_wheel.GetInfo(); } } else if (info.moduleName.ToLower() == "deployable solar panel") { var solar_panel = PartStats.GetModuleDeployableSolarPanel(part.partPrefab); if (solar_panel) { info.info = GetSolarPanelInfo(solar_panel); } } else if (info.moduleName.ToLower() == "landing leg") { var landing_leg = PartStats.GetModuleWheelBase(part.partPrefab); if (landing_leg) { info.info = landing_leg.GetInfo(); } } else if (info.moduleName.ToLower() == "fission generator") { var fission_generator = PartStats.GetFissionGenerator(part.partPrefab); if (fission_generator) { info.info = fission_generator.GetInfo(); } } else if (info.moduleName.ToLower() == "generator") { var generator = PartStats.GetModuleGenerator(part.partPrefab); if (generator) { info.info = generator.GetInfo(); } } else if (info.moduleName.ToLower() == "data transmitter") { var antenna = PartStats.GetModuleDataTransmitter(part.partPrefab); if (antenna) { info.info = antenna.GetInfo(); } } else if (info.moduleName.ToLower() == "science lab") { var lab = PartStats.GetModuleScienceLab(part.partPrefab); if (lab) { info.info = lab.GetInfo(); } } else if (info.moduleName.ToLower() == "active radiator") { var lab = PartStats.GetModuleActiveRadiator(part.partPrefab); if (lab) { info.info = lab.GetInfo(); } } else if (info.moduleName.ToLower() == "resource converter") { var converter_list = PartStats.GetModuleResourceConverterList(part.partPrefab); if (converter_list == null || converter_list.Count <= 0) { continue; } var converter = converter_list[converter_module_number]; info.info = converter.GetInfo(); converter_module_number++; } else if (info.moduleName.ToLower() == "parachute") { var parachute = PartStats.GetModuleParachute(part.partPrefab); if (parachute) { info.info = parachute.GetInfo(); } } else if (info.moduleName.ToLower() == "resource harvester") { var harvester = PartStats.GetModuleResourceHarvester(part.partPrefab); if (harvester) { info.info = harvester.GetInfo(); } } else if (info.moduleName.ToLower() == "custom-built fairing") { var fairing = PartStats.GetModuleProceduralFairing(part.partPrefab); if (fairing) { info.info = fairing.GetInfo(); } } } var fuel_resources = PartStats.GetFuelResources(part.partPrefab); var electric_charge = PartStats.GetElectricCharge(part.partPrefab); // The Resource-Names are not always formatted the same way, eg "Electric Charge" vs "ElectricCharge", so we do some reformatting. foreach (var info in part.resourceInfos) { if (electric_charge != null && info.resourceName.Replace(" ", "").ToLower() == electric_charge.resourceName.Replace(" ", "").ToLower()) { info.info = electric_charge.GetInfo(); info.primaryInfo = "<b>" + info.resourceName + ":</b> " + electric_charge.maxAmount; } else if (fuel_resources != null) { foreach (var fuel_resource in fuel_resources) { if (info.resourceName.Replace(" ", "").ToLower() == fuel_resource.resourceName.Replace(" ", "").ToLower()) { info.info = fuel_resource.GetInfo(); info.primaryInfo = "<b>" + info.resourceName + ":</b> " + fuel_resource.maxAmount; break; } } } } upgrades_applied++; } catch (Exception e) { Debug.LogError("[KRnD] updateGlobalParts(" + part.title + "): " + e); } } } catch (Exception e) { Debug.LogError("[KRnD] updateGlobalParts(): " + e); } return(upgrades_applied); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Updates the given part with all upgrades provided in "upgradesToApply".</summary> /// /// <exception cref="Exception"> Thrown when an exception error condition occurs.</exception> /// /// <param name="part"> The part.</param> /// <param name="upgrades_to_apply"> The upgrades to apply.</param> public static void UpdatePart(Part part, PartUpgrades upgrades_to_apply) { try { // Find all relevant modules of this part: var rnd_module = PartStats.GetKRnDModule(part); if (rnd_module == null) { return; } if (upgrades == null) { throw new Exception("upgrades-dictionary missing"); } if (originalStats == null) { throw new Exception("original-stats-dictionary missing"); } // Get the part-name ("): var part_name = SanitizePartName(part.name); // Get the original part-stats: if (!originalStats.TryGetValue(part_name, out var original_stats)) { throw new Exception("no original-stats for part '" + part_name + "'"); } /* * Updates the part to match the upgrade levels specified in the upgrades_to_apply parameter. This provides the hard * link between the ValueConstants class, the upgrade level field in PartUpgrades class, and the algorithm to actually * update the part -- sometimes the algorithm is simple, but could be more complex such as with ISP efficiency * curves. */ foreach (var u in ValueConstants.upgradeDatabase) { if (u.Value.applyUpgradeFunction != null) { u.Value.applyUpgradeFunction(u.Value, part, original_stats, upgrades_to_apply); } else { if (u.Key == StringConstants.ISP_VAC) { UpdateISPVacAtm(ValueConstants.GetData(StringConstants.ISP_VAC), ValueConstants.GetData(StringConstants.ISP_ATM), part, original_stats, upgrades_to_apply); } } } #if false UpdateDryMass(ValueConstants.GetData(StringConstants.DRY_MASS), part, original_stats, upgrades_to_apply); UpdateMaxTemperature(ValueConstants.GetData(StringConstants.MAX_TEMPERATURE), part, original_stats, upgrades_to_apply); UpdateFuelFlow(ValueConstants.GetData(StringConstants.FUEL_FLOW), part, original_stats, upgrades_to_apply); UpdateISPVacAtm(ValueConstants.GetData(StringConstants.ISP_VAC), ValueConstants.GetData(StringConstants.ISP_ATM), part, original_stats, upgrades_to_apply); UpdateTorque(ValueConstants.GetData(StringConstants.TORQUE), part, original_stats, upgrades_to_apply); UpdateChargeRate(ValueConstants.GetData(StringConstants.CHARGE_RATE), part, original_stats, upgrades_to_apply); UpdateCrashTolerance(ValueConstants.GetData(StringConstants.CRASH_TOLERANCE), part, original_stats, upgrades_to_apply); UpdateBatteryCharge(ValueConstants.GetData(StringConstants.BATTERY_CHARGE), part, original_stats, upgrades_to_apply); UpdateGeneratorEfficiency(ValueConstants.GetData(StringConstants.GENERATOR_EFFICIENCY), part, original_stats, upgrades_to_apply); UpdateConverterEfficiency(ValueConstants.GetData(StringConstants.CONVERTER_EFFICIENCY), part, original_stats, upgrades_to_apply); UpdateAntennaPower(ValueConstants.GetData(StringConstants.ANTENNA_POWER), part, original_stats, upgrades_to_apply); UpdatePacketSize(ValueConstants.GetData(StringConstants.PACKET_SIZE), part, original_stats, upgrades_to_apply); UpdateDataStorage(ValueConstants.GetData(StringConstants.DATA_STORAGE), part, original_stats, upgrades_to_apply); UpdateParachuteStrength(ValueConstants.GetData(StringConstants.PARACHUTE_STRENGTH), part, original_stats, upgrades_to_apply); UpdateResourceHarvester(ValueConstants.GetData(StringConstants.RESOURCE_HARVESTER), part, original_stats, upgrades_to_apply); UpdateFuelCapacity(ValueConstants.GetData(StringConstants.FUEL_CAPACITY), part, original_stats, upgrades_to_apply); UpdateActiveRadiator(ValueConstants.GetData(StringConstants.ENERGY_TRANSFER), part, original_stats, upgrades_to_apply); UpdateElConverter(ValueConstants.GetData(StringConstants.EL_CONVERTER), part, original_stats, upgrades_to_apply); #endif /* * Update the RnD module to reflect the upgrades specified. */ rnd_module.ApplyUpgrades(upgrades_to_apply); } catch (Exception e) { Debug.LogError("[KRnD] updatePart(" + part.name + "): " + e); } }
public static int UpdateISPVacAtm(UpgradeConstants data_vac, UpgradeConstants data_atm, Part part, PartStats original_stats, PartUpgrades isp) { List <ModuleEngines> engine_modules = PartStats.GetModuleEnginesList(part); ModuleRCS rcs_module = PartStats.GetModuleRCS(part); if (engine_modules == null && !rcs_module) { return(0); } var improvement_factor_vac = data_vac.CalculateImprovementFactor(isp.ispVac); var improvement_factor_atm = data_atm.CalculateImprovementFactor(isp.ispAtm); for (var i = 0; i < original_stats.atmosphereCurves.Count; i++) { var is_air_breather = false; if (engine_modules != null) { is_air_breather = engine_modules[i].engineType == EngineType.Turbine || engine_modules[i].engineType == EngineType.Piston || engine_modules[i].engineType == EngineType.ScramJet; } var fc = new FloatCurve(); for (var v = 0; v < original_stats.atmosphereCurves[i].Curve.length; v++) { var frame = original_stats.atmosphereCurves[i].Curve[v]; var pressure = frame.time; //var value = frame.value; float factor_at_this_pressure = 1; if (is_air_breather && original_stats.atmosphereCurves[i].Curve.length == 1) { factor_at_this_pressure = improvement_factor_atm; // Air-breathing engines have a pressure curve starting at 0, but they should use Atm. as improvement factor. } else if (Math.Abs(pressure) < Single.Epsilon) { factor_at_this_pressure = improvement_factor_vac; // In complete vacuum } else if (pressure >= 1) { factor_at_this_pressure = improvement_factor_atm; // At lowest kerbal atmosphere } else { factor_at_this_pressure = (1 - pressure) * improvement_factor_vac + pressure * improvement_factor_atm; // Mix both } var new_value = frame.value * factor_at_this_pressure; fc.Add(pressure, new_value); } if (engine_modules != null) { engine_modules[i].atmosphereCurve = fc; } else if (rcs_module) { rcs_module.atmosphereCurve = fc; // There is only one rcs-module } } return(0); }
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 static int UpdateMaxTemperature(UpgradeConstants u_constants, Part part, PartStats original_stats, PartUpgrades upgrades_to_apply) { part.skinMaxTemp = u_constants.CalculateImprovementValue(original_stats.skinMaxTemp, upgrades_to_apply.maxTemperature); part.maxTemp = u_constants.CalculateImprovementValue(original_stats.intMaxTemp, upgrades_to_apply.maxTemperature); return(0); }