Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fle/env/tools/agent/can_place_entity/agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 10 additions & 4 deletions fle/env/tools/agent/can_place_entity/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions tests/actions/test_can_place.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)