* Rotate all vehicles of a (crashed) train chain randomly to animate the crash. * @param v First crashed vehicle. */
| 3712 | * @param v First crashed vehicle. |
| 3713 | */ |
| 3714 | static void ChangeTrainDirRandomly(Train *v) |
| 3715 | { |
| 3716 | static const DirDiff delta[] = { |
| 3717 | DIRDIFF_45LEFT, DIRDIFF_SAME, DIRDIFF_SAME, DIRDIFF_45RIGHT |
| 3718 | }; |
| 3719 | |
| 3720 | do { |
| 3721 | /* We don't need to twist around vehicles if they're not visible */ |
| 3722 | if (!v->vehstatus.Test(VehState::Hidden)) { |
| 3723 | v->direction = ChangeDir(v->direction, delta[GB(Random(), 0, 2)]); |
| 3724 | /* Refrain from updating the z position of the vehicle when on |
| 3725 | * a bridge, because UpdateInclination() will put the vehicle under |
| 3726 | * the bridge in that case */ |
| 3727 | if (v->track != TRACK_BIT_WORMHOLE) { |
| 3728 | v->UpdatePosition(); |
| 3729 | v->UpdateInclination(false, true); |
| 3730 | } else { |
| 3731 | v->UpdateViewport(false, true); |
| 3732 | } |
| 3733 | } |
| 3734 | } while ((v = v->Next()) != nullptr); |
| 3735 | } |
| 3736 | |
| 3737 | /** |
| 3738 | * Handle a crashed train. |
no test coverage detected