Skip to content

Commit 3f5b4e6

Browse files
DaleStanshpaass
authored andcommitted
fix(#272, 696fd52): Boilers respect the selected input temperature again.
When used as inputs to be boiled, fluids with multiple temperatures were treated as if they were already at their maximum temperature.
1 parent bb7b838 commit 3f5b4e6

File tree

5 files changed

+186
-1
lines changed

5 files changed

+186
-1
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
data = {
2+
raw = {
3+
recipe = {
4+
-- Recipes so Yafc will split water into the required temperatures
5+
cold_water = {
6+
type = "recipe",
7+
name = "cold_water",
8+
category = "oil-processing",
9+
energy_required = 5,
10+
results = {
11+
{
12+
type = "fluid",
13+
name = "water",
14+
amount = 50,
15+
temperature = 15,
16+
},
17+
},
18+
},
19+
warm_water = {
20+
type = "recipe",
21+
name = "warm_water",
22+
category = "oil-processing",
23+
energy_required = 5,
24+
results = {
25+
{
26+
type = "fluid",
27+
name = "water",
28+
amount = 50,
29+
temperature = 50,
30+
},
31+
},
32+
},
33+
hot_water = {
34+
type = "recipe",
35+
name = "hot_water",
36+
category = "oil-processing",
37+
energy_required = 5,
38+
results = {
39+
{
40+
type = "fluid",
41+
name = "water",
42+
amount = 50,
43+
temperature = 90,
44+
},
45+
},
46+
},
47+
},
48+
item = {
49+
coal = {
50+
type = "item",
51+
name = "coal",
52+
fuel_category = "chemical",
53+
fuel_value = "4MJ",
54+
},
55+
},
56+
fluid = {
57+
water = {
58+
type = "fluid",
59+
name = "water",
60+
default_temperature = 15,
61+
max_temperature = 1000,
62+
heat_capacity = "0.2KJ",
63+
icon = "",
64+
},
65+
steam = {
66+
type = "fluid",
67+
name = "steam",
68+
default_temperature = 15,
69+
max_temperature = 1000,
70+
heat_capacity = "0.2KJ",
71+
gas_temperature = 15,
72+
auto_barrel = False,
73+
icon = "",
74+
},
75+
},
76+
boiler = {
77+
boiler = {
78+
type = "boiler",
79+
name = "boiler",
80+
mode = "output-to-separate-pipe",
81+
target_temperature = 165,
82+
fluid_box = {
83+
filter = "water",
84+
},
85+
output_fluid_box = {
86+
filter = "steam",
87+
},
88+
energy_consumption = "1.8MW",
89+
energy_source = {
90+
type = "burner",
91+
fuel_category = "chemical",
92+
},
93+
},
94+
["heat-exchanger"] = {
95+
type = "boiler",
96+
name = "heat-exchanger",
97+
mode = "output-to-separate-pipe",
98+
target_temperature = 500,
99+
fluid_box = {
100+
filter = "water",
101+
},
102+
output_fluid_box = {
103+
filter = "steam",
104+
},
105+
energy_consumption = "10MW",
106+
energy_source = {
107+
type = "heat",
108+
max_temperature = 1000,
109+
specific_heat = "1MJ",
110+
},
111+
},
112+
},
113+
},
114+
}
115+
defines.prototypes = {
116+
entity = {
117+
boiler = 0,
118+
},
119+
item = {
120+
item = 0,
121+
},
122+
fluid = {
123+
fluid = 0,
124+
},
125+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Google.OrTools.ConstraintSolver;
7+
using Xunit;
8+
9+
namespace Yafc.Model.Tests.Model;
10+
11+
[Collection("LuaDependentTests")]
12+
public class RecipeParametersTests {
13+
[Fact]
14+
public void FluidBoilingRecipes_HaveCorrectConsumption() {
15+
Project project = LuaDependentTestHelper.GetProjectForLua();
16+
17+
ProjectPage page = new(project, typeof(ProductionTable));
18+
project.pages.Add(page);
19+
ProductionTable table = (ProductionTable)page.content;
20+
table.AddRecipe(Database.recipes.all.Single(r => r.name == "boiler.boiler.steam"), DataUtils.DeterministicComparer);
21+
table.AddRecipe(Database.recipes.all.Single(r => r.name == "boiler.heat-exchanger.steam"), DataUtils.DeterministicComparer);
22+
23+
List<Fluid> water = Database.fluidVariants["Fluid.water"];
24+
25+
RecipeRow boiler = table.recipes[0];
26+
RecipeRow heatExchanger = table.recipes[1];
27+
boiler.fixedBuildings = 1;
28+
heatExchanger.fixedBuildings = 1;
29+
table.Solve((ProjectPage)table.owner).Wait(); // Initial Solve to set RecipeRow.Ingredients
30+
31+
for (int i = 0; i < 3; i++) {
32+
boiler.ChangeVariant(boiler.Ingredients.Single().Goods, water[i]);
33+
heatExchanger.ChangeVariant(boiler.Ingredients.Single().Goods, water[i]);
34+
35+
table.Solve((ProjectPage)table.owner).Wait();
36+
37+
// boil 60, 78.26, 120 water per second from 15, 50, 90° to 165°
38+
float expectedBoilerAmount = 1800 / .2f / (165 - water[i].temperature);
39+
// boil 103.09, 111.11, 121.95 water per second from 15, 50, 90° to 500°
40+
float expectedHeatExchangerAmount = 10000 / .2f / (500 - water[i].temperature);
41+
// Equation is boiler power (KW) / heat capacity (KJ/unit°C) / temperature change (°C) => unit/s
42+
43+
Assert.Equal(.45f, boiler.FuelInformation.Amount, .45f * .0001f); // Always .45 coal per second
44+
Assert.Equal(expectedBoilerAmount, boiler.Ingredients.Single().Amount, expectedBoilerAmount * .0001f);
45+
Assert.Equal(expectedBoilerAmount, boiler.Products.Single().Amount, expectedBoilerAmount * .0001f);
46+
47+
Assert.Equal(10, heatExchanger.FuelInformation.Amount); // Always 10 MW heat
48+
Assert.Equal(expectedHeatExchangerAmount, heatExchanger.Ingredients.Single().Amount, expectedHeatExchangerAmount * .0001f);
49+
Assert.Equal(expectedHeatExchangerAmount, heatExchanger.Products.Single().Amount, expectedHeatExchangerAmount * .0001f);
50+
}
51+
}
52+
}

Yafc.Model.Tests/Yafc.Model.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
<ItemGroup>
4343
<EmbeddedResource Include="Model\ProductionTableContentTests.lua" />
44+
<EmbeddedResource Include="Model\RecipeParametersTests.FluidBoilingRecipes_HaveCorrectConsumption.lua" />
4445
<EmbeddedResource Include="Model\SelectableVariantsTests.lua" />
4546
</ItemGroup>
4647

Yafc.Model/Model/RecipeParameters.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23

34
namespace Yafc.Model {
45
[Flags]
@@ -120,7 +121,7 @@ public static RecipeParameters CalculateParameters(RecipeRow row) {
120121
var fluid = recipe.ingredients[0].goods.fluid;
121122
if (fluid != null) {
122123
float inputTemperature = fluid.temperature;
123-
foreach (Fluid variant in fluid.variants ?? []) {
124+
foreach (Fluid variant in row.variants.OfType<Fluid>()) {
124125
if (variant.originalName == fluid.originalName) {
125126
inputTemperature = variant.temperature;
126127
}

changelog.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
// Internal changes:
1616
// Changes to the code that do not affect the behavior of the program.
1717
----------------------------------------------------------------------------------------------------------------------
18+
Version: 0.9.1
19+
Date:
20+
Bugfixes:
21+
- Fix boiler recipes that accept multiple input temperatures; they respect the selected temperature again.
22+
(Note: This is specific to boilers. Factorio does not let assembly machines react to input temperatures.)
23+
----------------------------------------------------------------------------------------------------------------------
1824
Version: 0.9.0
1925
Date: September 6th 2024
2026
Features:

0 commit comments

Comments
 (0)