Compare commits

...

2 Commits

Author SHA1 Message Date
agp8x 6d778d16aa fix missing byproduct markers 2023-04-10 17:33:06 +02:00
agp8x 1e1fcba3cb improve handling of by products by excluding them 2023-04-10 11:41:55 +02:00
4 changed files with 38 additions and 29 deletions

View File

@ -10,6 +10,7 @@ import satisfactory.items.type.*;
import java.util.*; import java.util.*;
public class Database { public class Database {
public static final Item TODO_ITEM = new Ore("TODO ITEM");
// BUILDINGS // BUILDINGS
public static final class Buildings { public static final class Buildings {
public static final Building ASSEMBLER = new ProductionBuilding("Assembler", 15, assembler()); public static final Building ASSEMBLER = new ProductionBuilding("Assembler", 15, assembler());
@ -40,7 +41,7 @@ public class Database {
private static Map<Item, Integer> blender() { private static Map<Item, Integer> blender() {
Map<Item, Integer> cost = new HashMap<>(); Map<Item, Integer> cost = new HashMap<>();
cost.put(null, null); //FIXME values cost.put(TODO_ITEM, 1); //FIXME values
return cost; return cost;
} }
@ -110,7 +111,7 @@ public class Database {
private static Map<Item, Integer> minerMk3() { private static Map<Item, Integer> minerMk3() {
Map<Item, Integer> cost = new HashMap<>(); Map<Item, Integer> cost = new HashMap<>();
cost.put(Database.PortableMiner, 2); cost.put(Database.PortableMiner, 2);
cost.put(null, null); //FIXME values cost.put(TODO_ITEM, 1); //FIXME values
return cost; return cost;
} }
@ -145,7 +146,7 @@ public class Database {
private static Map<Item, Integer> resourceWellExtractor() { private static Map<Item, Integer> resourceWellExtractor() {
Map<Item, Integer> cost = new HashMap<>(); Map<Item, Integer> cost = new HashMap<>();
cost.put(null, null); // FIXME values cost.put(TODO_ITEM, 1); // FIXME values
return cost; return cost;
} }
@ -731,7 +732,7 @@ public class Database {
// TODO: duration=60/130 // TODO: duration=60/130
polymerResin.addInput(CrudeOil, 6); polymerResin.addInput(CrudeOil, 6);
polymerResin.addOutput(PolymerResin, 13); polymerResin.addOutput(PolymerResin, 13);
polymerResin.addOutput(HeavyOilResidue, 2); polymerResin.addOutput(HeavyOilResidue, 2, true);
PolymerResin.add(polymerResin); PolymerResin.add(polymerResin);
} }
{ {
@ -744,7 +745,7 @@ public class Database {
Recipe unpack = new Recipe(2, Buildings.PACKAGER); Recipe unpack = new Recipe(2, Buildings.PACKAGER);
recipe.addInput(PackagedLiquidBiofuel, 2); recipe.addInput(PackagedLiquidBiofuel, 2);
recipe.addOutput(LiquidBiofuel, 2); recipe.addOutput(LiquidBiofuel, 2);
recipe.addOutput(EmptyCanister, 2); recipe.addOutput(EmptyCanister, 2,true);
LiquidBiofuel.add(unpack); LiquidBiofuel.add(unpack);
} }
{ {
@ -755,7 +756,7 @@ public class Database {
// Plastic // Plastic
Recipe recipe = new Recipe(6, false, Buildings.REFINERY); Recipe recipe = new Recipe(6, false, Buildings.REFINERY);
recipe.addInput(CrudeOil, 3); recipe.addInput(CrudeOil, 3);
recipe.addOutput(HeavyOilResidue, 1); recipe.addOutput(HeavyOilResidue, 1, true);
Plastic.add(recipe, 2); Plastic.add(recipe, 2);
Recipe residualPlastic = new Recipe(6, "Residual Plastic", false, Buildings.REFINERY); Recipe residualPlastic = new Recipe(6, "Residual Plastic", false, Buildings.REFINERY);
residualPlastic.addInput(PolymerResin, 6); residualPlastic.addInput(PolymerResin, 6);
@ -768,7 +769,7 @@ public class Database {
// Rubber // Rubber
Recipe recipe = new Recipe(6, false, Buildings.REFINERY); Recipe recipe = new Recipe(6, false, Buildings.REFINERY);
recipe.addInput(CrudeOil, 3); recipe.addInput(CrudeOil, 3);
recipe.addOutput(HeavyOilResidue, 2); recipe.addOutput(HeavyOilResidue, 2, true);
Rubber.add(recipe, 2); Rubber.add(recipe, 2);
Recipe residualRubber = new Recipe(6, "Residual Rubber", false, Buildings.REFINERY); Recipe residualRubber = new Recipe(6, "Residual Rubber", false, Buildings.REFINERY);
residualRubber.addInput(PolymerResin, 6); residualRubber.addInput(PolymerResin, 6);
@ -825,14 +826,14 @@ public class Database {
recipe.addInput(Bauxite, 12); recipe.addInput(Bauxite, 12);
recipe.addInput(Water, 18); recipe.addInput(Water, 18);
recipe.addOutput(Silica, 5); recipe.addOutput(Silica, 5);
recipe.addOutput(AluminaSolution, 12); recipe.addOutput(AluminaSolution, 12,true);
} }
{ {
Recipe recipe = new Recipe(1, Buildings.REFINERY); Recipe recipe = new Recipe(1, Buildings.REFINERY);
recipe.addInput(AluminaSolution, 4); recipe.addInput(AluminaSolution, 4);
recipe.addInput(Coal, 2); recipe.addInput(Coal, 2);
recipe.addOutput(AluminumScrap, 6); recipe.addOutput(AluminumScrap, 6);
recipe.addOutput(Water, 2); recipe.addOutput(Water, 2,true);
} }
{ {
Recipe recipe = new Recipe(6, Buildings.REFINERY); Recipe recipe = new Recipe(6, Buildings.REFINERY);
@ -853,7 +854,7 @@ public class Database {
recipe.addInput(Concrete, 3); recipe.addInput(Concrete, 3);
recipe.addInput(SulfuricAcid, 8); recipe.addInput(SulfuricAcid, 8);
recipe.addOutput(EncasedUraniumCell, 5); recipe.addOutput(EncasedUraniumCell, 5);
recipe.addOutput(SulfuricAcid, 2); recipe.addOutput(SulfuricAcid, 2,true);
} }
{ {
Recipe recipe = new Recipe(120, Buildings.MANUFACTURER); Recipe recipe = new Recipe(120, Buildings.MANUFACTURER);
@ -868,7 +869,7 @@ public class Database {
recipe.addInput(AluminaSolution, 2); recipe.addInput(AluminaSolution, 2);
recipe.addInput(AluminumCasing, 1); recipe.addInput(AluminumCasing, 1);
recipe.addOutput(Battery, 1); recipe.addOutput(Battery, 1);
recipe.addOutput(Water, 1.5); recipe.addOutput(Water, 1.5,true);
} }
{ {
Recipe recipe = new Recipe(8, Buildings.ASSEMBLER); Recipe recipe = new Recipe(8, Buildings.ASSEMBLER);
@ -920,7 +921,7 @@ public class Database {
Recipe packaged = new Recipe(3, Buildings.PACKAGER); Recipe packaged = new Recipe(3, Buildings.PACKAGER);
recipe.addInput(PackagedTurboFuel, 2); recipe.addInput(PackagedTurboFuel, 2);
recipe.addOutput(Turbofuel, 2); recipe.addOutput(Turbofuel, 2);
recipe.addOutput(EmptyCanister, 2); recipe.addOutput(EmptyCanister, 2, true);
Turbofuel.add(packaged); Turbofuel.add(packaged);
} }
{ {

View File

@ -14,13 +14,14 @@ import java.util.stream.Collectors;
public class Recipe { public class Recipe {
private final Map<Item, Double> inputs; private final Map<Item, Double> inputs;
private final Map<Item, Double> outputs; private final Map<Item, Double> outputs;
private final Set<Item> byProducts;
private final int duration; private final int duration;
private final Building building; private final Building building;
private boolean isHandCraftable = true; private boolean isHandCraftable = true;
private String name; private String name;
public Recipe(int duration, Building building) { public Recipe(int duration, Building building) {
this(duration, new HashMap<>(), new HashMap<>(), building); this(duration, new HashMap<>(), new HashMap<>(), new HashSet<>(), building);
} }
public Recipe(int duration, boolean isHandCraftable, Building building) { public Recipe(int duration, boolean isHandCraftable, Building building) {
@ -33,10 +34,11 @@ public class Recipe {
addInput(item, input); addInput(item, input);
} }
public Recipe(int duration, Map<Item, Double> inputs, Map<Item, Double> outputs, Building building) { public Recipe(int duration, Map<Item, Double> inputs, Map<Item, Double> outputs, Set<Item> byProducts, Building building) {
this.duration = duration; this.duration = duration;
this.inputs = inputs; this.inputs = inputs;
this.outputs = outputs; this.outputs = outputs;
this.byProducts = byProducts;
this.building = building; this.building = building;
} }
@ -77,11 +79,22 @@ public class Recipe {
addInput(input, 1); addInput(input, 1);
} }
public void addOutput(Item item, int amount, boolean isByProduct) {
addOutput(item, (double) amount, isByProduct);
}
public void addOutput(Item item, int amount) { public void addOutput(Item item, int amount) {
this.outputs.put(item, (double) amount); this.outputs.put(item, (double) amount);
item.add(this, amount); item.add(this, amount);
} }
public void addOutput(Item item, double amount, boolean isByProduct) {
addOutput(item, amount);
if (isByProduct) {
byProducts.add(item);
}
}
public void addOutput(Item item, double amount) { public void addOutput(Item item, double amount) {
this.outputs.put(item, amount); this.outputs.put(item, amount);
item.add(this, amount); item.add(this, amount);
@ -123,15 +136,8 @@ public class Recipe {
return inputs; return inputs;
} }
public Map<Item, Double> getByProducts(Item reference) { public boolean isByProduct(Item test) {
if (!outputs.containsKey(reference)) { return byProducts.contains(test);
return null;
}
return outputs.entrySet().stream().filter(itemIntegerEntry -> isByProduct(reference, itemIntegerEntry.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
public boolean isByProduct(Item reference, Item test) {
return !reference.equals(test) && outputs.containsKey(reference) && outputs.containsKey(test);
} }
public Graph<Item, DefaultWeightedEdge> buildGraph(Item target) { public Graph<Item, DefaultWeightedEdge> buildGraph(Item target) {
@ -201,7 +207,7 @@ public class Recipe {
for (DefaultWeightedEdge edge : buildGraph.outgoingEdgesOf(item)) { for (DefaultWeightedEdge edge : buildGraph.outgoingEdgesOf(item)) {
Item product = buildGraph.getEdgeTarget(edge); Item product = buildGraph.getEdgeTarget(edge);
Double productWantedPerMinute = map.get(product); Double productWantedPerMinute = map.get(product);
if (item.getRecipe().outputs.containsKey(product)) { // TODO: method isByProduct if (item.getRecipe().isByProduct(product)) { // TODO: method isByProduct
// product is by-product, no forward dependency // product is by-product, no forward dependency
System.out.println("BY-PRODUCT " + item.getName() + " -> " + product.getName() + "... " + queue); System.out.println("BY-PRODUCT " + item.getName() + " -> " + product.getName() + "... " + queue);
byProducts.add(product); byProducts.add(product);
@ -247,7 +253,8 @@ public class Recipe {
public String getName() { public String getName() {
return name; return name;
} }
public String formatName(){
public String formatName() {
if (name == null) { if (name == null) {
return formatOutputs(); return formatOutputs();
} }

View File

@ -47,8 +47,7 @@ class ItemTest {
@Test @Test
void productionUraniumFuelRod(){ void productionUraniumFuelRod(){
//test(Database.UraniumFuelRod, "uranium_fuel_rod"); test(Database.UraniumFuelRod, "uranium_fuel_rod");
fail();
} }
} }

View File

@ -27,13 +27,15 @@ public class TestHelper {
} }
public static void test(Item item, String name) { public static void test(Item item, String name) {
name = "test_" + name;
Map<Item, Double> ref = ValidatedValues.get(item); Map<Item, Double> ref = ValidatedValues.get(item);
SumResult calculations = calculate(item); SumResult calculations = calculate(item);
assertMap(ref, calculations.getMap()); //plot
name = "test_" + name;
plot2(calculations.getProduction(), name); plot2(calculations.getProduction(), name);
javaPlot(name); javaPlot(name);
list(calculations, name); list(calculations, name);
// assert
assertMap(ref, calculations.getMap());
} }
private static SumResult calculate(Item item) { private static SumResult calculate(Item item) {