1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-14 10:13:13 +02:00
RedMew/map_gen/Diggy/Scanner.lua

42 lines
1.2 KiB
Lua

-- dependencies
local insert = table.insert
-- this
local Scanner = {}
--[[--
returns a list with all direct positions that contain tile_search.
@param surface LuaSurface
@param position Position
@param tile_search string name of the tile to search for
@return table with 0~4 directions of which have the tile searched for adjacent
]]
function Scanner.scan_around_position(surface, position, tile_search)
local tile_found = {}
-- north
if (tile_search == surface.get_tile(position.x, position.y - 1).name) then
insert(tile_found, { x = position.x, y = position.y - 1})
end
-- east
if (tile_search == surface.get_tile(position.x + 1, position.y).name) then
insert(tile_found, { x = position.x + 1, y = position.y})
end
-- south
if (tile_search == surface.get_tile(position.x, position.y + 1).name) then
insert(tile_found, { x = position.x, y = position.y + 1})
end
-- west
if (tile_search == surface.get_tile(position.x - 1, position.y).name) then
insert(tile_found, { x = position.x - 1, y = position.y})
end
return tile_found;
end
return Scanner