New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ottd_display_speed to reflect changes done in OpenTTD #75
Conversation
adea28a
to
5bc8f9d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy if you're happy
nml/actions/action0properties.py
Outdated
@@ -255,7 +255,7 @@ def cargo_list(value, max_num_cargos): | |||
} | |||
|
|||
def ottd_display_speed(value, divisor, unit): | |||
return int(value.value / divisor) * 10 // 16 * unit.ottd_mul >> unit.ottd_shift | |||
return (round(value.value // divisor * 10 * unit.ottd_mul) >> unit.ottd_shift) // 16 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there an integer division "// divisor" inside a round? That looks wrong to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this function is meant to replicate the exact behaviour of OTTD's ConvertKmhishSpeedToDisplaySpeed.
Thus I would expect:
(round(value.value / divisor * 10 * unit.ottd_mul) >> unit.ottd_shift) // 16
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was actually wondering whether we may have a round there at all... or whether we get some platform dependency there which we might not want.
Though without an integer being left of the shift operator, we get a type error... but then with float math we can skip using the shift operator and do float math all the way; the original #35 simply does not work at all.
This is a rebased version of #35
Closes #35