Skip to content

Commit d5c6c05

Browse files
committed
Bugfix/Feature: added support for catalysts (products that are not affected by productivity, ex: uranium 235 in kovarex)
1 parent 3d2140a commit d5c6c05

9 files changed

+73
-20
lines changed

Foreman/DataCache/DataCache.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private void GenerateHelperObjects()
165165

166166
HeatRecipe = new RecipePrototype(this, "§§r:h:heat-generation", "Heat Generation", energySubgroupEnergy, "1");
167167
HeatRecipe.SetIconAndColor(heatIcon);
168-
HeatRecipe.InternalOneWayAddProduct(HeatItem, 1);
168+
HeatRecipe.InternalOneWayAddProduct(HeatItem, 1, true);
169169
HeatItem.productionRecipes.Add(HeatRecipe);
170170
HeatRecipe.Time = 1;
171171

@@ -428,9 +428,9 @@ public void ProcessImportedBeaconsSet(IEnumerable<string> beaconNames)
428428
foreach (var product in recipeShort.Products)
429429
{
430430
if (items.ContainsKey(product.Key))
431-
missingRecipe.InternalOneWayAddProduct((ItemPrototype)items[product.Key], product.Value);
431+
missingRecipe.InternalOneWayAddProduct((ItemPrototype)items[product.Key], product.Value, false);
432432
else
433-
missingRecipe.InternalOneWayAddProduct((ItemPrototype)missingItems[product.Key], product.Value);
433+
missingRecipe.InternalOneWayAddProduct((ItemPrototype)missingItems[product.Key], product.Value, false);
434434
}
435435
missingRecipe.assemblers.Add(missingAssembler);
436436
missingAssembler.recipes.Add(missingRecipe);
@@ -579,9 +579,9 @@ private void ProcessRecipe(JToken objJToken, Dictionary<string, IconColorPair> i
579579
if (amount != 0)
580580
{
581581
if ((string)productJToken["type"] == "fluid")
582-
recipe.InternalOneWayAddProduct(product, amount, productJToken["temperature"] == null ? ((FluidPrototype)product).DefaultTemperature : (double)productJToken["temperature"]);
582+
recipe.InternalOneWayAddProduct(product, amount, (productJToken["catalyst"] != null && (bool)productJToken["catalyst"]), productJToken["temperature"] == null ? ((FluidPrototype)product).DefaultTemperature : (double)productJToken["temperature"]);
583583
else
584-
recipe.InternalOneWayAddProduct(product, amount);
584+
recipe.InternalOneWayAddProduct(product, amount, (productJToken["catalyst"] != null && (bool)productJToken["catalyst"]));
585585

586586
product.productionRecipes.Add(recipe);
587587
}
@@ -665,7 +665,7 @@ private void ProcessResource(JToken objJToken, Dictionary<string, List<RecipePro
665665
if (!items.ContainsKey((string)productJToken["name"]) || (double)productJToken["amount"] <= 0)
666666
continue;
667667
ItemPrototype product = (ItemPrototype)items[(string)productJToken["name"]];
668-
recipe.InternalOneWayAddProduct(product, (double)productJToken["amount"]);
668+
recipe.InternalOneWayAddProduct(product, (double)productJToken["amount"], false);
669669
product.productionRecipes.Add(recipe);
670670
}
671671

@@ -1027,7 +1027,7 @@ private bool OffshorePumpAdditionalProcessing(JToken objJToken, AssemblerPrototy
10271027
recipe.SetIconAndColor(new IconColorPair(fluid.Icon, fluid.AverageColor));
10281028
recipe.Time = 1;
10291029

1030-
recipe.InternalOneWayAddProduct(fluid, 60);
1030+
recipe.InternalOneWayAddProduct(fluid, 60, false);
10311031
fluid.productionRecipes.Add(recipe);
10321032

10331033

@@ -1086,7 +1086,7 @@ private bool OffshorePumpAdditionalProcessing(JToken objJToken, AssemblerPrototy
10861086

10871087
recipe.InternalOneWayAddIngredient(ingredient, 60);
10881088
ingredient.consumptionRecipes.Add(recipe);
1089-
recipe.InternalOneWayAddProduct(product, 60, temp);
1089+
recipe.InternalOneWayAddProduct(product, 60, true, temp);
10901090
product.productionRecipes.Add(recipe);
10911091

10921092

@@ -1301,7 +1301,7 @@ private void ProcessRocketLaunch(JToken objJToken)
13011301
}
13021302
}
13031303
foreach (ItemPrototype product in products.Keys)
1304-
recipe.InternalOneWayAddProduct(product, inputSize * products[product], productTemp.ContainsKey(product) ? productTemp[product] : double.NaN);
1304+
recipe.InternalOneWayAddProduct(product, inputSize * products[product], false, productTemp.ContainsKey(product) ? productTemp[product] : double.NaN);
13051305

13061306
recipe.InternalOneWayAddIngredient(launchItem, inputSize);
13071307
launchItem.consumptionRecipes.Add(recipe);

Foreman/DataCache/DataTypes/Recipe.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public interface Recipe : DataObjectBase
1818
IReadOnlyDictionary<Item, double> ProductSet { get; }
1919
IReadOnlyList<Item> ProductList { get; }
2020
IReadOnlyDictionary<Item, double> ProductTemperatureMap { get; }
21+
IReadOnlyCollection<Item> ProductCatalysts { get; }
2122

2223
IReadOnlyDictionary<Item, double> IngredientSet { get; }
2324
IReadOnlyList<Item> IngredientList { get; }
@@ -44,6 +45,7 @@ public class RecipePrototype : DataObjectBasePrototype, Recipe
4445
public IReadOnlyDictionary<Item, double> ProductSet { get { return productSet; } }
4546
public IReadOnlyList<Item> ProductList { get { return productList; } }
4647
public IReadOnlyDictionary<Item, double> ProductTemperatureMap { get { return productTemperatureMap; } }
48+
public IReadOnlyCollection<Item> ProductCatalysts { get { return productCatalysts; } }
4749

4850
public IReadOnlyDictionary<Item, double> IngredientSet { get { return ingredientSet; } }
4951
public IReadOnlyList<Item> IngredientList { get { return ingredientList; } }
@@ -59,6 +61,7 @@ public class RecipePrototype : DataObjectBasePrototype, Recipe
5961

6062
internal Dictionary<Item, double> productSet { get; private set; }
6163
internal Dictionary<Item, double> productTemperatureMap { get; private set; }
64+
internal HashSet<Item> productCatalysts { get; private set; }
6265
internal List<ItemPrototype> productList { get; private set; }
6366

6467
internal Dictionary<Item, double> ingredientSet { get; private set; }
@@ -93,6 +96,7 @@ public RecipePrototype(DataCache dCache, string name, string friendlyName, Subgr
9396
productSet = new Dictionary<Item, double>();
9497
productList = new List<ItemPrototype>();
9598
productTemperatureMap = new Dictionary<Item, double>();
99+
productCatalysts = new HashSet<Item>();
96100

97101
assemblers = new HashSet<AssemblerPrototype>();
98102
modules = new HashSet<ModulePrototype>();
@@ -144,7 +148,7 @@ internal void InternalOneWayDeleteIngredient(ItemPrototype item) //only from del
144148
ingredientTemperatureMap.Remove(item);
145149
}
146150

147-
public void InternalOneWayAddProduct(ItemPrototype item, double quantity, double temperature = double.NaN)
151+
public void InternalOneWayAddProduct(ItemPrototype item, double quantity, bool catalyst, double temperature = double.NaN)
148152
{
149153
if (productSet.ContainsKey(item))
150154
productSet[item] += quantity;
@@ -156,13 +160,16 @@ public void InternalOneWayAddProduct(ItemPrototype item, double quantity, double
156160
temperature = (item is Fluid fluid && double.IsNaN(temperature)) ? fluid.DefaultTemperature : temperature;
157161
productTemperatureMap.Add(item, temperature);
158162
}
163+
if (catalyst)
164+
productCatalysts.Add(item);
159165
}
160166

161167
internal void InternalOneWayDeleteProduct(ItemPrototype item) //only from delete calls
162168
{
163169
productSet.Remove(item);
164170
productList.Remove(item);
165171
productTemperatureMap.Remove(item);
172+
productCatalysts.Remove(item);
166173
}
167174

168175
public override string ToString() { return String.Format("Recipe: {0} Id:{1}", Name, RecipeID); }

Foreman/Models/Nodes/RecipeNode.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,15 @@ internal override double inputRateFor(Item item)
290290
if (item != FuelRemains)
291291
{
292292
if (SelectedAssembler.EntityType == EntityType.Reactor)
293-
return BaseRecipe.ProductSet[item] * (1 + SelectedAssembler.NeighbourBonus * NeighbourCount) * GetProductivityMultiplier();
293+
return BaseRecipe.ProductSet[item] * (1 + SelectedAssembler.NeighbourBonus * NeighbourCount) * (BaseRecipe.ProductCatalysts.Contains(item) ? 1 : GetProductivityMultiplier());
294294
else
295-
return BaseRecipe.ProductSet[item] * GetProductivityMultiplier();
295+
return BaseRecipe.ProductSet[item] * (BaseRecipe.ProductCatalysts.Contains(item) ? 1 : GetProductivityMultiplier());
296296
}
297297
else
298298
{
299299
if (SelectedAssembler == null || !SelectedAssembler.IsBurner)
300300
Trace.Fail(string.Format("input rate requested for {0} fuel while the assembler was either null or not a burner!", item));
301-
return (BaseRecipe.ProductSet.ContainsKey(item) ? BaseRecipe.ProductSet[item] * GetProductivityMultiplier() : 0) + inputRateForFuel();
301+
return (BaseRecipe.ProductSet.ContainsKey(item) ? BaseRecipe.ProductSet[item] * (BaseRecipe.ProductCatalysts.Contains(item) ? 1 : GetProductivityMultiplier()) : 0) + inputRateForFuel();
302302
}
303303
}
304304

