Skip to content
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

Merged
merged 3 commits into from May 5, 2020

Conversation

@planetmaker
Copy link
Contributor

planetmaker commented Dec 20, 2019

This is a rebased version of #35

Closes #35

@planetmaker planetmaker force-pushed the planetmaker:speed_fixes branch from adea28a to 5bc8f9d Dec 20, 2019
Copy link
Member

LordAro left a comment

I'm happy if you're happy

@@ -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

This comment has been minimized.

Copy link
@frosch123

frosch123 Dec 20, 2019

Member

Why is there an integer division "// divisor" inside a round? That looks wrong to me.

This comment has been minimized.

Copy link
@frosch123

frosch123 Dec 20, 2019

Member

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

This comment has been minimized.

Copy link
@planetmaker

planetmaker Dec 20, 2019

Author Contributor

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.

@LordAro LordAro dismissed their stale review Dec 28, 2019

nope

@frosch123 frosch123 force-pushed the planetmaker:speed_fixes branch from 5bc8f9d to 3664feb May 5, 2020
@frosch123 frosch123 merged commit 7affc55 into OpenTTD:master May 5, 2020
15 checks passed
15 checks passed
Python 3.5 on ubuntu-latest
Details
Python 3.x on ubuntu-latest
Details
Python 3.6 on ubuntu-latest
Details
Python 3.x on macOS-latest
Details
Python 3.7 on ubuntu-latest
Details
Python 3.x on windows-2016
Details
Python 3.8 on ubuntu-latest
Details
Python 3.5 on macOS-latest
Details
Python 3.6 on macOS-latest
Details
Python 3.7 on macOS-latest
Details
Python 3.8 on macOS-latest
Details
Python 3.5 on windows-2016
Details
Python 3.6 on windows-2016
Details
Python 3.7 on windows-2016
Details
Python 3.8 on windows-2016
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.