Fix fuel consumption UI inaccuracies #59297
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
tolong 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