QTfrontend/util/namegen.cpp
changeset 12505 82c75a317d48
parent 12502 f4b0e164a0d5
child 12630 11f5fe0407e5
equal deleted inserted replaced
12504:b393a6308662 12505:82c75a317d48
    59 void HWNamegen::teamRandomFort(HWTeam & team, bool withDLC)
    59 void HWNamegen::teamRandomFort(HWTeam & team, bool withDLC)
    60 {
    60 {
    61     team.setFort(getRandomFort(withDLC));
    61     team.setFort(getRandomFort(withDLC));
    62 }
    62 }
    63 
    63 
    64 void HWNamegen::teamRandomEverything(HWTeam & team, const RandomTeamMode mode)
    64 void HWNamegen::teamRandomEverything(HWTeam & team)
    65 {
    65 {
    66     // load types if not already loaded
    66     // load types if not already loaded
    67     if (!typesAvailable)
    67     if (!typesAvailable)
    68         if (!loadTypes())
    68         if (!loadTypes())
    69             return; // abort if loading failed
    69             return; // abort if loading failed
    74 
    74 
    75     // the hat will influence which names the hogs get
    75     // the hat will influence which names the hogs get
    76     int kind = (rand()%(TypesHatnames.size()));
    76     int kind = (rand()%(TypesHatnames.size()));
    77 
    77 
    78     // pick team name based on hat
    78     // pick team name based on hat
    79     if (mode == HWNamegen::rtmEverything)
    79     team.setName(getRandomTeamName(kind));
    80     {        team.setName(getRandomTeamName(kind));
    80     team.setGrave(getRandomGrave());
    81         team.setGrave(getRandomGrave());
    81     team.setFort(getRandomFort());
    82         team.setFort(getRandomFort());
    82     team.setFlag(getRandomFlag());
    83         team.setFlag(getRandomFlag());
    83     team.setVoicepack(getRandomVoice());
    84         team.setVoicepack(getRandomVoice());
       
    85     }
       
    86 
    84 
    87     QStringList dicts;
    85     QStringList dicts;
    88     QStringList dict;
    86     QStringList dict;
    89 
    87 
    90     if ((mode == HWNamegen::rtmHogNames || mode == HWNamegen::rtmEverything) && (TypesHatnames[kind].size()) <= 0)
    88     // Randomness mode:
    91     {
    89     // 0: Themed hats (from types.ini)
    92         dicts = dictsForHat(team.hedgehog(0).Hat);
    90     // 1: Equal hats for all
    93         dict  = dictContents(dicts[rand()%(dicts.size())]);
    91     // 2: Random hat for each hedgehog
    94     }
    92     int r = rand() % 10;
    95 
    93     int randomMode;
       
    94     if (r <= 4)		// 0-4 (50%)
       
    95        randomMode = 0;
       
    96     else if (r <= 8)	// 5-8 (40%)
       
    97        randomMode = 1;
       
    98     else		// 9   (10%)
       
    99        randomMode = 2;
       
   100 
       
   101     // Generate random hats
    96     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
   102     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
    97     {
   103     {
    98         if (mode == HWNamegen::rtmEverything && (TypesHatnames[kind].size()) > 0)
   104         HWHog hh = team.hedgehog(i);
    99         {
   105 
   100             HWHog hh = team.hedgehog(i);
   106         if (randomMode == 0)
       
   107         {
   101             hh.Hat = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())];
   108             hh.Hat = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())];
   102             team.setHedgehog(i,hh);
   109         }
   103         }
   110         else if (randomMode == 1)
       
   111         {
       
   112             if (i == 0)
       
   113             {
       
   114                 hh.Hat = getRandomHat();
       
   115             }
       
   116             else
       
   117             {
       
   118                 hh.Hat = team.hedgehog(i-1).Hat;
       
   119             }
       
   120         }
       
   121         else if (randomMode == 2)
       
   122         {
       
   123             hh.Hat = getRandomHat();
       
   124         }
       
   125 
       
   126         team.setHedgehog(i,hh);
   104 
   127 
   105         // there is a chance that this hog has the same hat as the previous one
   128         // there is a chance that this hog has the same hat as the previous one
   106         // let's reuse the hat-specific dict in this case
   129         // let's reuse the hat-specific dict in this case
   107         if ( (mode == HWNamegen::rtmHogNames || mode == HWNamegen::rtmEverything) && ((i == 0) || (team.hedgehog(i).Hat != team.hedgehog(i-1).Hat)))
   130         if ((i == 0) || (team.hedgehog(i).Hat != team.hedgehog(i-1).Hat))
   108         {
   131         {
   109             dicts = dictsForHat(team.hedgehog(i).Hat);
   132             dicts = dictsForHat(team.hedgehog(i).Hat);
   110             dict  = dictContents(dicts[rand()%(dicts.size())]);
   133             dict  = dictContents(dicts[rand()%(dicts.size())]);
   111         }
   134         }
   112 
   135 
   113         // give each hedgehog a random name
   136         // give each hedgehog a random name
   114         if (mode == HWNamegen::rtmHogNames || mode == HWNamegen::rtmEverything)
   137         HWNamegen::teamRandomHogName(team,i,dict);
   115             HWNamegen::teamRandomHogName(team,i,dict);
       
   116     }
   138     }
   117 
   139 
   118 }
   140 }
   119 
   141 
   120 // Set random hats for entire team
   142 // Set random hats for entire team
   149     HWHog hh = team.hedgehog(HedgehogNumber);
   171     HWHog hh = team.hedgehog(HedgehogNumber);
   150 
   172 
   151     hh.Name = dict[rand()%(dict.size())];
   173     hh.Name = dict[rand()%(dict.size())];
   152 
   174 
   153     team.setHedgehog(HedgehogNumber, hh);
   175     team.setHedgehog(HedgehogNumber, hh);
       
   176 }
       
   177 
       
   178 void HWNamegen::teamRandomHogNames(HWTeam & team)
       
   179 {
       
   180     QStringList dicts, dict;
       
   181     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
       
   182     {
       
   183         // there is a chance that this hog has the same hat as the previous one
       
   184         // let's reuse the hat-specific dict in this case
       
   185         if ((i == 0) || (team.hedgehog(i).Hat != team.hedgehog(i-1).Hat))
       
   186         {
       
   187             dicts = dictsForHat(team.hedgehog(i).Hat);
       
   188             dict  = dictContents(dicts[rand()%(dicts.size())]);
       
   189         }
       
   190 
       
   191         // give each hedgehog a random name
       
   192         HWNamegen::teamRandomHogName(team,i,dict);
       
   193     }
   154 }
   194 }
   155 
   195 
   156 void HWNamegen::teamRandomHogName(HWTeam & team, const int HedgehogNumber)
   196 void HWNamegen::teamRandomHogName(HWTeam & team, const int HedgehogNumber)
   157 {
   197 {
   158     QStringList dicts = dictsForHat(team.hedgehog(HedgehogNumber).Hat);
   198     QStringList dicts = dictsForHat(team.hedgehog(HedgehogNumber).Hat);