OpenTTD

Tasklist

FS#6503 - Abnormalities in train subtile coordinates when reversing at the end of line

Attached to Project: OpenTTD
Opened by dP (_dp_) - Thursday, 01 September 2016, 13:45 GMT
Type Bug
Category Core
Status New
Assigned To No-one
Operating System All
Severity Low
Priority Normal
Reported Version 1.6.1
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 0
Private No

Details

I was investigating train movement mechanics and noticed some abnormalities. Opening this bug to sum up what I found so far.

I made python script(in attachment) to visualize train path in subtile coordinates. And apparently its location jumps one subtile when it reverses at the end of line (see attached image, loco lenght is 6 subtiles). From what I can tell it's a combination of several bugs:
1. Train goes one subtile too far before stopping. Speed also confirms it going 25->5->7...->25 on that extra subtile (that's not showing in gui though).
2. Reversing is wrong. It keeps coordinates unchanged and only flips direction. Because of _initial_tile_subcoord, real train position actually depends on train direction(dx,dy): real_x = pos_x + int(dx == -1) + dx * progress%, same for y. So flipping direction moves the train and x,y should be changed to compensate for it.

Just playing around with code I found that adding 1 to condition in TrainApproachingLineEnd fixes #1. And removing TrainCheckIfLineEnds call in TrainLocoHandler somehow fixes #2. But I didn't dig into it enough to understand what's going on there, so not sure if it's a right way to fix it (especially #2).

Also I ran out of time I can spend on this for now. Hope someone can pick it up from where I left it ;) Also can be useful to check subpixel movement for other situations and vehicle types.

P.S. Also attaching diff that outputs coordinates for python script from game and save that I used to generate the image.
This task depends upon

Comment by dP (_dp_) - Thursday, 01 September 2016, 23:01 GMT
One more thing. After reversing train keeps subtile progress which doesn't seem right either. Because at this point leftover progress means extra time, not distance. And after reverse it has 0 speed so it covers almost no distance in that extra time. Currently if train is lucky it can cover half(or mb even more) of subtile instantly after reverse because of this.

Loading...