Complete.Org: Mailing Lists: Archives: freeciv-dev: November 1998:
[Freeciv-Dev] Need more city names?
Home

[Freeciv-Dev] Need more city names?

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Need more city names?
From: Falk Hueffner <falk.hueffner@xxxxxxxxxxxxxxxxxxxxxxxx>
Date: 16 Nov 1998 17:38:18 +0100

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)) 


[Prev in Thread] Current Thread [Next in Thread]