/** * 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 */ bool VerifyTownName(uint32 r, const TownNameParams *par, TownNames *town_names) { /* reserve space for extra unicode character and terminating '\0' */ char buf1[(MAX_LENGTH_TOWN_NAME_CHARS + 1) * MAX_CHAR_LENGTH]; char buf2[(MAX_LENGTH_TOWN_NAME_CHARS + 1) * MAX_CHAR_LENGTH]; GetTownName(buf1, par, r, lastof(buf1)); /* Check size and width */ if (Utf8StringLength(buf1) >= MAX_LENGTH_TOWN_NAME_CHARS) return false; if (town_names != NULL) { if (town_names->find(buf1) != town_names->end()) return false; town_names->insert(buf1); } else { const Town *t; FOR_ALL_TOWNS(t) { /* We can't just compare the numbers since * several numbers may map to a single name. */ const char *buf = t->name; if (buf == NULL) { GetTownName(buf2, t, lastof(buf2)); buf = buf2; } if (strcmp(buf1, buf) == 0) return false; } } return true; }
/** * Fills buffer with town's name * @param buff buffer start * @param t we want to get name of this town * @param last end of buffer * @return pointer to terminating '\0' */ char *GetTownName(char *buff, const Town *t, const char *last) { TownNameParams par(t); return GetTownName(buff, &par, t->townnameparts, last); }
TownScene::TownScene(boost::shared_ptr<const Graph> default_frame_graph) : SceneSelectorScene(default_frame_graph, GetTownName(), CreateSceneList(default_frame_graph)) { }