Last active
October 20, 2018 16:30
-
-
Save david-wm-sanders/3d9a8182219eb4429541 to your computer and use it in GitHub Desktop.
Factorio Console Script: Fill in lake(s).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
game.player.print("Getting player position...") | |
local player_position = game.player.position | |
game.player.print(string.format("Player is at x=%.3f, y=%.3f", player_position.x, player_position.y)) | |
game.player.print("Checking for neighbouring water tiles...") | |
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 | |
game.player.print(string.format("Found %i neighbouring water tiles", #neighbouring_water_tiles)) | |
local first_neighbour = neighbouring_water_tiles[1] | |
game.player.print(string.format("First neighbouring water tile at x=%.3f, y=%.3f", first_neighbour.x, first_neighbour.y)) | |
game.player.print("Finding all water tiles that are connected to first neighbour...") | |
local connected_water_tiles = game.player.surface.get_connected_tiles(first_neighbour, {"water", "deepwater"}) | |
game.player.print("Replacing water tiles...") | |
local replacement_tiles = {} | |
for i, p in ipairs(connected_water_tiles) do | |
if p.x % 2 == 0 then | |
if p.y % 2 == 0 then | |
table.insert(replacement_tiles, {name="refined-hazard-concrete-left", position=p}) | |
else | |
table.insert(replacement_tiles, {name="refined-hazard-concrete-right", position=p}) | |
end | |
else | |
if p.y % 2 == 0 then | |
table.insert(replacement_tiles, {name="refined-hazard-concrete-right", position=p}) | |
else | |
table.insert(replacement_tiles, {name="refined-hazard-concrete-left", position=p}) | |
end | |
end | |
end | |
game.player.surface.set_tiles(replacement_tiles) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment