Refactor team name generator
authorWuzzy <almikes@aol.com>
Thu, 13 Apr 2017 15:18:07 +0200
changeset 12244 45c83c88ac4b
parent 12243 8a6a40f2e3dc
child 12245 5206f9a803d1
Refactor team name generator
QTfrontend/game.cpp
QTfrontend/hwform.cpp
QTfrontend/ui/page/pageeditteam.cpp
QTfrontend/ui/page/pageeditteam.h
QTfrontend/util/namegen.cpp
QTfrontend/util/namegen.h
--- a/QTfrontend/game.cpp	Thu Apr 13 06:39:01 2017 +0200
+++ b/QTfrontend/game.cpp	Thu Apr 13 15:18:07 2017 +0200
@@ -154,7 +154,7 @@
     team1.setDifficulty(0);
     team1.setColor(0);
     team1.setNumHedgehogs(4);
-    HWNamegen::teamRandomNames(team1,true);
+    HWNamegen::teamRandomEverything(team1,true);
     team1.setVoicepack("Default");
     HWProto::addStringListToBuffer(teamscfg,
                                    team1.teamGameConfig(100));
@@ -164,7 +164,7 @@
     team2.setColor(1);
     team2.setNumHedgehogs(4);
     do
-        HWNamegen::teamRandomNames(team2,true);
+        HWNamegen::teamRandomEverything(team2,true);
     while(!team2.name().compare(team1.name()) || !team2.hedgehog(0).Hat.compare(team1.hedgehog(0).Hat));
     team2.setVoicepack("Default");
     HWProto::addStringListToBuffer(teamscfg,
--- a/QTfrontend/hwform.cpp	Thu Apr 13 06:39:01 2017 +0200
+++ b/QTfrontend/hwform.cpp	Thu Apr 13 15:18:07 2017 +0200
@@ -474,8 +474,8 @@
 
         HWTeam defaultTeam(teamName);
         // Randomize fort and grave for greater variety by default
-        defaultTeam.setGrave(HWNamegen::getRandomGrave());
-        defaultTeam.setFort(HWNamegen::getRandomFort());
+        HWNamegen::teamRandomGrave(defaultTeam);
+        HWNamegen::teamRandomFort(defaultTeam);
         defaultTeam.saveToFile();
         teamslist.push_back(teamName);
 
@@ -484,8 +484,8 @@
         {
             teamName = tr("Team %1").arg(i);
             HWTeam numberTeam(teamName);
-            numberTeam.setGrave(HWNamegen::getRandomGrave());
-            numberTeam.setFort(HWNamegen::getRandomFort());
+            HWNamegen::teamRandomGrave(numberTeam);
+            HWNamegen::teamRandomFort(numberTeam);
             numberTeam.saveToFile();
             teamslist.push_back(teamName);
         }
--- a/QTfrontend/ui/page/pageeditteam.cpp	Thu Apr 13 06:39:01 2017 +0200
+++ b/QTfrontend/ui/page/pageeditteam.cpp	Thu Apr 13 15:18:07 2017 +0200
@@ -187,7 +187,7 @@
     signalMapper2 = new QSignalMapper(this);
 
     connect(signalMapper1, SIGNAL(mapped(int)), this, SLOT(fixHHname(int)));
-    connect(signalMapper2, SIGNAL(mapped(int)), this, SLOT(setRandomName(int)));
+    connect(signalMapper2, SIGNAL(mapped(int)), this, SLOT(setRandomHogName(int)));
 
     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
     {
@@ -198,7 +198,7 @@
         signalMapper2->setMapping(btnRandomHogName[i], i);
     }
 
-    connect(btnRandomTeam, SIGNAL(clicked()), this, SLOT(setRandomNames()));
+    connect(btnRandomTeam, SIGNAL(clicked()), this, SLOT(setRandomTeam()));
 
     connect(btnTestSound, SIGNAL(clicked()), this, SLOT(testSound()));
 
@@ -350,9 +350,9 @@
     // Mostly create a default team, with 2 important exceptions:
     HWTeam newTeam(name);
     // Randomize grave to make it less likely that default teams have equal graves (important for resurrector)
-    newTeam.setGrave(HWNamegen::getRandomGrave());
+    HWNamegen::teamRandomGrave(newTeam);
     // Randomize fort for greater variety in fort mode with default teams
-    newTeam.setFort(HWNamegen::getRandomFort());
+    HWNamegen::teamRandomFort(newTeam);
     loadTeam(newTeam);
 }
 
@@ -379,17 +379,17 @@
         HWTeam(name).deleteFile();
 }
 
