From 8437b20feda7d0dc3a97cdb76ad87c68fb1f8077 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 28 Nov 2023 21:59:00 +0000 Subject: [PATCH] Fix: Deleting towns did not check for waypoints referencing the town --- src/town_cmd.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index d59fb78a15..48fbf03940 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -17,6 +17,7 @@ #include "command_func.h" #include "industry.h" #include "station_base.h" +#include "waypoint_base.h" #include "station_kdtree.h" #include "company_base.h" #include "news_func.h" @@ -3040,6 +3041,11 @@ CommandCost CmdDeleteTown(DoCommandFlag flags, TownID town_id) } } + /* Waypoints refer to towns. */ + for (const Waypoint *wp : Waypoint::Iterate()) { + if (wp->town == t) return CMD_ERROR; + } + /* Depots refer to towns. */ for (const Depot *d : Depot::Iterate()) { if (d->town == t) return CMD_ERROR;