Fix tow cables crashing and not keeping connections properly #71482
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 tow cables crashing and not keeping connections properly"
Purpose of change
Fixes #71412. Also fixes tow cables being fully disconnected when you only detach one end - the other end now stays connected, as with other cable links.
Describe the solution
Adds a check for a valid vehicle part, rather than naïvely assuming it'll always be valid. Adjusts the order invalidate_towing handles things so it removes parts and then makes a connection, since tow cables can't be attached to vehicles that already have one.
Describe alternatives you've considered
Tow cables still have a bunch of weird jank to them, but here I just wanted to fix them back to the workable state they were in before.
Testing
Repeated the steps of the linked issue, no problem. Attached a tow cable to two cars in both directions, both worked, cars tow properly. Tried connecting both cable ends to same car, fail as intended. While towing car, map edit a stone wall in between to make sure the cable snaps off as it should; it does.
Additional context