Guest User

Untitled

a guest
Jan 25th, 2015
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.76 KB | None | 0 0
  1. require "util"
  2. require "defines"
  3.  
  4. -- Only purge water if we're on a ribbon map
  5. function should_purge()
  6.     return true
  7.     --if glob.purge_water_should_purge ~= nil then
  8.     --  return glob.purge_water_should_purge
  9.     --end
  10.    
  11.     --tiles_to_check = {{-51, 0}, {51, 0}, {0, -51}, {0, 51}}
  12.     --for i, xy in ipairs(tiles_to_check) do
  13.     --  x, y = xy[1], xy[2]
  14.     --  name = game.gettile(x, y).name
  15.     --  if name == "out-of-map" then
  16.     --      glob.purge_water_should_purge = true
  17.     --      return glob.purge_water_should_purge
  18.     --  end
  19.     --end
  20.     --glob.purge_water_should_purge = false
  21.     --return glob.purge_water_should_purge
  22. end
  23.  
  24. function purge_water(x1, y1, x2, y2)
  25.     if not glob.purge_water_printed_warning then
  26.         game.player.print('Purging water outside starting area (100x100 tiles)')
  27.         glob.purge_water_printed_warning = true
  28.     end
  29.     idx = 1
  30.     local newtiles = {}
  31.     for x=x1,x2,1 do
  32.         for y=y1,y2,1 do
  33.             if (x < -50 or x > 50) or (y < -50 or y > 50) then
  34.                 name = game.gettile(x, y).name
  35.                 if name == "water" or name == "deepwater" then
  36.                     newtiles[idx] = {name = "sand", position = {x, y}}
  37.                     idx = idx + 1
  38.                 end
  39.             end
  40.         end
  41.     end
  42.     game.settiles(newtiles)
  43. end
  44.  
  45. function purge_all_water()
  46.     for coord in game.getchunks() do
  47.         if game.ischunkgenerated(coord) then
  48.             x1 = coord.x * 32
  49.             y1 = coord.y * 32
  50.             x2 = x1 + 32
  51.             y2 = y1 + 32
  52.             purge_water(x1, y1, x2, y2)
  53.         end
  54.     end
  55. end
  56.  
  57. game.onevent(defines.events.onchunkgenerated, function(event)
  58.     if not should_purge() then
  59.         return
  60.     end
  61.    
  62.     local x1 = event.area.lefttop.x
  63.     local y1 = event.area.lefttop.y
  64.     local x2 = event.area.rightbottom.x
  65.     local y2 = event.area.rightbottom.y
  66.     purge_water(x1, y1, x2, y2)
  67. end)
  68.  
  69. game.onload(function()
  70.     if not should_purge() then
  71.         return
  72.     end
  73.     purge_all_water()
  74. end)
Advertisement
Add Comment
Please, Sign In to add comment