/// <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); }
/// <summary> /// Add Components to stockpile places increment number of componentDefs into the planetary stockpile. /// </summary> /// <param name="ComponentDef">Component to be added. This is the class all components inherit from, not any particular type of component.</param> /// <param name="increment">Number to add to the stockpile.</param> public void AddComponentsToStockpile(ComponentDefTN ComponentDef, float increment) { if (ComponentStockpileLookup.ContainsKey(ComponentDef.Id) == true) { ComponentStockpileCount[ComponentStockpileLookup[ComponentDef.Id]] = ComponentStockpileCount[ComponentStockpileLookup[ComponentDef.Id]] + increment; } else { ComponentStockpile.Add(ComponentDef); ComponentStockpileCount.Add(increment); ComponentStockpileLookup.Add(ComponentDef.Id, ComponentStockpile.IndexOf(ComponentDef)); } }