Landfill plus | Breakable landfill, recipe changer and more


Allows the player to break landfill and enable various other landfill related tweaks.

Utilities
2 years ago
1.0 - 1.1
21.7K

i Option: Landfill only near Land

3 years ago

I'd like a mod option "landfill only near land tiles yes/no". The landfill tiles should not be taken into account. This way you could only edit the shorelines close to the original shore and you would not be able to create giant artifical islands in the middle of an ocean. This seems to realizable within the control.lua file by checking a radius of e. g. 5 tiles around for land tiles and disallowing the placement of landfill tiles if there are no land tiles close to this position.

2 years ago

Hey Prehistoric, do you see any chance to implement this feature? In the options you could make selectable for the user: Max distance to shoreline [ ] (number).

Currently you use the collision_mask to avoid landfilling on deep water (if option is set). In order to make the more complicated feature of landfilling shallow water OR a radius around normal land tiles, you would have to remove the collision mask again and allow to landfill everywhere in water according to collision mask. But in the event of laying down landfill, there must be check to ask if the landfill tile would be max x tiles away from normal land tile.

I mean something like this:

local function player_built_tile(event)
local surface = game.get_surface(event.surface_index)

if surface and surface.valid then
    local newTiles = {}

    for _,tile in pairs(event.tiles) do
        local oldTile = tile.old_tile

        if oldTile.name == "water" then
            local newTile = surface.get_tile(tile.position.x, tile.position.y)

            for ... all neighbour tiles in radius 5 ...
                if newTile and newTile.valid then
                    newTiles[#newTiles + 1] = {
                        name = "landfill",
                        position = tile.position
                    }
                end
            end
        end
    end

    if #newTiles > 0 then
        surface.set_tiles(newTiles)
    end
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)
else
end

This would really help correcting cluttered shorelines without being so overpowered that you could generate gigantic islands out of nothing. It would keep everything balanced but just allowing the user the use the island space more efficiently and just in a more beautiful way.

2 years ago

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

2 years ago

For the time being I uploaded the changed mod as a fork here: https://mods.factorio.com/mod/Landfill_plus_near_land

2 years ago

Sorry for not responding and thanks for the feedback and the help with the code.
I am currently working on the feature that you can only place landfill near a shore it should be released later this day.

2 years ago

While playing around with the above mentioned changes I noticed that I forgot to give back the landfill items to the player for all tiles where his landfilling was not successful. Due to using the event on_player_built_tile the player already "payed" the landfill items but when it was not successfull, he would like to get it back.

2 years ago

The changes are now live in version 1.0.16.
The player also gets back the wrongly placed landfill. Though you shouldn't get to close to the water when placing landfill with the shore only setting because the player dies when doing so.
Have a good day!

2 years ago

"Though you shouldn't get to close to the water when placing landfill with the shore only setting because the player dies when doing so." dont get the point. The player dies when landfill is removed, but not when it is placed, isn't that the case?

2 years ago

Yes but how the mod works is that the landfill gets placed and if it isn't near a shore then it instantly gets removed again. So you still can die.

2 years ago

Ngl DE-Schmitt, you've been going around several landfill/waterfill mods asking for this, its getting annoying.

New response