/// <summary> /// TakeComponents from Stockpile takes the specified number of components out of the stockpile, and returns how many were subtracted. /// </summary> /// <param name="ComponentDef">Component def to be removed.</param> /// <param name="decrement">number to remove</param> /// <returns>number that were removed.</returns> public float TakeComponentsFromStockpile(ComponentDefTN ComponentDef, float decrement) { float Components = 0.0f; if (ComponentStockpileLookup.ContainsKey(ComponentDef.Id) == true) { Components = ComponentStockpileCount[ComponentStockpileLookup[ComponentDef.Id]]; if (Components - decrement <= 0.0f) { ComponentStockpile.RemoveAt(ComponentStockpileLookup[ComponentDef.Id]); ComponentStockpileCount.RemoveAt(ComponentStockpileLookup[ComponentDef.Id]); ComponentStockpileLookup.Remove(ComponentDef.Id); return(Components); } else { Components = Components - decrement; ComponentStockpileCount[ComponentStockpileLookup[ComponentDef.Id]] = Components; } } else { /// <summary> /// Invalid remove request sent from somewhere. Error reporting? logs? /// </summary> return(-1.0f); } return(decrement); }