Files
DSP_Mods/UXAssist/Production/MiningProcessAdapter.cs
soarqin f0773ffb9b fix(production): correct blueprint power and planner edge cases
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.
2026-10-25 22:01:05 +08:00

91 lines
4.2 KiB
C#

using System;
using System.Collections.Generic;
using static UXAssist.Production.ProductionMath;
namespace UXAssist.Production;
public sealed class MiningProcessAdapter : IProductionProcessAdapter
{
public bool CanEvaluate(ProductionRecipe recipe, ProductionBuilding building)
{
return recipe == null && building?.Kind == ProductionBuildingKind.Miner;
}
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 (building.MiningPeriodTicks <= 0 || building.MinerKind == ProductionMinerKind.None)
{
diagnostic = new ProductionDiagnostic(ProductionDiagnosticCode.UnsupportedProcess,
"The mining building has no native period or resource type.", buildingItemId: building.ItemId);
return false;
}
if (operatingParameters == null ||
!operatingParameters.TryGetValue("ResourceItemId", out var outputId) ||
!PositiveId(outputId) || !catalog.Items.ContainsKey((int)outputId) ||
!operatingParameters.TryGetValue("MiningSpeedMultiplier", out var miningSpeed) ||
!FinitePositive(miningSpeed))
{
diagnostic = new ProductionDiagnostic(ProductionDiagnosticCode.MissingOperatingParameter,
"Provide the resource item and mining technology speed.", buildingItemId: building.ItemId);
return false;
}
var resourceFactor = 1.0;
if (building.MinerKind == ProductionMinerKind.Vein &&
(!operatingParameters.TryGetValue("VeinCount", out resourceFactor) ||
resourceFactor != Math.Truncate(resourceFactor) || !FinitePositive(resourceFactor)))
{
diagnostic = new ProductionDiagnostic(ProductionDiagnosticCode.MissingOperatingParameter,
"Provide the number of covered veins.", buildingItemId: building.ItemId);
return false;
}
if (building.MinerKind == ProductionMinerKind.Oil &&
(!operatingParameters.TryGetValue("OilUnits", out resourceFactor) ||
!FinitePositive(resourceFactor)))
{
diagnostic = new ProductionDiagnostic(ProductionDiagnosticCode.MissingOperatingParameter,
"Provide the covered oil well's native flow factor.", buildingItemId: building.ItemId);
return false;
}
var machineSpeed = 1.0;
if (operatingParameters.TryGetValue("MachineSpeedFactor", out var suppliedSpeed))
{
if (!FinitePositive(suppliedSpeed))
{
diagnostic = new ProductionDiagnostic(ProductionDiagnosticCode.InvalidRequest,
"The miner speed factor must be positive.", buildingItemId: building.ItemId);
return false;
}
machineSpeed = suppliedSpeed;
}
// The native speed damper only throttles backed-up output, so full load keeps its unobstructed value of 1.
var perMinute = ProductionUnits.TicksPerMinute * ProductionUnits.FixedPointScale /
building.MiningPeriodTicks * miningSpeed * machineSpeed * resourceFactor;
var powerRatio = machineSpeed * machineSpeed;
var workingWatts = building.WorkingPowerWatts * powerRatio +
building.IdlePowerWatts * (1 - powerRatio);
if (!FinitePositive(perMinute) || !FiniteNonnegative(workingWatts))
{
diagnostic = new ProductionDiagnostic(ProductionDiagnosticCode.InvalidRequest,
"The mineral output rate or power demand is outside the supported range.",
buildingItemId: building.ItemId);
return false;
}
process = new ProductionProcess(0, building.ItemId, ProliferationMode.None, 0,
Array.Empty<KeyValuePair<int, double>>(),
new[] { new KeyValuePair<int, double>((int)outputId, 1) },
perMinute, workingWatts, true);
return true;
}
}