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

43 lines
1.2 KiB
Lua
Raw Normal View History

2018-09-08 18:29:27 +02:00
-- dependencies
local insert = table.insert
2018-09-08 18:29:27 +02:00
-- this
local Scanner = {}
--[[--
returns a list with all direct positions that contain tile_search.
2018-09-08 18:29:27 +02:00
@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 = {}
2018-10-11 20:13:42 +02:00
local get_tile = surface.get_tile
2018-09-08 18:29:27 +02:00
-- north
2018-10-11 20:13:42 +02:00
if (tile_search == get_tile(position.x, position.y - 1).name) then
insert(tile_found, {x = position.x, y = position.y - 1})
2018-09-08 18:29:27 +02:00
end
-- east
2018-10-11 20:13:42 +02:00
if (tile_search == get_tile(position.x + 1, position.y).name) then
insert(tile_found, {x = position.x + 1, y = position.y})
2018-09-08 18:29:27 +02:00
end
-- south
2018-10-11 20:13:42 +02:00
if (tile_search == get_tile(position.x, position.y + 1).name) then
insert(tile_found, {x = position.x, y = position.y + 1})
2018-09-08 18:29:27 +02:00
end
-- west
2018-10-11 20:13:42 +02:00
if (tile_search == get_tile(position.x - 1, position.y).name) then
insert(tile_found, {x = position.x - 1, y = position.y})
2018-09-08 18:29:27 +02:00
end
return tile_found;
2018-09-08 18:29:27 +02:00
end
return Scanner