From 9f8c9724be89c2a836361627af227b39041c0805 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Tue, 7 May 2024 12:13:47 +0100 Subject: [PATCH] Codechange: Add station/roadstop class labels for DFLT/WAYP. This avoids repeating the same multichar literal value. --- src/newgrf_roadstop.cpp | 8 ++++---- src/newgrf_roadstop.h | 3 +++ src/newgrf_station.cpp | 8 ++++---- src/newgrf_station.h | 3 +++ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/newgrf_roadstop.cpp b/src/newgrf_roadstop.cpp index eaa76fe5f9..ff84e3a52a 100644 --- a/src/newgrf_roadstop.cpp +++ b/src/newgrf_roadstop.cpp @@ -31,10 +31,10 @@ template <> void RoadStopClass::InsertDefaults() { /* Set up initial data */ - RoadStopClass::Get(RoadStopClass::Allocate('DFLT'))->name = STR_STATION_CLASS_DFLT; - RoadStopClass::Get(RoadStopClass::Allocate('DFLT'))->Insert(nullptr); - RoadStopClass::Get(RoadStopClass::Allocate('WAYP'))->name = STR_STATION_CLASS_WAYP; - RoadStopClass::Get(RoadStopClass::Allocate('WAYP'))->Insert(nullptr); + RoadStopClass::Get(RoadStopClass::Allocate(ROADSTOP_CLASS_LABEL_DEFAULT))->name = STR_STATION_CLASS_DFLT; + RoadStopClass::Get(RoadStopClass::Allocate(ROADSTOP_CLASS_LABEL_DEFAULT))->Insert(nullptr); + RoadStopClass::Get(RoadStopClass::Allocate(ROADSTOP_CLASS_LABEL_WAYPOINT))->name = STR_STATION_CLASS_WAYP; + RoadStopClass::Get(RoadStopClass::Allocate(ROADSTOP_CLASS_LABEL_WAYPOINT))->Insert(nullptr); } template <> diff --git a/src/newgrf_roadstop.h b/src/newgrf_roadstop.h index 4c031c560a..233e1f9cc8 100644 --- a/src/newgrf_roadstop.h +++ b/src/newgrf_roadstop.h @@ -22,6 +22,9 @@ /** The maximum amount of roadstops a single GRF is allowed to add */ static const int NUM_ROADSTOPS_PER_GRF = UINT16_MAX - 1; +static const uint32_t ROADSTOP_CLASS_LABEL_DEFAULT = 'DFLT'; +static const uint32_t ROADSTOP_CLASS_LABEL_WAYPOINT = 'WAYP'; + enum RoadStopClassID : uint16_t { ROADSTOP_CLASS_BEGIN = 0, ///< The lowest valid value ROADSTOP_CLASS_DFLT = 0, ///< Default road stop class. diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index a6d0d77f8c..a53983e56c 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -32,10 +32,10 @@ template <> /* static */ void StationClass::InsertDefaults() { /* Set up initial data */ - StationClass::Get(StationClass::Allocate('DFLT'))->name = STR_STATION_CLASS_DFLT; - StationClass::Get(StationClass::Allocate('DFLT'))->Insert(nullptr); - StationClass::Get(StationClass::Allocate('WAYP'))->name = STR_STATION_CLASS_WAYP; - StationClass::Get(StationClass::Allocate('WAYP'))->Insert(nullptr); + StationClass::Get(StationClass::Allocate(STATION_CLASS_LABEL_DEFAULT))->name = STR_STATION_CLASS_DFLT; + StationClass::Get(StationClass::Allocate(STATION_CLASS_LABEL_DEFAULT))->Insert(nullptr); + StationClass::Get(StationClass::Allocate(STATION_CLASS_LABEL_WAYPOINT))->name = STR_STATION_CLASS_WAYP; + StationClass::Get(StationClass::Allocate(STATION_CLASS_LABEL_WAYPOINT))->Insert(nullptr); } template <> diff --git a/src/newgrf_station.h b/src/newgrf_station.h index 3fd47d8676..fbb7ac7fd6 100644 --- a/src/newgrf_station.h +++ b/src/newgrf_station.h @@ -79,6 +79,9 @@ struct StationResolverObject : public ResolverObject { uint32_t GetDebugID() const override; }; +static const uint32_t STATION_CLASS_LABEL_DEFAULT = 'DFLT'; +static const uint32_t STATION_CLASS_LABEL_WAYPOINT = 'WAYP'; + enum StationClassID : uint16_t { STAT_CLASS_BEGIN = 0, ///< the lowest valid value STAT_CLASS_DFLT = 0, ///< Default station class.