from dataclasses import dataclass import typing as tp import pdbp @dataclass(frozen=True) class Resource: name: str root: bool = False # item definitions class RS: iron_ore = Resource("Iron Ore") copper_ore = Resource("Copper Ore") uranium_ore = Resource("Uranium Ore") stone = Resource("Stone") coal = Resource("Coal") crude_oil = Resource("Crude Oil") water = Resource("Water") petroleum_gas = Resource("Petroleum Gas") light_oil = Resource("Light Oil") heavy_oil = Resource("Heavy Oil") solid_fuel = Resource("Solid Fuel") rocket_fuel = Resource("Rocket Fuel") energy = Resource("Energy (kW)", root=True) assembler = Resource("Assembler", root=True) mining_drill = Resource("Mining Drill", root=True) furnace = Resource("Furnace", root=True) chemical_plant = Resource("Chemical Plant", root=True) oil_refinery = Resource("Oil Refinery", root=True) rocket_silo = Resource("Rocket Silo", root=True) steam_engine_time = Resource("Steam Engine (time)", root=True) iron_plate = Resource("Iron Plate") copper_plate = Resource("Copper Plate") stone_brick = Resource("Stone Brick") steel = Resource("Steel") concrete = Resource("Concrete") iron_gear = Resource("Iron Gear") iron_stick = Resource("Iron Stick") pipe = Resource("Pipe") copper_cable = Resource("Copper Cable") circuit_a = Resource("Electronic Circuit") circuit_b = Resource("Advanced Circuit") circuit_c = Resource("Processing Unit") rail = Resource("Rail") electric_furnace = Resource("Electric Furnace") sulfur = Resource("Sulfur") sulfuric_acid = Resource("Sulfuric Acid") plastic = Resource("Plastic Bar") explosives = Resource("Explosives") battery = Resource("Battery") accumulator = Resource("Accumulator") solar_panel = Resource("Solar Panel") engine_unit = Resource("Engine Unit") engine_unit_electric = Resource("Electric Engine Unit") belt_y = Resource("Transport Belt") # belt_r = Resource("Fast Transport Belt") # belt_b = Resource("Express Transport Belt") inserter_y = Resource("Inserter") # inserter_r = Resource("Long-Handed Inserter") # inserter_b = Resource("Fast Inserter") steam = Resource("Steam") lubricant = Resource("Lubricant") flying_robot_frame = Resource("Flying Robot Frame") low_density_structure = Resource("Low Density Structure") magazine_y = Resource("Firearm Magazine") magazine_r = Resource("Piercing Magazine") grenade = Resource("Grenade") wall = Resource("Wall") radar = Resource("Radar") rocket_y = Resource("Rocket") rocket_r = Resource("Explosive Rocket") rocket_control_unit = Resource("Rocket Control Unit") rocket_part = Resource("Rocket Part") sattelite = Resource("Sattelite") module_productivity = Resource("Productivity Module") module_speed = Resource("Productivity Module") science_red = Resource("Automation Science Pack") science_green = Resource("Logistic Science Pack") science_gray = Resource("Military Science Pack") science_blue = Resource("Chemical Science Pack") science_purple = Resource("Production Science Pack") science_yellow = Resource("Utility Science Pack") science_white = Resource("Space Science Pack") @dataclass class Recipe: name: str resources: dict[Resource, float] class Recipies: # mining iron_ore = Recipe("Iron Ore", {RS.mining_drill: -1, RS.iron_ore: 0.5}) copper_ore = Recipe("Copper Ore", {RS.mining_drill: -1, RS.copper_ore: 0.5}) stone = Recipe("Stone", {RS.mining_drill: -1, RS.stone: 0.5}) coal = Recipe("Coal", {RS.mining_drill: -1, RS.coal: 0.5}) uranium_ore = Recipe("Uranium Ore", {RS.mining_drill: -1, RS.sulfuric_acid: -0.25, RS.uranium_ore: 0.25}) # oil basic_oil_processing = Recipe( "Basic Oil Processing", { RS.oil_refinery: -5, RS.crude_oil: -100, RS.petroleum_gas: 45, } ) advanced_oil_processing = Recipe( "Advanced Oil Processing", { RS.oil_refinery: -5, RS.crude_oil: -100, RS.water: -50, RS.petroleum_gas: 55, RS.light_oil: 45, RS.heavy_oil: 25, }, ) coal_liquefaction = Recipe( "Coal Liquefaction", { RS.oil_refinery: -5, RS.coal: -10, RS.steam: -50, RS.petroleum_gas: 10, RS.light_oil: 20, RS.heavy_oil: -25 + 90, } ) heavy_oil_cracking = Recipe("Heavy Oil Cracking", {RS.chemical_plant: -2, RS.heavy_oil: -40, RS.water: -30, RS.light_oil: 30}) light_oil_cracking = Recipe("Light Oil Cracking", {RS.chemical_plant: -2, RS.light_oil: -30, RS.water: -30, RS.petroleum_gas: 20}) # fuel solid_fuel_pg = Recipe("Solid Fuel (Petroleum Gas)", {RS.chemical_plant: -2, RS.petroleum_gas: -20, RS.solid_fuel: 1}) solid_fuel_lo = Recipe("Solid Fuel (Light Oil)", {RS.chemical_plant: -2, RS.light_oil: -10, RS.solid_fuel: 1}) solid_fuel_ho = Recipe("Solid Fuel (Heavy Oil)", {RS.chemical_plant: -2, RS.heavy_oil: -20, RS.solid_fuel: 1}) rocket_fuel = Recipe("Rocket Fuel", {RS.assembler: -30, RS.light_oil: -10, RS.solid_fuel: -10, RS.rocket_fuel: 1}) # smelting iron_plate = Recipe("Iron Plate", {RS.furnace: -3.2, RS.iron_ore: -1, RS.iron_plate: 1}) copper_plate = Recipe("Copper Plate", {RS.furnace: -3.2, RS.copper_ore: -1, RS.copper_plate: 1}) stone_brick = Recipe("Stone Brick", {RS.furnace: -3.2, RS.stone: -2, RS.stone_brick: 1}) steel = Recipe("Steel", {RS.furnace: -16, RS.iron_plate: -5, RS.steel: 1}) # crafting basics concrete = Recipe("Concrete", {RS.assembler: -10, RS.iron_ore: -1, RS.stone_brick: -5, RS.water: -100, RS.concrete: 10}) iron_gear = Recipe("Iron Gear", {RS.assembler: -0.5, RS.iron_plate: -2, RS.iron_gear: 1}) iron_stick = Recipe("Iron Stick", {RS.assembler: -0.5, RS.iron_plate: -1, RS.iron_stick: 2}) pipe = Recipe("Pipe", {RS.assembler: -0.5, RS.iron_plate: -1, RS.pipe: 1}) copper_cable = Recipe("Copper Cable", {RS.assembler: -0.5, RS.copper_plate: -1, RS.copper_cable: 2}) circuit_a = Recipe("Electronic Circuit", {RS.assembler: -0.5, RS.copper_cable: -3, RS.iron_plate: -1, RS.circuit_a: 1}) circuit_b = Recipe("Advanced Circuit", {RS.assembler: -6, RS.copper_cable: -4, RS.circuit_a: -2, RS.plastic: -2, RS.circuit_b: 1}) circuit_c = Recipe("Processing Unit", {RS.assembler: -10, RS.circuit_b: -2, RS.circuit_a: -20, RS.sulfuric_acid: -5, RS.circuit_c: 1}) # logistics belt_y = Recipe("Transport Belt", {RS.assembler: -0.5, RS.iron_gear: -1, RS.iron_plate: -1, RS.belt_y: 2}) inserter_y = Recipe("Inserter", {RS.assembler: -0.5, RS.circuit_a: -1, RS.iron_gear: -1, RS.iron_plate: -1, RS.inserter_y: 1}) rail = Recipe("Rail", {RS.assembler: -0.5, RS.iron_stick: -1, RS.steel: -1, RS.stone: -1, RS.rail: 1}) electric_furnace = Recipe("Electric Furnace", {RS.assembler: -5, RS.circuit_b: -5, RS.steel: -10, RS.stone_brick: -10, RS.electric_furnace: 1}) # chemicals sulfur = Recipe("Sulfur", {RS.chemical_plant: -1, RS.petroleum_gas: -30, RS.water: -30, RS.sulfur: 2}) sulfuric_acid = Recipe("Sulfuric Acid", {RS.chemical_plant: -1, RS.iron_plate: -1, RS.sulfur: -5, RS.water: -100, RS.sulfuric_acid: 50}) plastic = Recipe("Plastic", {RS.chemical_plant: -1, RS.coal: -1, RS.petroleum_gas: -20, RS.plastic: 2}) explosives = Recipe("Explosives", {RS.chemical_plant: -4, RS.coal: -1, RS.sulfur: -1, RS.water: -10, RS.explosives: 2}) battery = Recipe("Battery", {RS.chemical_plant: -4, RS.copper_plate: -1, RS.iron_plate: -20, RS.sulfuric_acid: -20, RS.battery: 1}) # other energy accumulator = Recipe("Accumulator", {RS.assembler: -10, RS.battery: -5, RS.iron_plate: -2, RS.accumulator: 1}) solar_panel = Recipe("Solar Panel", {RS.assembler: -10, RS.copper_plate: -5, RS.circuit_a: -15, RS.steel: -5, RS.solar_panel: 1}) # military magazine_y = Recipe("Firearm Magazine", {RS.assembler: -1 , RS.iron_plate: -4, RS.magazine_y: 1}) magazine_r = Recipe("Piercing Magazine", {RS.assembler: -1 , RS.copper_plate: -5, RS.magazine_y: -1, RS.steel: -1, RS.magazine_r: 1}) grenade = Recipe("Grenade", {RS.assembler: -8 , RS.coal: -10, RS.iron_plate: -5, RS.grenade: 1}) wall = Recipe("Wall", {RS.assembler: -0.5, RS.stone_brick: -5, RS.wall: 1}) rocket_y = Recipe("Rocket", {RS.assembler: -8, RS.circuit_a: -1, RS.explosives: -1, RS.iron_plate: -2, RS.rocket_y: 1}) rocket_r = Recipe("Explosive Rocket", {RS.assembler: -8, RS.explosives: -2, RS.rocket_r: 1}) # crafting intermediates engine_unit = Recipe("Engine Unit", {RS.assembler: -10, RS.iron_gear: -1, RS.pipe: -2, RS.steel: -1, RS.engine_unit: 1}) engine_unit_electric = Recipe("Electric Engine Unit", {RS.assembler: -10, RS.circuit_a: -2, RS.engine_unit: -1, RS.lubricant: -15, RS.engine_unit_electric: 1}) rocket_control_unit = Recipe("Rocket Control Unit", {RS.assembler: -30, RS.circuit_c: -1, RS.module_speed: -1, RS.rocket_control_unit: 1}) flying_robot_frame = Recipe("Flying Robot Frame", {RS.assembler: -20, RS.battery: -2, RS.engine_unit_electric: -1, RS.circuit_a: -3, RS.steel: -1, RS.flying_robot_frame: 1}) low_density_structure = Recipe("Low Density Structure", {RS.assembler: -20, RS.copper_plate: -20, RS.plastic: -5, RS.steel: -2, RS.low_density_structure: 1}) # modules module_productivity = Recipe("Productivity Module", {RS.assembler: -15, RS.circuit_b: -5, RS.circuit_a: -5, RS.module_speed: 1}) module_speed = Recipe("Speed Module", {RS.assembler: -15, RS.circuit_b: -5, RS.circuit_a: -5, RS.module_speed: 1}) # end-game satellite = Recipe("Sattelite", { RS.assembler: -5, RS.accumulator: -100, RS.low_density_structure: -100, RS.circuit_c: -100, RS.radar: -5, RS.rocket_fuel: -50, RS.solar_panel: -100, RS.sattelite: 1, }) rocket_part = Recipe("Rocket Part", {RS.rocket_silo: -3, RS.low_density_structure: -10, RS.rocket_control_unit: -10, RS.rocket_fuel: -10, RS.rocket_part: 1}) # science packs science_red = Recipe("Automation Science Pack", {RS.assembler: -5, RS.copper_plate: -1, RS.iron_gear: -1, RS.science_red: 1}) science_green = Recipe("Logistic Science Pack", {RS.assembler: -6, RS.belt_y: -1, RS.inserter_y: -1, RS.science_green: 1}) science_gray = Recipe("Military Science Pack", {RS.assembler: -10, RS.magazine_r: -1, RS.grenade: -1, RS.wall: -2, RS.science_gray: 2}) science_blue = Recipe("Chemical Science Pack", {RS.assembler: -24, RS.sulfur: -1, RS.circuit_b: -3, RS.engine_unit: -2, RS.science_blue: 2}) science_purple = Recipe("Production Science Pack", {RS.assembler: -21, RS.rail: -30, RS.electric_furnace: -1, RS.module_productivity: -1, RS.science_purple: 3}) science_yellow = Recipe("Utility Science Pack", {RS.assembler: -21, RS.circuit_c: -2, RS.flying_robot_frame: -1, RS.low_density_structure: -3, RS.science_yellow: 3}) science_white = Recipe("Space Science Pack", {RS.rocket_part: -100, RS.sattelite: -1, RS.science_white: 1}) T = tp.TypeVar("T") def props(cls: type, _t: type[T]) -> list[T]: return [v for k, v in cls.__dict__.items() if not k.startswith("_")] # ensure that all Resources have a Recipe for resource in props(RS, Resource): assert resource.root or any(resource in recipe.resources.keys() for recipe in props(Recipies, Recipe)), f"missing {resource.name}" # TODO: draw recipe graph breakpoint() # michael