19#include "table/strings.h"
23static std::vector<GRFTownName> _grf_townnames;
24static std::vector<StringID> _grf_townname_names;
34 if (found != std::end(_grf_townnames))
return &*found;
47 t = &_grf_townnames.emplace_back();
65 for (
const auto &partlist : t->
partlists[
id]) {
66 uint8_t count = partlist.bitcount;
67 uint16_t maxprob = partlist.maxprob;
68 uint32_t r = (
GB(seed, partlist.bitstart, count) * maxprob) >> count;
69 for (
const auto &part : partlist.parts) {
70 maxprob -=
GB(part.prob, 0, 7);
71 if (maxprob > r)
continue;
72 if (
HasBit(part.prob, 7)) {
73 RandomPart(builder, t, seed, part.id);
93 assert(gen < t->styles.size());
94 RandomPart(builder, t, seed, t->
styles[gen].id);
102 _grf_townname_names.clear();
103 for (
const auto &t : _grf_townnames) {
104 for (
const auto &style : t.
styles) {
105 _grf_townname_names.push_back(style.name);
110const std::vector<StringID> &GetGRFTownNameList()
112 return _grf_townname_names;
115StringID GetGRFTownNameName(uint16_t gen)
117 return gen < _grf_townname_names.size() ? _grf_townname_names[gen] : STR_UNDEFINED;
120void CleanUpGRFTownNames()
122 _grf_townnames.clear();
125GrfID GetGRFTownNameId(uint16_t gen)
127 for (
const auto &t : _grf_townnames) {
129 gen -=
static_cast<uint16_t
>(t.
styles.size());
135uint16_t GetGRFTownNameType(uint16_t gen)
137 for (
const auto &t : _grf_townnames) {
138 if (gen < t.
styles.size())
return gen;
139 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.
Types and functions related to the internal workings of formatting OpenTTD's strings.
static constexpr uint16_t SPECSTR_TOWNNAME_START
Special strings for town names.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
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.