QTfrontend/util/namegen.cpp
changeset 11888 618d99523933
parent 11046 47a8c19ecb60
child 12244 45c83c88ac4b
--- a/QTfrontend/util/namegen.cpp	Tue Nov 15 03:00:56 2016 +0100
+++ b/QTfrontend/util/namegen.cpp	Wed Nov 16 16:18:32 2016 +0100
@@ -56,7 +56,8 @@
 
         team.setGrave(getRandomGrave());
         team.setFort(getRandomFort());
-        team.setVoicepack("Default");
+        team.setFlag(getRandomFlag());
+        team.setVoicepack(getRandomVoice());
     }
 
     QStringList dicts;
@@ -255,6 +256,31 @@
     return Graves[rand()%(Graves.size())];
 }
 
+QString HWNamegen::getRandomFlag()
+{
+    QStringList Flags;
+
+    //list all available flags
+    Flags.append(DataManager::instance().entryList(
+                      "Graphics/Flags",
+                      QDir::Files,
+                      QStringList("*.png")
+                  ).replaceInStrings(QRegExp("\\.png$"), "")
+                 );
+    //remove internal flags
+    Flags.removeAll("cpu");
+    Flags.removeAll("cpu_plain");
+
+    if(Flags.size()==0)
+    {
+        // TODO do some serious error handling
+        return "Error";
+    }
+
+    //pick a random flag
+    return Flags[rand()%(Flags.size())];
+}
+
 QString HWNamegen::getRandomFort()
 {
     QStringList Forts;
@@ -276,3 +302,23 @@
     //pick a random fort
     return Forts[rand()%(Forts.size())];
 }
+
+QString HWNamegen::getRandomVoice()
+{
+    QStringList Voices;
+
+    //list all available voices 
+    Voices.append(DataManager::instance().entryList(
+                     "Sounds/voices",
+                     QDir::Dirs | QDir::NoDotAndDotDot,
+                     QStringList("*")));
+
+    if(Voices.size()==0)
+    {
+        // TODO do some serious error handling
+        return "Error";
+    }
+
+    //pick a random voice
+    return Voices[rand()%(Voices.size())];
+}