add rate
parent
5343d26b12
commit
992dd8a409
|
|
@ -1,15 +1,17 @@
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
|
import items.Database;
|
||||||
import items.Item;
|
import items.Item;
|
||||||
import items.Recipe;
|
import items.Recipe;
|
||||||
|
import items.Utils;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class Test {
|
public class Test {
|
||||||
public static void main(String[] args) throws JsonProcessingException {
|
public static void main(String[] args) throws JsonProcessingException {
|
||||||
//System.out.println(Database.AdaptiveControlUnit);
|
//System.out.println(items.Database.AdaptiveControlUnit);
|
||||||
Map<Item, Integer> totalRequirements = Database.HeavyModularFrame.getRecipes().stream().findFirst().get().getTotalRequirements();
|
Map<Item, Integer> totalRequirements = Database.HeavyModularFrame.getRecipe().getTotalRequirements();
|
||||||
System.out.println(totalRequirements);
|
System.out.println(totalRequirements);
|
||||||
|
|
||||||
ObjectMapper om = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
|
ObjectMapper om = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
|
||||||
|
|
@ -17,12 +19,22 @@ public class Test {
|
||||||
String json = om.writeValueAsString(totalRequirements);
|
String json = om.writeValueAsString(totalRequirements);
|
||||||
System.out.println(json);
|
System.out.println(json);
|
||||||
|
|
||||||
Map<Item, Integer> rawOnly = Database.HeavyModularFrame.getRecipes().iterator().next().getRawOnly();
|
Map<Item, Integer> rawOnly = Utils.getRawOnly(Database.HeavyModularFrame.getRecipe().getTotalRequirements());
|
||||||
String json2 = om.writeValueAsString(rawOnly);
|
String json2 = om.writeValueAsString(rawOnly);
|
||||||
|
|
||||||
String json3 = om.writeValueAsString(Recipe.getInputs(rawOnly));
|
String json3 = om.writeValueAsString(Recipe.getInputs(rawOnly));
|
||||||
System.out.println(json2);
|
System.out.println(json2);
|
||||||
System.out.println(json3);
|
System.out.println(json3);
|
||||||
System.out.println(om.writeValueAsString(Database.AdaptiveControlUnit.getRecipes().iterator().next().getRawOnly()));
|
System.out.println(om.writeValueAsString(Utils.getRawOnly(Database.AdaptiveControlUnit.getRecipe().getTotalRequirements())));
|
||||||
|
System.out.println(om.writeValueAsString(Database.AdaptiveControlUnit.getRecipe().getTotalRequirements()));
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
System.out.println(om.writeValueAsString(Database.AdaptiveControlUnit));
|
||||||
|
System.out.println(Database.AdaptiveControlUnit.getProductionRate());
|
||||||
|
System.out.println("total requirements for ACU");
|
||||||
|
System.out.println(om.writeValueAsString(Utils.shorten(Database.AdaptiveControlUnit.getRecipe().getTotalRequirements())));
|
||||||
|
//System.out.println(Database.AdaptiveControlUnit.getRecipe().getRequirementRates(Database.AdaptiveControlUnit));
|
||||||
|
System.out.println("requirement rate for ACU");
|
||||||
|
System.out.println(om.writeValueAsString(Utils.shorten(Database.AdaptiveControlUnit.getRecipe().getRequirementRates(Database.AdaptiveControlUnit))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,15 @@
|
||||||
import items.Item;
|
package items;
|
||||||
import items.Recipe;
|
|
||||||
import items.type.*;
|
import items.type.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
public class Database {
|
public class Database {
|
||||||
|
// dirty!
|
||||||
|
private static final Collection<Item> items = new HashSet<>();
|
||||||
|
public static final Map<Item, Recipe> preferences = new HashMap<>();
|
||||||
|
|
||||||
|
// Items & recipes
|
||||||
public static final Item IronOre = new Ore("Iron Ore");
|
public static final Item IronOre = new Ore("Iron Ore");
|
||||||
public static final Item IronIngot = new Ingot("Iron Ingot", new Recipe(2, IronOre, 1));
|
public static final Item IronIngot = new Ingot("Iron Ingot", new Recipe(2, IronOre, 1));
|
||||||
public static final Item CopperOre = new Ore("Copper Ore");
|
public static final Item CopperOre = new Ore("Copper Ore");
|
||||||
|
|
@ -73,19 +80,37 @@ public class Database {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
{
|
{
|
||||||
|
Set<Item> ores = new HashSet<>(Arrays.asList(IronOre, Coal, Limestone, CopperOre, CateriumOre, Sulfur));
|
||||||
|
for (Item ore : ores) {
|
||||||
|
Recipe mk1 = new Recipe(1, "Miner MK 1", false);
|
||||||
|
ore.add(mk1, 1);
|
||||||
|
Recipe mk2 = new Recipe(1, "Miner MK2", false);
|
||||||
|
ore.add(mk2, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<Item> rawFluids = new HashSet<>(Arrays.asList(CrudeOil, Water));
|
||||||
|
// no common well yet
|
||||||
|
CrudeOil.add(new Recipe(1, "Oil extracting thingy", false), 2);
|
||||||
|
Water.add(new Recipe(1, "water pump thingy", false), 2);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// Steel Ingot
|
||||||
Recipe recipe = new Recipe(4);
|
Recipe recipe = new Recipe(4);
|
||||||
recipe.addInput(IronOre, 3);
|
recipe.addInput(IronOre, 3);
|
||||||
recipe.addInput(Coal, 3);
|
recipe.addInput(Coal, 3);
|
||||||
SteelIngot.add(recipe, 3);
|
SteelIngot.add(recipe, 3);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Iron Plate
|
||||||
Recipe recipe = new Recipe(6, IronIngot, 3);
|
Recipe recipe = new Recipe(6, IronIngot, 3);
|
||||||
IronPlate.add(recipe, 2);
|
IronPlate.add(recipe, 2);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Screw
|
||||||
Screw.add(new Recipe(6, IronRod, 1), 4);
|
Screw.add(new Recipe(6, IronRod, 1), 4);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Reinforced Iron Plate
|
||||||
Recipe recipe = new Recipe(12);
|
Recipe recipe = new Recipe(12);
|
||||||
recipe.addInput(IronPlate, 6);
|
recipe.addInput(IronPlate, 6);
|
||||||
recipe.addInput(Screw, 12);
|
recipe.addInput(Screw, 12);
|
||||||
|
|
@ -94,25 +119,31 @@ public class Database {
|
||||||
bolted.addInput(IronPlate, 18);
|
bolted.addInput(IronPlate, 18);
|
||||||
bolted.addInput(Screw, 50);
|
bolted.addInput(Screw, 50);
|
||||||
ReinforcedIronPlate.add(bolted, 3);
|
ReinforcedIronPlate.add(bolted, 3);
|
||||||
|
|
||||||
|
ReinforcedIronPlate.setPreference(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Modular Frame
|
||||||
Recipe recipe = new Recipe(60);
|
Recipe recipe = new Recipe(60);
|
||||||
recipe.addInput(ReinforcedIronPlate, 3);
|
recipe.addInput(ReinforcedIronPlate, 3);
|
||||||
recipe.addInput(IronRod, 12);
|
recipe.addInput(IronRod, 12);
|
||||||
ModularFrame.add(recipe, 2);
|
ModularFrame.add(recipe, 2);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Steel Pipe
|
||||||
Recipe recipe = new Recipe(6);
|
Recipe recipe = new Recipe(6);
|
||||||
recipe.addInput(SteelIngot, 3);
|
recipe.addInput(SteelIngot, 3);
|
||||||
SteelPipe.add(recipe, 2);
|
SteelPipe.add(recipe, 2);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Encased Industrial Beam
|
||||||
Recipe recipe = new Recipe(10);
|
Recipe recipe = new Recipe(10);
|
||||||
recipe.addInput(SteelBeam, 4);
|
recipe.addInput(SteelBeam, 4);
|
||||||
recipe.addInput(Concrete, 5);
|
recipe.addInput(Concrete, 5);
|
||||||
EncasedIndustrialBeam.add(recipe);
|
EncasedIndustrialBeam.add(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Heavy Modular Frame
|
||||||
Recipe recipe = new Recipe(30);
|
Recipe recipe = new Recipe(30);
|
||||||
recipe.addInput(ModularFrame, 5);
|
recipe.addInput(ModularFrame, 5);
|
||||||
recipe.addInput(SteelPipe, 15);
|
recipe.addInput(SteelPipe, 15);
|
||||||
|
|
@ -121,24 +152,29 @@ public class Database {
|
||||||
HeavyModularFrame.add(recipe);
|
HeavyModularFrame.add(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Wire
|
||||||
Wire.add(new Recipe(4, CopperIngot, 1), 2);
|
Wire.add(new Recipe(4, CopperIngot, 1), 2);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Quickwire
|
||||||
Quickwire.add(new Recipe(5, CateriumIngot, 1), 5);
|
Quickwire.add(new Recipe(5, CateriumIngot, 1), 5);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Circuit Board
|
||||||
Recipe recipe = new Recipe(8);
|
Recipe recipe = new Recipe(8);
|
||||||
recipe.addInput(CopperSheet, 2);
|
recipe.addInput(CopperSheet, 2);
|
||||||
recipe.addInput(Plastic, 4);
|
recipe.addInput(Plastic, 4);
|
||||||
CircuitBoard.add(recipe);
|
CircuitBoard.add(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// A.I. Limiter
|
||||||
Recipe recipe = new Recipe(12);
|
Recipe recipe = new Recipe(12);
|
||||||
recipe.addInput(CopperSheet, 5);
|
recipe.addInput(CopperSheet, 5);
|
||||||
recipe.addInput(Quickwire, 20);
|
recipe.addInput(Quickwire, 20);
|
||||||
AILimiter.add(recipe);
|
AILimiter.add(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// High Speed Connector
|
||||||
Recipe recipe = new Recipe(16);
|
Recipe recipe = new Recipe(16);
|
||||||
recipe.addInput(Quickwire, 56);
|
recipe.addInput(Quickwire, 56);
|
||||||
recipe.addInput(Cable, 10);
|
recipe.addInput(Cable, 10);
|
||||||
|
|
@ -146,6 +182,7 @@ public class Database {
|
||||||
HighSpeedConnector.add(recipe);
|
HighSpeedConnector.add(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Biomass
|
||||||
Biomass.add(new Recipe(5, Leaves, 10), 5);
|
Biomass.add(new Recipe(5, Leaves, 10), 5);
|
||||||
Biomass.add(new Recipe(4, Wood, 4), 20);
|
Biomass.add(new Recipe(4, Wood, 4), 20);
|
||||||
Biomass.add(new Recipe(4, Mycelia, 10), 10);
|
Biomass.add(new Recipe(4, Mycelia, 10), 10);
|
||||||
|
|
@ -153,47 +190,56 @@ public class Database {
|
||||||
Biomass.add(new Recipe(8, AlienOrgans, 1), 200);
|
Biomass.add(new Recipe(8, AlienOrgans, 1), 200);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Fabric
|
||||||
Recipe recipe = new Recipe(4);
|
Recipe recipe = new Recipe(4);
|
||||||
recipe.addInput(Mycelia);
|
recipe.addInput(Mycelia);
|
||||||
recipe.addInput(Biomass, 5);
|
recipe.addInput(Biomass, 5);
|
||||||
Fabric.add(recipe);
|
Fabric.add(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Solid Biofuel
|
||||||
SolidBiofuel.add(new Recipe(4, Biomass, 8), 4);
|
SolidBiofuel.add(new Recipe(4, Biomass, 8), 4);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Rotator
|
||||||
Recipe recipe = new Recipe(15);
|
Recipe recipe = new Recipe(15);
|
||||||
recipe.addInput(IronRod, 5);
|
recipe.addInput(IronRod, 5);
|
||||||
recipe.addInput(Screw, 25);
|
recipe.addInput(Screw, 25);
|
||||||
Rotor.add(recipe);
|
Rotor.add(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Stator
|
||||||
Recipe recipe = new Recipe(12);
|
Recipe recipe = new Recipe(12);
|
||||||
recipe.addInput(SteelPipe, 3);
|
recipe.addInput(SteelPipe, 3);
|
||||||
recipe.addInput(Wire, 8);
|
recipe.addInput(Wire, 8);
|
||||||
Stator.add(recipe);
|
Stator.add(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Motor
|
||||||
Recipe recipe = new Recipe(12);
|
Recipe recipe = new Recipe(12);
|
||||||
recipe.addInput(Rotor, 2);
|
recipe.addInput(Rotor, 2);
|
||||||
recipe.addInput(Stator, 2);
|
recipe.addInput(Stator, 2);
|
||||||
Motor.add(recipe);
|
Motor.add(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Power Shard
|
||||||
PowerShard.add(new Recipe(8, GreenPowerSlug, 1));
|
PowerShard.add(new Recipe(8, GreenPowerSlug, 1));
|
||||||
PowerShard.add(new Recipe(12, YellowPowerSlug, 1), 2);
|
PowerShard.add(new Recipe(12, YellowPowerSlug, 1), 2);
|
||||||
PowerShard.add(new Recipe(24, PurplePowerSlug, 1), 5);
|
PowerShard.add(new Recipe(24, PurplePowerSlug, 1), 5);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Black Powder
|
||||||
Recipe recipe = new Recipe(8);
|
Recipe recipe = new Recipe(8);
|
||||||
recipe.addInput(Coal);
|
recipe.addInput(Coal);
|
||||||
recipe.addInput(Sulfur, 2);
|
recipe.addInput(Sulfur, 2);
|
||||||
BlackPowder.add(recipe);
|
BlackPowder.add(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Color Catridge
|
||||||
ColorCatridge.add(new Recipe(8, FlowerPetals, 5), 10);
|
ColorCatridge.add(new Recipe(8, FlowerPetals, 5), 10);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Rifle Catridge
|
||||||
Recipe recipe = new Recipe(20);
|
Recipe recipe = new Recipe(20);
|
||||||
recipe.addInput(Beacon, 1);
|
recipe.addInput(Beacon, 1);
|
||||||
recipe.addInput(SteelPipe, 10);
|
recipe.addInput(SteelPipe, 10);
|
||||||
|
|
@ -202,6 +248,7 @@ public class Database {
|
||||||
RifleCatridge.add(recipe, 5);
|
RifleCatridge.add(recipe, 5);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Gas Filter
|
||||||
Recipe recipe = new Recipe(8);
|
Recipe recipe = new Recipe(8);
|
||||||
recipe.addInput(Coal, 5);
|
recipe.addInput(Coal, 5);
|
||||||
recipe.addInput(Rubber, 2);
|
recipe.addInput(Rubber, 2);
|
||||||
|
|
@ -209,6 +256,7 @@ public class Database {
|
||||||
GasFilter.add(recipe);
|
GasFilter.add(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Computer
|
||||||
Recipe recipe = new Recipe(24);
|
Recipe recipe = new Recipe(24);
|
||||||
recipe.addInput(CircuitBoard, 10);
|
recipe.addInput(CircuitBoard, 10);
|
||||||
recipe.addInput(Cable, 9);
|
recipe.addInput(Cable, 9);
|
||||||
|
|
@ -220,8 +268,11 @@ public class Database {
|
||||||
alternative.addInput(Quickwire, 28);
|
alternative.addInput(Quickwire, 28);
|
||||||
alternative.addInput(Rubber, 12);
|
alternative.addInput(Rubber, 12);
|
||||||
Computer.add(alternative);
|
Computer.add(alternative);
|
||||||
|
|
||||||
|
Computer.setPreference(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Super Computer
|
||||||
Recipe recipe = new Recipe(32);
|
Recipe recipe = new Recipe(32);
|
||||||
recipe.addInput(Computer, 2);
|
recipe.addInput(Computer, 2);
|
||||||
recipe.addInput(AILimiter, 2);
|
recipe.addInput(AILimiter, 2);
|
||||||
|
|
@ -230,9 +281,11 @@ public class Database {
|
||||||
SuperComputer.add(recipe);
|
SuperComputer.add(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Empty Canister
|
||||||
EmptyCanister.add(new Recipe(4, Plastic, 2), 4);
|
EmptyCanister.add(new Recipe(4, Plastic, 2), 4);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Beacon
|
||||||
Recipe recipe = new Recipe(8);
|
Recipe recipe = new Recipe(8);
|
||||||
recipe.addInput(IronPlate, 3);
|
recipe.addInput(IronPlate, 3);
|
||||||
recipe.addInput(IronRod);
|
recipe.addInput(IronRod);
|
||||||
|
|
@ -241,6 +294,7 @@ public class Database {
|
||||||
Beacon.add(recipe);
|
Beacon.add(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Modular Engine
|
||||||
Recipe recipe = new Recipe(60, false);
|
Recipe recipe = new Recipe(60, false);
|
||||||
recipe.addInput(Motor, 2);
|
recipe.addInput(Motor, 2);
|
||||||
recipe.addInput(Rubber, 15);
|
recipe.addInput(Rubber, 15);
|
||||||
|
|
@ -248,6 +302,7 @@ public class Database {
|
||||||
ModularEngine.add(recipe);
|
ModularEngine.add(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Adaptive Control Unit
|
||||||
Recipe recipe = new Recipe(120, false);
|
Recipe recipe = new Recipe(120, false);
|
||||||
recipe.addInput(AutomatedWiring, 15);
|
recipe.addInput(AutomatedWiring, 15);
|
||||||
recipe.addInput(CircuitBoard, 10);
|
recipe.addInput(CircuitBoard, 10);
|
||||||
|
|
@ -256,30 +311,35 @@ public class Database {
|
||||||
AdaptiveControlUnit.add(recipe);
|
AdaptiveControlUnit.add(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Nobelisk
|
||||||
Recipe recipe = new Recipe(20, false);
|
Recipe recipe = new Recipe(20, false);
|
||||||
recipe.addInput(BlackPowder, 5);
|
recipe.addInput(BlackPowder, 5);
|
||||||
recipe.addInput(SteelPipe, 10);
|
recipe.addInput(SteelPipe, 10);
|
||||||
Nobelisk.add(recipe);
|
Nobelisk.add(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Smart Plating
|
||||||
Recipe recipe = new Recipe(30, false);
|
Recipe recipe = new Recipe(30, false);
|
||||||
recipe.addInput(ReinforcedIronPlate);
|
recipe.addInput(ReinforcedIronPlate);
|
||||||
recipe.addInput(Rotor);
|
recipe.addInput(Rotor);
|
||||||
SmartPlating.add(recipe);
|
SmartPlating.add(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Automated Wiring
|
||||||
Recipe recipe = new Recipe(24, false);
|
Recipe recipe = new Recipe(24, false);
|
||||||
recipe.addInput(Stator);
|
recipe.addInput(Stator);
|
||||||
recipe.addInput(Cable, 20);
|
recipe.addInput(Cable, 20);
|
||||||
AutomatedWiring.add(recipe);
|
AutomatedWiring.add(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Versatile Framework
|
||||||
Recipe recipe = new Recipe(24, false);
|
Recipe recipe = new Recipe(24, false);
|
||||||
recipe.addInput(ModularFrame);
|
recipe.addInput(ModularFrame);
|
||||||
recipe.addInput(SteelBeam, 12);
|
recipe.addInput(SteelBeam, 12);
|
||||||
VersatileFrameWork.add(recipe, 2);
|
VersatileFrameWork.add(recipe, 2);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Fuel
|
||||||
Recipe residualFuel = new Recipe(6, "Residual Fuel", false);
|
Recipe residualFuel = new Recipe(6, "Residual Fuel", false);
|
||||||
residualFuel.addInput(HeavyOilResidue, 6);
|
residualFuel.addInput(HeavyOilResidue, 6);
|
||||||
Fuel.add(residualFuel, 4);
|
Fuel.add(residualFuel, 4);
|
||||||
|
|
@ -287,14 +347,18 @@ public class Database {
|
||||||
recipe.addInput(CrudeOil, 6);
|
recipe.addInput(CrudeOil, 6);
|
||||||
recipe.addOutput(PolymerResin, 3);
|
recipe.addOutput(PolymerResin, 3);
|
||||||
Fuel.add(recipe, 4);
|
Fuel.add(recipe, 4);
|
||||||
|
|
||||||
|
Fuel.setPreference(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Liquid Biofuel
|
||||||
Recipe recipe = new Recipe(4, false);
|
Recipe recipe = new Recipe(4, false);
|
||||||
recipe.addInput(SolidBiofuel, 6);
|
recipe.addInput(SolidBiofuel, 6);
|
||||||
recipe.addInput(Water, 3);
|
recipe.addInput(Water, 3);
|
||||||
LiquidBiofuel.add(recipe, 4);
|
LiquidBiofuel.add(recipe, 4);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Plastic
|
||||||
Recipe recipe = new Recipe(6, false);
|
Recipe recipe = new Recipe(6, false);
|
||||||
recipe.addInput(CrudeOil, 3);
|
recipe.addInput(CrudeOil, 3);
|
||||||
recipe.addOutput(HeavyOilResidue, 1);
|
recipe.addOutput(HeavyOilResidue, 1);
|
||||||
|
|
@ -303,8 +367,11 @@ public class Database {
|
||||||
residualPlastic.addInput(PolymerResin, 6);
|
residualPlastic.addInput(PolymerResin, 6);
|
||||||
residualPlastic.addInput(Water, 2);
|
residualPlastic.addInput(Water, 2);
|
||||||
Plastic.add(residualPlastic, 2);
|
Plastic.add(residualPlastic, 2);
|
||||||
|
|
||||||
|
Plastic.setPreference(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Rubber
|
||||||
Recipe recipe = new Recipe(6, false);
|
Recipe recipe = new Recipe(6, false);
|
||||||
recipe.addInput(CrudeOil, 3);
|
recipe.addInput(CrudeOil, 3);
|
||||||
recipe.addOutput(HeavyOilResidue, 2);
|
recipe.addOutput(HeavyOilResidue, 2);
|
||||||
|
|
@ -312,12 +379,23 @@ public class Database {
|
||||||
Recipe residualRubber = new Recipe(6, "Residual Rubber", false);
|
Recipe residualRubber = new Recipe(6, "Residual Rubber", false);
|
||||||
residualRubber.addInput(PolymerResin, 6);
|
residualRubber.addInput(PolymerResin, 6);
|
||||||
residualRubber.addInput(Water, 4);
|
residualRubber.addInput(Water, 4);
|
||||||
Plastic.add(residualRubber, 2);
|
Rubber.add(residualRubber, 2);
|
||||||
|
|
||||||
|
Rubber.setPreference(recipe);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
// Petroleum Coke
|
||||||
Recipe recipe = new Recipe(6, false);
|
Recipe recipe = new Recipe(6, false);
|
||||||
recipe.addInput(HeavyOilResidue, 4);
|
recipe.addInput(HeavyOilResidue, 4);
|
||||||
PetroleumCoke.add(recipe, 12);
|
PetroleumCoke.add(recipe, 12);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void add(Item i) {
|
||||||
|
items.add(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<Item> getItems() {
|
||||||
|
return new HashSet<>(items);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4,24 +4,28 @@ import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
public class Item {
|
public class Item {
|
||||||
protected boolean isRaw = false;
|
protected boolean isRaw = false;
|
||||||
private String name;
|
private String name;
|
||||||
private Set<Recipe> recipes;
|
private Set<Recipe> recipes;
|
||||||
|
private Recipe preference = null;
|
||||||
|
|
||||||
public Item(String name, Set<Recipe> recipes) {
|
protected Item(String name, Set<Recipe> recipes) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.recipes = recipes;
|
this.recipes = recipes;
|
||||||
|
Database.add(this);
|
||||||
|
for (Recipe recipe : recipes) {
|
||||||
|
add(recipe);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Item(String name, Recipe... recipes) {
|
public Item(String name, Recipe... recipes) {
|
||||||
this(name);
|
this(name, new HashSet<>(Arrays.asList(recipes)));
|
||||||
Arrays.asList(recipes).forEach(this::add);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Item(String name) {
|
public Item(String name) {
|
||||||
this.name = name;
|
this(name, new HashSet<>());
|
||||||
this.recipes = new HashSet<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Recipe recipe) {
|
public void add(Recipe recipe) {
|
||||||
|
|
@ -45,6 +49,27 @@ public class Item {
|
||||||
return isRaw;
|
return isRaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getProductionRate() {
|
||||||
|
Recipe recipe = getRecipe();
|
||||||
|
if (recipe == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return recipe.getProductionRate(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Recipe getRecipe() {
|
||||||
|
Recipe recipe = preference;
|
||||||
|
if (recipe == null) {
|
||||||
|
recipe = recipes.stream().findFirst().orElse(null);
|
||||||
|
if (recipe == null) {
|
||||||
|
if (Database.preferences.containsKey(this)) {
|
||||||
|
recipe = Database.preferences.get(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return recipe;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Item{" +
|
return "Item{" +
|
||||||
|
|
@ -52,4 +77,9 @@ public class Item {
|
||||||
", recipes=" + recipes +
|
", recipes=" + recipes +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPreference(Recipe preference) {
|
||||||
|
this.preference = preference;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
package items;
|
package items;
|
||||||
|
|
||||||
|
import items.requirements.RateAccumulator;
|
||||||
|
import items.requirements.TotalAccumulator;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
@ -28,6 +31,7 @@ public class Recipe {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Recipe(int duration, Map<Item, Integer> inputs, Map<Item, Integer> outputs) {
|
public Recipe(int duration, Map<Item, Integer> inputs, Map<Item, Integer> outputs) {
|
||||||
|
this.duration = duration;
|
||||||
this.inputs = inputs;
|
this.inputs = inputs;
|
||||||
this.outputs = outputs;
|
this.outputs = outputs;
|
||||||
}
|
}
|
||||||
|
|
@ -82,34 +86,21 @@ public class Recipe {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Item, Integer> getTotalRequirements() {
|
public Map<Item, Integer> getTotalRequirements() {
|
||||||
Map<Item, Integer> total = new HashMap<>();
|
return new TotalAccumulator(inputs).accumulate();
|
||||||
Map<Item, Integer> queue = new HashMap<>();
|
|
||||||
for (Item i : inputs.keySet()) {
|
|
||||||
queue.put(i, inputs.get(i));
|
|
||||||
}
|
|
||||||
while (!queue.isEmpty()) {
|
|
||||||
Item i = queue.keySet().iterator().next();
|
|
||||||
int amount = queue.remove(i);
|
|
||||||
total.put(i, total.getOrDefault(i, 0) + amount);
|
|
||||||
if (i.getRecipes().isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Recipe r = i.getRecipes().iterator().next();
|
|
||||||
Map<Item, Integer> subRequirements = r.getTotalRequirements();
|
|
||||||
for (Item subItem : subRequirements.keySet()) {
|
|
||||||
int subAmount = subRequirements.get(subItem);
|
|
||||||
total.put(subItem, total.getOrDefault(subItem, 0) + subAmount * amount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return total;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Item, Integer> getRawOnly() {
|
public float getProductionRate(Item item) {
|
||||||
Map<Item, Integer> totals = getTotalRequirements();
|
Integer integer = outputs.get(item);
|
||||||
Map<Item, Integer> raws = new HashMap<>();
|
float production = integer;
|
||||||
for (Item item : totals.keySet().stream().filter(Item::isRaw).collect(Collectors.toList())) {
|
return production / duration;
|
||||||
raws.put(item, totals.get(item));
|
}
|
||||||
}
|
|
||||||
return raws;
|
public Map<Item, Float> getRequirementRates(Item item){
|
||||||
|
float rate = getProductionRate(item);
|
||||||
|
return new RateAccumulator(this, item).accumulate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<Item, Integer> getInputs() {
|
||||||
|
return inputs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
package items;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
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())) {
|
||||||
|
raws.put(item, totals.get(item));
|
||||||
|
}
|
||||||
|
return raws;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <E extends Number> Map<String, E> shorten(Map<Item, E> totals){
|
||||||
|
Map<String, E> shortend = new HashMap<>();
|
||||||
|
totals.forEach((item, e) -> shortend.put(item.getName(), e));
|
||||||
|
return shortend;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
package items.requirements;
|
||||||
|
|
||||||
|
import items.Item;
|
||||||
|
import items.Recipe;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public abstract class Accumulator<E extends Number> implements RequirementAccumulator<E>{
|
||||||
|
protected Map<Item, E> inputs;
|
||||||
|
|
||||||
|
public Accumulator(Map<Item, E> inputs) {
|
||||||
|
this.inputs = inputs;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract E calculate(Item i, E subAmount, E amount, Map<Item, E> total);
|
||||||
|
|
||||||
|
protected abstract E dequeue(Item item, E amount, Map<Item, E> totals);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<Item, E> accumulate() {
|
||||||
|
Map<Item, E> total = new HashMap<>();
|
||||||
|
Map<Item, E> queue = new HashMap<>();
|
||||||
|
for (Item i : inputs.keySet()) {
|
||||||
|
queue.put(i, inputs.get(i));
|
||||||
|
}
|
||||||
|
while (!queue.isEmpty()) {
|
||||||
|
Item i = queue.keySet().iterator().next();
|
||||||
|
E amount = queue.remove(i);
|
||||||
|
E newTotal = dequeue(i, amount, total);
|
||||||
|
total.put(i,newTotal);
|
||||||
|
if (i.getRecipes().isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Recipe r = i.getRecipes().iterator().next();
|
||||||
|
Map<Item, E> subRequirements = getRequirements(r, i);
|
||||||
|
for (Item subItem : subRequirements.keySet()) {
|
||||||
|
E subAmount = subRequirements.get(subItem);
|
||||||
|
E newSubTotal = calculate(subItem, subAmount, amount, total);
|
||||||
|
total.put(subItem, newSubTotal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract Map<Item,E> getRequirements(Recipe r, Item i);// r.getTotalRequirements()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package items.requirements;
|
||||||
|
|
||||||
|
import items.Item;
|
||||||
|
import items.Recipe;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class RateAccumulator extends Accumulator<Float> {
|
||||||
|
private Item item;
|
||||||
|
|
||||||
|
public RateAccumulator(Recipe recipe, Item item) {
|
||||||
|
super(new HashMap<>());
|
||||||
|
recipe.getInputs().forEach((item1, integer) -> inputs.put(item1, Float.valueOf(integer)));
|
||||||
|
this.item = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Float calculate(Item i, Float subAmount, Float amount, Map<Item, Float> total) {
|
||||||
|
Float base = total.getOrDefault(i, 0f);
|
||||||
|
float additional = subAmount * amount * i.getProductionRate();
|
||||||
|
return base + additional;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Float dequeue(Item item, Float amount, Map<Item, Float> totals) {
|
||||||
|
return totals.getOrDefault(item, 0f) + amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Map<Item, Float> getRequirements(Recipe r, Item i) {
|
||||||
|
return r.getRequirementRates(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
package items.requirements;
|
||||||
|
|
||||||
|
import items.Item;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface RequirementAccumulator<E extends Number> {
|
||||||
|
Map<Item, E> accumulate();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package items.requirements;
|
||||||
|
|
||||||
|
import items.Item;
|
||||||
|
import items.Recipe;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class TotalAccumulator extends Accumulator<Integer>{
|
||||||
|
|
||||||
|
public TotalAccumulator(Map<Item, Integer> inputs) {
|
||||||
|
super(inputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Integer calculate(Item i, Integer subAmount, Integer amount, Map<Item, Integer> total) {
|
||||||
|
return total.getOrDefault(i, 0) + subAmount * amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Integer dequeue(Item item, Integer amount, Map<Item, Integer> totals) {
|
||||||
|
return totals.getOrDefault(item, 0) + amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Map<Item, Integer> getRequirements(Recipe r, Item i) {
|
||||||
|
return r.getTotalRequirements();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -6,9 +6,6 @@ import items.Recipe;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public abstract class Fluid extends Item {
|
public abstract class Fluid extends Item {
|
||||||
public Fluid(String name, Set<Recipe> recipes) {
|
|
||||||
super(name, recipes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Fluid(String name, Recipe... recipes) {
|
public Fluid(String name, Recipe... recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,6 @@ import items.Recipe;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class Ingot extends Item {
|
public class Ingot extends Item {
|
||||||
public Ingot(String name, Set<Recipe> recipes) {
|
|
||||||
super(name, recipes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Ingot(String name, Recipe... recipes) {
|
public Ingot(String name, Recipe... recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,6 @@ import items.Recipe;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class Ore extends Item {
|
public class Ore extends Item {
|
||||||
public Ore(String name, Set<Recipe> recipes) {
|
|
||||||
super(name, recipes);
|
|
||||||
setIsRaw();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Ore(String name, Recipe... recipes) {
|
public Ore(String name, Recipe... recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,6 @@ import items.Recipe;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class Part extends Item {
|
public class Part extends Item {
|
||||||
public Part(String name, Set<Recipe> recipes) {
|
|
||||||
super(name, recipes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Part(String name, Recipe... recipes) {
|
public Part(String name, Recipe... recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,6 @@ import items.Recipe;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class Pickup extends Item {
|
public class Pickup extends Item {
|
||||||
public Pickup(String name, Set<Recipe> recipes) {
|
|
||||||
super(name, recipes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Pickup(String name, Recipe... recipes) {
|
public Pickup(String name, Recipe... recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,6 @@ import items.Recipe;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ProcessedFluid extends Fluid {
|
public class ProcessedFluid extends Fluid {
|
||||||
public ProcessedFluid(String name, Set<Recipe> recipes) {
|
|
||||||
super(name, recipes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProcessedFluid(String name, Recipe... recipes) {
|
public ProcessedFluid(String name, Recipe... recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,6 @@ import items.Recipe;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class RawFluid extends Fluid {
|
public class RawFluid extends Fluid {
|
||||||
public RawFluid(String name, Set<Recipe> recipes) {
|
|
||||||
super(name, recipes);
|
|
||||||
setIsRaw();
|
|
||||||
}
|
|
||||||
|
|
||||||
public RawFluid(String name, Recipe... recipes) {
|
public RawFluid(String name, Recipe... recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,6 @@ import items.Recipe;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class Tool extends Item {
|
public class Tool extends Item {
|
||||||
public Tool(String name, Set<Recipe> recipes) {
|
|
||||||
super(name, recipes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Tool(String name, Recipe... recipes) {
|
public Tool(String name, Recipe... recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue