/** * Find the best depot for a road vehicle. * @param v Vehicle * @param tile Tile of the vehicle. * @param td Trackdir of the vehicle. * @param max_distance max length (penalty) for paths. */ inline FindDepotData FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance) { /* Set origin. */ Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td)); Yapf().SetMaxCost(max_distance); /* Find the best path and return if no depot is found. */ if (!Yapf().FindPath(v)) return FindDepotData(); /* Return the cost of the best path and its depot. */ Node *n = Yapf().GetBestNode(); return FindDepotData(n->m_segment_last_tile, n->m_cost); }
FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_distance) { TileIndex tile = v->tile; Trackdir trackdir = v->GetVehicleTrackdir(); if (!HasTrackdir(TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, v->compatible_roadtypes)), trackdir)) { return FindDepotData(); } /* default is YAPF type 2 */ typedef FindDepotData (*PfnFindNearestDepot)(const RoadVehicle*, TileIndex, Trackdir, int); PfnFindNearestDepot pfnFindNearestDepot = &CYapfRoadAnyDepot2::stFindNearestDepot; /* check if non-default YAPF type should be used */ if (_settings_game.pf.yapf.disable_node_optimization) { pfnFindNearestDepot = &CYapfRoadAnyDepot1::stFindNearestDepot; // Trackdir } return pfnFindNearestDepot(v, tile, trackdir, max_distance); }
FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_distance) { TileIndex tile = v->tile; Trackdir trackdir = v->GetVehicleTrackdir(); if ((TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, v->compatible_roadtypes)) & TrackdirToTrackdirBits(trackdir)) == 0) { return FindDepotData(); } /* default is YAPF type 2 */ typedef bool (*PfnFindNearestDepot)(const RoadVehicle*, TileIndex, Trackdir, int, TileIndex*); PfnFindNearestDepot pfnFindNearestDepot = &CYapfRoadAnyDepot2::stFindNearestDepot; /* check if non-default YAPF type should be used */ if (_settings_game.pf.yapf.disable_node_optimization) { pfnFindNearestDepot = &CYapfRoadAnyDepot1::stFindNearestDepot; // Trackdir, allow 90-deg } FindDepotData fdd; bool ret = pfnFindNearestDepot(v, tile, trackdir, max_distance, &fdd.tile); fdd.best_length = ret ? max_distance / 2 : UINT_MAX; // some fake distance or NOT_FOUND return fdd; }