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 fuel consumption UI inaccuracies #59297

Merged
merged 1 commit into from
Jul 16, 2022

Conversation

natsirt721
Copy link
Contributor

@natsirt721 natsirt721 commented Jul 15, 2022

Summary

Bugfixes "Fix inaccuracies in fuel consumption display"

Purpose of change

Fixes #37943
probably Fixes #58385

Related: #47384
As has been frequently noted, the fuel consumption display in the vehicle UI vastly over-reports fuel efficiency for chemical engines. This changes that.

Describe the solution

consumption_per_hour() was making some assumptions that are no longer true about fuel usage. Fortunately, we already have how much energy's worth of each type of fuel was used, and we can determine the most recent consumption rate by dividing by the specific energy of the fuel and doing some unit conversion.

I also changed the return type from int to long long to avoid overflows.

Describe alternatives you've considered

Something more like #47384, using a running average to populate the display instead of consumption for the most recent turn.

Testing

Spawned a variety of vehicle (electric bicycle, car, ambulance, semi truck, portable generator, mini locomotive) and drove them around, watching their reported fuel rates and noting when they actually ran out of fuel.

Additional context

I didn't see #47384 until I was writing this PR, if there's rationale for the more complex fix implemented there then I can try to bring those changes into this PR. Either way I think this is a good step in that direction.

Edit: fixed related PR number

@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` Vehicles Vehicles, parts, mechanics & interactions <Bugfix> This is a fix for a bug (or closes open issue) astyled astyled PR, label is assigned by github actions json-styled JSON lint passed, label assigned by github actions labels Jul 15, 2022
src/vehicle.cpp Outdated Show resolved Hide resolved
src/vehicle.cpp Outdated Show resolved Hide resolved
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Jul 16, 2022
@natsirt721 natsirt721 force-pushed the fix-fuel-consumption-ui branch from 53c6baf to f456512 Compare July 16, 2022 00:55
@dseguin dseguin merged commit 554df77 into CleverRaven:master Jul 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions Vehicles Vehicles, parts, mechanics & interactions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Big fuel loss after "fake parts update" Fuel remaining wildly inaccurate
3 participants