I want to use the pipe connections to see where the entity could connect to Factorissimo ports. So I don't actually need the entities the fluidbox is connected to, but rather the locations of the potential connections. Right now, as a workaround, I just copy-paste the connection information directly from the prototypes into my code and transform it myself, so nontransformed connection data is perfectly fine for me.
I suppose you could expose the untransformed connection data in LuaEntityPrototype, since that is where people would look and transformations don't make sense there. The connected entities are actually already available in entity.neighbours, but you could possibly expose them in a more fine-grained manner as entity.fluid_neighbours[fluidbox_index][connection_index].
Here's the transformation code I use, for public reference:
Code: Select all
local DX = {
[defines.direction.north] = 0,
[defines.direction.east] = 1,
[defines.direction.south] = 0,
[defines.direction.west] = -1,
}
local DY = {
[defines.direction.north] = -1,
[defines.direction.east] = 0,
[defines.direction.south] = 1,
[defines.direction.west] = 0,
}
local FLUIDBOX_DATA = {
["pipe"] = {base_area = 1, connections = {{x=0,y=-1},{x=1,y=0},{x=0,y=1},{x=-1,y=0}}},
["pipe-to-ground"] = {base_area = 1, connections = {{x=0,y=-1}}},
["storage-tank"] = {base_area = 250, connections = {{x=-1,y=-2},{x=2,y=1},{x=1,y=2},{x=-2,y=-1}}},
["small-pump"] = {base_area = 1, connections = {{x=0,y=-1,type="output"},{x=0,y=1,type="input"}}},
}
local function has_connection_towards(entity, x, y)
if FLUIDBOX_DATA[entity.name] == nil then return false end
local fconns = FLUIDBOX_DATA[entity.name].connections
local position = entity.position
local direction = entity.direction
for _,fconn in pairs(fconns) do
local dx = position.x + (-fconn.x*DY[direction]-fconn.y*DX[direction]) - x
local dy = position.y + (-fconn.y*DY[direction]+fconn.x*DX[direction]) - y
if (dx*dx+dy*dy) < 0.1 then
return fconn.type or true
end
end
return false
end
PS: Writing this up I realize I could actually make do with the current API, by placing dummy fluid tanks at the connection locations and searching for them in entity.neighbours. That's very convenient since I wanted to place dummy tanks anyway in order to make pipe connections apparent and hide the pipe covers. Quick question, do two small pumps facing each other (meaning that both involved pipe_connections have "output" type) count as neighbors?