KUDr@3900: /* $Id$ */ KUDr@3900: celestar@6447: /** @file yapf_road.cpp */ celestar@6447: KUDr@3900: #include "../stdafx.h" KUDr@3900: KUDr@3900: #include "yapf.hpp" KUDr@3900: #include "yapf_node_road.hpp" KUDr@3900: KUDr@3900: KUDr@3900: template KUDr@3900: class CYapfCostRoadT KUDr@3900: { KUDr@3900: public: KUDr@3914: typedef typename Types::Tpf Tpf; ///< pathfinder (derived from THIS class) KUDr@3914: typedef typename Types::TrackFollower TrackFollower; ///< track follower helper KUDr@3900: typedef typename Types::NodeList::Titem Node; ///< this will be our node type KUDr@3900: typedef typename Node::Key Key; ///< key to hash tables KUDr@3900: KUDr@3900: protected: KUDr@3914: /// to access inherited path finder KUDr@3900: Tpf& Yapf() {return *static_cast(this);} KUDr@3900: KUDr@3900: int SlopeCost(TileIndex tile, TileIndex next_tile, Trackdir trackdir) KUDr@3900: { KUDr@3900: // height of the center of the current tile KUDr@3900: int x1 = TileX(tile) * TILE_SIZE; KUDr@3900: int y1 = TileY(tile) * TILE_SIZE; peter1138@3993: int z1 = GetSlopeZ(x1 + TILE_SIZE / 2, y1 + TILE_SIZE / 2); KUDr@3900: KUDr@3900: // height of the center of the next tile KUDr@3900: int x2 = TileX(next_tile) * TILE_SIZE; KUDr@3900: int y2 = TileY(next_tile) * TILE_SIZE; peter1138@3993: int z2 = GetSlopeZ(x2 + TILE_SIZE / 2, y2 + TILE_SIZE / 2); KUDr@3900: KUDr@3900: if (z2 - z1 > 1) { KUDr@3900: /* Slope up */ KUDr@3981: return Yapf().PfGetSettings().road_slope_penalty; KUDr@3900: } KUDr@3900: return 0; KUDr@3900: } KUDr@3900: KUDr@3900: /** return one tile cost */ KUDr@3900: FORCEINLINE int OneTileCost(TileIndex tile, Trackdir trackdir) KUDr@3900: { KUDr@3900: int cost = 0; KUDr@3900: // set base cost KUDr@3900: if (IsDiagonalTrackdir(trackdir)) { KUDr@3981: cost += YAPF_TILE_LENGTH; KUDr@3900: switch (GetTileType(tile)) { rubidium@7866: case MP_ROAD: KUDr@3900: /* Increase the cost for level crossings */ KUDr@3900: if (IsLevelCrossing(tile)) KUDr@3981: cost += Yapf().PfGetSettings().road_crossing_penalty; KUDr@3900: break; rubidium@6338: case MP_STATION: rubidium@6338: if (IsDriveThroughStopTile(tile)) rubidium@6338: cost += Yapf().PfGetSettings().road_stop_penalty; rubidium@6338: break; KUDr@3900: KUDr@3900: default: KUDr@3900: break; KUDr@3900: } KUDr@3900: } else { KUDr@3900: // non-diagonal trackdir KUDr@4411: cost = YAPF_TILE_CORNER_LENGTH + Yapf().PfGetSettings().road_curve_penalty; KUDr@3900: } KUDr@3900: return cost; KUDr@3900: } KUDr@3900: KUDr@3900: public: KUDr@3914: /** Called by YAPF to calculate the cost from the origin to the given node. rubidium@4549: * Calculates only the cost of given node, adds it to the parent node cost rubidium@4549: * and stores the result into Node::m_cost member */ KUDr@7533: FORCEINLINE bool PfCalcCost(Node& n, const TrackFollower *tf) KUDr@3900: { KUDr@3900: int segment_cost = 0; KUDr@3900: // start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment KUDr@3900: TileIndex tile = n.m_key.m_tile; KUDr@3900: Trackdir trackdir = n.m_key.m_td; KUDr@3900: while (true) { KUDr@3900: // base tile cost depending on distance between edges KUDr@3900: segment_cost += Yapf().OneTileCost(tile, trackdir); KUDr@3900: rubidium@6338: const Vehicle* v = Yapf().GetVehicle(); rubidium@6338: // we have reached the vehicle's destination - segment should end here to avoid target skipping rubidium@6338: if (v->current_order.type == OT_GOTO_STATION && tile == v->dest_tile) break; rubidium@6338: KUDr@3976: // stop if we have just entered the depot KUDr@3976: if (IsTileDepotType(tile, TRANSPORT_ROAD) && trackdir == DiagdirToDiagTrackdir(ReverseDiagDir(GetRoadDepotDirection(tile)))) { KUDr@3976: // next time we will reverse and leave the depot KUDr@3976: break; KUDr@3976: } KUDr@3976: KUDr@3976: // if there are no reachable trackdirs on new tile, we have end of road KUDr@4407: TrackFollower F(Yapf().GetVehicle()); KUDr@3900: if (!F.Follow(tile, trackdir)) break; KUDr@3900: KUDr@3900: // if there are more trackdirs available & reachable, we are at the end of segment truelight@8329: if (KillFirstBit(F.m_new_td_bits) != TRACKDIR_BIT_NONE) break; KUDr@3900: KUDr@3900: Trackdir new_td = (Trackdir)FindFirstBit2x64(F.m_new_td_bits); KUDr@3900: KUDr@3900: // stop if RV is on simple loop with no junctions KUDr@3900: if (F.m_new_tile == n.m_key.m_tile && new_td == n.m_key.m_td) return false; KUDr@3900: KUDr@3900: // if we skipped some tunnel tiles, add their cost KUDr@3981: segment_cost += F.m_tiles_skipped * YAPF_TILE_LENGTH; KUDr@3900: KUDr@3900: // add hilly terrain penalty KUDr@3900: segment_cost += Yapf().SlopeCost(tile, F.m_new_tile, trackdir); KUDr@3900: KUDr@3900: // add min/max speed penalties KUDr@3900: int min_speed = 0; KUDr@3900: int max_speed = F.GetSpeedLimit(&min_speed); KUDr@3900: if (max_speed < v->max_speed) segment_cost += 1 * (v->max_speed - max_speed); KUDr@3900: if (min_speed > v->max_speed) segment_cost += 10 * (min_speed - v->max_speed); KUDr@3900: KUDr@3900: // move to the next tile KUDr@3900: tile = F.m_new_tile; KUDr@3900: trackdir = new_td; KUDr@3900: }; KUDr@3900: KUDr@3900: // save end of segment back to the node KUDr@3900: n.m_segment_last_tile = tile; KUDr@3900: n.m_segment_last_td = trackdir; KUDr@3900: KUDr@3900: // save also tile cost KUDr@3900: int parent_cost = (n.m_parent != NULL) ? n.m_parent->m_cost : 0; KUDr@3900: n.m_cost = parent_cost + segment_cost; KUDr@3900: return true; KUDr@3900: } KUDr@3900: }; KUDr@3900: KUDr@3900: KUDr@3900: template KUDr@3900: class CYapfDestinationAnyDepotRoadT KUDr@3900: { KUDr@3900: public: KUDr@3914: typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class) KUDr@3900: typedef typename Types::TrackFollower TrackFollower; KUDr@3914: typedef typename Types::NodeList::Titem Node; ///< this will be our node type KUDr@3914: typedef typename Node::Key Key; ///< key to hash tables KUDr@3900: KUDr@3914: /// to access inherited path finder KUDr@3900: Tpf& Yapf() {return *static_cast(this);} KUDr@3900: KUDr@3914: /// Called by YAPF to detect if node ends in the desired destination KUDr@3900: FORCEINLINE bool PfDetectDestination(Node& n) KUDr@3900: { KUDr@3900: bool bDest = IsTileDepotType(n.m_segment_last_tile, TRANSPORT_ROAD); KUDr@3900: return bDest; KUDr@3900: } KUDr@3900: KUDr@3914: /** Called by YAPF to calculate cost estimate. Calculates distance to the destination rubidium@4549: * adds it to the actual cost from origin and stores the sum to the Node::m_estimate */ KUDr@3900: FORCEINLINE bool PfCalcEstimate(Node& n) KUDr@3900: { KUDr@3900: n.m_estimate = n.m_cost; KUDr@3900: return true; KUDr@3900: } KUDr@3900: }; KUDr@3900: KUDr@3900: KUDr@3900: template KUDr@3900: class CYapfDestinationTileRoadT KUDr@3900: { KUDr@3900: public: KUDr@3914: typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class) KUDr@3900: typedef typename Types::TrackFollower TrackFollower; KUDr@3914: typedef typename Types::NodeList::Titem Node; ///< this will be our node type KUDr@3914: typedef typename Node::Key Key; ///< key to hash tables KUDr@3900: KUDr@3900: protected: KUDr@3900: TileIndex m_destTile; KUDr@3900: TrackdirBits m_destTrackdirs; KUDr@3900: KUDr@3900: public: KUDr@3900: void SetDestination(TileIndex tile, TrackdirBits trackdirs) KUDr@3900: { KUDr@3900: m_destTile = tile; KUDr@3900: m_destTrackdirs = trackdirs; KUDr@3900: } KUDr@3900: KUDr@3900: protected: KUDr@3914: /// to access inherited path finder KUDr@3900: Tpf& Yapf() {return *static_cast(this);} KUDr@3900: KUDr@3900: public: KUDr@3914: /// Called by YAPF to detect if node ends in the desired destination KUDr@3900: FORCEINLINE bool PfDetectDestination(Node& n) KUDr@3900: { KUDr@3900: bool bDest = (n.m_segment_last_tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(n.m_segment_last_td)) != TRACKDIR_BIT_NONE); KUDr@3900: return bDest; KUDr@3900: } KUDr@3900: KUDr@3914: /** Called by YAPF to calculate cost estimate. Calculates distance to the destination rubidium@4549: * adds it to the actual cost from origin and stores the sum to the Node::m_estimate */ KUDr@3900: inline bool PfCalcEstimate(Node& n) KUDr@3900: { KUDr@3900: static int dg_dir_to_x_offs[] = {-1, 0, 1, 0}; KUDr@3900: static int dg_dir_to_y_offs[] = {0, 1, 0, -1}; KUDr@3900: if (PfDetectDestination(n)) { KUDr@3900: n.m_estimate = n.m_cost; KUDr@3900: return true; KUDr@3900: } KUDr@3900: KUDr@3900: TileIndex tile = n.m_segment_last_tile; KUDr@3900: DiagDirection exitdir = TrackdirToExitdir(n.m_segment_last_td); KUDr@3900: int x1 = 2 * TileX(tile) + dg_dir_to_x_offs[(int)exitdir]; KUDr@3900: int y1 = 2 * TileY(tile) + dg_dir_to_y_offs[(int)exitdir]; KUDr@3900: int x2 = 2 * TileX(m_destTile); KUDr@3900: int y2 = 2 * TileY(m_destTile); KUDr@3900: int dx = abs(x1 - x2); KUDr@3900: int dy = abs(y1 - y2); KUDr@3900: int dmin = min(dx, dy); KUDr@3900: int dxy = abs(dx - dy); KUDr@3981: int d = dmin * YAPF_TILE_CORNER_LENGTH + (dxy - 1) * (YAPF_TILE_LENGTH / 2); KUDr@3900: n.m_estimate = n.m_cost + d; KUDr@3900: assert(n.m_estimate >= n.m_parent->m_estimate); KUDr@3900: return true; KUDr@3900: } KUDr@3900: }; KUDr@3900: KUDr@3900: KUDr@3900: KUDr@3900: template KUDr@3900: class CYapfFollowRoadT KUDr@3900: { KUDr@3900: public: KUDr@3914: typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class) KUDr@3900: typedef typename Types::TrackFollower TrackFollower; KUDr@3914: typedef typename Types::NodeList::Titem Node; ///< this will be our node type KUDr@3914: typedef typename Node::Key Key; ///< key to hash tables KUDr@3900: KUDr@3900: protected: KUDr@3914: /// to access inherited path finder KUDr@3900: FORCEINLINE Tpf& Yapf() {return *static_cast(this);} KUDr@3900: KUDr@3900: public: KUDr@3900: KUDr@3914: /** Called by YAPF to move from the given node to the next tile. For each rubidium@4549: * reachable trackdir on the new tile creates new node, initializes it rubidium@4549: * and adds it to the open list by calling Yapf().AddNewNode(n) */ KUDr@3900: inline void PfFollowNode(Node& old_node) KUDr@3900: { KUDr@4407: TrackFollower F(Yapf().GetVehicle()); KUDr@3900: if (F.Follow(old_node.m_segment_last_tile, old_node.m_segment_last_td)) KUDr@6458: Yapf().AddMultipleNodes(&old_node, F); KUDr@3900: } KUDr@3900: KUDr@3914: /// return debug report character to identify the transportation type KUDr@3900: FORCEINLINE char TransportTypeChar() const {return 'r';} KUDr@3900: KUDr@3900: static Trackdir stChooseRoadTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir) KUDr@3900: { KUDr@3900: Tpf pf; KUDr@3900: return pf.ChooseRoadTrack(v, tile, enterdir); KUDr@3900: } KUDr@3900: KUDr@3900: FORCEINLINE Trackdir ChooseRoadTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir) KUDr@3900: { KUDr@3900: // handle special case - when next tile is destination tile KUDr@3900: if (tile == v->dest_tile) { KUDr@3900: // choose diagonal trackdir reachable from enterdir KUDr@3900: return (Trackdir)DiagdirToDiagTrackdir(enterdir); KUDr@3900: } KUDr@3900: // our source tile will be the next vehicle tile (should be the given one) KUDr@3900: TileIndex src_tile = tile; KUDr@3900: // get available trackdirs on the start tile rubidium@7179: uint ts = GetTileTrackStatus(tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes); KUDr@3900: TrackdirBits src_trackdirs = (TrackdirBits)(ts & TRACKDIR_BIT_MASK); KUDr@3900: // select reachable trackdirs only KUDr@3900: src_trackdirs &= DiagdirReachesTrackdirs(enterdir); KUDr@3900: KUDr@3900: // get available trackdirs on the destination tile KUDr@3900: TileIndex dest_tile = v->dest_tile; rubidium@7179: uint dest_ts = GetTileTrackStatus(dest_tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes); KUDr@3900: TrackdirBits dest_trackdirs = (TrackdirBits)(dest_ts & TRACKDIR_BIT_MASK); KUDr@3900: KUDr@3900: // set origin and destination nodes KUDr@3900: Yapf().SetOrigin(src_tile, src_trackdirs); KUDr@3900: Yapf().SetDestination(dest_tile, dest_trackdirs); KUDr@3900: KUDr@3900: // find the best path KUDr@3900: Yapf().FindPath(v); KUDr@3900: KUDr@3900: // if path not found - return INVALID_TRACKDIR KUDr@3900: Trackdir next_trackdir = INVALID_TRACKDIR; KUDr@7006: Node *pNode = Yapf().GetBestNode(); KUDr@3900: if (pNode != NULL) { KUDr@3900: // path was found or at least suggested KUDr@3900: // walk through the path back to its origin KUDr@3900: while (pNode->m_parent != NULL) { KUDr@3900: pNode = pNode->m_parent; KUDr@3900: } KUDr@3900: // return trackdir from the best origin node (one of start nodes) KUDr@3900: Node& best_next_node = *pNode; KUDr@3900: assert(best_next_node.GetTile() == tile); KUDr@3900: next_trackdir = best_next_node.GetTrackdir(); KUDr@3900: } KUDr@3900: return next_trackdir; KUDr@3900: } KUDr@3900: KUDr@3915: static uint stDistanceToTile(const Vehicle *v, TileIndex tile) KUDr@3915: { KUDr@3915: Tpf pf; KUDr@3915: return pf.DistanceToTile(v, tile); KUDr@3915: } KUDr@3915: KUDr@3915: FORCEINLINE uint DistanceToTile(const Vehicle *v, TileIndex dst_tile) KUDr@3915: { KUDr@3915: // handle special case - when current tile is the destination tile KUDr@3915: if (dst_tile == v->tile) { KUDr@3915: // distance is zero in this case KUDr@3915: return 0; KUDr@3915: } KUDr@3915: KUDr@3918: if (!SetOriginFromVehiclePos(v)) return UINT_MAX; KUDr@3915: KUDr@3915: // set destination tile, trackdir KUDr@3915: // get available trackdirs on the destination tile rubidium@7179: uint dest_ts = GetTileTrackStatus(dst_tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes); KUDr@3915: TrackdirBits dst_td_bits = (TrackdirBits)(dest_ts & TRACKDIR_BIT_MASK); KUDr@3915: Yapf().SetDestination(dst_tile, dst_td_bits); KUDr@3915: KUDr@3915: // find the best path KUDr@3915: Yapf().FindPath(v); KUDr@3915: KUDr@3915: // if path not found - return distance = UINT_MAX KUDr@3915: uint dist = UINT_MAX; KUDr@7006: Node *pNode = Yapf().GetBestNode(); KUDr@3915: if (pNode != NULL) { KUDr@3915: // path was found or at least suggested KUDr@3915: // get the path cost estimate KUDr@3915: dist = pNode->GetCostEstimate(); KUDr@3915: } KUDr@3915: KUDr@3915: return dist; KUDr@3915: } KUDr@3915: KUDr@3918: /** Return true if the valid origin (tile/trackdir) was set from the current vehicle position. */ KUDr@3918: FORCEINLINE bool SetOriginFromVehiclePos(const Vehicle *v) KUDr@3918: { KUDr@3918: // set origin (tile, trackdir) KUDr@3918: TileIndex src_tile = v->tile; KUDr@3918: Trackdir src_td = GetVehicleTrackdir(v); rubidium@7179: if ((GetTileTrackStatus(src_tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes) & TrackdirToTrackdirBits(src_td)) == 0) { KUDr@3918: // sometimes the roadveh is not on the road (it resides on non-existing track) KUDr@3918: // how should we handle that situation? KUDr@3918: return false; KUDr@3918: } KUDr@3918: Yapf().SetOrigin(src_tile, TrackdirToTrackdirBits(src_td)); KUDr@3918: return true; KUDr@3918: } KUDr@3918: tron@4989: static Depot* stFindNearestDepot(const Vehicle* v, TileIndex tile, Trackdir td) KUDr@3900: { KUDr@3900: Tpf pf; KUDr@3900: return pf.FindNearestDepot(v, tile, td); KUDr@3900: } KUDr@3900: tron@4989: FORCEINLINE Depot* FindNearestDepot(const Vehicle* v, TileIndex tile, Trackdir td) KUDr@3900: { KUDr@3900: // set origin and destination nodes KUDr@3900: Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td)); KUDr@3900: KUDr@3900: // find the best path KUDr@3900: bool bFound = Yapf().FindPath(v); KUDr@3900: if (!bFound) return false; KUDr@3900: KUDr@3900: // some path found KUDr@3900: // get found depot tile KUDr@7006: Node *n = Yapf().GetBestNode(); KUDr@7006: TileIndex depot_tile = n->m_segment_last_tile; KUDr@3900: assert(IsTileDepotType(depot_tile, TRANSPORT_ROAD)); KUDr@3900: Depot* ret = GetDepotByTile(depot_tile); KUDr@3900: return ret; KUDr@3900: } KUDr@3900: }; KUDr@3900: KUDr@3900: template class Tdestination> KUDr@3900: struct CYapfRoad_TypesT KUDr@3900: { KUDr@3900: typedef CYapfRoad_TypesT Types; KUDr@3900: KUDr@3900: typedef Tpf_ Tpf; KUDr@3900: typedef CFollowTrackRoad TrackFollower; KUDr@3900: typedef Tnode_list NodeList; KUDr@3900: typedef CYapfBaseT PfBase; KUDr@3900: typedef CYapfFollowRoadT PfFollow; KUDr@3900: typedef CYapfOriginTileT PfOrigin; KUDr@3900: typedef Tdestination PfDestination; KUDr@3900: typedef CYapfSegmentCostCacheNoneT PfCache; KUDr@3900: typedef CYapfCostRoadT PfCost; KUDr@3900: }; KUDr@3900: KUDr@3900: struct CYapfRoad1 : CYapfT > {}; KUDr@3900: struct CYapfRoad2 : CYapfT > {}; KUDr@3900: KUDr@3900: struct CYapfRoadAnyDepot1 : CYapfT > {}; KUDr@3900: struct CYapfRoadAnyDepot2 : CYapfT > {}; KUDr@3900: KUDr@3900: KUDr@3900: Trackdir YapfChooseRoadTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir) KUDr@3900: { KUDr@3900: // default is YAPF type 2 KUDr@3900: typedef Trackdir (*PfnChooseRoadTrack)(Vehicle*, TileIndex, DiagDirection); KUDr@3900: PfnChooseRoadTrack pfnChooseRoadTrack = &CYapfRoad2::stChooseRoadTrack; // default: ExitDir, allow 90-deg KUDr@3900: KUDr@3900: // check if non-default YAPF type should be used KUDr@3900: if (_patches.yapf.disable_node_optimization) KUDr@3900: pfnChooseRoadTrack = &CYapfRoad1::stChooseRoadTrack; // Trackdir, allow 90-deg KUDr@3900: KUDr@3900: Trackdir td_ret = pfnChooseRoadTrack(v, tile, enterdir); KUDr@3900: return td_ret; KUDr@3900: } KUDr@3900: KUDr@3915: uint YapfRoadVehDistanceToTile(const Vehicle* v, TileIndex tile) KUDr@3915: { KUDr@3915: // default is YAPF type 2 KUDr@3915: typedef uint (*PfnDistanceToTile)(const Vehicle*, TileIndex); KUDr@3915: PfnDistanceToTile pfnDistanceToTile = &CYapfRoad2::stDistanceToTile; // default: ExitDir, allow 90-deg KUDr@3915: KUDr@3915: // check if non-default YAPF type should be used KUDr@3915: if (_patches.yapf.disable_node_optimization) KUDr@3915: pfnDistanceToTile = &CYapfRoad1::stDistanceToTile; // Trackdir, allow 90-deg KUDr@3915: KUDr@3915: // measure distance in YAPF units KUDr@3915: uint dist = pfnDistanceToTile(v, tile); KUDr@3915: // convert distance to tiles KUDr@3915: if (dist != UINT_MAX) KUDr@4410: dist = (dist + YAPF_TILE_LENGTH - 1) / YAPF_TILE_LENGTH; KUDr@3915: return dist; KUDr@3915: } KUDr@3915: KUDr@3900: Depot* YapfFindNearestRoadDepot(const Vehicle *v) KUDr@3900: { KUDr@3900: TileIndex tile = v->tile; KUDr@3900: Trackdir trackdir = GetVehicleTrackdir(v); rubidium@7179: if ((GetTileTrackStatus(tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes) & TrackdirToTrackdirBits(trackdir)) == 0) KUDr@3900: return NULL; KUDr@3900: KUDr@3975: // handle the case when our vehicle is already in the depot tile rubidium@7866: if (IsTileType(tile, MP_ROAD) && IsTileDepotType(tile, TRANSPORT_ROAD)) { KUDr@3975: // only what we need to return is the Depot* KUDr@3975: return GetDepotByTile(tile); KUDr@3975: } KUDr@3975: KUDr@3900: // default is YAPF type 2 tron@4989: typedef Depot* (*PfnFindNearestDepot)(const Vehicle*, TileIndex, Trackdir); KUDr@3900: PfnFindNearestDepot pfnFindNearestDepot = &CYapfRoadAnyDepot2::stFindNearestDepot; KUDr@3900: KUDr@3900: // check if non-default YAPF type should be used KUDr@3900: if (_patches.yapf.disable_node_optimization) KUDr@3900: pfnFindNearestDepot = &CYapfRoadAnyDepot1::stFindNearestDepot; // Trackdir, allow 90-deg KUDr@3900: tron@4989: Depot* ret = pfnFindNearestDepot(v, tile, trackdir); KUDr@3900: return ret; KUDr@3900: }