diff --git a/fle/env/tools/agent/can_place_entity/agent.md b/fle/env/tools/agent/can_place_entity/agent.md index 726bf7e5b..e1d1bf91e 100644 --- a/fle/env/tools/agent/can_place_entity/agent.md +++ b/fle/env/tools/agent/can_place_entity/agent.md @@ -49,5 +49,5 @@ else: 3. Special Cases -- Offshore pumps require water tiles +- Offshore pumps are placed on land at the edge of water (Factorio 2.0), not on water tiles - Some entities have specific placement requirements diff --git a/fle/env/tools/agent/can_place_entity/server.lua b/fle/env/tools/agent/can_place_entity/server.lua index c2e481107..577b400e3 100644 --- a/fle/env/tools/agent/can_place_entity/server.lua +++ b/fle/env/tools/agent/can_place_entity/server.lua @@ -50,11 +50,17 @@ storage.actions.can_place_entity = function(player_index, entity, direction, x, error("Cannot place the entity at the specified location due to collision with other entities.") end - -- Additional checks for specific entities like offshore-pump + -- Factorio 2.0: an offshore pump stands on land at the edge of water, so the tile + -- under it is usually not water. Let the game's placement rules decide. if entity == "offshore-pump" then - local tile = player.surface.get_tile(x, y) - if not tile.prototype.name:match("water") then - error("Cannot place the entity at the specified position due to lack of water.") + local can_place = player.surface.can_place_entity{ + name = entity, + force = player.force, + position = position, + direction = direction_enum + } + if not can_place then + error("Cannot place the offshore pump at the specified position: it must be placed at the edge of water.") end end diff --git a/tests/actions/test_can_place.py b/tests/actions/test_can_place.py index 3bcb58ddd..9586c7c9f 100644 --- a/tests/actions/test_can_place.py +++ b/tests/actions/test_can_place.py @@ -34,3 +34,22 @@ def test_can_place_over_player_large(game): game.place_entity( Prototype.SteamEngine, position=Position(x=0, y=0), direction=Direction.UP ) + + +def test_can_place_offshore_pump_at_shore(configure_game): + game = configure_game( + inventory={"offshore-pump": 2}, merge=True, reset_position=True + ) + water = game.nearest(Resource.Water) + game.move_to(water) + pump = game.place_entity(Prototype.OffshorePump, position=water) + position = pump.position + assert game.pickup_entity(pump) + + # Factorio 2.0: the pump stands on land next to the water, not on a water tile + assert any( + game.can_place_entity( + Prototype.OffshorePump, direction=direction, position=position + ) + for direction in (Direction.UP, Direction.RIGHT, Direction.DOWN, Direction.LEFT) + )