Set random flags and voice in random teams
authorWuzzy <almikes@aol.com>
Wed, 16 Nov 2016 16:18:32 +0100
changeset 11888 618d99523933
parent 11887 083c12795632
child 11889 c8979eeb73fa
Set random flags and voice in random teams Except in quick matches, which always uses default voice (for native speakers)
QTfrontend/game.cpp
QTfrontend/util/namegen.cpp
QTfrontend/util/namegen.h
--- a/QTfrontend/game.cpp	Tue Nov 15 03:00:56 2016 +0100
+++ b/QTfrontend/game.cpp	Wed Nov 16 16:18:32 2016 +0100
@@ -154,6 +154,7 @@
     team1.setColor(0);
     team1.setNumHedgehogs(4);
     HWNamegen::teamRandomNames(team1,true);
+    team1.setVoicepack("Default");
     HWProto::addStringListToBuffer(teamscfg,
                                    team1.teamGameConfig(100));
 
@@ -164,6 +165,7 @@
     do
         HWNamegen::teamRandomNames(team2,true);
     while(!team2.name().compare(team1.name()) || !team2.hedgehog(0).Hat.compare(team1.hedgehog(0).Hat));
+    team2.setVoicepack("Default");
     HWProto::addStringListToBuffer(teamscfg,
                                    team2.teamGameConfig(100));
 
--- 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())];
+}
--- a/QTfrontend/util/namegen.h	Tue Nov 15 03:00:56 2016 +0100
+++ b/QTfrontend/util/namegen.h	Wed Nov 16 16:18:32 2016 +0100
@@ -45,6 +45,8 @@
 
         static QString getRandomGrave();
         static QString getRandomFort();
+        static QString getRandomFlag();
+        static QString getRandomVoice();
         static void teamRandomName(HWTeam & team, const int HedgehogNumber, const QStringList & dict);
 };