@@ -107,12 +107,18 @@ struct BaseStation : StationPool::PoolIt
/**
* Update the coordinated of the sign (as shown in the viewport).
*/
virtual void UpdateVirtCoord() = 0;
virtual void MoveSign(TileIndex new_xy)
{
this->xy = new_xy;
this->UpdateVirtCoord();
}
* Get the tile area for a given station type.
* @param ta tile area to fill.
* @param type the type of the area
virtual void GetTileArea(TileArea *ta, StationType type) const = 0;
@@ -204,13 +204,13 @@ RoadStop *Station::GetPrimaryRoadStop(co
* Called when new facility is built on the station. If it is the first facility
* it initializes also 'xy' and 'random_bits' members
void Station::AddFacility(StationFacility new_facility_bit, TileIndex facil_xy)
if (this->facilities == FACIL_NONE) {
this->xy = facil_xy;
this->MoveSign(facil_xy);
this->random_bits = Random();
this->facilities |= new_facility_bit;
this->owner = _current_company;
this->build_date = _date;
@@ -489,12 +489,14 @@ public:
void AddFacility(StationFacility new_facility_bit, TileIndex facil_xy);
void MarkTilesDirty(bool cargo_change) const;
void UpdateVirtCoord() override;
void MoveSign(TileIndex new_xy) override;
void AfterStationTileSetChange(bool adding, StationType type);
uint GetPlatformLength(TileIndex tile, DiagDirection dir) const override;
uint GetPlatformLength(TileIndex tile) const override;
void RecomputeCatchment();
static void RecomputeCatchmentForAll();
@@ -426,12 +426,29 @@ void Station::UpdateVirtCoord()
SetDParam(1, this->facilities);
this->sign.UpdatePosition(pt.x, pt.y, STR_VIEWPORT_STATION);
SetWindowDirty(WC_STATION_VIEW, this->index);
* Move the station main coordinate somewhere else.
* @param new_xy new tile location of the sign
void Station::MoveSign(TileIndex new_xy)
if (this->xy == new_xy) return;
_viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeStation(this->index));
_station_kdtree.Remove(this->index);
this->BaseStation::MoveSign(new_xy);
_station_kdtree.Insert(this->index);
_viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeStation(this->index));
/** Update the virtual coords needed to draw the station sign for all stations. */
void UpdateAllStationVirtCoords()
BaseStation *st;
FOR_ALL_BASE_STATIONS(st) {
@@ -669,20 +686,13 @@ static void UpdateStationSignCoord(BaseS
const StationRect *r = &st->rect;
if (r->IsEmpty()) return; // no tiles belong to this station
/* clamp sign coord to be inside the station rect */
TileIndex new_xy = TileXY(ClampU(TileX(st->xy), r->left, r->right), ClampU(TileY(st->xy), r->top, r->bottom));
if (new_xy != st->xy) {
_viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeStation(st->index));
_station_kdtree.Remove(st->index);
st->xy = new_xy;
_station_kdtree.Insert(st->index);
_viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeStation(st->index));
st->UpdateVirtCoord();
st->MoveSign(new_xy);
if (!Station::IsExpected(st)) return;
Station *full_station = Station::From(st);
for (CargoID c = 0; c < NUM_CARGO; ++c) {
LinkGraphID lg = full_station->goods[c].link_graph;
if (!LinkGraph::IsValidID(lg)) continue;
Status change: