mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-11-19 17:05:20 +08:00
Read the Advanced Mining Machine speed stored with station settings in prebuild and blueprint captures, and count charging power nodes such as Satellite Substations at their idle draw. Skip recipes that consume their own product when choosing an item's default recipe, so Refined Oil uses Plasma Refining instead of Reforming Refine. Run each planner recipe in one proliferation mode and report conflicting explicit modes, keep material flows for recipe types the catalog does not know, and attribute receiver warnings to their recipe. Compare simplex ratio ties relatively and drive out near-zero artificials without amplifying residuals. Bound the steady-state reduction so lossless cycles cannot stall blueprint descriptions, and choose power units after rounding. Remove redundant code: share the numeric and flow helpers, and drop the unused IsExcessIntermediate threshold, legacy constructor and Capture overloads, the multi-field updater, and the unused proliferator source table.
80 lines
3.7 KiB
C#
80 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using static UXAssist.Production.ProductionMath;
|
|
|
|
namespace UXAssist.Production;
|
|
|
|
public sealed class FractionationProcessAdapter : IProductionProcessAdapter
|
|
{
|
|
public bool CanEvaluate(ProductionRecipe recipe, ProductionBuilding building)
|
|
{
|
|
return recipe?.Category == ProductionRecipeCategory.Fractionate;
|
|
}
|
|
|
|
public bool TryEvaluate(ProductionCatalog catalog, ProductionRecipe recipe, ProductionBuilding building,
|
|
ProliferationMode mode, int level, IReadOnlyDictionary<string, double> operatingParameters,
|
|
out ProductionProcess process, out ProductionDiagnostic diagnostic)
|
|
{
|
|
process = null;
|
|
diagnostic = null;
|
|
if (recipe.Inputs.Count != 1 || recipe.Outputs.Count != 1 ||
|
|
!FinitePositive(recipe.Inputs.Values.Single()) ||
|
|
!FinitePositive(recipe.Outputs.Values.Single()) ||
|
|
mode != ProliferationMode.None && mode != ProliferationMode.Speedup)
|
|
{
|
|
diagnostic = new ProductionDiagnostic(ProductionDiagnosticCode.UnsupportedProcess,
|
|
"Fractionation requires one input, one output, and the native acceleration mode.",
|
|
recipeId: recipe.Id);
|
|
return false;
|
|
}
|
|
|
|
if (building != null && building.Kind != ProductionBuildingKind.Fractionator)
|
|
{
|
|
diagnostic = new ProductionDiagnostic(ProductionDiagnosticCode.IncompatibleBuilding,
|
|
"The selected building cannot fractionate items.", recipeId: recipe.Id,
|
|
buildingItemId: building.ItemId);
|
|
return false;
|
|
}
|
|
|
|
var speedBonus = 0.0;
|
|
var powerMultiplier = 1.0;
|
|
if (mode == ProliferationMode.Speedup &&
|
|
(level <= 0 || !catalog.TryGetProliferation(level, out speedBonus, out _, out powerMultiplier)))
|
|
{
|
|
diagnostic = new ProductionDiagnostic(ProductionDiagnosticCode.UnsupportedProliferation,
|
|
"The fractionator's proliferation level is unavailable.", recipeId: recipe.Id);
|
|
return false;
|
|
}
|
|
|
|
var throughput = 0.0;
|
|
if (building != null)
|
|
{
|
|
if (operatingParameters == null ||
|
|
!operatingParameters.TryGetValue("CirculatingItemsPerMinute", out throughput) ||
|
|
!operatingParameters.TryGetValue("StackSize", out var stackSize) ||
|
|
!FinitePositive(throughput) || !FinitePositive(stackSize) ||
|
|
stackSize > 4 || throughput > stackSize * 30 * ProductionUnits.SecondsPerMinute + 1e-9)
|
|
{
|
|
diagnostic = new ProductionDiagnostic(ProductionDiagnosticCode.MissingOperatingParameter,
|
|
"Provide circulating items per minute and a valid stack size for the fractionator.",
|
|
recipeId: recipe.Id, buildingItemId: building.ItemId);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
var input = recipe.Inputs.Single();
|
|
var output = recipe.Outputs.Single();
|
|
var probability = Math.Min(1, output.Value / input.Value * (1 + speedBonus));
|
|
var throughputPerSecond = throughput / ProductionUnits.SecondsPerMinute;
|
|
var watts = building == null ? 0 : building.WorkingPowerWatts *
|
|
(1 + Math.Max(0, throughputPerSecond - 30) * 0.05) * powerMultiplier;
|
|
process = new ProductionProcess(recipe.Id, building?.ItemId ?? 0, mode,
|
|
mode == ProliferationMode.None ? 0 : level,
|
|
new[] { new KeyValuePair<int, double>(input.Key, probability) },
|
|
new[] { new KeyValuePair<int, double>(output.Key, probability) },
|
|
throughput, watts, building != null, throughput);
|
|
return true;
|
|
}
|
|
}
|