MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / VerifyTownName

Function VerifyTownName

src/townname.cpp:103–126  ·  view source on GitHub ↗

* Verifies the town name is valid and unique. * @param r random bits * @param par town name parameters * @param town_names if a name is generated, check its uniqueness with the set * @return true iff name is valid and unique */

Source from the content-addressed store, hash-verified

101 * @return true iff name is valid and unique
102 */
103bool VerifyTownName(uint32_t r, const TownNameParams *par, TownNames *town_names)
104{
105 std::string name = GetTownName(par, r);
106
107 /* Check size and width */
108 if (Utf8StringLength(name) >= MAX_LENGTH_TOWN_NAME_CHARS) return false;
109
110 if (town_names != nullptr) {
111 if (town_names->find(name) != town_names->end()) return false;
112 town_names->insert(std::move(name));
113 } else {
114 for (const Town *t : Town::Iterate()) {
115 /* We can't just compare the numbers since
116 * several numbers may map to a single name. */
117 if (t->name.empty()) {
118 if (name == GetTownName(t)) return false;
119 } else {
120 if (name == t->name) return false;
121 }
122 }
123 }
124
125 return true;
126}
127
128
129/**

Callers 2

GenerateTownNameFunction · 0.85
CmdFoundTownFunction · 0.85

Calls 6

GetTownNameFunction · 0.85
Utf8StringLengthFunction · 0.85
findMethod · 0.45
endMethod · 0.45
insertMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected