Recalculate vehicle viability after part destruction #38487
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 "Recalculate vehicle viability after part destruction"
Purpose of change
Fixes #38473.
Describe the solution
Previously, the vehicle info cache was not being refreshed when parts on your car were destroyed via damage_direct.
This fix calls refresh() when a part is destroyed. It also calls stop() if the vehicle is no longer viable to drive, which fixes a bug that just calling refresh() caused where the vehicle still reported a positive velocity after stopping due to wheels being blown out, and endlessly reporting that it could not move.
Describe alternatives you've considered
Leaving this to someone who is more of an expert in the vehicle code.
Testing
Before and after, dropped multiple bear traps and drove over them in a vehicle. Previously, you could drive forever as long as you never stopped driving, even after losing all wheels. Now, after you lose 2 wheels in a normal car, you immediately come to a screeching halt with the "X doesn't have enough wheels to move" message.
Additional context
I added the stop() call to boats that become too leaky, but I am not sure if currently it's possible to set up a situation where you can be driving a boat and it gets hit by something to make it too leaky to continue. If so, please let me know the repro for this and I will test it as well.
This change definitely makes accidents more dangerous if they blow out tires while you're in a dangerous spot, which I'm all in favor of!