Refactor autodrive and not allow unsafe autodrive speed #46317
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
SUMMARY: Bugfixes "Refactor autodrive activity and not allow unsafe autodrive speed"
Purpose of change
Fixes #45260
Also erases drawn path on overmap screen when cancelling autodrive.
Describe the solution
When autodrive is enabled, the vehicle max speed is limited to the safe speed.
The fix to control the autodrive speed was simple, but the problem was the boolean
is_autodriving
was not being reset on cancelling the activity. So the speed limit would be enforced even after cancelling - not good.For an elegant solution I wanted to use a cancel method but activity handlers do not have them, and since handlers are deprecated I did not want to rewrite any of that code. So I refactored the autodrive activity to be an activity actor instead.
Cancelling autodrive disables the
is_autodriving
boolean so the speed limiting code properly reflects either manual or autodrive control.I also took the opportunity to erase the overmap character path which was persisting after cancelling an autodrive.
Describe alternatives you've considered
Handling the code similar to how foot travel is cancelled. It would have worked but the refactor to an activity actor needed to be done eventually anyway.
Also had coded in a cancel activity into the existing handler and it worked fine, but decided that deprecated code should not be expanded upon.
Testing
Full test program: no faults found.
Tested with a mountain bike and a 4 by 4 car.
Mountain bike before the fix: The bike would often exceed the safe limit of 15 mph and would tire out the player character.
Mountain bike after the fix: the bike speed never exceeds 15 mph and is easier on the player character.
4 by 4 car before and after the fix: the max autodrive speed is limited to 35 mph. No difference noticed.
Additional context
No serialize support included - the activity is not saved.