using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; namespace UXAssist.Production; public enum ProductionStatus { Complete, Partial, Failed, DataNotReady } public enum ProductionPowerScope { ProductionBuildings, SelectedFacilities, ProductionBuildingsAndAuxiliary } public sealed class ProductionPower { public double ConsumptionWatts { get; } public double PeakConsumptionWatts { get; } public double GenerationWatts { get; } public double AccumulatorChargingWatts { get; } public double AccumulatorDischargingWatts { get; } public double DysonSphereRequirementWatts { get; } public ProductionPowerScope Scope { get; } public ProductionPower(double consumptionWatts, double peakConsumptionWatts, double generationWatts, double accumulatorChargingWatts, double accumulatorDischargingWatts, double dysonSphereRequirementWatts, ProductionPowerScope scope) { ConsumptionWatts = consumptionWatts; PeakConsumptionWatts = peakConsumptionWatts; GenerationWatts = generationWatts; AccumulatorChargingWatts = accumulatorChargingWatts; AccumulatorDischargingWatts = accumulatorDischargingWatts; DysonSphereRequirementWatts = dysonSphereRequirementWatts; Scope = scope; } } public sealed class ProductionItemFlow { public int ItemId { get; } public double GrossProduction { get; } public double GrossConsumption { get; } public double NetFlow => GrossProduction - GrossConsumption; public double ExternalImports { get; } public double KnownExternalSupply { get; } public double Delivered { get; } public double Surplus { get; } public double RequiredExternalSupply { get; } public bool IsFinalProduct { get; } public bool IsExcessIntermediate { get; } public double SingleBuildingSurplusThreshold { get; } public IReadOnlyList ProducerGroups { get; } public IReadOnlyList ConsumerGroups { get; } public ProductionItemFlow(int itemId, double grossProduction, double grossConsumption, double externalImports, double knownExternalSupply, double delivered, double surplus, double requiredExternalSupply, bool isFinalProduct, bool isExcessIntermediate, double singleBuildingSurplusThreshold, IEnumerable producerGroups, IEnumerable consumerGroups) { ItemId = itemId; GrossProduction = grossProduction; GrossConsumption = grossConsumption; ExternalImports = externalImports; KnownExternalSupply = knownExternalSupply; Delivered = delivered; Surplus = surplus; RequiredExternalSupply = requiredExternalSupply; IsFinalProduct = isFinalProduct; IsExcessIntermediate = isExcessIntermediate; SingleBuildingSurplusThreshold = singleBuildingSurplusThreshold; ProducerGroups = Array.AsReadOnly(producerGroups.ToArray()); ConsumerGroups = Array.AsReadOnly(consumerGroups.ToArray()); } } public sealed class ProductionGroupFlow { public ProductionProcess Process { get; } public double BuildingCount { get; } public double ExecutionsPerMinute { get; } public double? EquivalentBuildings { get; } public int? RoundedDeploymentCount { get; } public double? ConsumptionWatts { get; } public double? PeakConsumptionWatts { get; } public double? GenerationWatts { get; } public double? AccumulatorChargingWatts { get; } public double? AccumulatorDischargingWatts { get; } public double? DysonSphereRequirementWatts { get; } public double LaunchesPerMinute { get; } public double ResearchHashesPerMinute { get; } public IReadOnlyDictionary GrossProduction { get; } public IReadOnlyDictionary GrossConsumption { get; } public ProductionGroupFlow(ProductionProcess process, double buildingCount, double executionsPerMinute, double? equivalentBuildings, int? roundedDeploymentCount, double? consumptionWatts, double? peakConsumptionWatts, IEnumerable> grossProduction, IEnumerable> grossConsumption, double? generationWatts = 0, double? accumulatorChargingWatts = 0, double? accumulatorDischargingWatts = 0, double? dysonSphereRequirementWatts = 0, double launchesPerMinute = 0, double researchHashesPerMinute = 0) { Process = process; BuildingCount = buildingCount; ExecutionsPerMinute = executionsPerMinute; EquivalentBuildings = equivalentBuildings; RoundedDeploymentCount = roundedDeploymentCount; ConsumptionWatts = consumptionWatts; PeakConsumptionWatts = peakConsumptionWatts; GenerationWatts = generationWatts; AccumulatorChargingWatts = accumulatorChargingWatts; AccumulatorDischargingWatts = accumulatorDischargingWatts; DysonSphereRequirementWatts = dysonSphereRequirementWatts; LaunchesPerMinute = launchesPerMinute; ResearchHashesPerMinute = researchHashesPerMinute; GrossProduction = ProductionRecipe.CopyFlows(grossProduction); GrossConsumption = ProductionRecipe.CopyFlows(grossConsumption); } } public sealed class ProductionReport { public ProductionStatus Status { get; } public bool MaterialComplete { get; } public bool PowerComplete { get; } public IReadOnlyDictionary ItemFlows { get; } public IReadOnlyList Groups { get; } public IReadOnlyList Diagnostics { get; } public ProductionPower Power { get; } public double LaunchesPerMinute => Groups.Sum(group => group.LaunchesPerMinute); public double ResearchHashesPerMinute => Groups.Sum(group => group.ResearchHashesPerMinute); public ProductionReport(ProductionStatus status, bool materialComplete, bool powerComplete, IEnumerable itemFlows, IEnumerable groups, IEnumerable diagnostics, ProductionPower power) { Status = status; MaterialComplete = materialComplete; PowerComplete = powerComplete; ItemFlows = new ReadOnlyDictionary(itemFlows.ToDictionary(flow => flow.ItemId)); Groups = Array.AsReadOnly(groups.ToArray()); Diagnostics = Array.AsReadOnly(diagnostics.ToArray()); Power = power; } internal static ProductionReport Failure(ProductionDiagnostic diagnostic) { return new ProductionReport(diagnostic.Code == ProductionDiagnosticCode.DataNotReady ? ProductionStatus.DataNotReady : ProductionStatus.Failed, false, false, Array.Empty(), Array.Empty(), new[] { diagnostic }, null); } }