mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-06 22:37:22 +00:00
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
This commit is contained in:
parent
1c013055b6
commit
22dc618582
@ -1663,7 +1663,13 @@ void OnNewDay_RoadVeh(Vehicle *v)
|
|||||||
RoadStop* best = NULL;
|
RoadStop* best = NULL;
|
||||||
|
|
||||||
if (rs != NULL) {
|
if (rs != NULL) {
|
||||||
if (DistanceManhattan(v->tile, st->xy) < 16) {
|
/* We try to obtain a slot if:
|
||||||
|
* 1) we're reasonably close to the primary road stop
|
||||||
|
* or
|
||||||
|
* 2) we're somewhere close to the station rectangle (to make sure we do assign
|
||||||
|
* slots even if the station and its road stops are incredibly spread out)
|
||||||
|
*/
|
||||||
|
if (DistanceManhattan(v->tile, rs->xy) < 16 || st->rect.PtInExtendedRect(TileX(v->tile), TileY(v->tile), 2)) {
|
||||||
uint dist, badness;
|
uint dist, badness;
|
||||||
uint minbadness = UINT_MAX;
|
uint minbadness = UINT_MAX;
|
||||||
|
|
||||||
|
@ -202,9 +202,18 @@ void StationRect::MakeEmpty()
|
|||||||
left = top = right = bottom = 0;
|
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
|
bool StationRect::IsEmpty() const
|
||||||
@ -221,7 +230,7 @@ bool StationRect::BeforeAddTile(TileIndex tile, StationRectMode mode)
|
|||||||
left = right = x;
|
left = right = x;
|
||||||
top = bottom = y;
|
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 */
|
/* current rect is not empty and new point is outside this rect */
|
||||||
/* make new spread-out rectangle */
|
/* make new spread-out rectangle */
|
||||||
Rect new_rect = {min(x, left), min(y, top), max(x, right), max(y, bottom)};
|
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)
|
bool StationRect::AfterRemoveRect(Station *st, TileIndex tile, int w, int h)
|
||||||
{
|
{
|
||||||
assert(PtInRectXY(TileX(tile), TileY(tile)));
|
assert(PtInExtendedRect(TileX(tile), TileY(tile)));
|
||||||
assert(PtInRectXY(TileX(tile) + w - 1, TileY(tile) + h - 1));
|
assert(PtInExtendedRect(TileX(tile) + w - 1, TileY(tile) + h - 1));
|
||||||
|
|
||||||
bool empty = AfterRemoveTile(st, tile);
|
bool empty = AfterRemoveTile(st, tile);
|
||||||
if (w != 1 || h != 1) empty = empty || AfterRemoveTile(st, TILE_ADDXY(tile, w - 1, h - 1));
|
if (w != 1 || h != 1) empty = empty || AfterRemoveTile(st, TILE_ADDXY(tile, w - 1, h - 1));
|
||||||
|
@ -84,7 +84,7 @@ struct StationRect : public Rect {
|
|||||||
|
|
||||||
StationRect();
|
StationRect();
|
||||||
void MakeEmpty();
|
void MakeEmpty();
|
||||||
bool PtInRectXY(int x, int y) const;
|
bool PtInExtendedRect(int x, int y, int distance = 0) const;
|
||||||
bool IsEmpty() const;
|
bool IsEmpty() const;
|
||||||
bool BeforeAddTile(TileIndex tile, StationRectMode mode);
|
bool BeforeAddTile(TileIndex tile, StationRectMode mode);
|
||||||
bool BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode);
|
bool BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode);
|
||||||
|
Loading…
Reference in New Issue
Block a user