/// <summary> /// Changes the maximum storage capacity. /// </summary> /// <param name="newCapacity">The new capacity</param> /// <returns>The amount of overflow if the current value needs to be adjusted.</returns> public ConstructionMaterial ChangeMaxStorage(ConstructionMaterial newCapacity) { if (currentValue <= newCapacity) { capacity = newCapacity; return(new ConstructionMaterial()); } var overflow = currentValue - newCapacity; currentValue = newCapacity; return(overflow); }
public void Store(ConstructionMaterial material) { material = constructionMaterialBaseStorage.Store(material); using (var storages = constructionMaterialStorages.GetEnumerator()) { while (material > ConstructionMaterial.Zero && storages.MoveNext()) { Debug.Assert(storages.Current != null, "storages.Current != null"); material = storages.Current.Store(material); } } }
public bool TryConsume(ConstructionMaterial material) { if (material > ConstructionMaterialAvailable) { return(false); } material = constructionMaterialBaseStorage.Consume(material); foreach (var storage in constructionMaterialStorages) { material = storage.Consume(material); } return(true); }
public ConstructionMaterial Store(ConstructionMaterial value) { if (value < new ConstructionMaterial()) { return(-Consume(-value)); } if (currentValue + value > capacity) { value -= capacity - currentValue; currentValue = capacity; return(value); } currentValue += value; return(new ConstructionMaterial()); }
public ConstructionMaterial Consume(ConstructionMaterial value) { if (value < new ConstructionMaterial()) { return(-Store(-value)); } if (currentValue - value < new ConstructionMaterial()) { value -= currentValue; currentValue = new ConstructionMaterial(); return(value); } currentValue -= value; return(new ConstructionMaterial()); }
public ConstructionMaterialStorage(ConstructionMaterial capacity) { this.capacity = capacity; }
public static ConstructionMaterial Max(ConstructionMaterial a, ConstructionMaterial b) => a > b ? a : b;
public static ConstructionMaterial Min(ConstructionMaterial a, ConstructionMaterial b) => a < b ? a : b;