From 07f2984d06ca02985eefc24c86dc04fb067a9506 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 11 Apr 2023 18:18:13 +0100 Subject: [PATCH] Allow generating new default name for station Ctrl-click default button in rename station query window --- src/station_cmd.cpp | 25 ++++++++++++++++++++++--- src/station_gui.cpp | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index d6a837cfe2..3430f0026f 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -236,7 +236,7 @@ static bool FindNearIndustryName(TileIndex tile, void *user_data) return !sni->indtypes[indtype]; } -static StringID GenerateStationName(Station *st, TileIndex tile, StationNaming name_class) +static StringID GenerateStationName(Station *st, TileIndex tile, StationNaming name_class, bool force_change = false) { static const uint32 _gen_station_name_bits[] = { 0, // STATIONNAMING_RAIL @@ -256,7 +256,7 @@ static StringID GenerateStationName(Station *st, TileIndex tile, StationNaming n std::bitset extra_names; for (const Station *s : Station::Iterate()) { - if (s != st && s->town == t) { + if ((force_change || s != st) && s->town == t) { if (s->indtype != IT_INVALID) { indtypes[s->indtype] = true; StringID name = GetIndustrySpec(s->indtype)->station_name; @@ -282,6 +282,8 @@ static StringID GenerateStationName(Station *st, TileIndex tile, StationNaming n } } + st->extra_name_index = UINT16_MAX; + TileIndex indtile = tile; StationNameInformation sni = { free_names, indtypes }; if (CircularTileSearch(&indtile, 7, FindNearIndustryName, &sni)) { @@ -4727,7 +4729,8 @@ static bool IsUniqueStationName(const char *name) * @param tile unused * @param flags operation to perform * @param p1 station ID that is to be renamed - * @param p2 unused + * @param p2 various bitstuffed elements + * - p2 = (bit 0) - whether to generate a new default name, if resetting name * @param text the new name or an empty string when resetting to the default * @return the cost of this operation or an error */ @@ -4750,6 +4753,22 @@ CommandCost CmdRenameStation(TileIndex tile, DoCommandFlag flags, uint32 p1, uin st->cached_name.clear(); if (reset) { st->name.clear(); + if (HasBit(p2, 0) && st->industry == nullptr) { + StationNaming name_class; + if (st->facilities & FACIL_AIRPORT) { + name_class = STATIONNAMING_AIRPORT; + } else if (st->facilities & FACIL_DOCK) { + name_class = STATIONNAMING_DOCK; + } else if (st->facilities & FACIL_TRAIN) { + name_class = STATIONNAMING_RAIL; + } else if (st->facilities & (FACIL_BUS_STOP | FACIL_TRUCK_STOP)) { + name_class = STATIONNAMING_ROAD; + } else { + name_class = STATIONNAMING_RAIL; + } + Random(); // Advance random seed each time this is called + st->string_id = GenerateStationName(st, st->xy, name_class, true); + } } else { st->name = text; } diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 4d2f8de092..1fbdeab11b 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -2224,7 +2224,7 @@ struct StationViewWindow : public Window { { if (str == nullptr) return; - DoCommandP(0, this->window_number, 0, CMD_RENAME_STATION | CMD_MSG(STR_ERROR_CAN_T_RENAME_STATION), nullptr, str); + DoCommandP(0, this->window_number, _ctrl_pressed ? 1 : 0, CMD_RENAME_STATION | CMD_MSG(STR_ERROR_CAN_T_RENAME_STATION), nullptr, str); } void OnResize() override