private void SetNewRatios(PropellantResources propellantResources, float startingEMR, float finalEMR, float emrSplitPercentage) { Dictionary <int, float> startRatios = GetRatiosForEMR(propellantResources, startingEMR); Dictionary <int, float> endRatios = GetRatiosForEMR(propellantResources, finalEMR); foreach (var prop in engineModule.propellants) { if (endRatios.ContainsKey(prop.id) && startRatios.ContainsKey(prop.id)) { var ratioDiff = endRatios[prop.id] - startRatios[prop.id]; //EMRUtils.Log("Ratio Diff for ", prop.name, ": ", ratioDiff); prop.ratio = startRatios[prop.id] + ((emrSplitPercentage / 100) * ratioDiff); } else { prop.ratio = propellantResources.GetById(prop.id).Ratio; } //EMRUtils.Log("New ratio for ", prop.name, ": ", prop.ratio); if (propellantResources.Oxidizer.Id == prop.id && fuelReservePercentage > 0) { //EMRUtils.Log("Adjusting oxidizer capacity to account for boiloff"); prop.ratio = prop.ratio * ((100 - fuelReservePercentage) / 100); } if (propellantResources.Oxidizer.Id != prop.id && fuelReservePercentage < 0) { //EMRUtils.Log("Adjusting fuel capacity to account for boiloff"); prop.ratio = prop.ratio * ((100 + fuelReservePercentage) / 100); } } }
private string BuildInFlightFuelReserveText() { //EMRUtils.Log("Building new PropellantResources to build fuel reserve text"); PropellantResources propResources = new PropellantResources(engineModule); Dictionary <int, double> propAmounts = new Dictionary <int, double>(); foreach (var prop in propResources) { double propVolume; double propMaxVolume; //EMRUtils.Log("About to get In Flight Fuel Reserve Text"); try { //EMRUtils.Log("Trying to get resource totals: ", prop.Name); part.GetConnectedResourceTotals(prop.Id, out propVolume, out propMaxVolume); propAmounts.Add(prop.Id, propVolume / prop.Ratio); //EMRUtils.Log("Found for ", prop.Name, ": ", propVolume); } catch (Exception ex) { //EMRUtils.Log("Error trying to get resource ", prop.Name, " (", ex.Message, ")"); return("UNKNOWN"); } } double minAmount = propAmounts.Min(item => item.Value); //EMRUtils.Log("Min Amount: ", minAmount); StringBuilder result = StringBuilderCache.Acquire(); foreach (var kvp in propAmounts) { double propDiff = kvp.Value - minAmount; //EMRUtils.Log("Diff from min: ", propDiff); if (propDiff > 0) { //EMRUtils.Log("Diff GT 0"); if (result.Length > 0) { result.Append(Environment.NewLine); //EMRUtils.Log("Adding newline"); } PropellantResource propResource = propResources.GetById(kvp.Key); double fuelVolume = propDiff * propResource.Ratio; if (fuelVolume * propResource.Density > .001) { result.Append(propResource.Name).Append(": ").Append(FormatVolumeAndMass(fuelVolume, propResource.Density)); } //EMRUtils.Log("Text now reads: ", result); } } if (result.Length == 0) { result.Append("None"); } return(result.ToStringAndRelease()); }