diff options
author | celestar <celestar@openttd.org> | 2007-02-02 16:51:10 +0000 |
---|---|---|
committer | celestar <celestar@openttd.org> | 2007-02-02 16:51:10 +0000 |
commit | c09e73a5e506ee36ac2c80029ffa610df8620245 (patch) | |
tree | b452bc1cfa211c8321cb8bfaf097f53557a3fafc /src/station.cpp | |
parent | 22a22a7d3f8c220725ecdbe2103d3a0e74c792bf (diff) | |
download | openttd-c09e73a5e506ee36ac2c80029ffa610df8620245.tar.xz |
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
Diffstat (limited to 'src/station.cpp')
-rw-r--r-- | src/station.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/station.cpp b/src/station.cpp index c9dc3a9f7..985d39850 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -202,9 +202,18 @@ void StationRect::MakeEmpty() left = top = right = bottom = 0; } -bool StationRect::PtInRectXY(int x, int y) const +/** + * Determines whether a given point (x, y) is within a certain distance of + * the station rectangle. + * @note x and y are in Tile coordinates + * @param x X coordinate + * @param y Y coordinate + * @param distance The maxmium distance a point may have (L1 norm) + * @return true if the point is within distance tiles of the station rectangle + */ +bool StationRect::PtInExtendedRect(int x, int y, int distance) const { - return (left <= x && x <= right && top <= y && y <= bottom); + return (left - distance <= x && x <= right + distance && top - distance <= y && y <= bottom + distance); } bool StationRect::IsEmpty() const @@ -221,7 +230,7 @@ bool StationRect::BeforeAddTile(TileIndex tile, StationRectMode mode) left = right = x; top = bottom = y; - } else if (!PtInRectXY(x, y)) { + } else if (!PtInExtendedRect(x, y)) { /* current rect is not empty and new point is outside this rect */ /* make new spread-out rectangle */ Rect new_rect = {min(x, left), min(y, top), max(x, right), max(y, bottom)}; @@ -316,8 +325,8 @@ bool StationRect::AfterRemoveTile(Station *st, TileIndex tile) bool StationRect::AfterRemoveRect(Station *st, TileIndex tile, int w, int h) { - assert(PtInRectXY(TileX(tile), TileY(tile))); - assert(PtInRectXY(TileX(tile) + w - 1, TileY(tile) + h - 1)); + assert(PtInExtendedRect(TileX(tile), TileY(tile))); + assert(PtInExtendedRect(TileX(tile) + w - 1, TileY(tile) + h - 1)); bool empty = AfterRemoveTile(st, tile); if (w != 1 || h != 1) empty = empty || AfterRemoveTile(st, TILE_ADDXY(tile, w - 1, h - 1)); |