Codechange: refactor FindClosestDepot to not use pointers, but return a struct

This commit is contained in:
Rubidium
2023-01-03 22:33:09 +01:00
committed by rubidium42
parent b3907b1359
commit 375a5b8e3f
12 changed files with 69 additions and 82 deletions

View File

@@ -3185,17 +3185,15 @@ bool AfterLoadGame()
TileIndex cur_tile = rv->tile;
if (!IsLevelCrossingTile(cur_tile)) continue;
TileIndex location;
DestinationID destination;
bool reverse = true;
ClosestDepot closestDepot = rv->FindClosestDepot();
/* Try to find a depot with a distance limit of 512 tiles (Manhattan distance). */
if (rv->FindClosestDepot(&location, &destination, &reverse) && DistanceManhattan(rv->tile, location) < 512u) {
if (closestDepot.found && DistanceManhattan(rv->tile, closestDepot.location) < 512u) {
/* Teleport all parts of articulated vehicles. */
for (RoadVehicle *u = rv; u != nullptr; u = u->Next()) {
u->tile = location;
int x = TileX(location) * TILE_SIZE + TILE_SIZE / 2;
int y = TileY(location) * TILE_SIZE + TILE_SIZE / 2;
u->tile = closestDepot.location;
int x = TileX(closestDepot.location) * TILE_SIZE + TILE_SIZE / 2;
int y = TileY(closestDepot.location) * TILE_SIZE + TILE_SIZE / 2;
u->x_pos = x;
u->y_pos = y;
u->z_pos = GetSlopePixelZ(x, y);