Fix possible incorrect tile index in FindNearestHangar
See also: https://github.com/OpenTTD/OpenTTD/issues/7619
This commit is contained in:
@@ -124,7 +124,7 @@ static StationID FindNearestHangar(const Aircraft *v)
|
||||
const Station *st;
|
||||
uint best = 0;
|
||||
StationID index = INVALID_STATION;
|
||||
TileIndex vtile = TileVirtXY(v->x_pos, v->y_pos);
|
||||
TileIndex vtile = TileVirtXYClampedToMap(v->x_pos, v->y_pos);
|
||||
const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type);
|
||||
uint max_range = v->acache.cached_max_range_sqr;
|
||||
|
||||
@@ -714,9 +714,7 @@ static int UpdateAircraftSpeed(Aircraft *v, uint speed_limit = SPEED_LIMIT_NONE,
|
||||
*/
|
||||
int GetTileHeightBelowAircraft(const Vehicle *v)
|
||||
{
|
||||
int safe_x = Clamp(v->x_pos, 0, MapMaxX() * TILE_SIZE);
|
||||
int safe_y = Clamp(v->y_pos, 0, MapMaxY() * TILE_SIZE);
|
||||
return TileHeight(TileVirtXY(safe_x, safe_y)) * TILE_HEIGHT;
|
||||
return TileHeight(TileVirtXYClampedToMap(v->x_pos, v->y_pos)) * TILE_HEIGHT;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -197,6 +197,19 @@ static inline TileIndex TileVirtXY(uint x, uint y)
|
||||
return (y >> 4 << MapLogX()) + (x >> 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a tile from the virtual XY-coordinate.
|
||||
* This is clamped to be within the map bounds.
|
||||
* @param x The virtual x coordinate of the tile.
|
||||
* @param y The virtual y coordinate of the tile.
|
||||
* @return The TileIndex calculated by the coordinate.
|
||||
*/
|
||||
static inline TileIndex TileVirtXYClampedToMap(int x, int y)
|
||||
{
|
||||
int safe_x = Clamp<int>(x, 0, MapMaxX() * TILE_SIZE);
|
||||
int safe_y = Clamp<int>(y, 0, MapMaxY() * TILE_SIZE);
|
||||
return TileVirtXY((uint) safe_x, (uint) safe_y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the X component of a tile
|
||||
|
Reference in New Issue
Block a user