commit 84f4526dbe5b6e03be87ffcd94e8a8d5a27863bf Author: agp8x Date: Thu Mar 18 23:18:48 2021 +0100 initial draft diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8117b8f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea/ +out/ +*.iml diff --git a/src/Database.java b/src/Database.java new file mode 100644 index 0000000..7b8e72d --- /dev/null +++ b/src/Database.java @@ -0,0 +1,323 @@ +import items.Item; +import items.Recipe; +import items.type.*; + +public class Database { + 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 CopperOre = new Ore("Copper Ore"); + public static final Item CopperIngot = new Ingot("Copper Ingot", new Recipe(2, CopperOre, 1)); + public static final Item Coal = new Ore("Coal"); + public static final Item SteelIngot = new Ingot("Steel Ingot"); + public static final Item CateriumOre = new Ore("Caterium Ore"); + public static final Item CateriumIngot = new Ingot("Caterium Ingot", new Recipe(4, CateriumOre, 3)); + public static final Item IronPlate = new Part("Iron Plate"); + public static final Item IronRod = new Part("IronRod", new Recipe(4, IronIngot, 1)); + public static final Item Screw = new Part("Screw"); + public static final Item ReinforcedIronPlate = new Part("Reinforced Iron Plate"); + public static final Item ModularFrame = new Part("Modular Frame"); + public static final Item SteelBeam = new Part("Steel Beam", new Recipe(4, SteelIngot, 4)); + public static final Item SteelPipe = new Part("Steel Pipe"); + public static final Item Limestone = new Ore("Limestone"); + public static final Item Concrete = new Part("Concrete", new Recipe(4, Limestone, 3)); + public static final Item EncasedIndustrialBeam = new Part("Encased Industrial Beam"); + public static final Item HeavyModularFrame = new Part("HeavyModularFrame"); + public static final Item CopperSheet = new Part("CopperSheet", new Recipe(6, CopperIngot, 2)); + public static final Item Wire = new Part("Wire"); + public static final Item Cable = new Part("Cable", new Recipe(2, Wire, 2)); + public static final Item Quickwire = new Part("Quickwire"); + public static final Item CircuitBoard = new Part("CircuitBoard"); + public static final Item AILimiter = new Part("A.I. Limiter"); + public static final Item HighSpeedConnector = new Part("High-Speed Connector"); + public static final Item Biomass = new Part("Biomass"); + public static final Item SolidBiofuel = new Part("Solid Biofuel"); + public static final Item Mycelia = new Pickup("Mycelia"); + public static final Item Leaves = new Pickup("Leaves"); + public static final Item Wood = new Pickup("Wood"); + public static final Item AlienCarapace = new Pickup("Alien Carapace"); + public static final Item AlienOrgans = new Pickup("Alien Organs"); + public static final Item Fabric = new Part("Fabric"); + public static final Item Rotor = new Part("Rotor"); + public static final Item Stator = new Part("Stator"); + public static final Item Motor = new Part("Motor"); + public static final Item GreenPowerSlug = new Pickup("Green Power Slug"); + public static final Item YellowPowerSlug = new Pickup("Yellow Power Slug"); + public static final Item PurplePowerSlug = new Pickup("Purple Power Slug"); + public static final Item PowerShard = new Pickup("PowerShard"); + public static final Item Sulfur = new Ore("Sulfur"); + public static final Item BlackPowder = new Part("Black powder"); + public static final Item SpikedRebar = new Part("SpikedRebar", new Recipe(4, IronRod, 1)); + public static final Item FlowerPetals = new Pickup("Flower Petals"); + public static final Item ColorCatridge = new Part("Color Catridge"); + public static final Item Beacon = new Tool("Beacon"); + public static final Item Rubber = new Part("Rubber"); + public static final Item RifleCatridge = new Part("RifleCatridge"); + public static final Item GasFilter = new Tool("Gas Filter"); + public static final Item Plastic = new Part("Plastic"); + public static final Item Computer = new Part("Computer"); + public static final Item SuperComputer = new Part("SuperComputer"); + public static final Item EmptyCanister = new Part("Empty Canister"); + public static final Item ModularEngine = new Part("Modular Engine"); + public static final Item AdaptiveControlUnit = new Part("Adaptive Control Unit"); + public static final Item SmartPlating = new Part("Smart Plating"); + public static final Item AutomatedWiring = new Part("Automated Wiring"); + public static final Item VersatileFrameWork = new Part("Versatile Framework"); + public static final Item Nobelisk = new Part("Nobelisk"); + public static final Item Water = new RawFluid("Water"); + public static final Item CrudeOil = new RawFluid("Water"); + public static final Item HeavyOilResidue = new ProcessedFluid("Heavy Oil Residue"); + public static final Item Fuel = new ProcessedFluid("Fuel"); + public static final Item LiquidBiofuel = new ProcessedFluid("Liquid Biofuel"); + public static final Item PetroleumCoke = new Part("Petroleum Coke"); + public static final Item PolymerResin = new Part("Polymer Resin"); + + static { + { + Recipe recipe = new Recipe(4); + recipe.addInput(IronOre, 3); + recipe.addInput(Coal, 3); + SteelIngot.add(recipe, 3); + } + { + Recipe recipe = new Recipe(6, IronIngot, 3); + IronPlate.add(recipe, 2); + } + { + Screw.add(new Recipe(6, IronRod, 1), 4); + } + { + Recipe recipe = new Recipe(12); + recipe.addInput(IronPlate, 6); + recipe.addInput(Screw, 12); + ReinforcedIronPlate.add(recipe); + Recipe bolted = new Recipe(12, "Bolted Iron Plate", false); + bolted.addInput(IronPlate, 18); + bolted.addInput(Screw, 50); + ReinforcedIronPlate.add(bolted, 3); + } + { + Recipe recipe = new Recipe(60); + recipe.addInput(ReinforcedIronPlate, 3); + recipe.addInput(IronRod, 12); + ModularFrame.add(recipe, 2); + } + { + Recipe recipe = new Recipe(6); + recipe.addInput(SteelIngot, 3); + SteelPipe.add(recipe, 2); + } + { + Recipe recipe = new Recipe(10); + recipe.addInput(SteelBeam, 4); + recipe.addInput(Concrete, 5); + EncasedIndustrialBeam.add(recipe); + } + { + Recipe recipe = new Recipe(30); + recipe.addInput(ModularFrame, 5); + recipe.addInput(SteelPipe, 15); + recipe.addInput(EncasedIndustrialBeam, 5); + recipe.addInput(Screw, 100); + HeavyModularFrame.add(recipe); + } + { + Wire.add(new Recipe(4, CopperIngot, 1), 2); + } + { + Quickwire.add(new Recipe(5, CateriumIngot, 1), 5); + } + { + Recipe recipe = new Recipe(8); + recipe.addInput(CopperSheet, 2); + recipe.addInput(Plastic, 4); + CircuitBoard.add(recipe); + } + { + Recipe recipe = new Recipe(12); + recipe.addInput(CopperSheet, 5); + recipe.addInput(Quickwire, 20); + AILimiter.add(recipe); + } + { + Recipe recipe = new Recipe(16); + recipe.addInput(Quickwire, 56); + recipe.addInput(Cable, 10); + recipe.addInput(CircuitBoard, 1); + HighSpeedConnector.add(recipe); + } + { + Biomass.add(new Recipe(5, Leaves, 10), 5); + Biomass.add(new Recipe(4, Wood, 4), 20); + Biomass.add(new Recipe(4, Mycelia, 10), 10); + Biomass.add(new Recipe(4, AlienCarapace, 1), 100); + Biomass.add(new Recipe(8, AlienOrgans, 1), 200); + } + { + Recipe recipe = new Recipe(4); + recipe.addInput(Mycelia); + recipe.addInput(Biomass, 5); + Fabric.add(recipe); + } + { + SolidBiofuel.add(new Recipe(4, Biomass, 8), 4); + } + { + Recipe recipe = new Recipe(15); + recipe.addInput(IronRod, 5); + recipe.addInput(Screw, 25); + Rotor.add(recipe); + } + { + Recipe recipe = new Recipe(12); + recipe.addInput(SteelPipe, 3); + recipe.addInput(Wire, 8); + Stator.add(recipe); + } + { + Recipe recipe = new Recipe(12); + recipe.addInput(Rotor, 2); + recipe.addInput(Stator, 2); + Motor.add(recipe); + } + { + PowerShard.add(new Recipe(8, GreenPowerSlug, 1)); + PowerShard.add(new Recipe(12, YellowPowerSlug, 1), 2); + PowerShard.add(new Recipe(24, PurplePowerSlug, 1), 5); + } + { + Recipe recipe = new Recipe(8); + recipe.addInput(Coal); + recipe.addInput(Sulfur, 2); + BlackPowder.add(recipe); + } + { + ColorCatridge.add(new Recipe(8, FlowerPetals, 5), 10); + } + { + Recipe recipe = new Recipe(20); + recipe.addInput(Beacon, 1); + recipe.addInput(SteelPipe, 10); + recipe.addInput(BlackPowder, 10); + recipe.addInput(Rubber, 10); + RifleCatridge.add(recipe, 5); + } + { + Recipe recipe = new Recipe(8); + recipe.addInput(Coal, 5); + recipe.addInput(Rubber, 2); + recipe.addInput(Fabric, 2); + GasFilter.add(recipe); + } + { + Recipe recipe = new Recipe(24); + recipe.addInput(CircuitBoard, 10); + recipe.addInput(Cable, 9); + recipe.addInput(Plastic, 18); + recipe.addInput(Screw, 52); + Computer.add(recipe); + Recipe alternative = new Recipe(16, "Caterium Computer", false); + alternative.addInput(CircuitBoard, 7); + alternative.addInput(Quickwire, 28); + alternative.addInput(Rubber, 12); + Computer.add(alternative); + } + { + Recipe recipe = new Recipe(32); + recipe.addInput(Computer, 2); + recipe.addInput(AILimiter, 2); + recipe.addInput(HighSpeedConnector, 3); + recipe.addInput(Plastic, 28); + SuperComputer.add(recipe); + } + { + EmptyCanister.add(new Recipe(4, Plastic, 2), 4); + } + { + Recipe recipe = new Recipe(8); + recipe.addInput(IronPlate, 3); + recipe.addInput(IronRod); + recipe.addInput(Wire, 15); + recipe.addInput(Cable, 2); + Beacon.add(recipe); + } + { + Recipe recipe = new Recipe(60, false); + recipe.addInput(Motor, 2); + recipe.addInput(Rubber, 15); + recipe.addInput(SmartPlating, 2); + ModularEngine.add(recipe); + } + { + Recipe recipe = new Recipe(120, false); + recipe.addInput(AutomatedWiring, 15); + recipe.addInput(CircuitBoard, 10); + recipe.addInput(HeavyModularFrame, 2); + recipe.addInput(Computer, 2); + AdaptiveControlUnit.add(recipe); + } + { + Recipe recipe = new Recipe(20, false); + recipe.addInput(BlackPowder, 5); + recipe.addInput(SteelPipe, 10); + Nobelisk.add(recipe); + } + { + Recipe recipe = new Recipe(30, false); + recipe.addInput(ReinforcedIronPlate); + recipe.addInput(Rotor); + SmartPlating.add(recipe); + } + { + Recipe recipe = new Recipe(24, false); + recipe.addInput(Stator); + recipe.addInput(Cable, 20); + AutomatedWiring.add(recipe); + } + { + Recipe recipe = new Recipe(24, false); + recipe.addInput(ModularFrame); + recipe.addInput(SteelBeam, 12); + VersatileFrameWork.add(recipe, 2); + } + { + Recipe residualFuel = new Recipe(6, "Residual Fuel", false); + residualFuel.addInput(HeavyOilResidue, 6); + Fuel.add(residualFuel, 4); + Recipe recipe = new Recipe(6, false); + recipe.addInput(CrudeOil, 6); + recipe.addOutput(PolymerResin, 3); + Fuel.add(recipe, 4); + } + { + Recipe recipe = new Recipe(4, false); + recipe.addInput(SolidBiofuel, 6); + recipe.addInput(Water, 3); + LiquidBiofuel.add(recipe, 4); + } + { + Recipe recipe = new Recipe(6, false); + recipe.addInput(CrudeOil, 3); + recipe.addOutput(HeavyOilResidue, 1); + Plastic.add(recipe, 2); + Recipe residualPlastic = new Recipe(6, "Residual Plastic", false); + residualPlastic.addInput(PolymerResin, 6); + residualPlastic.addInput(Water, 2); + Plastic.add(residualPlastic, 2); + } + { + Recipe recipe = new Recipe(6, false); + recipe.addInput(CrudeOil, 3); + recipe.addOutput(HeavyOilResidue, 2); + Rubber.add(recipe, 2); + Recipe residualRubber = new Recipe(6, "Residual Rubber", false); + residualRubber.addInput(PolymerResin, 6); + residualRubber.addInput(Water, 4); + Plastic.add(residualRubber, 2); + } + { + Recipe recipe = new Recipe(6, false); + recipe.addInput(HeavyOilResidue, 4); + PetroleumCoke.add(recipe, 12); + } + } +} diff --git a/src/Test.java b/src/Test.java new file mode 100644 index 0000000..e314dcc --- /dev/null +++ b/src/Test.java @@ -0,0 +1,8 @@ +import java.util.Map; + +public class Test { + public static void main(String[] args) { + //System.out.println(Database.AdaptiveControlUnit); + System.out.println(Database.HeavyModularFrame.getRecipes().stream().findFirst().get().getTotalRequirements()); + } +} diff --git a/src/items/Item.java b/src/items/Item.java new file mode 100644 index 0000000..2788510 --- /dev/null +++ b/src/items/Item.java @@ -0,0 +1,49 @@ +package items; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +public class Item { + private String name; + private Set recipes; + + public Item(String name, Set recipes) { + this.name = name; + this.recipes = recipes; + } + + public Item(String name, Recipe... recipes) { + this(name); + Arrays.asList(recipes).forEach(this::add); + } + + public Item(String name) { + this.name = name; + this.recipes = new HashSet<>(); + } + + public void add(Recipe recipe) { + add(recipe,1); + } + public void add(Recipe recipe, int amount){ + recipes.add(recipe); + recipe.checkOutput(this, amount); + } + + public String getName() { + return name; + } + + public Set getRecipes(){ + return recipes; + } + + @Override + public String toString() { + return "Item{" + + "name='" + name + '\'' + + ", recipes=" + recipes + + '}'; + } +} diff --git a/src/items/Recipe.java b/src/items/Recipe.java new file mode 100644 index 0000000..ebbdf8b --- /dev/null +++ b/src/items/Recipe.java @@ -0,0 +1,97 @@ +package items; + +import java.util.HashMap; +import java.util.Map; + +public class Recipe { + private Map inputs; + private Map outputs; + private boolean isHandCraftable = true; + private String name; + private int duration; + + public Recipe(int duration) { + inputs = new HashMap<>(); + outputs = new HashMap<>(); + this.duration = duration; + } + + public Recipe(int duration, boolean isHandCraftable) { + this(duration); + this.isHandCraftable = isHandCraftable; + } + + public Recipe(int duration, Item input, int amount) { + this(duration); + addInput(input, amount); + } + + public Recipe(int duration, Map inputs, Map outputs) { + this.inputs = inputs; + this.outputs = outputs; + } + + public Recipe(int duration, String name, boolean isHandCraftable) { + this(duration); + this.name = name; + this.isHandCraftable = isHandCraftable; + } + + public void addInput(Item item, int amount) { + inputs.put(item, amount); + } + + @Override + public String toString() { + return "Recipe{" + + "inputs=" + inputs + + ", outputs=" + formatIO(outputs) + + ", isHandCraftable=" + isHandCraftable + + ", name='" + name + '\'' + + ", duration=" + duration + + '}'; + } + + public void addInput(Item input) { + addInput(input, 1); + } + + public void addOutput(Item item, int amount) { + this.outputs.put(item, amount); + } + + public void checkOutput(Item item, int amount) { + if (!(outputs.containsKey(item) && outputs.get(item) == amount)) { + outputs.put(item, amount); + } + } + + private String formatIO(Map map) { + StringBuilder sb = new StringBuilder("{"); + map.forEach((item, integer) -> sb.append(item.getName()).append(": ").append(integer).append(", ")); + return sb.append("}").toString(); + } + + public Map getTotalRequirements() { + Map total = new HashMap<>(); + Map 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 subRequirements = r.getTotalRequirements(); + for (Item subItem : subRequirements.keySet()) { + int subAmount = subRequirements.get(subItem); + total.put(subItem, total.getOrDefault(subItem, 0) + subAmount*amount); + } + } + return total; + } +} diff --git a/src/items/type/Fluid.java b/src/items/type/Fluid.java new file mode 100644 index 0000000..07afb80 --- /dev/null +++ b/src/items/type/Fluid.java @@ -0,0 +1,20 @@ +package items.type; + +import items.Item; +import items.Recipe; + +import java.util.Set; + +public abstract class Fluid extends Item { + public Fluid(String name, Set recipes) { + super(name, recipes); + } + + public Fluid(String name, Recipe... recipes) { + super(name, recipes); + } + + public Fluid(String name) { + super(name); + } +} diff --git a/src/items/type/Ingot.java b/src/items/type/Ingot.java new file mode 100644 index 0000000..f5e7017 --- /dev/null +++ b/src/items/type/Ingot.java @@ -0,0 +1,20 @@ +package items.type; + +import items.Item; +import items.Recipe; + +import java.util.Set; + +public class Ingot extends Item { + public Ingot(String name, Set recipes) { + super(name, recipes); + } + + public Ingot(String name, Recipe... recipes) { + super(name, recipes); + } + + public Ingot(String name) { + super(name); + } +} diff --git a/src/items/type/Ore.java b/src/items/type/Ore.java new file mode 100644 index 0000000..2cc22ff --- /dev/null +++ b/src/items/type/Ore.java @@ -0,0 +1,20 @@ +package items.type; + +import items.Item; +import items.Recipe; + +import java.util.Set; + +public class Ore extends Item { + public Ore(String name, Set recipes) { + super(name, recipes); + } + + public Ore(String name, Recipe... recipes) { + super(name, recipes); + } + + public Ore(String name) { + super(name); + } +} diff --git a/src/items/type/Part.java b/src/items/type/Part.java new file mode 100644 index 0000000..afe361d --- /dev/null +++ b/src/items/type/Part.java @@ -0,0 +1,20 @@ +package items.type; + +import items.Item; +import items.Recipe; + +import java.util.Set; + +public class Part extends Item { + public Part(String name, Set recipes) { + super(name, recipes); + } + + public Part(String name, Recipe... recipes) { + super(name, recipes); + } + + public Part(String name) { + super(name); + } +} diff --git a/src/items/type/Pickup.java b/src/items/type/Pickup.java new file mode 100644 index 0000000..16d9543 --- /dev/null +++ b/src/items/type/Pickup.java @@ -0,0 +1,20 @@ +package items.type; + +import items.Item; +import items.Recipe; + +import java.util.Set; + +public class Pickup extends Item { + public Pickup(String name, Set recipes) { + super(name, recipes); + } + + public Pickup(String name, Recipe... recipes) { + super(name, recipes); + } + + public Pickup(String name) { + super(name); + } +} diff --git a/src/items/type/ProcessedFluid.java b/src/items/type/ProcessedFluid.java new file mode 100644 index 0000000..0ae19d3 --- /dev/null +++ b/src/items/type/ProcessedFluid.java @@ -0,0 +1,19 @@ +package items.type; + +import items.Recipe; + +import java.util.Set; + +public class ProcessedFluid extends Fluid{ + public ProcessedFluid(String name, Set recipes) { + super(name, recipes); + } + + public ProcessedFluid(String name, Recipe... recipes) { + super(name, recipes); + } + + public ProcessedFluid(String name) { + super(name); + } +} diff --git a/src/items/type/RawFluid.java b/src/items/type/RawFluid.java new file mode 100644 index 0000000..8ed7460 --- /dev/null +++ b/src/items/type/RawFluid.java @@ -0,0 +1,19 @@ +package items.type; + +import items.Recipe; + +import java.util.Set; + +public class RawFluid extends Fluid{ + public RawFluid(String name, Set recipes) { + super(name, recipes); + } + + public RawFluid(String name, Recipe... recipes) { + super(name, recipes); + } + + public RawFluid(String name) { + super(name); + } +} diff --git a/src/items/type/Tool.java b/src/items/type/Tool.java new file mode 100644 index 0000000..8bcd233 --- /dev/null +++ b/src/items/type/Tool.java @@ -0,0 +1,20 @@ +package items.type; + +import items.Item; +import items.Recipe; + +import java.util.Set; + +public class Tool extends Item { + public Tool(String name, Set recipes) { + super(name, recipes); + } + + public Tool(String name, Recipe... recipes) { + super(name, recipes); + } + + public Tool(String name) { + super(name); + } +}