Foreman/Mods/foremanexport_1.0.0/instrument-control - ee.lua

+11
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@ local function ExportRecipes()
114114

115115
tproduct['amount'] = amount
116116

117+
for _, ingredient in pairs(recipe.ingredients) do
118+
if ingredient.name == product.name then
119+
if product.catalyst_amount ~= nil and product.catalyst_amount >= ingredient.amount then
120+
tproduct["catalyst"] = true
121+
end
122+
if product.amount ~= nil and product.amount_min == nil and product.amount_max == nil and product.probability == nil and product.amount <= ingredient.amount then
123+
tproduct["catalyst"] = true
124+
end
125+
end
126+
end
127+
117128
if product.type == 'fluid' and product.temperature ~= nil then
118129
tproduct['temperature'] = ProcessTemperature(product.temperature)
119130
end

Foreman/Mods/foremanexport_1.0.0/instrument-control - en.lua

+11
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@ local function ExportRecipes()
114114

115115
tproduct['amount'] = amount
116116

117+
for _, ingredient in pairs(recipe.ingredients) do
118+
if ingredient.name == product.name then
119+
if product.catalyst_amount ~= nil and product.catalyst_amount >= ingredient.amount then
120+
tproduct["catalyst"] = true
121+
end
122+
if product.amount ~= nil and product.amount_min == nil and product.amount_max == nil and product.probability == nil and product.amount <= ingredient.amount then
123+
tproduct["catalyst"] = true
124+
end
125+
end
126+
end
127+
117128
if product.type == 'fluid' and product.temperature ~= nil then
118129
tproduct['temperature'] = ProcessTemperature(product.temperature)
119130
end

Foreman/Mods/foremanexport_1.0.0/instrument-control - ne.lua

+11
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@ local function ExportRecipes()
114114

115115
tproduct['amount'] = amount
116116

117+
for _, ingredient in pairs(recipe.ingredients) do
118+
if ingredient.name == product.name then
119+
if product.catalyst_amount ~= nil and product.catalyst_amount >= ingredient.amount then
120+
tproduct["catalyst"] = true
121+
end
122+
if product.amount ~= nil and product.amount_min == nil and product.amount_max == nil and product.probability == nil and product.amount <= ingredient.amount then
123+
tproduct["catalyst"] = true
124+
end
125+
end
126+
end
127+
117128
if product.type == 'fluid' and product.temperature ~= nil then
118129
tproduct['temperature'] = ProcessTemperature(product.temperature)
119130
end

Foreman/Mods/foremanexport_1.0.0/instrument-control - nn.lua

+11
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@ local function ExportRecipes()
114114

115115
tproduct['amount'] = amount
116116

117+
for _, ingredient in pairs(recipe.ingredients) do
118+
if ingredient.name == product.name then
119+
if product.catalyst_amount ~= nil and product.catalyst_amount >= ingredient.amount then
120+
tproduct["catalyst"] = true
121+
end
122+
if product.amount ~= nil and product.amount_min == nil and product.amount_max == nil and product.probability == nil and product.amount <= ingredient.amount then
123+
tproduct["catalyst"] = true
124+
end
125+
end
126+
end
127+
117128
if product.type == 'fluid' and product.temperature ~= nil then
118129
tproduct['temperature'] = ProcessTemperature(product.temperature)
119130
end

Foreman/Presets/Factorio 1.1 Vanilla.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
{
1212
"name": "base",
13-
"version": "1.1.45"
13+
"version": "1.1.46"
1414
},
1515
{
1616
"name": "foremanexport",
@@ -6604,7 +6604,8 @@
66046604
{
66056605
"name": "heavy-oil",
66066606
"type": "fluid",
6607-
"amount": 90
6607+
"amount": 90,
6608+
"catalyst": true
66086609
},
66096610
{
66106611
"name": "light-oil",
@@ -12624,7 +12625,8 @@
1262412625
{
1262512626
"name": "uranium-235",
1262612627
"type": "item",
12627-
"amount": 41
12628+
"amount": 41,
12629+
"catalyst": true
1262812630
},
1262912631
{
1263012632
"name": "uranium-238",

Foreman/Program.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -195,22 +195,22 @@ static void test4()
195195
RecipePrototype a = new RecipePrototype(null, "a", "a", sg, "-");
196196
a.InternalOneWayAddIngredient(i1, 1);
197197
a.InternalOneWayAddIngredient(i2, 1);
198-
a.InternalOneWayAddProduct(i5, 1);
198+
a.InternalOneWayAddProduct(i5, 1, false);
199199

200200
RecipePrototype b = new RecipePrototype(null, "a", "a", sg, "-");
201201
b.InternalOneWayAddIngredient(i1, 1);
202202
b.InternalOneWayAddIngredient(i2, 1);
203-
b.InternalOneWayAddProduct(i5, 1);
203+
b.InternalOneWayAddProduct(i5, 1, false);
204204

205205
RecipePrototype c = new RecipePrototype(null, "a", "a", sg, "-");
206206
c.InternalOneWayAddIngredient(i1, 10);
207207
c.InternalOneWayAddIngredient(i2, 10);
208-
c.InternalOneWayAddProduct(i5, 1);
208+
c.InternalOneWayAddProduct(i5, 1, false);
209209

210210
RecipePrototype d = new RecipePrototype(null, "a", "a", sg, "-");
211211
d.InternalOneWayAddIngredient(i3, 1);
212212
d.InternalOneWayAddIngredient(i4, 1);
213-
d.InternalOneWayAddProduct(i5, 1);
213+
d.InternalOneWayAddProduct(i5, 1, false);
214214

215215
HashSet<Recipe> recipes = new HashSet<Recipe>();
216216
HashSet<Recipe> missingRecipes = new HashSet<Recipe>(new RecipeNaInPrComparer());

0 commit comments

Comments
 (0)