20#include "table/strings.h"
24static std::vector<GRFTownName> _grf_townnames;
25static std::vector<StringID> _grf_townname_names;
35 if (found != std::end(_grf_townnames))
return &*found;
48 t = &_grf_townnames.emplace_back();
66 for (
const auto &partlist : t->
partlists[
id]) {
67 uint8_t count = partlist.bitcount;
68 uint16_t maxprob = partlist.maxprob;
69 uint32_t r = (
GB(seed, partlist.bitstart, count) * maxprob) >> count;
70 for (
const auto &part : partlist.parts) {
71 maxprob -=
GB(part.prob, 0, 7);
72 if (maxprob > r)
continue;
73 if (
HasBit(part.prob, 7)) {
74 RandomPart(builder, t, seed, part.id);
94 assert(gen < t->styles.size());
95 RandomPart(builder, t, seed, t->
styles[gen].id);
103 _grf_townname_names.clear();
104 for (
const auto &t : _grf_townnames) {
105 for (
const auto &style : t.
styles) {
106 _grf_townname_names.push_back(style.name);
111const std::vector<StringID> &GetGRFTownNameList()
113 return _grf_townname_names;
116StringID GetGRFTownNameName(uint16_t gen)
118 return gen < _grf_townname_names.size() ? _grf_townname_names[gen] : STR_UNDEFINED;
121void CleanUpGRFTownNames()
123 _grf_townnames.clear();
126GrfID GetGRFTownNameId(uint16_t gen)
128 for (
const auto &t : _grf_townnames) {
130 gen -=
static_cast<uint16_t
>(t.
styles.size());
136uint16_t GetGRFTownNameType(uint16_t gen)
138 for (
const auto &t : _grf_townnames) {
139 if (gen < t.
styles.size())
return gen;
140 gen -=
static_cast<uint16_t
>(t.
styles.size());
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Compose data into a growing std::string.
GRFTownName * GetGRFTownName(GrfID grfid)
Get the GRFTownName for the given GRFID.
void DelGRFTownName(GrfID grfid)
Remove the GRFTownName mapping for the given GRFID.
void GRFTownNameGenerate(StringBuilder &builder, GrfID grfid, uint16_t gen, uint32_t seed)
Construct a NewGRF town name into the builder.
GRFTownName * AddGRFTownName(GrfID grfid)
Get the GRFTownName for the given GRFID or allocate one if it does not exist.
void InitGRFTownGeneratorNames()
Allocate memory for the NewGRF town names.
Header of Action 0F "universal holder" structure and functions.
Label< struct GrfIDTag > GrfID
The unique identifier of a NewGRF.
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
Functions related to low-level strings.
Types and functions related to the internal workings of formatting OpenTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static constexpr StringID SPECSTR_TOWNNAME_START
Special strings for town names.
std::vector< NamePartList > partlists[MAX_LISTS]
Lists of town name parts.
GrfID grfid
GRF ID of NewGRF.
std::vector< TownNameStyle > styles
Style names defined by the Town Name NewGRF.