MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / RoadVehFindCloseTo

Function RoadVehFindCloseTo

src/roadveh_cmd.cpp:656–694  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

654}
655
656static 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.

Callers 2

RoadVehLeaveDepotFunction · 0.85

Calls 5

VehiclesOnTileClass · 0.85
GetOtherTunnelBridgeEndFunction · 0.85
VehiclesNearTileXYClass · 0.85
FirstMethod · 0.45

Tested by

no test coverage detected