Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "util"
- require "defines"
- -- Only purge water if we're on a ribbon map
- function should_purge()
- return true
- --if glob.purge_water_should_purge ~= nil then
- -- return glob.purge_water_should_purge
- --end
- --tiles_to_check = {{-51, 0}, {51, 0}, {0, -51}, {0, 51}}
- --for i, xy in ipairs(tiles_to_check) do
- -- x, y = xy[1], xy[2]
- -- name = game.gettile(x, y).name
- -- if name == "out-of-map" then
- -- glob.purge_water_should_purge = true
- -- return glob.purge_water_should_purge
- -- end
- --end
- --glob.purge_water_should_purge = false
- --return glob.purge_water_should_purge
- end
- function purge_water(x1, y1, x2, y2)
- if not glob.purge_water_printed_warning then
- game.player.print('Purging water outside starting area (100x100 tiles)')
- glob.purge_water_printed_warning = true
- end
- idx = 1
- local newtiles = {}
- for x=x1,x2,1 do
- for y=y1,y2,1 do
- if (x < -50 or x > 50) or (y < -50 or y > 50) then
- name = game.gettile(x, y).name
- if name == "water" or name == "deepwater" then
- newtiles[idx] = {name = "sand", position = {x, y}}
- idx = idx + 1
- end
- end
- end
- end
- game.settiles(newtiles)
- end
- function purge_all_water()
- for coord in game.getchunks() do
- if game.ischunkgenerated(coord) then
- x1 = coord.x * 32
- y1 = coord.y * 32
- x2 = x1 + 32
- y2 = y1 + 32
- purge_water(x1, y1, x2, y2)
- end
- end
- end
- game.onevent(defines.events.onchunkgenerated, function(event)
- if not should_purge() then
- return
- end
- local x1 = event.area.lefttop.x
- local y1 = event.area.lefttop.y
- local x2 = event.area.rightbottom.x
- local y2 = event.area.rightbottom.y
- purge_water(x1, y1, x2, y2)
- end)
- game.onload(function()
- if not should_purge() then
- return
- end
- purge_all_water()
- end)
Advertisement
Add Comment
Please, Sign In to add comment