diff options
Diffstat (limited to 'src/town.h')
-rw-r--r-- | src/town.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/town.h b/src/town.h index 9898e3fb6..8399fa63f 100644 --- a/src/town.h +++ b/src/town.h @@ -60,6 +60,7 @@ struct Town : TownPool::PoolItem<&_town_pool> { uint16 townnametype; uint32 townnameparts; char *name; ///< Custom town name. If nullptr, the town was not renamed and uses the generated name. + mutable std::string cached_name; ///< NOSAVE: Cache of the resolved name of the town, if not using a custom town name byte flags; ///< See #TownFlags. @@ -130,6 +131,13 @@ struct Town : TownPool::PoolItem<&_town_pool> { void UpdateVirtCoord(); + inline const char *GetCachedName() const + { + if (this->name != nullptr) return this->name; + if (this->cached_name.empty()) this->FillCachedName(); + return this->cached_name.c_str(); + } + static inline Town *GetByTile(TileIndex tile) { return Town::Get(GetTownIndex(tile)); @@ -137,11 +145,15 @@ struct Town : TownPool::PoolItem<&_town_pool> { static Town *GetRandom(); static void PostDestructor(size_t index); + +private: + void FillCachedName() const; }; uint32 GetWorldPopulation(); void UpdateAllTownVirtCoords(); +void ClearAllTownCachedNames(); void ShowTownViewWindow(TownID town); void ExpandTown(Town *t); |