From d19e1b5f0517f7d078b82b68cfeef8614833fbba Mon Sep 17 00:00:00 2001 From: AlchemistCH Date: Wed, 18 Nov 2015 00:25:45 +0200 Subject: [PATCH 1/4] Create ConverterValue.cs --- src/kOS/Suffixed/Part/ConverterValue.cs | 140 ++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 src/kOS/Suffixed/Part/ConverterValue.cs diff --git a/src/kOS/Suffixed/Part/ConverterValue.cs b/src/kOS/Suffixed/Part/ConverterValue.cs new file mode 100644 index 000000000..89be23845 --- /dev/null +++ b/src/kOS/Suffixed/Part/ConverterValue.cs @@ -0,0 +1,140 @@ +using kOS.Safe.Encapsulation; +using kOS.Safe.Encapsulation.Suffixes; +using System.Collections.Generic; +using kOS.Safe.Exceptions; +using kOS.Suffixed.PartModuleField; +using System; + +namespace kOS.Suffixed.Part +{ + + + class ConverterValue : PartValue + { + private ListValue Converters; + + public ConverterValue(global::Part part, SharedObjects sharedObj) + : base(part, sharedObj) + { + Converters = new ListValue(); + + foreach (PartModule module in Part.Modules) + { + var ConverterModule = module as ModuleResourceConverter; + if (ConverterModule != null) + { + Converters.Add(new ConverterFields(ConverterModule, sharedObj)); + } + } + + ConverterInitializeSuffixes(); + + } + + private void ConverterInitializeSuffixes() + { + AddSuffix(new[] { "CONVERTERMODULES", "CONVMODS" }, new Suffix>(() => Converters, "")); + AddSuffix(new[] { "HASCONVERTER", "HASCONV" }, new OneArgsSuffix(HasConverterModule)); + AddSuffix(new[] { "GETCONVERTER", "GETCONV" }, new OneArgsSuffix(GetConverterModule)); + + // all suffixes + + AddSuffix(new[] { "CONVERTERNAMES", "CONVNAMES" }, new Suffix(() => + { + var toReturn = new ListValue(); + foreach (ConverterFields conv in Converters) { toReturn.Add(conv.Converter.ConverterName); } + return toReturn; + })); + + //AddSuffix(new[] { "CONVERTERNAME", "CONVNAME" }, new Suffix(() => converter.ConverterName)); + + AddSuffix("START", new NoArgsSuffix(() => + { + foreach (ConverterFields conv in Converters) + { + conv.Converter.StartResourceConverter(); + } + })); + AddSuffix("STOP", new NoArgsSuffix(() => + { + foreach (ConverterFields conv in Converters) + { + conv.Converter.StopResourceConverter(); + } + })); + AddSuffix("STATUSALL", new Suffix(() => + { + var toReturn = new ListValue(); + foreach (ConverterFields conv in Converters) { toReturn.Add(conv.Converter.status); } + return toReturn; + })); + //AddSuffix("STATUS", new Suffix(() => converter.status)); + AddSuffix("ISACTIVATED", new SetSuffix(() => + { + foreach (ConverterFields conv in Converters) + { + if (conv.Converter.IsActivated) { return true; } + } + return false; + }, value => { + foreach (ConverterFields conv in Converters) + { + conv.toggle(value); + } + })); + AddSuffix("ALWAYSACTIVE", new Suffix(() => { + foreach (ConverterFields conv in Converters) + { + if (conv.Converter.AlwaysActive) { return true; } + } + return false; + })); + AddSuffix("GENERATESHEAT", new Suffix(() => { + foreach (ConverterFields conv in Converters) + { + if (conv.Converter.GeneratesHeat) { return true; } + } + return false; + })); + AddSuffix(new[] { "CORETEMPERATURE", "CORETEMP" }, new Suffix(() => { + if (Converters.Count == 0) { return 0; } + return Converters[0].Converter.GetCoreTemperature(); + })); //same for all (from another module) + AddSuffix(new[] { "GOALTEMPERATURE", "GOALTEMP" }, new Suffix(() => { + if (Converters.Count == 0) { return 0; } + return Converters[0].Converter.GetGoalTemperature(); + })); //same for all (from another module) + //AddSuffix("FILLAMOUNT", new Suffix(() => converter.FillAmount)); //stops when output exceeds this part of storage capacity (fuel cell stop condition). + //AddSuffix("TAKEAMOUNT", new Suffix(() => converter.TakeAmount)); + //AddSuffix("THERMALEFFICIENCY", new Suffix(() => converter.ThermalEfficiency.Evaluate((float)(converter.GetCoreTemperature())))); + // AddSuffix("GETINFO", new Suffix(() => converter.GetInfo())); //overwrite without extra formatting? + //AddSuffix("INPUT", new Suffix>(() => ResListLex(converter.inputList, 1))); //maximal input rate + //AddSuffix("OUTPUT", new Suffix>(() => ResListLex(converter.outputList, 1))); + + //AddSuffix(new[] { "CONVERTERLOAD", "CONVLOAD" }, new Suffix(() => conversionLoadParse(converter.status))); //actual converter load (fraction of maximal) + //AddSuffix("CONSUME", new Suffix>(() => ResListLex(converter.inputList, conversionLoadParse(converter.status)))); //actual consumption rate + //AddSuffix("PRODUCE", new Suffix>(() => ResListLex(converter.outputList, conversionLoadParse(converter.status)))); //actual production rate + + } + + private bool HasConverterModule(string convName) + { + foreach (ConverterFields module in Converters) + { + if (string.Equals(module.Converter.ConverterName, convName, StringComparison.OrdinalIgnoreCase)) { return true; } + } + return false; + } + + private ConverterFields GetConverterModule(string convName) + { + foreach (ConverterFields module in Converters) + { + if (string.Equals(module.Converter.ConverterName, convName, StringComparison.OrdinalIgnoreCase)) { return module; } + } + throw new KOSException("Resource Converter Module not found: " + convName); //if not found + } + } + + +} From f966edc9377e8f612476775cc95f5d5562545850 Mon Sep 17 00:00:00 2001 From: AlchemistCH Date: Wed, 18 Nov 2015 00:35:25 +0200 Subject: [PATCH 2/4] ModuleResourceConverter interface --- .../PartModuleField/ConverterFields.cs | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/kOS/Suffixed/PartModuleField/ConverterFields.cs diff --git a/src/kOS/Suffixed/PartModuleField/ConverterFields.cs b/src/kOS/Suffixed/PartModuleField/ConverterFields.cs new file mode 100644 index 000000000..2d31d7ca7 --- /dev/null +++ b/src/kOS/Suffixed/PartModuleField/ConverterFields.cs @@ -0,0 +1,72 @@ +using kOS.Safe.Encapsulation.Suffixes; +using kOS.Safe.Encapsulation; +using System.Collections.Generic; + +namespace kOS.Suffixed.PartModuleField +{ + class ConverterFields : PartModuleFields + { + private readonly ModuleResourceConverter converter; + + public ModuleResourceConverter Converter + { get { return converter; } } + + public ConverterFields(ModuleResourceConverter ConverterModule, SharedObjects sharedObj) + : base(ConverterModule, sharedObj) + { + converter = ConverterModule; + ConverterModuleInitializeSuffixes(); + } + + private void ConverterModuleInitializeSuffixes() + { + AddSuffix(new[] { "CONVERTERNAME", "CONVNAME" }, new Suffix(() => converter.ConverterName)); + AddSuffix("START", new NoArgsSuffix(() => converter.StartResourceConverter())); + AddSuffix("STOP", new NoArgsSuffix(() => converter.StopResourceConverter())); + AddSuffix("STATUS", new Suffix(() => converter.status)); + AddSuffix("ISACTIVATED", new SetSuffix(() => converter.IsActivated, value => toggle(value))); + AddSuffix("ALWAYSACTIVE", new Suffix(() => converter.AlwaysActive)); + AddSuffix("GENERATESHEAT", new Suffix(() => converter.GeneratesHeat)); + AddSuffix(new[] { "CORETEMPERATURE", "CORETEMP" }, new Suffix(() => converter.GetCoreTemperature())); + AddSuffix(new[] { "GOALTEMPERATURE", "GOALTEMP" }, new Suffix(() => converter.GetGoalTemperature())); //optimal temp (returns current temp, if temp independent) + AddSuffix("FILLAMOUNT", new Suffix(() => converter.FillAmount)); //stops when output exceeds this part of storage capacity (fuel cell stop condition). + AddSuffix("TAKEAMOUNT", new Suffix(() => converter.TakeAmount)); + AddSuffix("THERMALEFFICIENCY", new Suffix(() => converter.ThermalEfficiency.Evaluate((float)(converter.GetCoreTemperature())))); + // AddSuffix("GETINFO", new Suffix(() => converter.GetInfo())); //overwrite without extra formatting? + AddSuffix("INPUT", new Suffix>(() => ResListLex(converter.inputList, 1))); //maximal input rate + AddSuffix("OUTPUT", new Suffix>(() => ResListLex(converter.outputList, 1))); + + AddSuffix(new[] { "CONVERTERLOAD", "CONVLOAD" }, new Suffix(() => conversionLoadParse(converter.status))); //actual converter load (fraction of maximal) + AddSuffix("CONSUME", new Suffix>(() => ResListLex(converter.inputList, conversionLoadParse(converter.status)))); //actual consumption rate + AddSuffix("PRODUCE", new Suffix>(() => ResListLex(converter.outputList, conversionLoadParse(converter.status)))); //actual production rate + } + + public void toggle(bool value) + { + if (value) { converter.StartResourceConverter(); } else { converter.StopResourceConverter(); } + } + + public Lexicon ResListLex(List resList, float rate) + { + var toReturn = new Lexicon(); + foreach (ResourceRatio rr in resList) + { + toReturn.Add(rr.ResourceName, rr.Ratio * rate); + } + return toReturn; + } + + public float conversionLoadParse(string status) + { + if (status.EndsWith("% load")) + { + try { return float.Parse(status.Remove(status.Length - 6)) / 100; } + catch { return 0; } + } + else { return 0; } + } + + + + } +} From 5415f050e7c1c8071f032c68719748040c77d993 Mon Sep 17 00:00:00 2001 From: AlchemistCH Date: Sun, 22 Nov 2015 18:18:52 +0200 Subject: [PATCH 3/4] Full set of control-all suffixes --- src/kOS/Suffixed/Part/ConverterValue.cs | 190 +++++++++++++++++++++--- 1 file changed, 173 insertions(+), 17 deletions(-) diff --git a/src/kOS/Suffixed/Part/ConverterValue.cs b/src/kOS/Suffixed/Part/ConverterValue.cs index 89be23845..ae8844dd4 100644 --- a/src/kOS/Suffixed/Part/ConverterValue.cs +++ b/src/kOS/Suffixed/Part/ConverterValue.cs @@ -1,6 +1,5 @@ using kOS.Safe.Encapsulation; using kOS.Safe.Encapsulation.Suffixes; -using System.Collections.Generic; using kOS.Safe.Exceptions; using kOS.Suffixed.PartModuleField; using System; @@ -33,10 +32,13 @@ public ConverterValue(global::Part part, SharedObjects sharedObj) private void ConverterInitializeSuffixes() { - AddSuffix(new[] { "CONVERTERMODULES", "CONVMODS" }, new Suffix>(() => Converters, "")); + + + AddSuffix(new[] { "CONVERTERMODULES", "CONVMODS" }, new Suffix>(() => Converters)); AddSuffix(new[] { "HASCONVERTER", "HASCONV" }, new OneArgsSuffix(HasConverterModule)); AddSuffix(new[] { "GETCONVERTER", "GETCONV" }, new OneArgsSuffix(GetConverterModule)); + AddSuffix(new[] { "CONVERTERCOUNT", "CONVCOUNT" }, new Suffix(() => Converters.Count)); // all suffixes AddSuffix(new[] { "CONVERTERNAMES", "CONVNAMES" }, new Suffix(() => @@ -46,7 +48,13 @@ private void ConverterInitializeSuffixes() return toReturn; })); - //AddSuffix(new[] { "CONVERTERNAME", "CONVNAME" }, new Suffix(() => converter.ConverterName)); + AddSuffix(new[] { "CONVERTERNAME", "CONVNAME" }, new Suffix(() => + { + string toReturn = ""; + foreach (ConverterFields conv in Converters) { toReturn=StringAdd(toReturn, conv.Converter.ConverterName, ", "); } + return toReturn; + + })); AddSuffix("START", new NoArgsSuffix(() => { @@ -62,13 +70,30 @@ private void ConverterInitializeSuffixes() conv.Converter.StopResourceConverter(); } })); - AddSuffix("STATUSALL", new Suffix(() => + AddSuffix("STATUSLIST", new Suffix(() => { var toReturn = new ListValue(); foreach (ConverterFields conv in Converters) { toReturn.Add(conv.Converter.status); } return toReturn; })); - //AddSuffix("STATUS", new Suffix(() => converter.status)); + AddSuffix("STATUSFULL", new Suffix(() => + { + var toReturn = new ListValue(); + foreach (ConverterFields conv in Converters) { toReturn.Add(conv.Converter.ConverterName+": "+conv.Converter.status); } + return toReturn; + })); + + AddSuffix("STATUS", new Suffix(() => + { + if (Converters.Count == 1) { return Converters[0].Converter.status; } + else + { + string toReturn = ""; + foreach (ConverterFields conv in Converters) { toReturn= LineAdd(toReturn, (conv.Converter.ConverterName + ": " + conv.Converter.status)); } + return toReturn; + } + })); + AddSuffix("ISACTIVATED", new SetSuffix(() => { foreach (ConverterFields conv in Converters) @@ -82,6 +107,34 @@ private void ConverterInitializeSuffixes() conv.toggle(value); } })); + AddSuffix("ISRUNNING", new Suffix(() => + { + foreach (ConverterFields conv in Converters) + { + if (conv.Converter.status.EndsWith("% load")) { return true; } + } + return false; + })); + AddSuffix("ACTIVATED", new Suffix(() => + { + int toReturn = 0; + foreach (ConverterFields conv in Converters) + { + if (conv.Converter.IsActivated) { toReturn++; } + } + return toReturn; + })); //count of + AddSuffix("RUNNING", new Suffix(() => + { + int toReturn = 0; + foreach (ConverterFields conv in Converters) + { + if (conv.Converter.status.EndsWith("% load")) { toReturn++; } + } + return toReturn; + })); + + AddSuffix("ALWAYSACTIVE", new Suffix(() => { foreach (ConverterFields conv in Converters) { @@ -97,23 +150,106 @@ private void ConverterInitializeSuffixes() return false; })); AddSuffix(new[] { "CORETEMPERATURE", "CORETEMP" }, new Suffix(() => { - if (Converters.Count == 0) { return 0; } + if (Converters.Count == 0) { return Part.temperature; } //it seems to give that if there's no coreHeat module as well return Converters[0].Converter.GetCoreTemperature(); })); //same for all (from another module) AddSuffix(new[] { "GOALTEMPERATURE", "GOALTEMP" }, new Suffix(() => { - if (Converters.Count == 0) { return 0; } - return Converters[0].Converter.GetGoalTemperature(); + if (Converters.Count == 0) { return Part.temperature; } + return Converters[0].Converter.GetGoalTemperature(); })); //same for all (from another module) - //AddSuffix("FILLAMOUNT", new Suffix(() => converter.FillAmount)); //stops when output exceeds this part of storage capacity (fuel cell stop condition). - //AddSuffix("TAKEAMOUNT", new Suffix(() => converter.TakeAmount)); - //AddSuffix("THERMALEFFICIENCY", new Suffix(() => converter.ThermalEfficiency.Evaluate((float)(converter.GetCoreTemperature())))); - // AddSuffix("GETINFO", new Suffix(() => converter.GetInfo())); //overwrite without extra formatting? - //AddSuffix("INPUT", new Suffix>(() => ResListLex(converter.inputList, 1))); //maximal input rate - //AddSuffix("OUTPUT", new Suffix>(() => ResListLex(converter.outputList, 1))); - //AddSuffix(new[] { "CONVERTERLOAD", "CONVLOAD" }, new Suffix(() => conversionLoadParse(converter.status))); //actual converter load (fraction of maximal) - //AddSuffix("CONSUME", new Suffix>(() => ResListLex(converter.inputList, conversionLoadParse(converter.status)))); //actual consumption rate - //AddSuffix("PRODUCE", new Suffix>(() => ResListLex(converter.outputList, conversionLoadParse(converter.status)))); //actual production rate + AddSuffix("FILLAMOUNT", new Suffix(() => + { + if (Converters.Count == 0) { return 0; } + float sum = 0; float act = 0; int Nact = 0; + foreach (ConverterFields conv in Converters) + { + float t = conv.Converter.FillAmount; + sum = sum + t; + if (conv.Converter.IsActivated) { act = act + t; Nact++; } + } + if (Nact > 0) { return act / Nact; } else { return sum / Converters.Count; } + })); + + AddSuffix("TAKEAMOUNT", new Suffix(() => + { + if (Converters.Count == 0) { return 0; } + float sum = 0; float act = 0; int Nact = 0; + foreach (ConverterFields conv in Converters) + { + float t = conv.Converter.TakeAmount; + sum = sum + t; + if (conv.Converter.IsActivated) { act = act + t; Nact++; } + } + if (Nact > 0) { return act / Nact; } else { return sum / Converters.Count; } + })); + + AddSuffix(new[] { "THERMALEFFICIENCY", "THERMEFF" }, new Suffix(() => + { + if (Converters.Count == 0) { return 0; } + float sum = 0; float act = 0; int Nact = 0; + foreach (ConverterFields conv in Converters) + { + float te = conv.ThermEff(); + sum = sum + te; + if (conv.Converter.IsActivated) { act = act + te; Nact++; } + } + if (Nact > 0) { return act / Nact; } else { return sum / Converters.Count; } + })); + + AddSuffix("GETINFO", new Suffix(() => + { + string toReturn = ""; + foreach (ConverterFields conv in Converters) { toReturn = LineAdd(toReturn, conv.writeInfo()); } + return toReturn; + })); + + + AddSuffix(new[] { "CONVERTERLOAD", "CONVLOAD" }, new Suffix(() => + { + float sum = 0; int Nact = 0; + foreach (ConverterFields conv in Converters) + { + if (conv.Converter.IsActivated) { sum = sum + conv.conversionLoad(); Nact++; } + } + if (Nact == 0) { return 0; } else { return sum / Nact; } + })); //actual converter load (average for active converters) + + + AddSuffix("INPUT", new Suffix>(() => { + var toReturn = new Lexicon(); + foreach (ConverterFields conv in Converters) + { + MergeResLex(toReturn, conv.InputLex()); + } + return toReturn; + })); //maximal input rate + AddSuffix("OUTPUT", new Suffix>(() => { + var toReturn = new Lexicon(); + foreach (ConverterFields conv in Converters) + { + MergeResLex(toReturn, conv.OutputLex()); + } + return toReturn; + })); //maximal output rate + + AddSuffix("CONSUME", new Suffix>(() => { + var toReturn = new Lexicon(); + foreach (ConverterFields conv in Converters) + { + MergeResLex(toReturn, conv.ConsumeLex()); + } + return toReturn; + })); //actual consumption rate + + AddSuffix("PRODUCE", new Suffix>(() => { + var toReturn = new Lexicon(); + foreach (ConverterFields conv in Converters) + { + MergeResLex(toReturn, conv.ProduceLex()); + } + return toReturn; + })); //actual production rate } @@ -134,6 +270,26 @@ private ConverterFields GetConverterModule(string convName) } throw new KOSException("Resource Converter Module not found: " + convName); //if not found } + + private void MergeResLex(Lexicon Lex, Lexicon toAdd) + { + foreach (string res in toAdd.Keys) + { + if (Lex.ContainsKey(res)) { Lex[res] = Lex[res] + toAdd[res]; } + else { Lex.Add(res, toAdd[res]); } + } + } + + private string StringAdd(string s, string toAdd, string Sep) + { + if (s == "") { return toAdd; } + else { return (s + Sep + toAdd); } + } + private string LineAdd(string s, string toAdd) + { + return StringAdd(s, toAdd, "\n"); + } + } From 8d1c7d8ed1c0e71272631f31bc4dc7eb732602d5 Mon Sep 17 00:00:00 2001 From: AlchemistCH Date: Sun, 22 Nov 2015 18:20:10 +0200 Subject: [PATCH 4/4] Update ConverterFields.cs --- .../PartModuleField/ConverterFields.cs | 91 ++++++++++++++++--- 1 file changed, 80 insertions(+), 11 deletions(-) diff --git a/src/kOS/Suffixed/PartModuleField/ConverterFields.cs b/src/kOS/Suffixed/PartModuleField/ConverterFields.cs index 2d31d7ca7..4686aa1a0 100644 --- a/src/kOS/Suffixed/PartModuleField/ConverterFields.cs +++ b/src/kOS/Suffixed/PartModuleField/ConverterFields.cs @@ -25,20 +25,21 @@ private void ConverterModuleInitializeSuffixes() AddSuffix("STOP", new NoArgsSuffix(() => converter.StopResourceConverter())); AddSuffix("STATUS", new Suffix(() => converter.status)); AddSuffix("ISACTIVATED", new SetSuffix(() => converter.IsActivated, value => toggle(value))); + AddSuffix("ISRUNNING", new Suffix(() => converter.status.EndsWith("% load"))); //That's the only indication they give us AddSuffix("ALWAYSACTIVE", new Suffix(() => converter.AlwaysActive)); AddSuffix("GENERATESHEAT", new Suffix(() => converter.GeneratesHeat)); AddSuffix(new[] { "CORETEMPERATURE", "CORETEMP" }, new Suffix(() => converter.GetCoreTemperature())); AddSuffix(new[] { "GOALTEMPERATURE", "GOALTEMP" }, new Suffix(() => converter.GetGoalTemperature())); //optimal temp (returns current temp, if temp independent) AddSuffix("FILLAMOUNT", new Suffix(() => converter.FillAmount)); //stops when output exceeds this part of storage capacity (fuel cell stop condition). AddSuffix("TAKEAMOUNT", new Suffix(() => converter.TakeAmount)); - AddSuffix("THERMALEFFICIENCY", new Suffix(() => converter.ThermalEfficiency.Evaluate((float)(converter.GetCoreTemperature())))); - // AddSuffix("GETINFO", new Suffix(() => converter.GetInfo())); //overwrite without extra formatting? - AddSuffix("INPUT", new Suffix>(() => ResListLex(converter.inputList, 1))); //maximal input rate - AddSuffix("OUTPUT", new Suffix>(() => ResListLex(converter.outputList, 1))); + AddSuffix(new[] { "THERMALEFFICIENCY", "THERMEFF" }, new Suffix(() => ThermEff())); + AddSuffix("GETINFO", new Suffix(() => writeInfo())); + AddSuffix("INPUT", new Suffix>(() => InputLex())); //maximal input rate + AddSuffix("OUTPUT", new Suffix>(() => OutputLex())); - AddSuffix(new[] { "CONVERTERLOAD", "CONVLOAD" }, new Suffix(() => conversionLoadParse(converter.status))); //actual converter load (fraction of maximal) - AddSuffix("CONSUME", new Suffix>(() => ResListLex(converter.inputList, conversionLoadParse(converter.status)))); //actual consumption rate - AddSuffix("PRODUCE", new Suffix>(() => ResListLex(converter.outputList, conversionLoadParse(converter.status)))); //actual production rate + AddSuffix(new[] { "CONVERTERLOAD", "CONVLOAD" }, new Suffix(() => conversionLoad())); //actual converter load (fraction of maximal) + AddSuffix("CONSUME", new Suffix>(() => ConsumeLex())); //actual consumption rate + AddSuffix("PRODUCE", new Suffix>(() => ProduceLex())); //actual production rate } public void toggle(bool value) @@ -46,7 +47,7 @@ public void toggle(bool value) if (value) { converter.StartResourceConverter(); } else { converter.StopResourceConverter(); } } - public Lexicon ResListLex(List resList, float rate) + private Lexicon ResListLex(List resList, float rate) { var toReturn = new Lexicon(); foreach (ResourceRatio rr in resList) @@ -56,7 +57,36 @@ public Lexicon ResListLex(List resList, float rat return toReturn; } - public float conversionLoadParse(string status) + public float ThermEff() + { + return converter.ThermalEfficiency.Evaluate((float)(converter.GetCoreTemperature())); + } + + public Lexicon InputLex() + { + return ResListLex(converter.inputList, 1); + } + + public Lexicon OutputLex() + { + return ResListLex(converter.outputList, 1); + } + + public Lexicon ConsumeLex() + { + return ResListLex(converter.inputList, conversionLoad()); + } + + public Lexicon ProduceLex() + { + return ResListLex(converter.outputList, conversionLoad()); + } + + public float conversionLoad() + { + return conversionLoadParse(converter.status); + } + private float conversionLoadParse(string status) { if (status.EndsWith("% load")) { @@ -66,7 +96,46 @@ public float conversionLoadParse(string status) else { return 0; } } - - + public string writeInfo() + { + string toReturn = converter.ConverterName + ": "+ converter.status; + float CL = conversionLoad(); + if (CL == 0) + { + toReturn = LineAdd(toReturn, " Consumes:"); + foreach (ResourceRatio rr in converter.inputList) + { + toReturn = LineAdd(toReturn, " "+ rr.ResourceName+" ("+ (rr.Ratio).ToString("F2")+"/sec)"); + } + toReturn = LineAdd(toReturn, " Produces:"); + foreach (ResourceRatio rr in converter.outputList) + { + toReturn = LineAdd(toReturn, " " + rr.ResourceName + " (" + (rr.Ratio).ToString("F2") + "/sec)"); + } + } + else + { + toReturn = LineAdd(toReturn, " Consumes:"); + foreach (ResourceRatio rr in converter.inputList) + { + toReturn = LineAdd(toReturn, " " + rr.ResourceName + ": " + (rr.Ratio*CL).ToString("F2") + "/sec (" + (rr.Ratio).ToString("F2") + "/sec)"); + } + toReturn = LineAdd(toReturn, " Produces:"); + foreach (ResourceRatio rr in converter.outputList) + { + toReturn = LineAdd(toReturn, " " + rr.ResourceName + ": " + (rr.Ratio * CL).ToString("F2") + "/sec (" + (rr.Ratio).ToString("F2") + "/sec)"); + } + } + return toReturn; + } + private string StringAdd(string s, string toAdd, string Sep) + { + if (s == "") { return toAdd; } + else { return (s + Sep + toAdd); } + } + private string LineAdd(string s, string toAdd) + { + return StringAdd(s, toAdd, "\n"); + } } }