public double ScaledConsumptionProduction(ResourceData data, List <ResourceKeyValue> consumeResources, List <ResourceKeyValue> produceResources, double minimumRatio = 0, ConsumptionProductionFlags flags = ConsumptionProductionFlags.Empty) { var ratio = CalculateConsumptionRatio(data, consumeResources); if (ratio < minimumRatio) { return(0); } foreach (var resource in consumeResources) { data.Consume(resource.Resource, resource.Amount * ratio); } foreach (var resource in produceResources) { data.Produce(resource.Resource, resource.Amount * ratio); } return(ratio); }
public double ScaledConsumptionProduction(List <ResourceKeyValue> consumeResources, List <ResourceKeyValue> produceResources, double minimumRatio = 0, ConsumptionProductionFlags flags = ConsumptionProductionFlags.Empty) { // To implement when needed return(Upstream.ScaledConsumptionProduction(consumeResources, produceResources, minimumRatio, flags)); }
public double ScaledConsumptionProduction(List <ResourceKeyValue> consumeResources, List <ResourceKeyValue> produceResources, double minimumRatio = 0, ConsumptionProductionFlags flags = ConsumptionProductionFlags.Empty) { double ratio = OverheatMultiplier; if ((flags & ConsumptionProductionFlags.DoNotOverFill) != 0) { foreach (var resourceInfo in produceResources) { var capacityRatio = CalculateAvailableSpaceCapacity(resourceInfo); ratio = (capacityRatio < ratio) ? capacityRatio : ratio; } if (ratio == 0) { return(0); } } double updateWasteHeatInfo = 0; foreach (var resourceInfo in consumeResources) { // We may get resources on demand, so skip accounting for those at the moment if (VariableSupplierModules.ContainsKey(resourceInfo.Resource)) { continue; } var capacityRatio = CalculateAvailableResourceCapacity(resourceInfo); if (resourceInfo.Resource == ResourceName.WasteHeat && capacityRatio < ratio && (flags & ConsumptionProductionFlags.FallbackToElectricCharge) != 0) { updateWasteHeatInfo = capacityRatio; flags &= ~ConsumptionProductionFlags.FallbackToElectricCharge; } else { ratio = (capacityRatio < ratio) ? capacityRatio : ratio; } if (ratio == 0) { return(0); } } if (updateWasteHeatInfo > 0) { var idx = consumeResources.FindIndex(info => info.Resource == ResourceName.WasteHeat); var wasteHeat = consumeResources[idx]; _electricChargeKeyValue.Amount = wasteHeat.Amount * (1 - updateWasteHeatInfo); wasteHeat.Amount *= updateWasteHeatInfo; consumeResources[idx] = wasteHeat; consumeResources.Add(_electricChargeKeyValue); } consumeResources.ForEach(kv => kv.Amount *= ratio); produceResources.ForEach(kv => kv.Amount *= ratio); return(ResourceManager.ScaledConsumptionProduction(this, consumeResources, produceResources, minimumRatio, flags)); }