diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 4f0979ec86..bf148dcbd8 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -2222,7 +2222,7 @@ static void AddNearbyStation(TileIndex tile, TileArea *ctx) * @tparam T the station filter type, for stations to look for */ template -static const BaseStation *FindStationsNearby(TileArea ta, bool distant_join) +static void FindStationsNearby(TileArea ta, bool distant_join) { TileArea ctx = ta; @@ -2230,11 +2230,6 @@ static const BaseStation *FindStationsNearby(TileArea ta, bool distant_join) _stations_nearby_list.push_back(NEW_STATION); _deleted_stations_nearby.clear(); - /* Check the inside, to return, if we sit on another station */ - for (TileIndex t : ta) { - if (t < Map::Size() && IsTileType(t, MP_STATION) && T::IsValidID(GetStationIndex(t))) return BaseStation::GetByTile(t); - } - /* Look for deleted stations */ for (const BaseStation *st : BaseStation::Iterate()) { if (T::IsValidBaseStation(st) && !st->IsInUse() && st->owner == _local_company) { @@ -2251,17 +2246,20 @@ static const BaseStation *FindStationsNearby(TileArea ta, bool distant_join) } } + /* Add stations that are within station tile area. Stations do not have to occupy all tiles */ + for (auto t : ta) { + AddNearbyStation(t, &ctx); + } + /* Only search tiles where we have a chance to stay within the station spread. * The complete check needs to be done in the callback as we don't know the * extent of the found station, yet. */ - if (distant_join && std::min(ta.w, ta.h) >= _settings_game.station.station_spread) return nullptr; + if (distant_join && std::min(ta.w, ta.h) >= _settings_game.station.station_spread) return; uint max_dist = distant_join ? _settings_game.station.station_spread - std::min(ta.w, ta.h) : 1; for (auto tile : SpiralTileSequence(TileAddByDir(ctx.tile, DIR_N), max_dist, ta.w, ta.h)) { AddNearbyStation(tile, &ctx); } - - return nullptr; } static constexpr NWidgetPart _nested_select_station_widgets[] = { @@ -2421,7 +2419,7 @@ static WindowDesc _select_station_desc( * @return whether we need to show the station selection window. */ template -static bool StationJoinerNeeded(TileArea ta, const StationPickerCmdProc &proc) +static bool StationJoinerNeeded(const StationPickerCmdProc &proc) { /* Only show selection if distant join is enabled in the settings */ if (!_settings_game.station.distant_join_stations) return false; @@ -2439,9 +2437,7 @@ static bool StationJoinerNeeded(TileArea ta, const StationPickerCmdProc &proc) if (!_ctrl_pressed) return false; /* Now check if we could build there */ - if (!proc(true, StationID::Invalid())) return false; - - return FindStationsNearby(ta, false) == nullptr; + return proc(true, StationID::Invalid()); } /** @@ -2453,7 +2449,7 @@ static bool StationJoinerNeeded(TileArea ta, const StationPickerCmdProc &proc) template void ShowSelectBaseStationIfNeeded(TileArea ta, StationPickerCmdProc&& proc) { - if (StationJoinerNeeded(ta, proc)) { + if (StationJoinerNeeded(proc)) { if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace(); new SelectStationWindow(_select_station_desc, ta, std::move(proc)); } else {