|
@@ -94,25 +94,25 @@ static void FindStationsAroundSelection(
|
|
|
TileArea location(TileVirtXY(_thd.pos.x, _thd.pos.y), _thd.size.x / TILE_SIZE - 1, _thd.size.y / TILE_SIZE - 1);
|
|
|
|
|
|
/* Extended area by one tile */
|
|
|
uint x = TileX(location.tile);
|
|
|
uint y = TileY(location.tile);
|
|
|
|
|
|
int max_c = 1;
|
|
|
TileArea ta(TileXY(std::max<int>(0, x - max_c), std::max<int>(0, y - max_c)), TileXY(std::min<int>(MapMaxX(), x + location.w + max_c), std::min<int>(MapMaxY(), y + location.h + max_c)));
|
|
|
|
|
|
Station *adjacent = nullptr;
|
|
|
|
|
|
/* Direct loop instead of ForAllStationsAroundTiles as we are not interested in catchment area */
|
|
|
TILE_AREA_LOOP(tile, ta) {
|
|
|
for (TileIndex tile : ta) {
|
|
|
if (IsTileType(tile, MP_STATION) && GetTileOwner(tile) == _local_company) {
|
|
|
Station *st = Station::GetByTile(tile);
|
|
|
if (st == nullptr) continue;
|
|
|
if (adjacent != nullptr && st != adjacent) {
|
|
|
/* Multiple nearby, distant join is required. */
|
|
|
adjacent = nullptr;
|
|
|
break;
|
|
|
}
|
|
|
adjacent = st;
|
|
|
}
|
|
|
}
|
|
|
SetViewportCatchmentStation(adjacent, true);
|
|
@@ -2205,25 +2205,25 @@ static bool AddNearbyStation(TileIndex t
|
|
|
* within station spread
|
|
|
* @tparam T the type of station to look for
|
|
|
*/
|
|
|
template <class T>
|
|
|
static const T *FindStationsNearby(TileArea ta, bool distant_join)
|
|
|
{
|
|
|
TileArea ctx = ta;
|
|
|
|
|
|
_stations_nearby_list.clear();
|
|
|
_deleted_stations_nearby.clear();
|
|
|
|
|
|
/* Check the inside, to return, if we sit on another station */
|
|
|
TILE_AREA_LOOP(t, ta) {
|
|
|
for (TileIndex t : ta) {
|
|
|
if (t < MapSize() && IsTileType(t, MP_STATION) && T::IsValidID(GetStationIndex(t))) return T::GetByTile(t);
|
|
|
}
|
|
|
|
|
|
/* Look for deleted stations */
|
|
|
for (const BaseStation *st : BaseStation::Iterate()) {
|
|
|
if (T::IsExpected(st) && !st->IsInUse() && st->owner == _local_company) {
|
|
|
/* Include only within station spread (yes, it is strictly less than) */
|
|
|
if (std::max(DistanceMax(ta.tile, st->xy), DistanceMax(TILE_ADDXY(ta.tile, ta.w - 1, ta.h - 1), st->xy)) < _settings_game.station.station_spread) {
|
|
|
_deleted_stations_nearby.push_back({st->xy, st->index});
|
|
|
|
|
|
/* Add the station when it's within where we're going to build */
|
|
|
if (IsInsideBS(TileX(st->xy), TileX(ctx.tile), ctx.w) &&
|