|
@@ -82,49 +82,49 @@ int DrawStationCoverageAreaText(int left
|
|
|
* Find stations adjacent to the current tile highlight area, so that existing coverage
|
|
|
* area can be drawn.
|
|
|
*/
|
|
|
static void FindStationsAroundSelection()
|
|
|
{
|
|
|
/* With distant join we don't know which station will be selected, so don't show any */
|
|
|
if (_ctrl_pressed) {
|
|
|
SetViewportCatchmentStation(nullptr, true);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
/* Tile area for TileHighlightData */
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Check whether we need to redraw the station coverage text.
|
|
|
* If it is needed actually make the window for redrawing.
|
|
|
* @param w the window to check.
|
|
|
*/
|
|
|
void CheckRedrawStationCoverage(const Window *w)
|
|
|
{
|
|
|
/* Test if ctrl state changed */
|
|
|
static bool _last_ctrl_pressed;
|
|
|
if (_ctrl_pressed != _last_ctrl_pressed) {
|
|
@@ -2193,49 +2193,49 @@ static bool AddNearbyStation(TileIndex t
|
|
|
_stations_nearby_list.push_back(sid);
|
|
|
}
|
|
|
|
|
|
return false; // We want to include *all* nearby stations
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Circulate around the to-be-built station to find stations we could join.
|
|
|
* Make sure that only stations are returned where joining wouldn't exceed
|
|
|
* station spread and are our own station.
|
|
|
* @param ta Base tile area of the to-be-built station
|
|
|
* @param distant_join Search for adjacent stations (false) or stations fully
|
|
|
* 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) &&
|
|
|
IsInsideBS(TileY(st->xy), TileY(ctx.tile), ctx.h)) {
|
|
|
AddNearbyStation<T>(st->xy, &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;
|
|
|
uint max_dist = distant_join ? _settings_game.station.station_spread - std::min(ta.w, ta.h) : 1;
|