Files
DSP_Mods/UXAssist/Production/FuelGenerationAdapter.cs
T
soarqin d941de2810 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 15:24:38 +08:00

92 lines
4.2 KiB
C#

using System;
using System.Collections.Generic;
using static UXAssist.Production.ProductionMath;
namespace UXAssist.Production;
public sealed class FuelGenerationAdapter : IProductionProcessAdapter
{
public bool CanEvaluate(ProductionRecipe recipe, ProductionBuilding building)
{
return recipe == null && building?.Kind == ProductionBuildingKind.FuelGenerator;
}
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 (operatingParameters == null ||
!operatingParameters.TryGetValue("FuelItemId", out var fuelId) || !PositiveId(fuelId) ||
!catalog.Items.TryGetValue((int)fuelId, out var fuel) ||
fuel.HeatValueJoules <= 0 || (fuel.FuelTypeMask & building.FuelMask) == 0)
{
diagnostic = new ProductionDiagnostic(ProductionDiagnosticCode.MissingOperatingParameter,
"Select a fuel item compatible with the generator's native fuel mask.",
buildingItemId: building.ItemId);
return false;
}
if (mode != ProliferationMode.None && mode != ProliferationMode.Speedup &&
mode != ProliferationMode.ExtraProducts ||
mode == ProliferationMode.ExtraProducts && !fuel.ProductiveFuel)
{
diagnostic = new ProductionDiagnostic(ProductionDiagnosticCode.UnsupportedProliferation,
"The fuel cannot use the requested proliferation mode.", buildingItemId: building.ItemId);
return false;
}
if (!FinitePositive(building.FuelUseWatts) || !FinitePositive(building.RatedGenerationWatts))
{
diagnostic = new ProductionDiagnostic(ProductionDiagnosticCode.UnsupportedProcess,
"The generator's fuel consumption or power rating is unavailable.",
buildingItemId: building.ItemId);
return false;
}
var speedBonus = 0.0;
var extraBonus = 0.0;
if (mode != ProliferationMode.None &&
(level <= 0 || !catalog.TryGetProliferation(level, out speedBonus, out extraBonus, out _)))
{
diagnostic = new ProductionDiagnostic(ProductionDiagnosticCode.UnsupportedProliferation,
"The fuel's proliferation level is unavailable.", buildingItemId: building.ItemId);
return false;
}
var boostFactor = 1.0;
var boostModeKey = SandboxBoost.ModeKey(building);
if (boostModeKey != null)
{
if (!SandboxBoost.TryResolve(operatingParameters, boostModeKey, building.ItemId, out var boosted,
out diagnostic))
return false;
// Artificial stars apply the sandbox boost and the strange annihilation fuel multiplier natively.
boostFactor = (boosted ? 100 : 1) * fuel.StarOutputMultiplier;
}
var proliferationFactor = mode == ProliferationMode.None ? 1 :
fuel.ProductiveFuel ? 1 + extraBonus : 1 + speedBonus;
var generation = building.RatedGenerationWatts * proliferationFactor * boostFactor;
var burnedFuel = building.FuelUseWatts * (fuel.ProductiveFuel ? 1 : proliferationFactor) *
boostFactor * 60 / fuel.HeatValueJoules;
if (!Finite(generation) || !FinitePositive(burnedFuel))
{
diagnostic = new ProductionDiagnostic(ProductionDiagnosticCode.InvalidRequest,
"The selected fuel produces an invalid generation rate.", buildingItemId: building.ItemId);
return false;
}
process = new ProductionProcess(0, building.ItemId,
mode == ProliferationMode.None ? mode : fuel.ProductiveFuel
? ProliferationMode.ExtraProducts : ProliferationMode.Speedup,
mode == ProliferationMode.None ? 0 : level,
new[] { new KeyValuePair<int, double>(fuel.Id, 1) },
Array.Empty<KeyValuePair<int, double>>(), burnedFuel,
building.WorkingPowerWatts, true, generationWatts: generation);
return true;
}
}