2018-06-08 17:48:16 +02:00
|
|
|
local Event = require 'utils.event'
|
|
|
|
|
2018-11-10 18:47:08 +02:00
|
|
|
local replacement_tiles
|
|
|
|
local tile_count
|
|
|
|
local random = math.random
|
|
|
|
|
2018-06-08 17:48:16 +02:00
|
|
|
Event.add(
|
|
|
|
defines.events.on_player_built_tile,
|
|
|
|
function(event)
|
|
|
|
local item = event.item
|
2019-02-25 04:40:08 +02:00
|
|
|
if not item then
|
2018-06-08 17:48:16 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2019-02-25 04:40:08 +02:00
|
|
|
if item.name == 'landfill' then
|
2018-06-08 17:48:16 +02:00
|
|
|
local tiles = event.tiles
|
|
|
|
for i = 1, #tiles do
|
2018-11-21 15:35:47 +02:00
|
|
|
tiles[i].name = replacement_tiles[random(1, tile_count)]
|
2018-06-08 17:48:16 +02:00
|
|
|
end
|
2019-02-25 04:40:08 +02:00
|
|
|
|
2018-06-08 17:48:16 +02:00
|
|
|
local surface = game.surfaces[event.surface_index]
|
|
|
|
surface.set_tiles(tiles)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2018-11-10 18:47:08 +02:00
|
|
|
return function(tiles)
|
2018-11-21 15:35:47 +02:00
|
|
|
replacement_tiles = tiles or {'sand-1'}
|
2018-11-10 18:47:08 +02:00
|
|
|
tile_count = #replacement_tiles
|
2018-06-08 17:48:16 +02:00
|
|
|
end
|