| 654 | } |
| 655 | |
| 656 | static RoadVehicle *RoadVehFindCloseTo(RoadVehicle *v, int x, int y, Direction dir, bool update_blocked_ctr = true) |
| 657 | { |
| 658 | RoadVehFindData rvf; |
| 659 | RoadVehicle *front = v->First(); |
| 660 | |
| 661 | if (front->reverse_ctr != 0) return nullptr; |
| 662 | |
| 663 | rvf.x = x; |
| 664 | rvf.y = y; |
| 665 | rvf.dir = dir; |
| 666 | rvf.veh = v; |
| 667 | rvf.best_diff = UINT_MAX; |
| 668 | |
| 669 | if (front->state == RVSB_WORMHOLE) { |
| 670 | for (Vehicle *u : VehiclesOnTile(v->tile)) { |
| 671 | FindClosestBlockingRoadVeh(u, &rvf); |
| 672 | } |
| 673 | for (Vehicle *u : VehiclesOnTile(GetOtherTunnelBridgeEnd(v->tile))) { |
| 674 | FindClosestBlockingRoadVeh(u, &rvf); |
| 675 | } |
| 676 | } else { |
| 677 | for (Vehicle *u : VehiclesNearTileXY(x, y, 8)) { |
| 678 | FindClosestBlockingRoadVeh(u, &rvf); |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | /* This code protects a roadvehicle from being blocked for ever |
| 683 | * If more than 1480 / 74 days a road vehicle is blocked, it will |
| 684 | * drive just through it. The ultimate backup-code of TTD. |
| 685 | * It can be disabled. */ |
| 686 | if (rvf.best_diff == UINT_MAX) { |
| 687 | front->blocked_ctr = 0; |
| 688 | return nullptr; |
| 689 | } |
| 690 | |
| 691 | if (update_blocked_ctr && ++front->blocked_ctr > 1480) return nullptr; |
| 692 | |
| 693 | return RoadVehicle::From(rvf.best); |
| 694 | } |
| 695 | |
| 696 | /** |
| 697 | * A road vehicle arrives at a station. If it is the first time, create a news item. |
no test coverage detected