Randomized teams now can have any random hats (not just from types.ini)
authorWuzzy <almikes@aol.com>
Sat, 23 Sep 2017 21:05:57 +0200
changeset 12510 82c75a317d48
parent 12509 b393a6308662
child 12511 9a762e1729c6
Randomized teams now can have any random hats (not just from types.ini) The predefined hat sets still work, however. There are now 3 types of hat selections: 1) Use hats from types.ini 2) Randomly select one hat for all hedgehogs 3) Randomly select hat for each hedgehog (rare)
ChangeLog.txt
QTfrontend/game.cpp
QTfrontend/ui/page/pageeditteam.cpp
QTfrontend/util/namegen.cpp
QTfrontend/util/namegen.h
--- a/ChangeLog.txt	Sat Sep 23 20:05:16 2017 +0200
+++ b/ChangeLog.txt	Sat Sep 23 21:05:57 2017 +0200
@@ -225,6 +225,7 @@
  + New teams start with a random grave and fort
  + Hedgewars creates 4 teams instead of 1 on its first launch
  + Allow to randomize hog names, hats, team name, flag, grave, voice and fort separately
+ + “Random team” button is now able to randomly select from all available hats
  * Campaign screen does no longer show AI-controlled teams
  * Campaign names and campaign mission names can now be translated
  * Creating randomized teams now randomizes (almost) every aspect
--- a/QTfrontend/game.cpp	Sat Sep 23 20:05:16 2017 +0200
+++ b/QTfrontend/game.cpp	Sat Sep 23 21:05:57 2017 +0200
@@ -154,7 +154,7 @@
     team1.setDifficulty(0);
     team1.setColor(0);
     team1.setNumHedgehogs(4);
-    HWNamegen::teamRandomEverything(team1, HWNamegen::rtmEverything);
+    HWNamegen::teamRandomEverything(team1);
     team1.setVoicepack("Default");
     HWProto::addStringListToBuffer(teamscfg,
                                    team1.teamGameConfig(100));
@@ -164,7 +164,7 @@
     team2.setColor(1);
     team2.setNumHedgehogs(4);
     do
-        HWNamegen::teamRandomEverything(team2, HWNamegen::rtmEverything);
+        HWNamegen::teamRandomEverything(team2);
     while(!team2.name().compare(team1.name()) || !team2.hedgehog(0).Hat.compare(team1.hedgehog(0).Hat));
     team2.setVoicepack("Default");
     HWProto::addStringListToBuffer(teamscfg,
--- a/QTfrontend/ui/page/pageeditteam.cpp	Sat Sep 23 20:05:16 2017 +0200
+++ b/QTfrontend/ui/page/pageeditteam.cpp	Sat Sep 23 21:05:57 2017 +0200
@@ -474,14 +474,14 @@
 void PageEditTeam::setRandomTeam()
 {
     HWTeam team = data();
-    HWNamegen::teamRandomEverything(team, HWNamegen::rtmEverything);
+    HWNamegen::teamRandomEverything(team);
     loadTeam(team);
 }
 
 void PageEditTeam::setRandomHogNames()
 {
     HWTeam team = data();
-    HWNamegen::teamRandomEverything(team, HWNamegen::rtmHogNames);
+    HWNamegen::teamRandomHogNames(team);
     loadTeam(team);
 }
 
--- a/QTfrontend/util/namegen.cpp	Sat Sep 23 20:05:16 2017 +0200
+++ b/QTfrontend/util/namegen.cpp	Sat Sep 23 21:05:57 2017 +0200
@@ -61,7 +61,7 @@
     team.setFort(getRandomFort(withDLC));
 }
 
