* Swap vehicles \a l and \a r in consist \a v, and reverse their direction. * @param v Consist to change. * @param l %Vehicle index in the consist of the first vehicle. * @param r %Vehicle index in the consist of the second vehicle. */
| 1647 | * @param r %Vehicle index in the consist of the second vehicle. |
| 1648 | */ |
| 1649 | void ReverseTrainSwapVeh(Train *v, int l, int r) |
| 1650 | { |
| 1651 | Train *a, *b; |
| 1652 | |
| 1653 | /* locate vehicles to swap */ |
| 1654 | for (a = v; l != 0; l--) a = a->Next(); |
| 1655 | for (b = v; r != 0; r--) b = b->Next(); |
| 1656 | |
| 1657 | if (a != b) { |
| 1658 | /* swap the hidden bits */ |
| 1659 | { |
| 1660 | bool a_hidden = a->vehstatus.Test(VehState::Hidden); |
| 1661 | bool b_hidden = b->vehstatus.Test(VehState::Hidden); |
| 1662 | b->vehstatus.Set(VehState::Hidden, a_hidden); |
| 1663 | a->vehstatus.Set(VehState::Hidden, b_hidden); |
| 1664 | } |
| 1665 | |
| 1666 | std::swap(a->track, b->track); |
| 1667 | std::swap(a->direction, b->direction); |
| 1668 | std::swap(a->x_pos, b->x_pos); |
| 1669 | std::swap(a->y_pos, b->y_pos); |
| 1670 | std::swap(a->tile, b->tile); |
| 1671 | std::swap(a->z_pos, b->z_pos); |
| 1672 | |
| 1673 | SwapTrainFlags(&a->gv_flags, &b->gv_flags); |
| 1674 | |
| 1675 | UpdateStatusAfterSwap(a); |
| 1676 | UpdateStatusAfterSwap(b); |
| 1677 | } else { |
| 1678 | /* Swap GVF_GOINGUP_BIT/GVF_GOINGDOWN_BIT. |
| 1679 | * This is a little bit redundant way, a->gv_flags will |
| 1680 | * be (re)set twice, but it reduces code duplication */ |
| 1681 | SwapTrainFlags(&a->gv_flags, &a->gv_flags); |
| 1682 | UpdateStatusAfterSwap(a); |
| 1683 | } |
| 1684 | } |
| 1685 | |
| 1686 | /** |
| 1687 | * Check if the vehicle is a train |
no test coverage detected