-void PageEditTeam::setRandomNames()
+void PageEditTeam::setRandomTeam()
 {
     HWTeam team = data();
-    HWNamegen::teamRandomNames(team, true);
+    HWNamegen::teamRandomEverything(team, true);
     loadTeam(team);
 }
 
-void PageEditTeam::setRandomName(int hh_index)
+void PageEditTeam::setRandomHogName(int hh_index)
 {
     HWTeam team = data();
-    HWNamegen::teamRandomName(team,hh_index);
+    HWNamegen::teamRandomHogName(team,hh_index);
     loadTeam(team);
 }
 
--- a/QTfrontend/ui/page/pageeditteam.h	Thu Apr 13 06:39:01 2017 +0200
+++ b/QTfrontend/ui/page/pageeditteam.h	Thu Apr 13 15:18:07 2017 +0200
@@ -83,9 +83,9 @@
 
     private slots:
         void saveTeam();
-        void setRandomNames();
+        void setRandomTeam();
 
-        void setRandomName(int hh_index);
+        void setRandomHogName(int hh_index);
 
         /// Plays a random voice sound of the currently edited team.
         void testSound();
--- a/QTfrontend/util/namegen.cpp	Thu Apr 13 06:39:01 2017 +0200
+++ b/QTfrontend/util/namegen.cpp	Thu Apr 13 15:18:07 2017 +0200
@@ -33,8 +33,27 @@
 QList<QStringList> HWNamegen::TypesHatnames;
 bool HWNamegen::typesAvailable = false;
 
+void HWNamegen::teamRandomFlag(HWTeam & team)
+{
+    team.setFlag(getRandomFlag());
+}
 
-void HWNamegen::teamRandomNames(HWTeam & team, const bool changeteamname)
+void HWNamegen::teamRandomVoice(HWTeam & team)
+{
+    team.setVoicepack(getRandomVoice());
+}
+
+void HWNamegen::teamRandomGrave(HWTeam & team)
+{
+    team.setGrave(getRandomGrave());
+}
+
+void HWNamegen::teamRandomFort(HWTeam & team)
+{
+    team.setFort(getRandomFort());
+}
+
+void HWNamegen::teamRandomEverything(HWTeam & team, const bool changeteamname)
 {
     // load types if not already loaded
     if (!typesAvailable)
@@ -87,21 +106,21 @@
         }
 
         // give each hedgehog a random name
-        HWNamegen::teamRandomName(team,i,dict);
+        HWNamegen::teamRandomHogName(team,i,dict);
     }
 
 }
 
-void HWNamegen::teamRandomName(HWTeam & team, const int HedgehogNumber)
+void HWNamegen::teamRandomHogName(HWTeam & team, const int HedgehogNumber)
 {
     QStringList dicts = dictsForHat(team.hedgehog(HedgehogNumber).Hat);
 
     QStringList dict = dictContents(dicts[rand()%(dicts.size())]);
 
-    teamRandomName(team, HedgehogNumber, dict);
+    teamRandomHogName(team, HedgehogNumber, dict);
 }
 
-void HWNamegen::teamRandomName(HWTeam & team, const int HedgehogNumber, const QStringList & dict)
+void HWNamegen::teamRandomHogName(HWTeam & team, const int HedgehogNumber, const QStringList & dict)
 {
     QStringList namesDict = dict;
 
--- a/QTfrontend/util/namegen.h	Thu Apr 13 06:39:01 2017 +0200
+++ b/QTfrontend/util/namegen.h	Thu Apr 13 15:18:07 2017 +0200
@@ -29,16 +29,21 @@
 {
     public:
 
-        static void teamRandomName(HWTeam & team, const int HedgehogNumber);
-        static void teamRandomNames(HWTeam & team, const bool changeteamname);
+        static void teamRandomGrave(HWTeam & team);
+        static void teamRandomFort(HWTeam & team);
+        static void teamRandomFlag(HWTeam & team);
+        static void teamRandomVoice(HWTeam & team);
+        static void teamRandomHogName(HWTeam & team, const int HedgehogNumber);
+        static void teamRandomEverything(HWTeam & team, const bool changeteamname);
+
+    private:
+        HWNamegen();
+
         static QString getRandomGrave();
         static QString getRandomFort();
         static QString getRandomFlag();
         static QString getRandomVoice();
 
-    private:
-        HWNamegen();
-
         static QList<QStringList> TypesTeamnames;
         static QList<QStringList> TypesHatnames;
         static bool typesAvailable;
@@ -47,7 +52,7 @@
         static QStringList dictContents(const QString filename);
         static QStringList dictsForHat(const QString hatname);
 
-        static void teamRandomName(HWTeam & team, const int HedgehogNumber, const QStringList & dict);
+        static void teamRandomHogName(HWTeam & team, const int HedgehogNumber, const QStringList & dict);
 };