local function has_value (tab, val)
for index, value in ipairs(tab) do
if value == val then
return true
end
end
return false
end
local function player_built_tile(event)
local surface = game.get_surface(event.surface_index)
if not surface or not surface.valid then
return
end
local newTiles = {}
local tileWaereNaheEinerKueste = false
local originalLandTileTypes = {
'dirt-1',
'dirt-2',
'dirt-3',
'dirt-4',
'dirt-5',
'dirt-6',
'dirt-7',
'dry-dirt',
'grass-1',
'grass-2',
'grass-3',
'grass-4',
'red-desert-0',
'red-desert-1',
'red-desert-2',
'red-desert-3',
'sand-1',
'sand-2',
'sand-3'
}
for _,tile in pairs(event.tiles) do
if tile.old_tile.name == "water" or tile.old_tile.name == "deepwater" then
local newTile = surface.get_tile(tile.position.x, tile.position.y)
if newTile and newTile.valid then
tileWaereNaheEinerKueste = false
local radius = 5
for i = 0,radius * 2,1 do
for j = 0,radius * 2,1 do
local neighboredTile = surface.get_tile(tile.position.x + i - radius, tile.position.y + j - radius)
if neighboredTile and neighboredTile.valid and neighboredTile ~= newTile then
-- game.print ("neighboredTile "..(neighboredTile.name), {1.0, 1.0, 0.0, 1.0})
if has_value(originalLandTileTypes, neighboredTile.name) then
tileWaereNaheEinerKueste = true
break
end
end
end
end
-- game.print ("Und? tileWaereNaheEinerKueste "..(tileWaereNaheEinerKueste and 'true' or 'false'), {1.0, 1.0, 0.0, 1.0})
if tileWaereNaheEinerKueste or tile.old_tile.name == "water" then -- Landaufschüttung hat geklappt weil nahe der Küste
newTiles[#newTiles + 1] = {
name = "landfill",
position = tile.position
}
else -- Landaufschüttung fehlgeschlagen also wieder ursprüngliches Tile herstellen
newTiles[#newTiles + 1] = {
name = tile.old_tile.name,
position = tile.position
}
end
end
end
end
if #newTiles > 0 then
surface.set_tiles(newTiles)
end
end
if settings.startup["landfill-plus-allow-landfill-close-to-shoreline-setting"].value == true then
script.on_event(defines.events.on_player_built_tile, player_built_tile)
end