Make LuaFluidBox::get_connections() map to prototype order

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
Therax
Filter Inserter
Filter Inserter
Posts: 470
Joined: Sun May 21, 2017 6:28 pm
Contact:

Make LuaFluidBox::get_connections() map to prototype order

Post by Therax »

Entities can define multiple pipe_connections for a single fluidbox, any combination of which can be connected or disconnected.

LuaFluidBox::get_connections(index) returns an array, with one entry per connected pipe connection, but if less than all of them are connected it's impossible to determine which entry maps to which pipe connection.

The most important vanilla entity in this respect is the pump, because the two pipe connections are not interchangeable: one is input and one is output. If only one is connected, get_connections(1) returns an array of one element, without distinguishing which pipe connection is connected.

Proposals:
  1. Instead of having get_connections(index) return an array, have it return an associative map. Under this proposal, a pump with only its input connected (pipe connection 2 in the protoype) would return:

    Code: Select all

    { [1] = nil, [2] = connected_entity_fluidbox }
    Type (input/output) could then be determined by referencing LuaFluidBoxPrototype::pipe_connections.
  2. Instead of having get_connections(index) return an array of FluidBoxes, have it return an array of records. This would be similar to how CircuitConnectionDefinition's source_circuit_id works for decider and arithmetic combinators. Under this proposal, a pump with only its input connected would return something like:

    Code: Select all

    {
      {
        source_pipe_connection_id = 2,
        source_pipe_connection_type = "input",
        target_fluidbox = connected_entity_fluidbox,
        target_fluidbox_index = 1,
        target_pipe_connection_id = 1,
        target_pipe_connection_type = "input-output",
      }
    }
Miniloader — UPS-friendly 1x1 loaders
Bulk Rail Loaders — Rapid train loading and unloading
Beltlayer & Pipelayer — Route items and fluids freely underground

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Make LuaFluidBox::get_connections() map to prototype order

Post by Rseding91 »

I don't think I understand what you're actually trying to do with this change?
If you want to get ahold of me I'm almost always on Discord.

User avatar
Therax
Filter Inserter
Filter Inserter
Posts: 470
Joined: Sun May 21, 2017 6:28 pm
Contact:

Re: Make LuaFluidBox::get_connections() map to prototype order

Post by Therax »

Given a vanilla pump with prototype having 1 fluidbox with 2 pipe_connections, one input and one output:

Code: Select all

    fluid_box =
    {
      base_area = 1,
      height = 2,
      pipe_covers = pipecoverspictures(),
      pipe_connections =
      {
        { position = {0, -1.5}, type="output" },
        { position = {0, 1.5}, type="input" }
      }
    },
The pump is placed in world as LuaEntity "p1", with 1 fluid connection to pipe entity "e1". It is unknown whether e1 is connected to p1's input or output.

Goal: Determine at runtime whether e1 is connected to the p1's input or output.

Use case (general): Automatically determine direction of flow for script-driven fluid transfer, e.g. transfer between different surfaces.

Use case (specific): Factorissimo2, which in 0.16 requires the player to manually set direction of flow via a hotkey for each connection, or to place specific "input" or "output" connector entities. (See Fluid connections here.) In this case "e1" is the mod-provided connector entity.

Currently in 0.16: Calling p1.fluidbox.get_connections(1) returns {e1}, which offers no indication whether e1 is connected to the pump's input or output. Workaround is to compare position and direction of p1 and e1 to determine relative offset, and requires advance (hard-coded) knowledge of the prototypes for both to know the offsets for input/output connections.

Currently planned for 0.17: LuaFluidBoxPrototype exposes pipe connection offsets and direction. This removes the need for hard-coded connection information. Comparing positions and rotation directions of p1 and e1 would still be required.

Requested for 0.17: Starting with only a reference to e1, a way to determine if e1 is connected to p1's input or output, without having to resort to comparing positions.
Miniloader — UPS-friendly 1x1 loaders
Bulk Rail Loaders — Rapid train loading and unloading
Beltlayer & Pipelayer — Route items and fluids freely underground

Bilka
Factorio Staff
Factorio Staff
Posts: 3132
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Make LuaFluidBox::get_connections() map to prototype order

Post by Bilka »

Just to make this more clear, you can get the prototype of the connected fluidbox in 0.17 using

Code: Select all

game.player.selected.fluidbox.get_connections(1)[1].get_prototype(1)
But, from that prototype, you have no way of knowing if connection 1 or connection 2 are connected to your original entity, so you cannot determine the type of the connection.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Post Reply

Return to “Modding interface requests”