diff --git a/fle/env/entities.py b/fle/env/entities.py index 2e5b82a44..7a676c8e5 100644 --- a/fle/env/entities.py +++ b/fle/env/entities.py @@ -75,6 +75,7 @@ class EntityStatus(Enum): NO_INGREDIENTS = "no_ingredients" ITEM_INGREDIENT_SHORTAGE = "item_ingredient_shortage" RECIPE_NOT_RESEARCHED = "recipe_not_researched" + RECIPE_IS_PARAMETER = "recipe_is_parameter" # Fluid-related states NO_INPUT_FLUID = "no_input_fluid" @@ -98,6 +99,7 @@ class EntityStatus(Enum): # Inserter/logistics states WAITING_FOR_SOURCE_ITEMS = "waiting_for_source_items" + WAITING_FOR_MORE_ITEMS = "waiting_for_more_items" WAITING_FOR_SPACE_IN_DESTINATION = "waiting_for_space_in_destination" OUT_OF_LOGISTIC_NETWORK = "out_of_logistic_network" NO_FILTER = "no_filter" @@ -112,6 +114,7 @@ class EntityStatus(Enum): ON_THE_WAY = "on_the_way" WAITING_IN_ORBIT = "waiting_in_orbit" WAITING_FOR_ROCKET_TO_ARRIVE = "waiting_for_rocket_to_arrive" + WAITING_FOR_ROCKETS_TO_ARRIVE = "waiting_for_rockets_to_arrive" # Combat/turret states NO_AMMO = "no_ammo" diff --git a/fle/env/game_types.py b/fle/env/game_types.py index 363e5c4c2..5e9306e10 100644 --- a/fle/env/game_types.py +++ b/fle/env/game_types.py @@ -49,9 +49,7 @@ class RecipeName(enum.Enum): "basic-oil-processing" # Recipe for producing petroleum gas with a oil refinery ) AdvancedOilProcessing = "advanced-oil-processing" # Recipe for producing petroleum gas, heavy oil and light oil with a oil refinery - CoalLiquefaction = ( - "coal-liquefaction" # Recipe for producing petroleum gas in a oil refinery - ) + CoalLiquefaction = "coal-liquefaction" # Recipe for producing heavy oil, light oil and petroleum gas from coal, heavy oil and steam in an oil refinery HeavyOilCracking = ( "heavy-oil-cracking" # Recipe for producing light oil in a chemical plant ) @@ -123,7 +121,13 @@ class Prototype(enum.Enum, metaclass=PrototypeMetaclass): FastSplitter = "fast-splitter", ent.Splitter ExpressSplitter = "express-splitter", ent.Splitter + # Factorio 2.0: the "rail" item places a straight-rail; placed rails are one of + # straight-rail, curved-rail-a, curved-rail-b or half-diagonal-rail Rail = "rail", ent.Rail + StraightRail = "straight-rail", ent.Rail + CurvedRailA = "curved-rail-a", ent.Rail + CurvedRailB = "curved-rail-b", ent.Rail + HalfDiagonalRail = "half-diagonal-rail", ent.Rail TransportBelt = "transport-belt", ent.TransportBelt FastTransportBelt = "fast-transport-belt", ent.TransportBelt @@ -171,7 +175,8 @@ class Prototype(enum.Enum, metaclass=PrototypeMetaclass): StoneBrick = "stone-brick", None # Crafting requires smelting 2 stone CopperCable = "copper-cable", None PlasticBar = "plastic-bar", None - EmptyBarrel = "empty-barrel", None + Barrel = "barrel", None # Factorio 2.0: empty-barrel renamed to barrel + EmptyBarrel = "barrel", None # Alias of Barrel (the 1.1 name was empty-barrel) Battery = "battery", None SulfuricAcid = "sulfuric-acid", None Uranium235 = "uranium-235", None @@ -183,8 +188,11 @@ class Prototype(enum.Enum, metaclass=PrototypeMetaclass): "advanced-oil-processing", None, ) # These are recipes, not prototypes. - CoalLiquifaction = "coal-liquifaction", None # These are recipes, not prototypes. - SolidFuel = "solid-fuel", None # These are recipes, not prototypes. + CoalLiquefaction = ( + "coal-liquefaction", + None, + ) # These are recipes, not prototypes. + SolidFuel = "solid-fuel", None LightOil = "light-oil", None HeavyOil = "heavy-oil", None @@ -201,6 +209,10 @@ class Prototype(enum.Enum, metaclass=PrototypeMetaclass): PiercingRoundsMagazine = "piercing-rounds-magazine", ent.Ammo FirearmMagazine = "firearm-magazine", ent.Ammo Grenade = "grenade", None + Explosives = "explosives", None + CliffExplosives = "cliff-explosives", None + Landfill = "landfill", None + RepairPack = "repair-pack", None Radar = "radar", ent.Entity StoneWall = "stone-wall", ent.Entity @@ -225,10 +237,12 @@ class Prototype(enum.Enum, metaclass=PrototypeMetaclass): FlyingRobotFrame = "flying-robot-frame", None RocketSilo = "rocket-silo", ent.RocketSilo - Rocket = "rocket", ent.Rocket + Rocket = ( + "rocket", + ent.Ammo, + ) # The rocket launcher's ammo item, not the silo's rocket Satellite = "satellite", None RocketPart = "rocket-part", None - RocketControlUnit = "rocket-control-unit", None LowDensityStructure = "low-density-structure", None RocketFuel = "rocket-fuel", None SpaceSciencePack = "space-science-pack", None diff --git a/fle/eval/inspect/integration/experiments/condensed_prompts.py b/fle/eval/inspect/integration/experiments/condensed_prompts.py index d0956d98f..54c22aff7 100644 --- a/fle/eval/inspect/integration/experiments/condensed_prompts.py +++ b/fle/eval/inspect/integration/experiments/condensed_prompts.py @@ -149,7 +149,7 @@ class Prototype(enum.Enum): AutomationSciencePack, LogisticsSciencePack, ChemicalSciencePack MilitarySciencePack, ProductionSciencePack, UtilitySciencePack, SpaceSciencePack # Rocket - RocketSilo, Satellite, RocketPart, RocketControlUnit, LowDensityStructure, RocketFuel + RocketSilo, Satellite, RocketPart, LowDensityStructure, RocketFuel class RecipeName(enum.Enum): # Oil processing diff --git a/tests/entities/test_rockets.py b/tests/entities/test_rockets.py index 308b1f919..d9b62245f 100644 --- a/tests/entities/test_rockets.py +++ b/tests/entities/test_rockets.py @@ -21,7 +21,7 @@ def game(configure_game): "steam-engine": 5, "inserter": 10, "iron-chest": 5, - "rocket-control-unit": 100, + "processing-unit": 100, "rocket-fuel": 100, "low-density-structure": 100, "solar-panel": 10, @@ -112,7 +112,7 @@ def test_inserter_to_rocket_silo(configure_game): "coal": 100, "low-density-structure": 200, "rocket-fuel": 200, - "rocket-control-unit": 200, + "processing-unit": 200, }, merge=True, ) @@ -160,7 +160,7 @@ def test_inserter_to_rocket_silo(configure_game): for item_name, prototype in [ ("low-density-structure", Prototype.LowDensityStructure), ("rocket-fuel", Prototype.RocketFuel), - ("rocket-control-unit", Prototype.RocketControlUnit), + ("processing-unit", Prototype.ProcessingUnit), ]: try: game.insert_item(prototype, chest, quantity=10) diff --git a/tests/render/test_assembler_recipes.py b/tests/render/test_assembler_recipes.py index 1c6020199..b5e46b681 100644 --- a/tests/render/test_assembler_recipes.py +++ b/tests/render/test_assembler_recipes.py @@ -33,7 +33,6 @@ def game(instance): "sulfur": 50, "low-density-structure": 10, "rocket-fuel": 10, - "rocket-control-unit": 10, "flying-robot-frame": 10, "grenade": 20, "firearm-magazine": 50, @@ -97,7 +96,7 @@ def game(instance): Prototype.UndergroundPipe, Prototype.StorageTank, Prototype.Pump, - Prototype.EmptyBarrel, + Prototype.Barrel, # Storage Prototype.WoodenChest, Prototype.IronChest, @@ -124,7 +123,6 @@ def game(instance): # Rocket parts Prototype.RocketFuel, Prototype.LowDensityStructure, - Prototype.RocketControlUnit, Prototype.Satellite, # Misc Prototype.SmallLamp, @@ -202,7 +200,7 @@ def clear_terrain(game): "pipe-to-ground", "storage-tank", "pump", - "empty-barrel", + "barrel", # Storage "wooden-chest", "iron-chest", @@ -235,7 +233,6 @@ def clear_terrain(game): # Rocket parts "rocket-fuel", "low-density-structure", - "rocket-control-unit", "satellite", # Misc "small-lamp", diff --git a/tests/unit/test_prototype_names.py b/tests/unit/test_prototype_names.py new file mode 100644 index 000000000..1d5a90440 --- /dev/null +++ b/tests/unit/test_prototype_names.py @@ -0,0 +1,432 @@ +"""Prototype and EntityStatus names vs Factorio 2.0 (base game). Server-free.""" + +import pytest + +from fle.env import entities as ent +from fle.env.entities import EntityStatus +from fle.env.game_types import Prototype, prototype_by_name + +# prototypes.item on a Factorio 2.0.73 headless server, base mod only +FACTORIO_2_0_ITEMS = ( + "accumulator", + "active-provider-chest", + "advanced-circuit", + "arithmetic-combinator", + "artillery-shell", + "artillery-targeting-remote", + "artillery-turret", + "artillery-wagon", + "artillery-wagon-cannon", + "assembling-machine-1", + "assembling-machine-2", + "assembling-machine-3", + "atomic-bomb", + "automation-science-pack", + "barrel", + "battery", + "battery-equipment", + "battery-mk2-equipment", + "beacon", + "belt-immunity-equipment", + "big-electric-pole", + "blueprint", + "blueprint-book", + "boiler", + "bottomless-chest", + "buffer-chest", + "bulk-inserter", + "burner-generator", + "burner-inserter", + "burner-mining-drill", + "cannon-shell", + "car", + "cargo-landing-pad", + "cargo-wagon", + "centrifuge", + "chemical-plant", + "chemical-science-pack", + "cliff-explosives", + "cluster-grenade", + "coal", + "coin", + "combat-shotgun", + "concrete", + "constant-combinator", + "construction-robot", + "copper-cable", + "copper-ore", + "copper-plate", + "copper-wire", + "copy-paste-tool", + "crude-oil-barrel", + "cut-paste-tool", + "decider-combinator", + "deconstruction-planner", + "defender-capsule", + "depleted-uranium-fuel-cell", + "destroyer-capsule", + "discharge-defense-equipment", + "discharge-defense-remote", + "display-panel", + "distractor-capsule", + "efficiency-module", + "efficiency-module-2", + "efficiency-module-3", + "electric-energy-interface", + "electric-engine-unit", + "electric-furnace", + "electric-mining-drill", + "electronic-circuit", + "empty-module-slot", + "energy-shield-equipment", + "energy-shield-mk2-equipment", + "engine-unit", + "exoskeleton-equipment", + "explosive-cannon-shell", + "explosive-rocket", + "explosive-uranium-cannon-shell", + "explosives", + "express-loader", + "express-splitter", + "express-transport-belt", + "express-underground-belt", + "fast-inserter", + "fast-loader", + "fast-splitter", + "fast-transport-belt", + "fast-underground-belt", + "firearm-magazine", + "fission-reactor-equipment", + "flamethrower", + "flamethrower-ammo", + "flamethrower-turret", + "fluid-wagon", + "flying-robot-frame", + "gate", + "green-wire", + "grenade", + "gun-turret", + "hazard-concrete", + "heat-exchanger", + "heat-interface", + "heat-pipe", + "heavy-armor", + "heavy-oil-barrel", + "infinity-cargo-wagon", + "infinity-chest", + "infinity-pipe", + "inserter", + "iron-chest", + "iron-gear-wheel", + "iron-ore", + "iron-plate", + "iron-stick", + "item-unknown", + "lab", + "land-mine", + "landfill", + "lane-splitter", + "laser-turret", + "light-armor", + "light-oil-barrel", + "linked-belt", + "linked-chest", + "loader", + "locomotive", + "logistic-robot", + "logistic-science-pack", + "long-handed-inserter", + "low-density-structure", + "lubricant-barrel", + "medium-electric-pole", + "military-science-pack", + "modular-armor", + "night-vision-equipment", + "no-item", + "nuclear-fuel", + "nuclear-reactor", + "offshore-pump", + "oil-refinery", + "one-way-valve", + "overflow-valve", + "parameter-0", + "parameter-1", + "parameter-2", + "parameter-3", + "parameter-4", + "parameter-5", + "parameter-6", + "parameter-7", + "parameter-8", + "parameter-9", + "passive-provider-chest", + "personal-laser-defense-equipment", + "personal-roboport-equipment", + "personal-roboport-mk2-equipment", + "petroleum-gas-barrel", + "piercing-rounds-magazine", + "piercing-shotgun-shell", + "pipe", + "pipe-to-ground", + "pistol", + "plastic-bar", + "poison-capsule", + "power-armor", + "power-armor-mk2", + "power-switch", + "processing-unit", + "production-science-pack", + "productivity-module", + "productivity-module-2", + "productivity-module-3", + "programmable-speaker", + "proxy-container", + "pump", + "pumpjack", + "radar", + "rail", + "rail-chain-signal", + "rail-signal", + "raw-fish", + "red-wire", + "refined-concrete", + "refined-hazard-concrete", + "repair-pack", + "requester-chest", + "roboport", + "rocket", + "rocket-fuel", + "rocket-launcher", + "rocket-part", + "rocket-silo", + "satellite", + "science", + "selection-tool", + "selector-combinator", + "shotgun", + "shotgun-shell", + "simple-entity-with-force", + "simple-entity-with-owner", + "slowdown-capsule", + "small-electric-pole", + "small-lamp", + "solar-panel", + "solar-panel-equipment", + "solid-fuel", + "space-science-pack", + "speed-module", + "speed-module-2", + "speed-module-3", + "spidertron", + "spidertron-remote", + "spidertron-rocket-launcher-1", + "spidertron-rocket-launcher-2", + "spidertron-rocket-launcher-3", + "spidertron-rocket-launcher-4", + "splitter", + "steam-engine", + "steam-turbine", + "steel-chest", + "steel-furnace", + "steel-plate", + "stone", + "stone-brick", + "stone-furnace", + "stone-wall", + "storage-chest", + "storage-tank", + "submachine-gun", + "substation", + "sulfur", + "sulfuric-acid-barrel", + "tank", + "tank-cannon", + "tank-flamethrower", + "tank-machine-gun", + "top-up-valve", + "train-stop", + "transport-belt", + "underground-belt", + "upgrade-planner", + "uranium-235", + "uranium-238", + "uranium-cannon-shell", + "uranium-fuel-cell", + "uranium-ore", + "uranium-rounds-magazine", + "utility-science-pack", + "vehicle-machine-gun", + "water-barrel", + "wood", + "wooden-chest", +) + +# prototypes.fluid on the same server +FACTORIO_2_0_FLUIDS = ( + "crude-oil", + "fluid-unknown", + "heavy-oil", + "light-oil", + "lubricant", + "parameter-0", + "parameter-1", + "parameter-2", + "parameter-3", + "parameter-4", + "parameter-5", + "parameter-6", + "parameter-7", + "parameter-8", + "parameter-9", + "petroleum-gas", + "steam", + "sulfuric-acid", + "water", +) + +# Rail entities placed by the "rail" item (prototypes.entity, base mod only) +FACTORIO_2_0_RAIL_ENTITIES = ( + "straight-rail", + "curved-rail-a", + "curved-rail-b", + "half-diagonal-rail", +) + +# Prototype members that name a recipe, not an item +RECIPE_ONLY = ("advanced-oil-processing", "coal-liquefaction") + +# FLE's own entity groups; not game prototypes +FLE_GROUPS = ("belt-group", "pipe-group", "electricity-group") + +# defines.entity_status in the Factorio 2.0.73 Lua API +FACTORIO_2_0_ENTITY_STATUSES = ( + "working", + "normal", + "ghost", + "broken", + "no_power", + "low_power", + "no_fuel", + "frozen", + "disabled_by_control_behavior", + "opened_by_circuit_network", + "closed_by_circuit_network", + "disabled_by_script", + "marked_for_deconstruction", + "paused", + "not_plugged_in_electric_network", + "networks_connected", + "networks_disconnected", + "charging", + "discharging", + "fully_charged", + "out_of_logistic_network", + "no_recipe", + "no_ingredients", + "no_input_fluid", + "no_research_in_progress", + "no_minable_resources", + "not_connected_to_hub_or_pad", + "low_input_fluid", + "fluid_ingredient_shortage", + "full_output", + "not_enough_space_in_output", + "full_burnt_result_output", + "item_ingredient_shortage", + "missing_required_fluid", + "missing_science_packs", + "waiting_for_source_items", + "waiting_for_more_items", + "waiting_for_space_in_destination", + "preparing_rocket_for_launch", + "waiting_to_launch_rocket", + "waiting_for_space_in_platform_hub", + "launching_rocket", + "thrust_not_required", + "on_the_way", + "waiting_in_orbit", + "waiting_at_stop", + "waiting_for_rockets_to_arrive", + "not_enough_thrust", + "destination_stop_full", + "no_path", + "no_modules_to_transmit", + "recharging_after_power_outage", + "waiting_for_target_to_be_built", + "waiting_for_train", + "no_ammo", + "low_temperature", + "disabled", + "turned_off_during_daytime", + "not_connected_to_rail", + "cant_divide_segments", + "no_filter", + "no_spot_seedable_by_inputs", + "waiting_for_plants_to_grow", + "computing_navigation", + "pipeline_overextended", + "recipe_not_researched", + "recipe_is_parameter", +) + + +def test_every_prototype_names_a_factorio_2_0_prototype(): + known = ( + set(FACTORIO_2_0_ITEMS) + | set(FACTORIO_2_0_FLUIDS) + | set(FACTORIO_2_0_RAIL_ENTITIES) + | set(RECIPE_ONLY) + | set(FLE_GROUPS) + ) + unknown = sorted( + f"{member.name}={member.value[0]}" + for member in Prototype + if member.value[0] not in known + ) + assert unknown == [] + + +def test_barrel_uses_the_factorio_2_0_name(): + assert Prototype.Barrel.value[0] == "barrel" + assert Prototype.EmptyBarrel is Prototype.Barrel + assert prototype_by_name["barrel"] is Prototype.Barrel + + +def test_rocket_control_unit_is_removed(): + # Factorio 2.0 has no rocket-control-unit item or recipe + assert "rocket-control-unit" not in prototype_by_name + with pytest.raises(AttributeError): + Prototype.RocketControlUnit + + +def test_coal_liquefaction_spelling(): + assert Prototype.CoalLiquefaction.value[0] == "coal-liquefaction" + with pytest.raises(AttributeError, match="CoalLiquefaction"): + Prototype.CoalLiquifaction + + +@pytest.mark.parametrize("name", FACTORIO_2_0_RAIL_ENTITIES) +def test_placed_rails_have_a_prototype(name): + prototype = prototype_by_name[name] + assert prototype.entity_class is ent.Rail + + +def test_rail_item_is_kept(): + assert Prototype.Rail.value[0] == "rail" + + +@pytest.mark.parametrize( + "name", ["explosives", "cliff-explosives", "landfill", "repair-pack"] +) +def test_new_items_have_a_prototype(name): + assert name in prototype_by_name + + +def test_rocket_is_the_ammo_item(): + assert Prototype.Rocket.value[0] == "rocket" + assert Prototype.Rocket.entity_class is ent.Ammo + + +def test_every_factorio_2_0_entity_status_is_known(): + values = {status.value for status in EntityStatus} + assert sorted(set(FACTORIO_2_0_ENTITY_STATUSES) - values) == []