OpenBVE icon indicating copy to clipboard operation
OpenBVE copied to clipboard

[Request] A way to determine trackDistance value for other trains (or even TFOs if possible) and the rail its running in

Open NYCTRailer opened this issue 4 years ago • 4 comments

I'm trying to develop a series of countdown clocks for a route, while there is a function that determines the distance for the closest train, I can't think of a way to determine distances for other trains (or even TFOs if possible) , also a way to determine the rail index the specified train is running in. something like:

trackDistanceTrain[trainIndex] - A variable to represent the trackDistance of a train with Index trainIndex , this would be a solution for a.i trains trackDistanceTFO[TFOIndex] - A variable to represent the trackDistance of a TFO with index TFOIndex, this would be a solution to the TFOs (which are technically A.I trains that can run in any rail) RailIndex[trainIndex] - A variable that would return the rail index of the train with index trainIndex

NYCTRailer avatar Jan 04 '21 23:01 NYCTRailer

RailIndex is certainly doable for TFO objects & anything attached to trains. My immediate thought is that we actually want two here though- RailIndex (Returning the index of the rail at the front of the train) and RailIndex[Car] returning the index of the rail at the front of the selected car.

This possibly (probably?) ought to be flipped on direction of travel too. What exactly are you trying to achieve here?


TrackDistance is more complex though. To make this work reliably, TrainIndex would have to be the index to the train within the actual trains array. Doing it by closest train is a bad recipie for trouble. Even this isn't really particularly sensible though, as you don't really know exactly how many trains there are in the world, and for that matter adding another TFO or pretrain command can easily muck things up.

The solution to that is likely to replace the trains array with a dictionary, but where to get the key from I'm not sure off the top of my head..... Could add the key to the TFO XML files without too much trouble, but dunno off the top of my head how we'd do that for the player and pretrains without a random ID generator or something.....

leezer3 avatar Jan 05 '21 11:01 leezer3

Secondary thought: All current animated functions (IIRC) assume that in terms of cars, the train is travelling forwards on the route, as per direction of travel & cars are numbered from front to rear.

Probably need to consider how to number cars if a train is running in the opposite direction.

Coupling / uncoupling (your other issue) is also on my list of things to think about more closely; If we're accessing via carindex, what happens when we couple an additional car on? My immediate thought is that we probably have to compensate for this internally, but that feels like a nasty mess.....

TLDR: Shiny things are complex to implement.... We need to think about the implications of any design choices in terms of the longer term future, else things end up getting re-written at a later date :)

leezer3 avatar Jan 05 '21 12:01 leezer3

I have an idea not sure if it will help or worsen though: What if the direction of travel is determined by destination(bound to the start of the route, bound to the end of the route)? The destination it's bound to its determined by reverser position and rate of change, so a TFO traveling backward (towards the start of the route) but its reverser is forward means that its boundary is the station of origin of the player(or the segment where it is programmed to disappear). If this works it makes way for the variable TravelDirection[TrainIndex] , and maybe ease something else up, but what do I know.

What exactly are you trying to achieve here?

Some countdown clocks which are part of my creation, measure the assumed track the displayed train is going to arrive on, so I thought that the way to measure it is to determine the railIndex the train is running on

NYCTRailer avatar Jan 05 '21 20:01 NYCTRailer

Probably need to consider how to number cars if a train is running in the opposite direction.

I don't know if my idea would help a little bit to think about the elaboration of that

Coupling / uncoupling (your other issue) is also on my list of things to think about more closely; If we're accessing via carindex, what happens when we couple an additional car on?

What if Cars to be coupled had a unique section in the extensions file and a unique .dat file or something? For Indexes (if they can be negative) , have front coupled cars be negative, back coupled cars be the last original car + 1. But once again, I know nothing

NYCTRailer avatar Jan 05 '21 21:01 NYCTRailer