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 planetmaker commented Dec 20, 2019

This is a rebased version of #35

Closes #35

LordAro
LordAro previously approved these changes Dec 20, 2019
Copy link
Member

@LordAro 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
Copy link
Member

@frosch123 frosch123 Dec 20, 2019

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.

Copy link
Member

@frosch123 frosch123 Dec 20, 2019

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

Copy link
Contributor Author

@planetmaker planetmaker Dec 20, 2019

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.

@LordAro LordAro dismissed their stale review Dec 28, 2019

nope

@frosch123 frosch123 merged commit 7affc55 into OpenTTD:master May 5, 2020
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants