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:
soarqin committed 2026-10-25 22:01:05 +08:00
1 parent 6d86e1f5dd
commit a6225cf750
6 files changed
+51 -8

No files matched your search

+2 -2
View File
@@ -4,7 +4,7 @@
## Changlog
* 2.4.8 - Unreleased
* `Belt signal item generation`: Calculate raw-material, intermediate, and proliferator statistics from the game's current recipe data, using each item's standard recipe and counting by-products and consumption separately. If an item's recipe data is incomplete, only its upstream statistics pause, with the reason logged; item generation is unaffected.
* `Belt signal item generation`: Calculate raw-material, intermediate, and proliferator statistics from the game's current recipe data, counting by-products and consumption separately. If an item's recipe data is incomplete, only its upstream statistics pause, with the reason logged; item generation is unaffected.
* 2.4.7
* `Dev Shortcuts`: Work immediately when enabled after loading a save, and process each key press once per frame at accelerated game speeds.
* Extend `Unlock Tech with Key-Modifiers` with a downgrade mode.
@@ -204,7 +204,7 @@
## 更新日志
* 2.4.8 - Unreleased
* `传送带信号物品生成`:原料、中间产物和增产剂的统计改为按游戏当前配方数据计算,采用各物品的标准配方,并分别计入副产物和消耗。某物品的配方数据不完整时,仅暂停该物品的上游统计并在日志中说明原因,不影响物品生成。
* `传送带信号物品生成`:原料、中间产物和增产剂的统计改为按游戏当前配方数据计算,并分别计入副产物和消耗。某物品的配方数据不完整时,仅暂停该物品的上游统计并在日志中说明原因,不影响物品生成。
* 2.4.7
* `开发模式快捷键`:修复载入存档后启用时不生效的问题;加速游戏时每次按键仍只执行一次。
* `使用组合键点击解锁科技` 新增降级模式。
@@ -113,11 +113,27 @@ internal static class BeltSignalSourcePreset
if (catalog.Items.ContainsKey(externalItemId)) request.ExternalMaterials.Add(externalItemId);
}
// Keep the legacy preference for explicit recipes, which include the rare-resource alternatives. Explicit
// recipes that consume their own product, X-ray Cracking and Reforming Refine, never supply an item.
foreach (var recipe in catalog.Recipes.Values
.Where(recipe => recipe.Explicit && !recipe.Outputs.Keys.Any(recipe.Inputs.ContainsKey))
.OrderBy(recipe => recipe.Id))
{
foreach (var outputId in recipe.Outputs.Keys)
{
if (request.RecipeByItem.ContainsKey(outputId) || request.ExternalMaterials.Contains(outputId) ||
!catalog.Items.TryGetValue(outputId, out var output) || output.IsNatural) continue;
request.RecipeByItem[outputId] = recipe.Id;
}
}
if (!useProliferator) return request;
if (sprayDeliveredItem) request.SprayDeliveredItems.Add(itemId);
foreach (var item in catalog.Items.Values)
{
if (!catalog.Recipes.TryGetValue(item.DefaultRecipeId, out var recipe) ||
var recipeId = request.RecipeByItem.TryGetValue(item.Id, out var selectedRecipeId)
? selectedRecipeId : item.DefaultRecipeId;
if (!catalog.Recipes.TryGetValue(recipeId, out var recipe) ||
!recipe.Outputs.ContainsKey(item.Id) || recipe.Inputs.Count == 0) continue;
request.ProliferationModeByItem[item.Id] = ItemIds.NoProliferationItemIds.Contains(item.Id)
? ProliferationMode.None
@@ -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++)
+5 -1
View File
@@ -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);
}
+1 -1
View File
@@ -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
+24 -2
View File
@@ -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)