FS#3870 - Fix inaccurate display of velocites

Attached to Project: OpenTTD
Opened by Christian Hattemer (Krille) - Sunday, 06 June 2010, 22:00 GMT
Last edited by Remko Bijker (Rubidium) - Friday, 16 July 2010, 17:46 GMT
Type Patch
Category Core
Status Closed
Assigned To No-one
Operating System All
Severity Low
Priority Normal
Reported Version trunk
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


If you set the units to metric or SI then the value is converted twice when displaying a {VELOCITY}. First it's converted from the internal kph to mph, then to kph or m/s, depending on the setting.

This causes rounding errors which get especially noticeable for high values (e.g. fast planes).

The first part of the patch changes that to do at most one conversion. For metric units there's none at all.

Since the max speed conditional orders stored the conditional value in mph this is also fixed during afterload. This probably needs a bump of the savegame version which I haven't done yet. The case is simmilar for my other patch from  FS#3835 . It sounds like a good idea to commit both at the same time so that only one version bump is necessary.

One unnecessary cast is also removed by the patch.

I've attached a few pictures showing the effects of the patch.

The second patch adds/fixes a number of descriptive comments I made while working on the first patch.
This task depends upon

Closed by  Remko Bijker (Rubidium)
Friday, 16 July 2010, 17:46 GMT
Reason for closing:  Fixed
Additional comments about closing:  In r20164
Comment by Remko Bijker (Rubidium) - Monday, 07 June 2010, 13:21 GMT Comment by Christian Hattemer (Krille) - Monday, 07 June 2010, 20:02 GMT
I know of this changeset. However I couldn't make sense of the log message. Did he say that 1 mph = 1.6 kph isn't precise enough? The exact factor is 1 mph = 1.609344 kph.

If you look closer at the two pictures with imperial units you'll notice that the patch makes no difference there. But there is a difference for metric units. With the patch the displayed values exactly match those listed in the tables in the source. The conversion for SI units is also very accurate, sometimes more accurate than before, or at least about the same.

So the patch makes a (sometimes larger) improvement for metric units and changes about nothing for the other units.

Finally: All these points don't concern the second part of the patch in any way.
Comment by frosch (frosch) - Monday, 07 June 2010, 20:46 GMT
What rubidium wanted to point out. The conversions were already fixed once in r4322.
After lots of complains that e.g. vehicles no longer drove 100 km/h though they were previously designed to do so, it was reverted in r8464.
Comment by Christian Hattemer (Krille) - Monday, 07 June 2010, 22:08 GMT
I still don't get the point. When would the vehicles not reach their designed speed? Does it have something to do with NewGRF? Are there some of the complaints available to read? I'm unable to find the problem in my testing. Maybe things have changed since then? A lot of time and changes to the code have passed.

If nothing can be done the situation has to be described in the source, perhaps at the conversion table? Otherwise the next patch like this will appear sooner or later.

And how about my second part of the patch? It doesn't change anything in the code, it just adds useful (I think) documentation.

Comment by frosch (frosch) - Tuesday, 08 June 2010, 20:23 GMT
The point about the speed unit conversions is, that it does not matter how fast a vehicle moves exactly. You cannot distinguish 99 km/h from 100 km/h in game.

But for a lot of people and especially GRF authors it is important that a vehicles states it does 100 km/h, if that is the number written in the datasheet of the real engine. So they do a lot of trial&error until the GUI tells the numbers they want. For the game the precise speed is not important at all.

Now, when changing the conversions, there is no change in gameplay. But the GUI will show other numbers than it showed when the GRFs were created, and thus different numbers than intended. The number is important, not the relation to other units.
Comment by Christian Hattemer (Krille) - Saturday, 12 June 2010, 15:54 GMT
Thanks for sharing this insight. I'd suggest to put this description somewhere where it stays visible after closing this ticket, so other people having the same idea can find it.

For me the whole thing started when I looked at the aircraft code and noticed that they should taxi at 200 km/h but the display shows 201.

Just two things remain for me:
* What's the difference between plain km/h and km-ish/h?
* It seems that for aircrafts 1 unit is indeed 12.9 km-ish/h and not 12.8, which has been noted in table/engines.h. See e. g. r8973.
Comment by Remko Bijker (Rubidium) - Thursday, 15 July 2010, 22:40 GMT
The difference between km/h and km-ish/h is a factor 1.00584 (km-ish/h is the bigger of the two).
Back in r8973 km-ish/h wasn't coined yet, though they mean km-ish/h. As such 200 km-ish/h becomes 201.168, which rounded down is 201.

Furthermore I *think* that the new aircraft code was (initially) written in the time the base was km/h (i.e. before r8464), but nobody ever caught it being "wrong" before. So that part should be fixed.