用于批量填海的控制台指令。可以将自身相邻的整片水域一次性填平
/c local player_position = game.player.position
local neighbouring_water_tiles = {}
for x=player_position.x-1,player_position.x+1 do
for y=player_position.y-1,player_position.y+1 do
local t = game.player.surface.get_tile(x,y)
if t.name == "water" or t.name == "deepwater" then
table.insert(neighbouring_water_tiles, {x=x, y=y})
end
end
end
local first_water_tile = neighbouring_water_tiles[1]
local connected_water_tiles = game.player.surface.get_connected_tiles(first_water_tile, {"water", "deepwater"})
local replacement_tiles = {}
for i, p in ipairs(connected_water_tiles) do
table.insert(replacement_tiles, {name="landfill", position=p})
end
game.player.surface.set_tiles(replacement_tiles)
game.player.print(string.format("替换了 %i 个水方块", #replacement_tiles))
效果如图所示:
执行后:
必须相邻水单元格才会进行替换,自身没有相邻水单元格时不会执行任何替换。