[Freeciv-Dev] Need more city names?
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Hi,
since I always run out of city names, I've written a little patch to
generate new ones. It uses pseudo Markov chains to get names similar
to existing ones. The patch is heavily optimized for programmer
laziness and takes lots of memory and CPU time. It's funny, though.
Add more default city names to improve the result (and increase CPU
time even more).
Falk
diff -Nurd -X X.freeciv freeciv-cvs-11.06/common/city.c
freeciv-cvs-11.06-ffh/common/city.c
--- freeciv-cvs-11.06/common/city.c Fri Nov 6 13:30:43 1998
+++ freeciv-cvs-11.06-ffh/common/city.c Thu Nov 12 01:30:40 1998
@@ -12,6 +12,8 @@
***********************************************************************/
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
#include <game.h>
#include <map.h>
@@ -388,12 +397,40 @@
char *city_name_suggestion(struct player *pplayer)
{
char **nptr;
- int i;
+ int i, p = 0, len, c;
static char tempname[100];
+ char citynames[16000]; /* FIXME */
+
+ mysrand(time(NULL));
+
for(nptr=race_default_city_names[pplayer->race]; *nptr; nptr++) {
if(!game_find_city_by_name(*nptr))
return *nptr;
+ strcpy(&citynames[p], *nptr);
+ p += strlen(*nptr);
+ citynames[p++] = '\n';
}
+
+ len = strlen(citynames);
+ for(i = 0; i < 1000; i++) {
+ do {
+ p = myrand(len - 1);
+ tempname[0] = citynames[p];
+ tempname[1] = citynames[p + 1];
+ } while (!isupper(tempname[0]));
+
+ c = 1;
+
+ do {
+ p = myrand(len - 1);
+ if (citynames[p] == tempname[c] && citynames[p - 1] == tempname[c - 1])
+ tempname[++c] = citynames[p + 1];
+ } while(tempname[c] != '\n');
+ tempname[c] = 0;
+ if (strlen(tempname) < 16 && !game_find_city_by_name(tempname))
+ return tempname;
+ }
+
for (i = 0; i < 1000;i++ ) {
sprintf(tempname, "city %d", i);
if (!game_find_city_by_name(tempname))
- [Freeciv-Dev] Need more city names?,
Falk Hueffner <=
|
|