Fix split vehicles always using the incorrect pivot point #73055
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 split vehicles always using the incorrect pivot point"
Purpose of change
In
vehicle::split_vehicles
, every new vehicle created is supposed to get a new position and pivot based on the parts they have after the split. However, when the function checks to make sure the new pivot is a valid 0,0 part, it actually mistakenly assigns the pivot to the part index of the original vehicle, AKA the other half of the split. This makes both resulting halves of the vehicle end up with the same position and pivot points, which can cause issues with anything that relies on a vehicle's position, likevehicle::get_remote_part
.Describe the solution
Set split_part0 to the value inside the split_parts array, not to the index.
Describe alternatives you've considered
Testing
In debug mode, watch the position values of the split vehicles during the relevant functions. See that after splitting the vehicles up they both incorrectly have the same position in the end. Apply this fix, do it again, and see that both splits correctly end up with different positions.
Additional context
This is a cherry-picked commit from my larger power grid usability PR, since as a bug fix it deserves its own PR.