API doesn't provide a way to get front/back of trains in stations

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

API doesn't provide a way to get front/back of trains in stations

Post by Optera »

As mentioned in this thread there is currently no way to determine if a train is facing forward or backwards.
Neither front_stock/back_stock nor front_movers/back_movers actually reflect which part of the train is facing forward.

When driving there's the hack of getting negative speeds while in reverse, but that's no option for determining which way a train parked at a stop is facing.
Last edited by Optera on Tue Mar 28, 2017 6:25 pm, edited 1 time in total.
SilverB1rd
Inserter
Inserter
Posts: 47
Joined: Fri Mar 17, 2017 9:19 pm
Contact:

Re: API doesn't provide a way to get front/back trains

Post by SilverB1rd »

it might help to why this information is needed? what does this information allow a mod to do that it cannot do now?
orzelek
Smart Inserter
Smart Inserter
Posts: 3924
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: API doesn't provide a way to get front/back trains

Post by orzelek »

Optera wrote:As mentioned in this thread there is currently no way to determine if a train is facing forward or backwards.
Neither front_stock/back_stock nor front_movers/back_movers actually reflect which part of the train is facing forward.

When driving there's the hack of getting negative speeds while in reverse, but that's no option for determining which way a train parked at a stop is facing.
Did you consider rotation of locomotive?
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: API doesn't provide a way to get front/back trains

Post by Optera »

SilverB1rd wrote:it might help to why this information is needed? what does this information allow a mod to do that it cannot do now?
For example in LTN I provide train composition signals.
I'm sure we agree an LL-C-L with the 2 locos facing the stop needs different inserters active when refueling than when the single loco faces the stop.
So I was getting the LuaTrain.carriages but with no indicator which way is front I have no clue which direction i should parse it to provide an accurate representation according to the way the train faces inside the station.
orzelek wrote:Did you consider rotation of locomotive?
There are ppl out there using multi headed 2 way trains. Loco orientation does nothing.

Edit:
In simple terms, if LuaTrain.station is set there should be an indication which way is facing that station.
It can be as simple as a boolean LuaTrain.front_facing_station. true when front_stock is facing it and false when back_stock is facing it.
SilverB1rd
Inserter
Inserter
Posts: 47
Joined: Fri Mar 17, 2017 9:19 pm
Contact:

Re: API doesn't provide a way to get front/back of trains in stations

Post by SilverB1rd »

Maybe..

If LuaTrain.Station is set, Calculate the distance between the front_movers{1}.position, back_movers{1}.position, and the station.position, the one with the shortest distance is the one at the station.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14944
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: API doesn't provide a way to get front/back of trains in stations

Post by Rseding91 »

Trains have no concept of "forward" and "backwards" except in relation to the locomotive the player is sitting in.

What do you mean by "front"? If you have 2 locomotives each facing the opposite direction connected to each other which is "front"? If you're driving to the north in the south locomotive then again what is "front"? The one you're in or the one facing north? And if you get in the other then what is "front" again?

If you can better define what you're trying to do maybe I could make suggestions or expand the API to address your particular problem.
If you want to get ahold of me I'm almost always on Discord.
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: API doesn't provide a way to get front/back of trains in stations

Post by Optera »

Rseding91 wrote:Trains have no concept of "forward" and "backwards" except in relation to the locomotive the player is sitting in.

What do you mean by "front"? If you have 2 locomotives each facing the opposite direction connected to each other which is "front"? If you're driving to the north in the south locomotive then again what is "front"? The one you're in or the one facing north? And if you get in the other then what is "front" again?

If you can better define what you're trying to do maybe I could make suggestions or expand the API to address your particular problem.
The best definition of front for stationary trains with LuaTrain.station set would be front = closest to station back = furthest from station.
When station is nil the indicator for front can be nil too, as manual trains have no front.

As stated above I want to provide train composition from LuaTrain.carriages. What I lack is any indicator if carriages[1] or carriages[#carriages] is closest to the station.
I hope that makes sense now.
Post Reply

Return to “Modding interface requests”