public override void OnLoad(ConfigNode node) { base.OnLoad(node); ToolingDatabase.Load(node.GetNode("Tooling")); EnsureDefinitionsLoaded(); }
/// <summary> /// Use for purchasing multiple toolings at once. Does it's best to determine the best order to buy them so that the cost would be minimal. /// Also deducuts the funds required for purchase. /// Has an option for running a simulation to calculate the accurate cost of toolings while the tooling DB and funds are left untouched. /// </summary> /// <param name="toolingColl">Collection of toolings to purchase.</param> /// <param name="isSimulation">Whether to simulate the purchase to get the accurate cost of all toolings.</param> /// <returns>Total cost of all the toolings purchased.</returns> public static float PurchaseToolingBatch(List <ModuleTooling> toolingColl, bool isSimulation = false) { ConfigNode toolingBackup = null; if (isSimulation) { toolingBackup = new ConfigNode(); ToolingDatabase.Save(toolingBackup); } float totalCost = 0; try { // Currently all cost reducers are applied correctly when the tooling types are first sorted in alphabetical order toolingColl.Sort((mt1, mt2) => mt1.ToolingType.CompareTo(mt2.ToolingType)); //TODO: find the most optimal order to purchase toolings that have diameter and length. // If there are diameters 2.9; 3 and 3.1 only 3 needs to be purchased and others will fit inside the stretch margin. toolingColl.ForEach(mt => { if (mt.IsUnlocked()) { return; } totalCost += mt.GetToolingCost(); mt.PurchaseTooling(); }); if (totalCost > 0 && !isSimulation) { Funding.Instance.AddFunds(-totalCost, TransactionReasons.RnDPartPurchase); } } finally { if (isSimulation) { ToolingDatabase.Load(toolingBackup); } } return(totalCost); }
public override void OnLoad(ConfigNode node) { base.OnLoad(node); ToolingDatabase.Load(node.GetNode("Tooling")); }