Skip to content

Commit 31c9906

Browse files
authored
Non-recipe quality selection (#343)
This allows quality selection for everything except recipes, and should reflect the quality-related values everywhere they are relevant. This corresponds to tasks "Select quality of crafting entity with new GUI" through "Use quality-dependent stats for modules/beacons" and "UnlockQualityModifier in TechnologyPrototype::effects for milestone analysis" in #311.
2 parents 48cc872 + 0196bc3 commit 31c9906

31 files changed

+955
-478
lines changed

Yafc.Model.Tests/Model/ProductionTableContentTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public void ChangeFuelEntityModules_ShouldPreserveFixedAmount() {
1717
table.AddRecipe(Database.recipes.all.Single(r => r.name == "recipe"), DataUtils.DeterministicComparer);
1818
RecipeRow row = table.GetAllRecipes().Single();
1919

20-
table.modules.beacon = Database.allBeacons.Single();
21-
table.modules.beaconModule = Database.allModules.Single(m => m.name == "speed-module");
20+
table.modules.beacon = new(Database.allBeacons.Single(), Quality.Normal);
21+
table.modules.beaconModule = new(Database.allModules.Single(m => m.name == "speed-module"), Quality.Normal);
2222
table.modules.beaconsPerBuilding = 2;
2323
table.modules.autoFillPayback = MathF.Sqrt(float.MaxValue);
2424

@@ -28,7 +28,7 @@ public void ChangeFuelEntityModules_ShouldPreserveFixedAmount() {
2828
// assert will ensure the currently fixed value has not changed by more than 0.01%.
2929
static void testCombinations(RecipeRow row, ProductionTable table, Action assert) {
3030
foreach (EntityCrafter crafter in Database.allCrafters) {
31-
row.entity = crafter;
31+
row.entity = new(crafter, Quality.Normal);
3232

3333
foreach (Goods fuel in crafter.energy.fuels) {
3434
row.fuel = fuel;
@@ -37,7 +37,7 @@ static void testCombinations(RecipeRow row, ProductionTable table, Action assert
3737
ModuleTemplateBuilder builder = new();
3838

3939
if (module != null) {
40-
builder.list.Add((module, 0));
40+
builder.list.Add((new(module, Quality.Normal), 0));
4141
}
4242

4343
row.modules = builder.Build(row);
@@ -70,7 +70,7 @@ public void ChangeProductionTableModuleConfig_ShouldPreserveFixedAmount() {
7070
// Call assert for each combination. assert will ensure the currently fixed value has not changed by more than 0.01%.
7171
void testCombinations(RecipeRow row, ProductionTable table, Action assert) {
7272
foreach (EntityCrafter crafter in Database.allCrafters) {
73-
row.entity = crafter;
73+
row.entity = new(crafter, Quality.Normal);
7474

7575
foreach (Goods fuel in crafter.energy.fuels) {
7676
row.fuel = fuel;
@@ -82,14 +82,14 @@ void testCombinations(RecipeRow row, ProductionTable table, Action assert) {
8282
// Pre-emptive code for if ProductionTable.modules is made writable.
8383
// The ProductionTable.modules setter must notify all relevant recipes if it is added.
8484
_ = method.Invoke(table, [new ModuleFillerParameters(table) {
85-
beacon = beacon,
86-
beaconModule = module,
85+
beacon = new(beacon, Quality.Normal),
86+
beaconModule = new(module, Quality.Normal),
8787
beaconsPerBuilding = beaconCount,
8888
}]);
8989
}
9090
else {
91-
table.modules.beacon = beacon;
92-
table.modules.beaconModule = module;
91+
table.modules.beacon = new(beacon, Quality.Normal);
92+
table.modules.beaconModule = new(module, Quality.Normal);
9393
table.modules.beaconsPerBuilding = beaconCount;
9494
}
9595
table.Solve((ProjectPage)table.owner).Wait();
@@ -140,7 +140,7 @@ private static void RunTest(RecipeRow row, Action<RecipeRow, ProductionTable, Ac
140140

141141
// The complicated tests for when the fixed value is expected to reset when fixed fuels are involved.
142142
Action testFuel(RecipeRow row, ProductionTable table) => () => {
143-
if (row.entity.energy.fuels.Contains(oldFuel)) {
143+
if (row.entity.target.energy.fuels.Contains(oldFuel)) {
144144
Assert.Equal(fuelAmount, row.FuelInformation.Amount, fuelAmount * .0001);
145145
assertCalls++;
146146
}

Yafc.Model/Analysis/CostAnalysis.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public override void Compute(Project project, ErrorCollector warnings) {
135135
minSize = crafter.size;
136136
}
137137

138-
float power = crafter.energy.type == EntityEnergyType.Void ? 0f : recipe.time * crafter.power / (crafter.craftingSpeed * crafter.energy.effectivity);
138+
float power = crafter.energy.type == EntityEnergyType.Void ? 0f : recipe.time * crafter.basePower / (crafter.baseCraftingSpeed * crafter.energy.effectivity);
139139

140140
if (power < minPower) {
141141
minPower = power;

Yafc.Model/Blueprints/Blueprint.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,14 @@ public void Set(Goods goods) {
9898
public class BlueprintEntity {
9999
[JsonPropertyName("entity_number")] public int index { get; set; }
100100
public string? name { get; set; }
101+
public string? quality { get; set; }
101102
public BlueprintPosition position { get; set; } = new BlueprintPosition();
102103
public int direction { get; set; }
103104
public string? recipe { get; set; }
104105
[JsonPropertyName("control_behavior")] public BlueprintControlBehavior? controlBehavior { get; set; }
105106
public BlueprintConnection? connections { get; set; }
106107
[JsonPropertyName("request_filters")] public List<BlueprintRequestFilter> requestFilters { get; } = [];
107-
public Dictionary<string, int>? items { get; set; }
108+
public List<BlueprintItem> items { get; } = [];
108109

109110
public void Connect(BlueprintEntity other, bool red = true, bool secondPort = false, bool targetSecond = false) {
110111
ConnectSingle(other, red, secondPort, targetSecond);
@@ -168,3 +169,26 @@ public class BlueprintControlFilter {
168169
public int index { get; set; }
169170
public int count { get; set; }
170171
}
172+
173+
[Serializable]
174+
public class BlueprintItem {
175+
public BlueprintId id { get; } = new();
176+
public BlueprintItemInventory items { get; } = new();
177+
}
178+
179+
[Serializable]
180+
public class BlueprintId {
181+
public string? name { get; set; }
182+
public string? quality { get; set; }
183+
}
184+
185+
[Serializable]
186+
public class BlueprintItemInventory {
187+
[JsonPropertyName("in_inventory")] public List<BlueprintInventoryItem> inInventory { get; } = [];
188+
}
189+
190+
[Serializable]
191+
public class BlueprintInventoryItem {
192+
public int inventory { get; } = 4; // unknown magic number (probably 'modules', needs more investigating)
193+
public int stack { get; set; }
194+
}

0 commit comments

Comments
 (0)