diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp --- a/src/waypoint_cmd.cpp +++ b/src/waypoint_cmd.cpp @@ -20,6 +20,7 @@ #include "pathfinder/yapf/yapf_cache.h" #include "strings_func.h" #include "viewport_func.h" +#include "viewport_kdtree.h" #include "window_func.h" #include "date_func.h" #include "vehicle_func.h" @@ -225,11 +226,15 @@ CommandCost CmdBuildRailWaypoint(TileInd } if (flags & DC_EXEC) { + bool need_sign_update = false; if (wp == NULL) { wp = new Waypoint(start_tile); + need_sign_update = true; } else if (!wp->IsInUse()) { /* Move existing (recently deleted) waypoint to the new location */ + _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(wp->index)); wp->xy = start_tile; + need_sign_update = true; } wp->owner = GetTileOwner(start_tile); @@ -244,6 +249,7 @@ CommandCost CmdBuildRailWaypoint(TileInd if (wp->town == NULL) MakeDefaultName(wp); wp->UpdateVirtCoord(); + if (need_sign_update) _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeWaypoint(wp->index)); const StationSpec *spec = StationClass::Get(spec_class)->GetSpec(spec_index); byte *layout_ptr = AllocaM(byte, count); @@ -310,6 +316,7 @@ CommandCost CmdBuildBuoy(TileIndex tile, wp = new Waypoint(tile); } else { /* Move existing (recently deleted) buoy to the new location */ + _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(wp->index)); wp->xy = tile; InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index); } @@ -328,6 +335,7 @@ CommandCost CmdBuildBuoy(TileIndex tile, MarkTileDirtyByTile(tile); wp->UpdateVirtCoord(); + _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeWaypoint(wp->index)); InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index); }