public void RecalculateBuildRates() { VABRates.Clear(); SPHRates.Clear(); double rate = 0.1; int index = 0; while (rate > 0) { rate = KCT_MathParsing.ParseBuildRateFormula(KCT_BuildListVessel.ListType.VAB, index, this); if (rate >= 0) { VABRates.Add(rate); } index++; } rate = 0.1; index = 0; while (rate > 0) { rate = KCT_MathParsing.ParseBuildRateFormula(KCT_BuildListVessel.ListType.SPH, index, this); if (rate >= 0) { SPHRates.Add(rate); } index++; } }
public void RecalculateBuildRates() { VABRates.Clear(); SPHRates.Clear(); double rate = 0.1; int index = 0; // These loops could clean up a little, is it intended to add a rate=0 in the loop as the last entry? while (rate > 0) { rate = MathParser.ParseBuildRateFormula(BuildListVessel.ListType.VAB, index, this); if (rate >= 0) { VABRates.Add(rate); } index++; } rate = 0.1; index = 0; while (rate > 0) { rate = MathParser.ParseBuildRateFormula(BuildListVessel.ListType.SPH, index, this); if (rate >= 0) { SPHRates.Add(rate); } index++; } var m = StringBuilderCache.Acquire(); m.AppendLine("VAB Rates:"); foreach (double v in VABRates) { m.AppendLine($"{v}"); } m.AppendLine("SPH Rates:"); foreach (double v in SPHRates) { m.AppendLine($"{v}"); } KCTDebug.Log(m.ToStringAndRelease()); }
public void RecalculateBuildRates() { const string logBlockName = nameof(SpaceCenterConstruction) + "." + nameof(RecalculateBuildRates); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { VABRates.Clear(); SPHRates.Clear(); double rate = 0.1; int index = 0; while (rate > 0) { rate = KCT_MathParsing.ParseBuildRateFormula(BuildListVessel.ListType.VAB, index, this); if (rate >= 0) { VABRates.Add(rate); } index++; } rate = 0.1; index = 0; while (rate > 0) { rate = KCT_MathParsing.ParseBuildRateFormula(BuildListVessel.ListType.SPH, index, this); if (rate >= 0) { SPHRates.Add(rate); } index++; } Log.Trace("VAB Rates:"); foreach (double v in VABRates) { Log.Trace(v.ToString()); } Log.Trace("SPH Rates:"); foreach (double v in SPHRates) { Log.Trace(v.ToString()); } } }
public void RecalculateBuildRates() { VABRates.Clear(); SPHRates.Clear(); double rate = 0.1; int index = 0; while (rate > 0) { rate = KCT_MathParsing.ParseBuildRateFormula(KCT_BuildListVessel.ListType.VAB, index, this); if (rate >= 0) { VABRates.Add(rate); } index++; } rate = 0.1; index = 0; while (rate > 0) { rate = KCT_MathParsing.ParseBuildRateFormula(KCT_BuildListVessel.ListType.SPH, index, this); if (rate >= 0) { SPHRates.Add(rate); } index++; } KCTDebug.Log("VAB Rates:"); foreach (double v in VABRates) { KCTDebug.Log(v); } KCTDebug.Log("SPH Rates:"); foreach (double v in SPHRates) { KCTDebug.Log(v); } }
public KCT_KSC FromConfigNode(ConfigNode node) { VABUpgrades.Clear(); SPHUpgrades.Clear(); RDUpgrades.Clear(); VABList.Clear(); VABWarehouse.Clear(); SPHList.Clear(); SPHWarehouse.Clear(); KSCTech.Clear(); //TechList.Clear(); Recon_Rollout.Clear(); VABRates.Clear(); SPHRates.Clear(); this.KSCName = node.GetValue("KSCName"); if (!int.TryParse(node.GetValue("ActiveLPID"), out this.ActiveLaunchPadID)) { this.ActiveLaunchPadID = 0; } ConfigNode vabup = node.GetNode("VABUpgrades"); foreach (string upgrade in vabup.GetValues("Upgrade")) { this.VABUpgrades.Add(int.Parse(upgrade)); } ConfigNode sphup = node.GetNode("SPHUpgrades"); foreach (string upgrade in sphup.GetValues("Upgrade")) { this.SPHUpgrades.Add(int.Parse(upgrade)); } ConfigNode rdup = node.GetNode("RDUpgrades"); foreach (string upgrade in rdup.GetValues("Upgrade")) { this.RDUpgrades.Add(int.Parse(upgrade)); } ConfigNode tmp = node.GetNode("VABList"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; this.VABList.Add(blv); } tmp = node.GetNode("SPHList"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; this.SPHList.Add(blv); } tmp = node.GetNode("VABWarehouse"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; this.VABWarehouse.Add(blv); } tmp = node.GetNode("SPHWarehouse"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; this.SPHWarehouse.Add(blv); } /* tmp = node.GetNode("TechList"); * foreach (ConfigNode techNode in tmp.GetNodes("Tech")) * { * KCT_TechStorageItem techStorageItem = new KCT_TechStorageItem(); * ConfigNode.LoadObjectFromConfig(techStorageItem, techNode); * KCT_TechItem techItem = techStorageItem.ToTechItem(); * techItem.protoNode = new ProtoTechNode(techNode.GetNode("ProtoNode")); * this.TechList.Add(techItem); * }*/ tmp = node.GetNode("Recon_Rollout"); foreach (ConfigNode RRCN in tmp.GetNodes("Recon_Rollout_Item")) { KCT_Recon_Rollout tempRR = new KCT_Recon_Rollout(); ConfigNode.LoadObjectFromConfig(tempRR, RRCN); Recon_Rollout.Add(tempRR); } if (node.HasNode("KSCTech")) { tmp = node.GetNode("KSCTech"); foreach (ConfigNode upBuild in tmp.GetNodes("UpgradingBuilding")) { KCT_UpgradingBuilding tempUP = new KCT_UpgradingBuilding(); ConfigNode.LoadObjectFromConfig(tempUP, upBuild); KSCTech.Add(tempUP); } } if (node.HasNode("LaunchPads")) { LaunchPads.Clear(); tmp = node.GetNode("LaunchPads"); foreach (ConfigNode LP in tmp.GetNodes("KCT_LaunchPad")) { KCT_LaunchPad tempLP = new KCT_LaunchPad("LP0"); ConfigNode.LoadObjectFromConfig(tempLP, LP); tempLP.DestructionNode = LP.GetNode("DestructionState"); LaunchPads.Add(tempLP); } } if (node.HasNode("VABRateCache")) { foreach (string rate in node.GetNode("VABRateCache").GetValues("rate")) { double r; if (double.TryParse(rate, out r)) { VABRates.Add(r); } } } if (node.HasNode("SPHRateCache")) { foreach (string rate in node.GetNode("SPHRateCache").GetValues("rate")) { double r; if (double.TryParse(rate, out r)) { SPHRates.Add(r); } } } return(this); }
public KSCItem FromConfigNode(ConfigNode node) { VABUpgrades.Clear(); SPHUpgrades.Clear(); RDUpgrades.Clear(); VABList.Clear(); VABWarehouse.Clear(); SPHList.Clear(); SPHWarehouse.Clear(); VABPlans.Clear(); SPHPlans.Clear(); KSCTech.Clear(); Recon_Rollout.Clear(); AirlaunchPrep.Clear(); VABRates.Clear(); SPHRates.Clear(); KSCName = node.GetValue("KSCName"); if (!int.TryParse(node.GetValue("ActiveLPID"), out ActiveLaunchPadID)) { ActiveLaunchPadID = 0; } ConfigNode vabUp = node.GetNode("VABUpgrades"); foreach (string upgrade in vabUp.GetValues("Upgrade")) { VABUpgrades.Add(int.Parse(upgrade)); } ConfigNode sphUp = node.GetNode("SPHUpgrades"); foreach (string upgrade in sphUp.GetValues("Upgrade")) { SPHUpgrades.Add(int.Parse(upgrade)); } ConfigNode rdUp = node.GetNode("RDUpgrades"); foreach (string upgrade in rdUp.GetValues("Upgrade")) { RDUpgrades.Add(int.Parse(upgrade)); } ConfigNode tmp = node.GetNode("VABList"); foreach (ConfigNode cn in tmp.GetNodes("KCTVessel")) { var listItem = new BuildListStorageItem(); ConfigNode.LoadObjectFromConfig(listItem, cn); BuildListVessel blv = listItem.ToBuildListVessel(); blv.ShipNode = cn.GetNode("ShipNode"); blv.KSC = this; VABList.Add(blv); } tmp = node.GetNode("SPHList"); foreach (ConfigNode cn in tmp.GetNodes("KCTVessel")) { var listItem = new BuildListStorageItem(); ConfigNode.LoadObjectFromConfig(listItem, cn); BuildListVessel blv = listItem.ToBuildListVessel(); blv.ShipNode = cn.GetNode("ShipNode"); blv.KSC = this; SPHList.Add(blv); } BuildList.Sort((a, b) => a.BuildListIndex.CompareTo(b.BuildListIndex)); tmp = node.GetNode("VABWarehouse"); foreach (ConfigNode cn in tmp.GetNodes("KCTVessel")) { var listItem = new BuildListStorageItem(); ConfigNode.LoadObjectFromConfig(listItem, cn); BuildListVessel blv = listItem.ToBuildListVessel(); blv.ShipNode = cn.GetNode("ShipNode"); blv.KSC = this; VABWarehouse.Add(blv); } tmp = node.GetNode("SPHWarehouse"); foreach (ConfigNode cn in tmp.GetNodes("KCTVessel")) { var listItem = new BuildListStorageItem(); ConfigNode.LoadObjectFromConfig(listItem, cn); BuildListVessel blv = listItem.ToBuildListVessel(); blv.ShipNode = cn.GetNode("ShipNode"); blv.KSC = this; SPHWarehouse.Add(blv); } if (node.TryGetNode("VABPlans", ref tmp)) { if (tmp.HasNode("KCTVessel")) { foreach (ConfigNode cn in tmp.GetNodes("KCTVessel")) { var listItem = new BuildListStorageItem(); ConfigNode.LoadObjectFromConfig(listItem, cn); BuildListVessel blv = listItem.ToBuildListVessel(); blv.ShipNode = cn.GetNode("ShipNode"); blv.KSC = this; if (VABPlans.ContainsKey(blv.ShipName)) { VABPlans.Remove(blv.ShipName); } VABPlans.Add(blv.ShipName, blv); } } } if (node.TryGetNode("SPHPlans", ref tmp)) { if (tmp.HasNode("KCTVessel")) { foreach (ConfigNode cn in tmp.GetNodes("KCTVessel")) { var listItem = new BuildListStorageItem(); ConfigNode.LoadObjectFromConfig(listItem, cn); BuildListVessel blv = listItem.ToBuildListVessel(); blv.ShipNode = cn.GetNode("ShipNode"); blv.KSC = this; if (SPHPlans.ContainsKey(blv.ShipName)) { SPHPlans.Remove(blv.ShipName); } SPHPlans.Add(blv.ShipName, blv); } } } tmp = node.GetNode("Recon_Rollout"); foreach (ConfigNode RRCN in tmp.GetNodes("Recon_Rollout_Item")) { var tempRR = new ReconRolloutStorageItem(); ConfigNode.LoadObjectFromConfig(tempRR, RRCN); Recon_Rollout.Add(tempRR.ToReconRollout()); } if (node.TryGetNode("Airlaunch_Prep", ref tmp)) { foreach (ConfigNode cn in tmp.GetNodes("Airlaunch_Prep_Item")) { var storageItem = new AirlaunchPrepStorageItem(); ConfigNode.LoadObjectFromConfig(storageItem, cn); AirlaunchPrep.Add(storageItem.ToAirlaunchPrep()); } } if (node.HasNode("KSCTech")) { tmp = node.GetNode("KSCTech"); foreach (ConfigNode cn in tmp.GetNodes("UpgradingBuilding")) { var storageItem = new FacilityUpgradeStorageItem(); ConfigNode.LoadObjectFromConfig(storageItem, cn); KSCTech.Add(storageItem.ToFacilityUpgrade()); } } if (node.HasNode("LaunchPads")) { LaunchPads.Clear(); tmp = node.GetNode("LaunchPads"); foreach (ConfigNode cn in tmp.GetNodes("KCT_LaunchPad")) { var tempLP = new KCT_LaunchPad("LP0"); ConfigNode.LoadObjectFromConfig(tempLP, cn); tempLP.DestructionNode = cn.GetNode("DestructionState"); LaunchPads.Add(tempLP); } } if (node.HasNode("VABRateCache")) { foreach (string rate in node.GetNode("VABRateCache").GetValues("rate")) { if (double.TryParse(rate, out double r)) { VABRates.Add(r); } } } if (node.HasNode("SPHRateCache")) { foreach (string rate in node.GetNode("SPHRateCache").GetValues("rate")) { if (double.TryParse(rate, out double r)) { SPHRates.Add(r); } } } return(this); }
public KCT_KSC FromConfigNode(ConfigNode node) { VABUpgrades.Clear(); SPHUpgrades.Clear(); RDUpgrades.Clear(); VABList.Clear(); VABWarehouse.Clear(); SPHList.Clear(); SPHWarehouse.Clear(); VABPlans.Clear(); SPHPlans.Clear(); KSCTech.Clear(); //TechList.Clear(); Recon_Rollout.Clear(); AirlaunchPrep.Clear(); VABRates.Clear(); SPHRates.Clear(); this.KSCName = node.GetValue("KSCName"); if (!int.TryParse(node.GetValue("ActiveLPID"), out this.ActiveLaunchPadID)) { this.ActiveLaunchPadID = 0; } ConfigNode vabup = node.GetNode("VABUpgrades"); foreach (string upgrade in vabup.GetValues("Upgrade")) { this.VABUpgrades.Add(int.Parse(upgrade)); } ConfigNode sphup = node.GetNode("SPHUpgrades"); foreach (string upgrade in sphup.GetValues("Upgrade")) { this.SPHUpgrades.Add(int.Parse(upgrade)); } ConfigNode rdup = node.GetNode("RDUpgrades"); foreach (string upgrade in rdup.GetValues("Upgrade")) { this.RDUpgrades.Add(int.Parse(upgrade)); } ConfigNode tmp = node.GetNode("VABList"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; this.VABList.Add(blv); } tmp = node.GetNode("SPHList"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; this.SPHList.Add(blv); } tmp = node.GetNode("VABWarehouse"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; this.VABWarehouse.Add(blv); } tmp = node.GetNode("SPHWarehouse"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; this.SPHWarehouse.Add(blv); } if (node.TryGetNode("VABPlans", ref tmp)) { if (tmp.HasNode("KCTVessel")) { foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; if (this.VABPlans.ContainsKey(blv.shipName)) { this.VABPlans.Remove(blv.shipName); } this.VABPlans.Add(blv.shipName, blv); } } } if (node.TryGetNode("SPHPlans", ref tmp)) { if (tmp.HasNode("KCTVessel")) { foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; if (this.SPHPlans.ContainsKey(blv.shipName)) { this.SPHPlans.Remove(blv.shipName); } this.SPHPlans.Add(blv.shipName, blv); } } } tmp = node.GetNode("Recon_Rollout"); foreach (ConfigNode RRCN in tmp.GetNodes("Recon_Rollout_Item")) { KCT_Recon_Rollout tempRR = new KCT_Recon_Rollout(); ConfigNode.LoadObjectFromConfig(tempRR, RRCN); Recon_Rollout.Add(tempRR); } if (node.TryGetNode("Airlaunch_Prep", ref tmp)) { foreach (ConfigNode APCN in tmp.GetNodes("Airlaunch_Prep_Item")) { KCT_AirlaunchPrep temp = new KCT_AirlaunchPrep(); ConfigNode.LoadObjectFromConfig(temp, APCN); AirlaunchPrep.Add(temp); } } if (node.HasNode("KSCTech")) { tmp = node.GetNode("KSCTech"); foreach (ConfigNode upBuild in tmp.GetNodes("UpgradingBuilding")) { KCT_UpgradingBuilding tempUP = new KCT_UpgradingBuilding(); tempUP.Load(upBuild); KSCTech.Add(tempUP); } } if (node.HasNode("LaunchPads")) { LaunchPads.Clear(); tmp = node.GetNode("LaunchPads"); foreach (ConfigNode LP in tmp.GetNodes("KCT_LaunchPad")) { KCT_LaunchPad tempLP = new KCT_LaunchPad("LP0"); ConfigNode.LoadObjectFromConfig(tempLP, LP); tempLP.DestructionNode = LP.GetNode("DestructionState"); LaunchPads.Add(tempLP); } } if (node.HasNode("VABRateCache")) { foreach (string rate in node.GetNode("VABRateCache").GetValues("rate")) { double r; if (double.TryParse(rate, out r)) { VABRates.Add(r); } } } if (node.HasNode("SPHRateCache")) { foreach (string rate in node.GetNode("SPHRateCache").GetValues("rate")) { double r; if (double.TryParse(rate, out r)) { SPHRates.Add(r); } } } return(this); }