Page 1 of 1
API doesn't provide a way to get front/back of trains in stations
Posted: Tue Mar 28, 2017 5:22 pm
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.
Re: API doesn't provide a way to get front/back trains
Posted: Tue Mar 28, 2017 5:38 pm
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?
Re: API doesn't provide a way to get front/back trains
Posted: Tue Mar 28, 2017 5:42 pm
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?
Re: API doesn't provide a way to get front/back trains
Posted: Tue Mar 28, 2017 5:57 pm
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.
Re: API doesn't provide a way to get front/back of trains in stations
Posted: Tue Mar 28, 2017 7:40 pm
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.
Re: API doesn't provide a way to get front/back of trains in stations
Posted: Tue Mar 28, 2017 7:57 pm
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.
Re: API doesn't provide a way to get front/back of trains in stations
Posted: Tue Mar 28, 2017 8:16 pm
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.