19 #include "strings_internal.h"
21 #include "table/strings.h"
25 static std::vector<GRFTownName> _grf_townnames;
26 static std::vector<StringID> _grf_townname_names;
30 auto found = std::find_if(std::begin(_grf_townnames), std::end(_grf_townnames), [&grfid](
const GRFTownName &t) {
return t.
grfid == grfid; });
31 if (found != std::end(_grf_townnames))
return &*found;
39 t = &_grf_townnames.emplace_back();
45 void DelGRFTownName(uint32_t grfid)
47 _grf_townnames.erase(std::find_if(std::begin(_grf_townnames), std::end(_grf_townnames), [&grfid](
const GRFTownName &t) {
return t.
grfid == 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);
70 void 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);
91 const std::vector<StringID> &GetGRFTownNameList()
93 return _grf_townname_names;
96 StringID GetGRFTownNameName(uint16_t gen)
98 return gen < _grf_townname_names.size() ? _grf_townname_names[gen] : STR_UNDEFINED;
101 void CleanUpGRFTownNames()
103 _grf_townnames.clear();
106 uint32_t GetGRFTownNameId(uint16_t gen)
108 for (
const auto &t : _grf_townnames) {
110 gen -=
static_cast<uint16_t
>(t.
styles.size());
116 uint16_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());
123 return SPECSTR_TOWNNAME_ENGLISH;