// Returns the info-text of the given part with the given upgrades to be displayed in the GUI-comparison. private String getPartInfo(Part part, KRnDUpgrade upgradesToApply = null) { String info = ""; KRnDUpgrade originalUpgrades = null; try { KRnDModule rndModule = KRnD.getKRnDModule(part); if (rndModule == null || (originalUpgrades = rndModule.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, upgradesToApply); List <ModuleEngines> engineModules = KRnD.getEngineModules(part); ModuleRCS rcsModule = KRnD.getRcsModule(part); ModuleReactionWheel reactionWheelModule = KRnD.getReactionWheelModule(part); ModuleDeployableSolarPanel solarPanelModule = KRnD.getSolarPanelModule(part); ModuleWheelBase landingLegModule = KRnD.getLandingLegModule(part); PartResource electricChargeResource = KRnD.getChargeResource(part); ModuleGenerator generatorModule = KRnD.getGeneratorModule(part); PartModule fissionGenerator = KRnD.getFissionGeneratorModule(part); List <ModuleResourceConverter> converterModules = KRnD.getConverterModules(part); ModuleParachute parachuteModule = KRnD.getParachuteModule(part); ModuleProceduralFairing fairingModule = KRnD.getFairingModule(part); List <PartResource> fuelResources = KRnD.getFuelResources(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 (landingLegModule != null) { info += "<b>Crash Tolerance:</b> " + part.crashTolerance.ToString("0.#### m/s") + "\n"; } if (electricChargeResource != null) { info += "<b>Electric Charge:</b> " + electricChargeResource.maxAmount.ToString() + "\n"; } // Fuels: if (fuelResources != null) { foreach (PartResource fuelResource in fuelResources) { // Reformat resource-names like "ElectricCharge" to "Electric Charge": String fuelName = fuelResource.resourceName.ToString(); fuelName = Regex.Replace(fuelName, @"([a-z])([A-Z])", "$1 $2"); info += "<b>" + fuelName + ":</b> " + fuelResource.maxAmount.ToString() + "\n"; } } // Module stats: info += "\n"; if (engineModules != null) { foreach (ModuleEngines engineModule in engineModules) { info += "<color=#99FF00><b>Engine"; if (engineModules.Count > 1) { info += " (" + engineModule.engineID.ToString() + ")"; } info += ":</b></color>\n" + engineModule.GetInfo(); if (engineModules.Count > 1) { info += "\n"; } } } if (rcsModule) { info += "<color=#99FF00><b>RCS:</b></color>\n" + rcsModule.GetInfo(); } if (reactionWheelModule) { info += "<color=#99FF00><b>Reaction Wheel:</b></color>\n" + reactionWheelModule.GetInfo(); } if (solarPanelModule) { info += "<color=#99FF00><b>Solar Panel:</b></color>\n" + KRnD.getSolarPanelInfo(solarPanelModule); } if (generatorModule) { info += "<color=#99FF00><b>Generator:</b></color>\n" + generatorModule.GetInfo(); } if (fissionGenerator) { info += "<color=#99FF00><b>Fission-Generator:</b></color>\n" + fissionGenerator.GetInfo(); } if (converterModules != null) { foreach (ModuleResourceConverter converterModule in converterModules) { info += "<color=#99FF00><b>Converter " + converterModule.ConverterName + ":</b></color>\n" + converterModule.GetInfo() + "\n"; } } if (parachuteModule) { info += "<color=#99FF00><b>Parachute:</b></color>\n" + parachuteModule.GetInfo(); } if (fairingModule) { info += "<color=#99FF00><b>Fairing:</b></color>\n" + fairingModule.GetInfo(); } info += "</color>"; } catch (Exception e) { Debug.LogError("[KRnDGUI] getPartInfo(): " + e.ToString()); } finally { try { if (originalUpgrades != null) { KRnD.updatePart(part, originalUpgrades); } } catch (Exception e) { Debug.LogError("[KRnDGUI] getPartInfo() restore of part failed: " + e.ToString()); } } return(info); }
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; } } }