Page 1 of 1

dying_trigger_effect: if a unit dies on a certain tile, replace that tile with another

Posted: Mon Sep 19, 2022 6:57 am
by adamwong246
I'm trying to suss this out: if a unit dies on a `garbageFill` or a `sacrificezoneFill`, it should replace that tile with a landfill tile. I haven't so far been able to find the correct combination of collision masks. Perhaps some other mechanism exists?

Code: Select all

local CollisionMaskUtil = require("__core__.lualib.collision-mask-util");
local layer1 = CollisionMaskUtil.get_first_unused_layer();

-- you CAN pave over Garbage
local garbageFillMask = {layer1}

-- you CAN NOT pave over a Sacfice Zone
local sacrificeZoneMask = {layer1, "water-tile", "floor-layer", "item-layer", "object-layer"}

for _, unit in pairs(data.raw.unit) do

    if not unit.dying_trigger_effect then
        unit.dying_trigger_effect = {};
    end
    table.insert(unit.dying_trigger_effect, {
        type = "set-tile",
        tile_name = "landfill",
        radius = 5,
        apply_projection = true,
        tile_collision_mask = {layer1}; -- {"water-tile", "floor-layer", "item-layer", "object-layer"}
    });

    data:extend({unit});
end

Re: dying_trigger_effect: if a unit dies on a certain tile, replace that tile with another

Posted: Mon Sep 19, 2022 7:24 am
by adamwong246
solution:

Code: Select all

local CollisionMaskUtil = require("__core__.lualib.collision-mask-util");
local nonToxicTiles = CollisionMaskUtil.get_first_unused_layer();

for _, tile in pairs(data.raw.tile) do
    table.insert(tile.collision_mask, nonToxicTiles);
    data:extend({tile});
end


local toxicTiles = CollisionMaskUtil.get_first_unused_layer();


-- you CAN pave over Garbage
local garbageFillMask = {toxicTiles}

-- you CAN NOT pave over a Sacfice Zone
local sacrificeZoneMask = {toxicTiles, "water-tile", "floor-layer", "item-layer", "object-layer"}


for _, unit in pairs(data.raw.unit) do

    if not unit.dying_trigger_effect then
        unit.dying_trigger_effect = {};
    end
    table.insert(unit.dying_trigger_effect, {
        type = "set-tile",
        tile_name = "landfill",
        radius = 5,
        apply_projection = true,
        tile_collision_mask =  {nonToxicTiles}
    });

    data:extend({unit});
end