From 30ae07269de5722014071c10830983c62066606e Mon Sep 17 00:00:00 2001 From: Rubidium Date: Sat, 4 Mar 2023 20:56:17 +0100 Subject: [PATCH] Fix: game scripts must not build with non-existing road types --- src/road.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/road.cpp b/src/road.cpp index d143ae652d..7974ac33f3 100644 --- a/src/road.cpp +++ b/src/road.cpp @@ -111,7 +111,15 @@ RoadBits CleanUpRoadBits(const TileIndex tile, RoadBits org_rb) bool HasRoadTypeAvail(const CompanyID company, RoadType roadtype) { if (company == OWNER_DEITY || company == OWNER_TOWN || _game_mode == GM_EDITOR || _generating_world) { - return true; // TODO: should there be a proper check? + const RoadTypeInfo *rti = GetRoadTypeInfo(roadtype); + if (rti->label == 0) return false; + + /* + * Do not allow building hidden road types, except when a town may build it. + * The GS under deity mode, as well as anybody in the editor builds roads that are + * owned by towns. So if a town may build it, it should be buildable by them too. + */ + return (rti->flags & ROTFB_HIDDEN) == 0 || (rti->flags & ROTFB_TOWN_BUILD) != 0; } else { const Company *c = Company::GetIfValid(company); if (c == nullptr) return false;