diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1694,24 +1694,22 @@ static Vehicle *TrainApproachingCrossing /** * Finds a vehicle approaching rail-road crossing * @param tile tile to test - * @return pointer to vehicle approaching the crossing + * @return true if a vehicle is approaching the crossing * @pre tile is a rail-road crossing */ -static Vehicle *TrainApproachingCrossing(TileIndex tile) +static bool TrainApproachingCrossing(TileIndex tile) { assert(IsLevelCrossingTile(tile)); DiagDirection dir = AxisToDiagDir(GetCrossingRailAxis(tile)); TileIndex tile_from = tile + TileOffsByDiagDir(dir); - Vehicle *v = VehicleFromPos(tile_from, &tile, &TrainApproachingCrossingEnum); - - if (v != NULL) return v; + if (HasVehicleOnPos(tile_from, &tile, &TrainApproachingCrossingEnum)) return true; dir = ReverseDiagDir(dir); tile_from = tile + TileOffsByDiagDir(dir); - return VehicleFromPos(tile_from, &tile, &TrainApproachingCrossingEnum); + return HasVehicleOnPos(tile_from, &tile, &TrainApproachingCrossingEnum); } @@ -1726,7 +1724,7 @@ void UpdateLevelCrossing(TileIndex tile, assert(IsLevelCrossingTile(tile)); /* train on crossing || train approaching crossing || reserved */ - bool new_state = VehicleFromPos(tile, NULL, &TrainOnTileEnum) != NULL || TrainApproachingCrossing(tile) || GetCrossingReservation(tile); + bool new_state = HasVehicleOnPos(tile, NULL, &TrainOnTileEnum) || TrainApproachingCrossing(tile) || GetCrossingReservation(tile); if (new_state != IsCrossingBarred(tile)) { if (new_state && sound) { @@ -3028,7 +3026,7 @@ bool TryPathReserve(Vehicle *v, bool mar } } - Vehicle *other_train = NULL; + bool other_train = false; PBSTileInfo origin = FollowTrainReservation(v, &other_train); /* If we have a reserved path and the path ends at a safe tile, we are finished already. */ if (origin.okay && (v->tile != origin.tile || first_tile_okay)) { @@ -3041,7 +3039,7 @@ bool TryPathReserve(Vehicle *v, bool mar * This can only happen when tracks and signals are changed. A crash * is probably imminent, don't do any further reservation because * it might cause stale reservations. */ - if (other_train != NULL && v->tile != origin.tile) { + if (other_train && v->tile != origin.tile) { if (mark_as_stuck) MarkTrainAsStuck(v); return false; } @@ -3518,10 +3516,10 @@ static void CheckTrainCollision(Vehicle /* find colliding vehicles */ if (v->u.rail.track == TRACK_BIT_WORMHOLE) { - VehicleFromPos(v->tile, &tcc, FindTrainCollideEnum); - VehicleFromPos(GetOtherTunnelBridgeEnd(v->tile), &tcc, FindTrainCollideEnum); + FindVehicleOnPos(v->tile, &tcc, FindTrainCollideEnum); + FindVehicleOnPos(GetOtherTunnelBridgeEnd(v->tile), &tcc, FindTrainCollideEnum); } else { - VehicleFromPosXY(v->x_pos, v->y_pos, &tcc, FindTrainCollideEnum); + FindVehicleOnPosXY(v->x_pos, v->y_pos, &tcc, FindTrainCollideEnum); } /* any dead -> no crash */ @@ -3652,7 +3650,7 @@ static void TrainController(Vehicle *v, exitdir = ReverseDiagDir(exitdir); /* check if a train is waiting on the other side */ - if (VehicleFromPos(o_tile, &exitdir, &CheckVehicleAtSignal) == NULL) return; + if (!HasVehicleOnPos(o_tile, &exitdir, &CheckVehicleAtSignal)) return; } } @@ -3819,9 +3817,9 @@ reverse_train_direction: } /** Collect trackbits of all crashed train vehicles on a tile - * @param v Vehicle passed from VehicleFromPos() + * @param v Vehicle passed from Find/HasVehicleOnPos() * @param data trackdirbits for the result - * @return NULL to not abort VehicleFromPos() + * @return NULL to iterate over all vehicles on the tile. */ static Vehicle *CollectTrackbitsFromCrashedVehiclesEnum(Vehicle *v, void *data) { @@ -3894,7 +3892,7 @@ static void DeleteLastWagon(Vehicle *v) /* If there are still crashed vehicles on the tile, give the track reservation to them */ TrackBits remaining_trackbits = TRACK_BIT_NONE; - VehicleFromPos(tile, &remaining_trackbits, CollectTrackbitsFromCrashedVehiclesEnum); + FindVehicleOnPos(tile, &remaining_trackbits, CollectTrackbitsFromCrashedVehiclesEnum); /* It is important that these two are the first in the loop, as reservation cannot deal with every trackbit combination */ assert(TRACK_BEGIN == TRACK_X && TRACK_Y == TRACK_BEGIN + 1);