Merge branch 'master' of git.clkl.de:agp8x/satisfactory
commit
25b4444a73
10
build.gradle
10
build.gradle
|
|
@ -10,13 +10,13 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
|
||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
|
||||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.2'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
|
||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
|
||||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.3'
|
||||
implementation 'org.jgrapht:jgrapht-io:1.5.1'
|
||||
implementation 'guru.nidi:graphviz-java:0.18.1'
|
||||
implementation 'org.graalvm.js:js:20.0.0'
|
||||
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.13.0'
|
||||
implementation 'org.graalvm.js:js:22.1.0.1'
|
||||
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.17.2'
|
||||
}
|
||||
|
||||
test {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public class Database {
|
|||
public static final Map<Item, Recipe> preferences = new HashMap<>();
|
||||
|
||||
// Items & recipes
|
||||
public static final Item IronOre = add(new Ore("Iron Ore"));
|
||||
public static final Item IronOre = new Ore("Iron Ore");
|
||||
public static final Item IronIngot = new Ingot("Iron Ingot");
|
||||
public static final Item CopperOre = new Ore("Copper Ore");
|
||||
public static final Item CopperIngot = new Ingot("Copper Ingot");
|
||||
|
|
@ -329,10 +329,10 @@ public class Database {
|
|||
}
|
||||
{
|
||||
// Alien Protein
|
||||
AlienProtein.add(new Recipe(3,HogRemains,1, Constructor.class)); // TODO CraftBench
|
||||
AlienProtein.add(new Recipe(3,PlasmaSpitterRemains,1, Constructor.class)); // TODO CraftBench
|
||||
AlienProtein.add(new Recipe(3, StingerRemains,1, Constructor.class)); // TODO CraftBench
|
||||
AlienProtein.add(new Recipe(3,HatcherRemains,1, Constructor.class)); // TODO CraftBench
|
||||
AlienProtein.add(new Recipe(3, HogRemains, 1, Constructor.class)); // TODO CraftBench
|
||||
AlienProtein.add(new Recipe(3, PlasmaSpitterRemains, 1, Constructor.class)); // TODO CraftBench
|
||||
AlienProtein.add(new Recipe(3, StingerRemains, 1, Constructor.class)); // TODO CraftBench
|
||||
AlienProtein.add(new Recipe(3, HatcherRemains, 1, Constructor.class)); // TODO CraftBench
|
||||
}
|
||||
{
|
||||
// Fabric
|
||||
|
|
@ -341,9 +341,9 @@ public class Database {
|
|||
recipe.addInput(Biomass, 5);
|
||||
Fabric.add(recipe);
|
||||
Recipe alt = new Recipe(2, Refinery.class);
|
||||
recipe.addInput(PolymerResin,1);
|
||||
recipe.addInput(Water,1);
|
||||
recipe.addOutput(Fabric,1);
|
||||
recipe.addInput(PolymerResin, 1);
|
||||
recipe.addInput(Water, 1);
|
||||
recipe.addOutput(Fabric, 1);
|
||||
}
|
||||
{
|
||||
// Solid Biofuel
|
||||
|
|
@ -467,16 +467,16 @@ public class Database {
|
|||
{
|
||||
// Gas Nobelisk
|
||||
Recipe recipe = new Recipe(12, Assembler.class); //TODO EquipmentWorkshop
|
||||
recipe.addInput(Nobelisk,1);
|
||||
recipe.addInput(Biomass,10);
|
||||
recipe.addInput(Nobelisk, 1);
|
||||
recipe.addInput(Biomass, 10);
|
||||
recipe.addOutput(GasNobelisk, 1);
|
||||
GasNobelisk.add(recipe);
|
||||
}
|
||||
{
|
||||
// Cluster Nobelisk
|
||||
Recipe recipe = new Recipe(24, Assembler.class); //TODO EquipmentWorkshop
|
||||
recipe.addInput(Nobelisk,3);
|
||||
recipe.addInput(SmokelessPowder,4);
|
||||
recipe.addInput(Nobelisk, 3);
|
||||
recipe.addInput(SmokelessPowder, 4);
|
||||
recipe.addOutput(ClusterNobelisk, 1);
|
||||
ClusterNobelisk.add(recipe);
|
||||
|
||||
|
|
@ -485,9 +485,9 @@ public class Database {
|
|||
// NobeliskDetonator
|
||||
Recipe recipe = new Recipe(80, EquipmentWorkshop.class);
|
||||
recipe.addInput(ObjectScanner, 1);
|
||||
recipe.addInput(SteelBeam,10);
|
||||
recipe.addInput(Cable,50);
|
||||
recipe.addOutput(NobeliskDetonator,1);
|
||||
recipe.addInput(SteelBeam, 10);
|
||||
recipe.addInput(Cable, 50);
|
||||
recipe.addOutput(NobeliskDetonator, 1);
|
||||
NobeliskDetonator.add(recipe);
|
||||
}
|
||||
{
|
||||
|
|
@ -543,7 +543,7 @@ public class Database {
|
|||
Recipe unpack = new Recipe(2, Packager.class);
|
||||
recipe.addInput(PackagedLiquidBiofuel, 2);
|
||||
recipe.addOutput(LiquidBiofuel, 2);
|
||||
recipe.addOutput(EmptyCanister,2);
|
||||
recipe.addOutput(EmptyCanister, 2);
|
||||
LiquidBiofuel.add(unpack);
|
||||
}
|
||||
{
|
||||
|
|
@ -746,61 +746,61 @@ public class Database {
|
|||
{
|
||||
// Stun Rebar
|
||||
Recipe recipe = new Recipe(6, Assembler.class);//TODO , EquipmentWorkshop.class)
|
||||
recipe.addInput(IronRebar,1);
|
||||
recipe.addInput(Quickwire,5);
|
||||
recipe.addInput(IronRebar, 1);
|
||||
recipe.addInput(Quickwire, 5);
|
||||
recipe.addOutput(StunRebar, 1);
|
||||
StunRebar.add(recipe);
|
||||
}
|
||||
{
|
||||
// Explosive Rebar
|
||||
Recipe recipe = new Recipe(12, Manufacturer.class);//TODO , EquipmentWorkshop.class)
|
||||
recipe.addInput(IronRebar,1);
|
||||
recipe.addInput(SmokelessPowder,2);
|
||||
recipe.addInput(SteelPipe,2);
|
||||
recipe.addInput(IronRebar, 1);
|
||||
recipe.addInput(SmokelessPowder, 2);
|
||||
recipe.addInput(SteelPipe, 2);
|
||||
recipe.addOutput(ExplosiveRebar, 1);
|
||||
ExplosiveRebar.add(recipe);
|
||||
}
|
||||
{
|
||||
// Rebar Gun
|
||||
Recipe recipe = new Recipe(60, EquipmentWorkshop.class);
|
||||
recipe.addInput(ReinforcedIronPlate,6);
|
||||
recipe.addInput(IronRod,16);
|
||||
recipe.addInput(Screw,100);
|
||||
recipe.addInput(ReinforcedIronPlate, 6);
|
||||
recipe.addInput(IronRod, 16);
|
||||
recipe.addInput(Screw, 100);
|
||||
recipe.addOutput(RebarGun, 1);
|
||||
RebarGun.add(recipe);
|
||||
}
|
||||
{
|
||||
// Rifle Ammo
|
||||
Recipe recipe=new Recipe(12, Assembler.class);//TODO , EquipmentWorkshop.class)
|
||||
recipe.addInput(CopperSheet,3);
|
||||
Recipe recipe = new Recipe(12, Assembler.class);//TODO , EquipmentWorkshop.class)
|
||||
recipe.addInput(CopperSheet, 3);
|
||||
recipe.addInput(SmokelessPowder, 2);
|
||||
recipe.addOutput(RifleAmmo,15);
|
||||
recipe.addOutput(RifleAmmo, 15);
|
||||
RifleAmmo.add(recipe);
|
||||
}
|
||||
{
|
||||
// Homing Rifle Ammo
|
||||
Recipe recipe=new Recipe(12, Assembler.class);//TODO , EquipmentWorkshop.class)
|
||||
recipe.addInput(RifleAmmo,20);
|
||||
recipe.addInput(HighSpeedConnector,1);
|
||||
recipe.addOutput(HomingRifleAmmo,10);
|
||||
Recipe recipe = new Recipe(12, Assembler.class);//TODO , EquipmentWorkshop.class)
|
||||
recipe.addInput(RifleAmmo, 20);
|
||||
recipe.addInput(HighSpeedConnector, 1);
|
||||
recipe.addOutput(HomingRifleAmmo, 10);
|
||||
HomingRifleAmmo.add(recipe);
|
||||
}
|
||||
{
|
||||
// Rifle
|
||||
Recipe recipe=new Recipe(120, EquipmentWorkshop.class);
|
||||
recipe.addInput(Motor,2);
|
||||
recipe.addInput(Rubber,10);
|
||||
recipe.addInput(SteelPipe,25);
|
||||
recipe.addInput(Screw,250);
|
||||
recipe.addOutput(Rifle,1);
|
||||
Recipe recipe = new Recipe(120, EquipmentWorkshop.class);
|
||||
recipe.addInput(Motor, 2);
|
||||
recipe.addInput(Rubber, 10);
|
||||
recipe.addInput(SteelPipe, 25);
|
||||
recipe.addInput(Screw, 250);
|
||||
recipe.addOutput(Rifle, 1);
|
||||
Rifle.add(recipe);
|
||||
}
|
||||
{
|
||||
// Smokeless Powder
|
||||
Recipe recipe=new Recipe(6, Refinery.class);
|
||||
recipe.addInput(BlackPowder,2);
|
||||
recipe.addInput(HeavyOilResidue,1);
|
||||
recipe.addOutput(SmokelessPowder,2);
|
||||
Recipe recipe = new Recipe(6, Refinery.class);
|
||||
recipe.addInput(BlackPowder, 2);
|
||||
recipe.addInput(HeavyOilResidue, 1);
|
||||
recipe.addOutput(SmokelessPowder, 2);
|
||||
SmokelessPowder.add(recipe);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import org.jgrapht.event.ConnectedComponentTraversalEvent;
|
|||
import org.jgrapht.event.EdgeTraversalEvent;
|
||||
import org.jgrapht.event.TraversalListener;
|
||||
import org.jgrapht.event.VertexTraversalEvent;
|
||||
import org.jgrapht.graph.DefaultDirectedWeightedGraph;
|
||||
import org.jgrapht.graph.DefaultWeightedEdge;
|
||||
import org.jgrapht.graph.EdgeReversedGraph;
|
||||
import org.jgrapht.nio.Attribute;
|
||||
|
|
@ -15,11 +14,9 @@ import org.jgrapht.traverse.DepthFirstIterator;
|
|||
import org.jgrapht.traverse.GraphIterator;
|
||||
import satisfactory.items.Item;
|
||||
import satisfactory.items.ProductionEdge;
|
||||
import satisfactory.items.SumResult;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -30,7 +27,7 @@ public class Utils {
|
|||
|
||||
public static Map<Item, Integer> getRawOnly(Map<Item, Integer> totals) {
|
||||
Map<Item, Integer> raws = new HashMap<>();
|
||||
for (Item item : totals.keySet().stream().filter(Item::isRaw).collect(Collectors.toList())) {
|
||||
for (Item item : totals.keySet().stream().filter(Item::isRaw).toList()) {
|
||||
raws.put(item, totals.get(item));
|
||||
}
|
||||
return raws;
|
||||
|
|
@ -53,7 +50,7 @@ public class Utils {
|
|||
EdgeReversedGraph<Item, DefaultWeightedEdge> inverse = new EdgeReversedGraph<>(graph);
|
||||
|
||||
GraphIterator<Item, DefaultWeightedEdge> iterator = new DepthFirstIterator<>(inverse, target);
|
||||
iterator.addTraversalListener(new TraversalListener<Item, DefaultWeightedEdge>() {
|
||||
iterator.addTraversalListener(new TraversalListener<>() {
|
||||
@Override
|
||||
public void connectedComponentFinished(ConnectedComponentTraversalEvent e) {
|
||||
System.out.println("\tconnectedComponentFinished: " + e);
|
||||
|
|
@ -106,7 +103,7 @@ public class Utils {
|
|||
m.put("label", DefaultAttribute.createAttribute(label));
|
||||
return m;
|
||||
});
|
||||
de.exportGraph(sum, new File(PLOTS +filename + ".dot"));
|
||||
de.exportGraph(sum, new File(PLOTS + filename + ".dot"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import java.util.*;
|
|||
|
||||
public abstract class Item {
|
||||
protected boolean isRaw = false;
|
||||
private String name;
|
||||
private Set<Recipe> recipes;
|
||||
private final String name;
|
||||
private final Set<Recipe> recipes;
|
||||
private Recipe preference = null;
|
||||
public int sum = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ package satisfactory.items;
|
|||
|
||||
public class Production {
|
||||
private final Item item;
|
||||
private final int amount;
|
||||
private final double amount;
|
||||
|
||||
public Production(Item item, int amount) {
|
||||
public Production(Item item, double amount) {
|
||||
this.item = item;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
|
@ -13,7 +13,7 @@ public class Production {
|
|||
return item;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
public double getAmount() {
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import org.jgrapht.Graphs;
|
|||
import org.jgrapht.graph.DefaultDirectedWeightedGraph;
|
||||
import org.jgrapht.graph.DefaultWeightedEdge;
|
||||
import satisfactory.buildings.Building;
|
||||
import satisfactory.buildings.production.Assembler;
|
||||
import satisfactory.items.requirements.RateAccumulator;
|
||||
import satisfactory.items.requirements.TotalAccumulator;
|
||||
|
||||
|
|
@ -122,18 +121,19 @@ public class Recipe {
|
|||
return inputs;
|
||||
}
|
||||
|
||||
public Map<Item,Double> getByProducts(Item reference){
|
||||
if (!outputs.containsKey(reference)){
|
||||
public Map<Item, Double> getByProducts(Item reference) {
|
||||
if (!outputs.containsKey(reference)) {
|
||||
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){
|
||||
|
||||
public boolean isByProduct(Item reference, Item test) {
|
||||
return !reference.equals(test) && outputs.containsKey(reference) && outputs.containsKey(test);
|
||||
}
|
||||
|
||||
public Graph<Item, DefaultWeightedEdge> buildGraph(Item target) {
|
||||
System.out.println("buildGraph(" + target.getName() + ") @ "+ name);
|
||||
System.out.println("buildGraph(" + target.getName() + ") @ " + name);
|
||||
Graph<Item, DefaultWeightedEdge> graph = new DefaultDirectedWeightedGraph<>(DefaultWeightedEdge.class);
|
||||
graph.addVertex(target);
|
||||
target.sum += 1;
|
||||
|
|
@ -169,25 +169,25 @@ public class Recipe {
|
|||
return productWantedPerMinute / productPerProcess;
|
||||
}
|
||||
|
||||
private double getByproductRate(Item main, Item product, double production){
|
||||
private double getByproductRate(Item main, Item product, double production) {
|
||||
double runs = getRequiredProcessRuns(main, production);
|
||||
return product.getRecipe().outputs.get(product) * runs;
|
||||
}
|
||||
|
||||
public SumResult sum(Item target, int prodPerMinute) {
|
||||
public SumResult sum(Item target, double prodPerMinute) {
|
||||
Graph<Item, DefaultWeightedEdge> buildGraph = buildGraph(target);
|
||||
Graph<Item, ProductionEdge> production = new DefaultDirectedWeightedGraph<>(ProductionEdge.class);
|
||||
Map<Item, Double> map = new HashMap<>();
|
||||
Queue<Item> queue = new LinkedList<>();
|
||||
queue.add(target);
|
||||
map.put(target, (double) prodPerMinute);
|
||||
map.put(target, prodPerMinute);
|
||||
production.addVertex(target);
|
||||
production.addEdge(target, target, new ProductionEdge(target, target, prodPerMinute, processesNeeded(target, prodPerMinute)));
|
||||
Set<Item> visited = new HashSet<>();
|
||||
while (!queue.isEmpty()) {
|
||||
Item item = queue.remove();
|
||||
if (visited.contains(item)){
|
||||
System.out.println("hint: already processed " + item.getName()+ "! Skip!");
|
||||
if (visited.contains(item)) {
|
||||
System.out.println("hint: already processed " + item.getName() + "! Skip!");
|
||||
//continue;
|
||||
} else {
|
||||
// next items
|
||||
|
|
@ -205,7 +205,7 @@ public class Recipe {
|
|||
System.out.println(item.getName());
|
||||
if (item.getRecipe().outputs.containsKey(product)) { // TODO: method isByProduct
|
||||
// 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);
|
||||
continue;
|
||||
}
|
||||
|
|
@ -235,9 +235,7 @@ public class Recipe {
|
|||
}
|
||||
visited.add(item);
|
||||
}
|
||||
map.forEach((item, aDouble) -> {
|
||||
System.out.println(item.getName() + ": " + aDouble);
|
||||
});
|
||||
map.forEach((item, aDouble) -> System.out.println(item.getName() + ": " + aDouble));
|
||||
return new SumResult(production, map);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,10 +31,10 @@ public class SumResult {
|
|||
return map;
|
||||
}
|
||||
|
||||
public SumResult merge(SumResult other){
|
||||
public SumResult merge(SumResult other) {
|
||||
HashMap<Item, Double> map = new HashMap<>();
|
||||
this.map.forEach(map::put);
|
||||
other.map.forEach((item, aDouble) -> map.merge(item,aDouble,Double::sum));
|
||||
map.putAll(this.map);
|
||||
other.map.forEach((item, aDouble) -> map.merge(item, aDouble, Double::sum));
|
||||
return new SumResult(merge(production, other.getProduction()), map);
|
||||
}
|
||||
|
||||
|
|
@ -58,8 +58,7 @@ public class SumResult {
|
|||
graph1.vertexSet().forEach(result::addVertex);
|
||||
graph1.edgeSet().forEach(productionEdge -> {
|
||||
List<ProductionEdge> collect = result.edgeSet().stream()
|
||||
.filter(productionEdge1 -> productionEdge1.hasSource(productionEdge.getSource()))
|
||||
.collect(Collectors.toList());
|
||||
.filter(productionEdge1 -> productionEdge1.hasSource(productionEdge.getSource())).toList();
|
||||
collect.forEach(edge -> {
|
||||
Item src = result.getEdgeSource(edge);
|
||||
Item target = result.getEdgeTarget(edge);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import satisfactory.items.Recipe;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class Accumulator<E extends Number> implements RequirementAccumulator<E>{
|
||||
public abstract class Accumulator<E extends Number> implements RequirementAccumulator<E> {
|
||||
protected Map<Item, E> inputs;
|
||||
|
||||
public Accumulator(Map<Item, E> inputs) {
|
||||
|
|
@ -28,7 +28,7 @@ public abstract class Accumulator<E extends Number> implements RequirementAccumu
|
|||
Item i = queue.keySet().iterator().next();
|
||||
E amount = queue.remove(i);
|
||||
E newTotal = dequeue(i, amount, total);
|
||||
total.put(i,newTotal);
|
||||
total.put(i, newTotal);
|
||||
if (i.getRecipes().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -43,6 +43,6 @@ public abstract class Accumulator<E extends Number> implements RequirementAccumu
|
|||
return total;
|
||||
}
|
||||
|
||||
protected abstract Map<Item,E> getRequirements(Recipe r, Item i);// r.getTotalRequirements()
|
||||
protected abstract Map<Item, E> getRequirements(Recipe r, Item i);// r.getTotalRequirements()
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
public class RateAccumulator extends Accumulator<Double> {
|
||||
private Item item;
|
||||
private final Item item;
|
||||
|
||||
public RateAccumulator(Recipe recipe, Item item) {
|
||||
super(new HashMap<>());
|
||||
recipe.getInputs().forEach((item1, integer) -> inputs.put(item1, integer));
|
||||
inputs.putAll(recipe.getInputs());
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import satisfactory.items.Recipe;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
public class TotalAccumulator extends Accumulator<Double>{
|
||||
public class TotalAccumulator extends Accumulator<Double> {
|
||||
|
||||
public TotalAccumulator(Map<Item, Double> inputs) {
|
||||
super(inputs);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package satisfactory.items;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import satisfactory.Database;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class DatabaseTest {
|
||||
|
|
@ -9,7 +10,7 @@ public class DatabaseTest {
|
|||
void testWaterPreference() {
|
||||
Item i = Database.Water;
|
||||
assertSame(i.getPreference(), i.getRecipe());
|
||||
assertTrue(i.getPreference() == i.getRecipe());
|
||||
assertSame(i.getPreference(), i.getRecipe());
|
||||
assertTrue(i.getRecipe().toString().contains("water pump thingy"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue