Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /c
- --[[ HISTORICALLY ACCURATE TREE RESTORATION ]]
- local TREES = {"tree-01","tree-02","tree-02-red","tree-03","tree-04","tree-05","tree-06","tree-06-brown","tree-07","tree-08","tree-08-brown","tree-08-red","tree-09","tree-09-brown","tree-09-red"}
- local function bounding_box_from_gps_tags(s)
- local x1 = math.huge
- local y1,x2,y2 = x1,-x1,-x1
- for x,y in s:gmatch("%[gps=([+-]?%d+),([+-]?%d+)%]") do
- x1 = math.min(x1, x+0)
- y1 = math.min(y1, y+0)
- x2 = math.max(x2, x+0)
- y2 = math.max(y2, y+0)
- end
- return { left_top = {x=x1,y=y1}, right_bottom = {x=x2,y=y2} }
- end
- local function chunks_at_least_partly_inside(surface, bb)
- local result = {}
- for c in surface.get_chunks() do
- if c.area.left_top.x <= bb.right_bottom.x and
- c.area.left_top.y <= bb.right_bottom.y and
- c.area.right_bottom.x >= bb.left_top.x and
- c.area.right_bottom.y >= bb.left_top.y
- then
- result[#result+1] = c
- end
- end
- return result
- end
- local function go(s)
- local surface = game.player.surface
- local chunks = chunks_at_least_partly_inside(surface, bounding_box_from_gps_tags(s))
- if #chunks > 0 then
- surface.regenerate_entity(TREES, chunks)
- game.print("Restored default trees to " .. #chunks .. " chunks.")
- end
- end
- go ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement