mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-11-19 17:05:20 +08:00
fix(cheatenabler): keep the rare-recipe preference for belt statistics
The planner migration switched belt-signal upstream statistics to each item's standard recipe. Capture the native RecipeProto.Explicit flag in the production catalog and let the belt preset prefer explicit recipes again, which include the rare-resource alternatives such as Graphene from Fire Ice and Diamond from Kimberlite Ore. As before, explicit recipes that consume their own product (X-ray Cracking and Reforming Refine) never supply an item, and natural items stay raw. Proliferation modes now follow the selected recipe.
This commit is contained in:
1 parent
6d86e1f5dd
commit
a6225cf750
6 files changed
+51
-8
No files matched your search
@@ -69,7 +69,8 @@ public static class ProductionCatalogReader
|
||||
recipe.Results.Length != recipe.ResultCounts.Length) continue;
|
||||
|
||||
recipes.Add(new ProductionRecipe(recipe.ID, MapCategory(recipe.Type), recipe.TimeSpend, recipe.productive,
|
||||
PairFlows(recipe.Items, recipe.ItemCounts), PairFlows(recipe.Results, recipe.ResultCounts)));
|
||||
PairFlows(recipe.Items, recipe.ItemCounts), PairFlows(recipe.Results, recipe.ResultCounts),
|
||||
recipe.Explicit));
|
||||
// Follow native maincraft selection (lowest result index, then recipe order), but skip recipes such as
|
||||
// Reforming Refine that consume their own product and so cannot start its production chain.
|
||||
for (var resultIndex = 0; resultIndex < recipe.Results.Length; resultIndex++)
|
||||
|
||||
@@ -180,16 +180,20 @@ public sealed class ProductionRecipe
|
||||
public ProductionRecipeCategory Category { get; }
|
||||
public int TimeTicks { get; }
|
||||
public bool Productive { get; }
|
||||
// Native RecipeProto.Explicit, set for named recipes such as the rare-resource alternatives.
|
||||
public bool Explicit { get; }
|
||||
public IReadOnlyDictionary<int, double> Inputs { get; }
|
||||
public IReadOnlyDictionary<int, double> Outputs { get; }
|
||||
|
||||
public ProductionRecipe(int id, ProductionRecipeCategory category, int timeTicks, bool productive,
|
||||
IEnumerable<KeyValuePair<int, double>> inputs, IEnumerable<KeyValuePair<int, double>> outputs)
|
||||
IEnumerable<KeyValuePair<int, double>> inputs, IEnumerable<KeyValuePair<int, double>> outputs,
|
||||
bool explicitRecipe = false)
|
||||
{
|
||||
Id = id;
|
||||
Category = category;
|
||||
TimeTicks = timeTicks;
|
||||
Productive = productive;
|
||||
Explicit = explicitRecipe;
|
||||
Inputs = CopyFlows(inputs);
|
||||
Outputs = CopyFlows(outputs);
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ The ejector and silo assume a usable orbit or node when `LaunchAvailable = 1`; t
|
||||
|
||||
## CheatEnabler migration
|
||||
|
||||
The belt-signal generator uses `ProductionPlanner` material reports, not its former recursive ingredient table. Its caller-side preset chooses a proliferator with valid captured Proto capabilities and permits legacy natural-source boundaries only when those item IDs exist in the catalog. For each generated target unit, it records upstream gross production plus external imports, subtracts the already delivered target, and applies gross consumption independently. Each belt keeps separate fractional progress for production and consumption, while per-unit reports are cached by item, spray configuration, and catalog. `ProductionCatalogService.Changed` invalidates cached reports and refreshes existing belts; clearing the catalog drops their derived statistics without accessing unloaded factory objects. The game logic tick applies cached rates only. Signals can change inside the tick, for example when drones finish a blueprint, so a cache miss queues the belt and the planner runs from the next frame update. Request construction, calculation, and report conversion fail softly: if data is missing or calculation fails, only additional upstream statistics pause and a warning explains why; item generation and its own configured count switch remain unchanged.
|
||||
The belt-signal generator uses `ProductionPlanner` material reports, not its former recursive ingredient table. Its caller-side preset keeps the legacy recipe preference: explicit recipes, including the rare-resource alternatives, supply items first through `ProductionRecipe.Explicit`, except explicit recipes that consume their own product, such as X-ray Cracking and Reforming Refine; natural items stay raw. The preset also chooses a proliferator with valid captured Proto capabilities and permits legacy natural-source boundaries only when those item IDs exist in the catalog. For each generated target unit, it records upstream gross production plus external imports, subtracts the already delivered target, and applies gross consumption independently. Each belt keeps separate fractional progress for production and consumption, while per-unit reports are cached by item, spray configuration, and catalog. `ProductionCatalogService.Changed` invalidates cached reports and refreshes existing belts; clearing the catalog drops their derived statistics without accessing unloaded factory objects. The game logic tick applies cached rates only. Signals can change inside the tick, for example when drones finish a blueprint, so a cache miss queues the belt and the planner runs from the next frame update. Request construction, calculation, and report conversion fail softly: if data is missing or calculation fails, only additional upstream statistics pause and a warning explains why; item generation and its own configured count switch remain unchanged.
|
||||
|
||||
## Validation
|
||||
|
||||
|
||||
@@ -1086,6 +1086,28 @@ internal static class Program
|
||||
new[] { 1.0, 1.3, 1.7, 2.1, 2.5 });
|
||||
var updated = BeltSignalSourcePreset.Create(updatedCatalog, ItemIds.Steel, true, false);
|
||||
Equal(9999, updated.ProliferatorItemId, "updated game data selects a valid proliferator instead of a stale ID");
|
||||
|
||||
var alternativeCatalog = new ProductionCatalog(new[]
|
||||
{
|
||||
new ProductionItem(1, 0, true, false, 0, 0),
|
||||
new ProductionItem(2, 301, false, false, 0, 0),
|
||||
new ProductionItem(3, 303, false, false, 0, 0)
|
||||
}, new[]
|
||||
{
|
||||
Recipe(301, new[] { (1, 2.0) }, new[] { (2, 1.0) }),
|
||||
Recipe(302, new[] { (1, 1.0) }, new[] { (2, 1.0) }, explicitRecipe: true),
|
||||
Recipe(303, new[] { (2, 1.0) }, new[] { (3, 1.0) }),
|
||||
Recipe(304, new[] { (3, 2.0) }, new[] { (3, 3.0) }, explicitRecipe: true),
|
||||
Recipe(305, new[] { (2, 1.0) }, new[] { (1, 5.0) }, explicitRecipe: true)
|
||||
}, Array.Empty<ProductionBuilding>(), new[] { 0.0 }, new[] { 0.0 }, new[] { 1.0 });
|
||||
var alternative = BeltSignalSourcePreset.Create(alternativeCatalog, 3, false, false);
|
||||
Check(alternative.RecipeByItem.TryGetValue(2, out var alternativeRecipe) && alternativeRecipe == 302,
|
||||
"belt statistics keep preferring explicit alternative recipes");
|
||||
Check(!alternative.RecipeByItem.ContainsKey(3),
|
||||
"an explicit recipe that consumes its own product never supplies the item");
|
||||
Check(!alternative.RecipeByItem.ContainsKey(1), "natural items stay raw even when a recipe makes them");
|
||||
Equal(1, new ProductionPlanner(alternativeCatalog).Calculate(alternative).ItemFlows[1].ExternalImports,
|
||||
"the preferred recipe determines the raw input");
|
||||
}
|
||||
|
||||
private static void RayReceiverPowerAndPhotons()
|
||||
@@ -2385,11 +2407,11 @@ internal static class Program
|
||||
|
||||
// Synthetic recipes last 3600 ticks, so a unit-speed building completes one cycle per minute.
|
||||
private static ProductionRecipe Recipe(int id, (int id, double count)[] input,
|
||||
(int id, double count)[] output, bool productive = true)
|
||||
(int id, double count)[] output, bool productive = true, bool explicitRecipe = false)
|
||||
{
|
||||
return new ProductionRecipe(id, ProductionRecipeCategory.Assemble, 3600, productive,
|
||||
input.Select(flow => new KeyValuePair<int, double>(flow.id, flow.count)),
|
||||
output.Select(flow => new KeyValuePair<int, double>(flow.id, flow.count)));
|
||||
output.Select(flow => new KeyValuePair<int, double>(flow.id, flow.count)), explicitRecipe);
|
||||
}
|
||||
|
||||
private static void Check(bool condition, string message)
|
||||
|
||||
Reference in new issue
Block a user