19#include "strings_internal.h"
21#include "table/strings.h"
25static std::vector<GRFTownName> _grf_townnames;
26static std::vector<StringID> _grf_townname_names;
31 if (found != std::end(_grf_townnames))
return &*found;
39 t = &_grf_townnames.emplace_back();
45void DelGRFTownName(uint32_t grfid)
53 for (
const auto &partlist : t->partlists[id]) {
54 uint8_t count = partlist.bitcount;
55 uint16_t maxprob = partlist.maxprob;
56 uint32_t r = (
GB(seed, partlist.bitstart, count) * maxprob) >> count;
57 for (
const auto &part : partlist.parts) {
58 maxprob -=
GB(part.prob, 0, 7);
59 if (maxprob > r)
continue;
60 if (
HasBit(part.prob, 7)) {
61 RandomPart(builder, t, seed, part.id);
70void GRFTownNameGenerate(
StringBuilder &builder, uint32_t grfid, uint16_t gen, uint32_t seed)
74 assert(gen < t->styles.size());
75 RandomPart(builder, t, seed, t->
styles[gen].id);
83 _grf_townname_names.clear();
84 for (
const auto &t : _grf_townnames) {
85 for (
const auto &style : t.
styles) {
86 _grf_townname_names.push_back(style.name);
91const std::vector<StringID> &GetGRFTownNameList()
93 return _grf_townname_names;
96StringID GetGRFTownNameName(uint16_t gen)
98 return gen < _grf_townname_names.size() ? _grf_townname_names[gen] : STR_UNDEFINED;
101void CleanUpGRFTownNames()
103 _grf_townnames.clear();
106uint32_t GetGRFTownNameId(uint16_t gen)
108 for (
const auto &t : _grf_townnames) {
110 gen -=
static_cast<uint16_t
>(t.
styles.size());
116uint16_t GetGRFTownNameType(uint16_t gen)
118 for (
const auto &t : _grf_townnames) {
119 if (gen < t.
styles.size())
return gen;
120 gen -=
static_cast<uint16_t
>(t.
styles.size());
Functions related to the allocation of memory.
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Equivalent to the std::back_insert_iterator in function, with some convenience helpers for string con...
void InitGRFTownGeneratorNames()
Allocate memory for the NewGRF town names.
Header of Action 0F "universal holder" structure and functions.
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.
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< TownNameStyle > styles
Style names defined by the Town Name NewGRF.
uint32_t grfid
GRF ID of NewGRF.