-void HWNamegen::teamRandomEverything(HWTeam & team, const RandomTeamMode mode)
+void HWNamegen::teamRandomEverything(HWTeam & team)
 {
     // load types if not already loaded
     if (!typesAvailable)
@@ -76,43 +76,65 @@
     int kind = (rand()%(TypesHatnames.size()));
 
     // pick team name based on hat
-    if (mode == HWNamegen::rtmEverything)
-    {        team.setName(getRandomTeamName(kind));
-        team.setGrave(getRandomGrave());
-        team.setFort(getRandomFort());
-        team.setFlag(getRandomFlag());
-        team.setVoicepack(getRandomVoice());
-    }
+    team.setName(getRandomTeamName(kind));
+    team.setGrave(getRandomGrave());
+    team.setFort(getRandomFort());
+    team.setFlag(getRandomFlag());
+    team.setVoicepack(getRandomVoice());
 
     QStringList dicts;
     QStringList dict;
 
-    if ((mode == HWNamegen::rtmHogNames || mode == HWNamegen::rtmEverything) && (TypesHatnames[kind].size()) <= 0)
-    {
-        dicts = dictsForHat(team.hedgehog(0).Hat);
-        dict  = dictContents(dicts[rand()%(dicts.size())]);
-    }
+    // Randomness mode:
+    // 0: Themed hats (from types.ini)
+    // 1: Equal hats for all
+    // 2: Random hat for each hedgehog
+    int r = rand() % 10;
+    int randomMode;
+    if (r <= 4)		// 0-4 (50%)
+       randomMode = 0;
+    else if (r <= 8)	// 5-8 (40%)
+       randomMode = 1;
+    else		// 9   (10%)
+       randomMode = 2;
 
+    // Generate random hats
     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
     {
-        if (mode == HWNamegen::rtmEverything && (TypesHatnames[kind].size()) > 0)
+        HWHog hh = team.hedgehog(i);
+
+        if (randomMode == 0)
+        {
+            hh.Hat = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())];
+        }
+        else if (randomMode == 1)
         {
-            HWHog hh = team.hedgehog(i);
-            hh.Hat = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())];
-            team.setHedgehog(i,hh);
+            if (i == 0)
+            {
+                hh.Hat = getRandomHat();
+            }
+            else
+            {
+                hh.Hat = team.hedgehog(i-1).Hat;
+            }
         }
+        else if (randomMode == 2)
+        {
+            hh.Hat = getRandomHat();
+        }
+
+        team.setHedgehog(i,hh);
 
         // there is a chance that this hog has the same hat as the previous one
         // let's reuse the hat-specific dict in this case
-        if ( (mode == HWNamegen::rtmHogNames || mode == HWNamegen::rtmEverything) && ((i == 0) || (team.hedgehog(i).Hat != team.hedgehog(i-1).Hat)))
+        if ((i == 0) || (team.hedgehog(i).Hat != team.hedgehog(i-1).Hat))
         {
             dicts = dictsForHat(team.hedgehog(i).Hat);
             dict  = dictContents(dicts[rand()%(dicts.size())]);
         }
 
         // give each hedgehog a random name
-        if (mode == HWNamegen::rtmHogNames || mode == HWNamegen::rtmEverything)
-            HWNamegen::teamRandomHogName(team,i,dict);
+        HWNamegen::teamRandomHogName(team,i,dict);
     }
 
 }
@@ -153,6 +175,24 @@
     team.setHedgehog(HedgehogNumber, hh);
 }
 
+void HWNamegen::teamRandomHogNames(HWTeam & team)
+{
+    QStringList dicts, dict;
+    for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
+    {
+        // there is a chance that this hog has the same hat as the previous one
+        // let's reuse the hat-specific dict in this case
+        if ((i == 0) || (team.hedgehog(i).Hat != team.hedgehog(i-1).Hat))
+        {
+            dicts = dictsForHat(team.hedgehog(i).Hat);
+            dict  = dictContents(dicts[rand()%(dicts.size())]);
+        }
+
+        // give each hedgehog a random name
+        HWNamegen::teamRandomHogName(team,i,dict);
+    }
+}
+
 void HWNamegen::teamRandomHogName(HWTeam & team, const int HedgehogNumber)
 {
     QStringList dicts = dictsForHat(team.hedgehog(HedgehogNumber).Hat);
--- a/QTfrontend/util/namegen.h	Sat Sep 23 20:05:16 2017 +0200
+++ b/QTfrontend/util/namegen.h	Sat Sep 23 21:05:57 2017 +0200
@@ -28,12 +28,6 @@
 class HWNamegen
 {
     public:
-        enum RandomTeamMode
-        {
-            rtmEverything = 0,
-            rtmHogNames = 1,
-        };
-
         static void teamRandomTeamName(HWTeam & team);
         static void teamRandomGrave(HWTeam & team, bool withDLC = true);
         static void teamRandomFort(HWTeam & team, bool withDLC = true);
@@ -41,8 +35,9 @@
         static void teamRandomVoice(HWTeam & team, bool withDLC = true);
         static void teamRandomHats(HWTeam & team, bool withDLC = true);
         static void teamRandomHat(HWTeam & team, const int HedgehogNumber, bool withDLC = true);
+        static void teamRandomHogNames(HWTeam & team);
         static void teamRandomHogName(HWTeam & team, const int HedgehogNumber);
-        static void teamRandomEverything(HWTeam & team, const enum RandomTeamMode mode);
+        static void teamRandomEverything(HWTeam & team);
 
     private:
         HWNamegen();