I'd like it that certain types of buildings can't be placed on sand/desert tiles.
So I need to add a collision mask to the tiles and to the entities.
I got the tiles working. (I think). I'm placing it on all non minable tiles currently.
But am having difficulties with the entities.
The idea is that you can't place these building on non stone or concrete floors.
Here is my code:
Code: Select all
-- List of Entities Types that can't be placed on sand
local Blocked_Buildings =
{
["furnace"] = true,
["boiler"] = true,
["generator"] = true,
["radar"] = true,
["assembling-machine"] = true,
["solar-panel"] = true,
["lab"] = true,
["rocket-silo"] = true,
["roboport"] = true,
["storage-tank"] = true,
["pump"] = true,
["market"] = true,
["accumulator"] = true,
["beacon"] = true,
["electric-turret"] = true,
["ammo-turret"] = true,
["reactor"] = true
}
--- Collision Layer
local terrain_collision_layer = "layer-15"
--add collision mask to entities
local function add_Collision_Layer(entity,layer)
if not entity then return end
if entity.collision_mask then
table.insert(entity.collision_mask, layer);
else
entity.collision_mask = {layer,"water-tile","player-layer"}
end
end
--Add collision to mask for non mineable tiles
for _,tile in pairs(data.raw["tile"]) do
if not tile.minable then
add_Collision_Layer(tile,terrain_collision_layer);
end
end
--Add Collision layer to the Entity List.
for i = 1, #Blocked_Buildings do
local entity = data.raw.Blocked_Buildings[i]
add_Collision_Layer(entity, terrain_collision_layer)
end
Thanks.