QTfrontend/util/namegen.cpp
changeset 12501 92c597704e57
parent 12499 d97050a7c074
child 12502 f4b0e164a0d5
equal deleted inserted replaced
12500:2e7a32c44ab3 12501:92c597704e57
    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     if (mode == HWNamegen::rtmEverything)
    80     {
    80     {        team.setName(getRandomTeamName(kind));
    81         team.setName(getRandomTeamName(kind));
       
    82         team.setGrave(getRandomGrave());
    81         team.setGrave(getRandomGrave());
    83         team.setFort(getRandomFort());
    82         team.setFort(getRandomFort());
    84         team.setFlag(getRandomFlag());
    83         team.setFlag(getRandomFlag());
    85         team.setVoicepack(getRandomVoice());
    84         team.setVoicepack(getRandomVoice());
    86     }
    85     }
    87 
    86 
    88     QStringList dicts;
    87     QStringList dicts;
    89     QStringList dict;
    88     QStringList dict;
    90 
    89 
    91     if ((TypesHatnames[kind].size()) <= 0)
    90     if ((mode == HWNamegen::rtmHogNames || mode == HWNamegen::rtmEverything) && (TypesHatnames[kind].size()) <= 0)
    92     {
    91     {
    93         dicts = dictsForHat(team.hedgehog(0).Hat);
    92         dicts = dictsForHat(team.hedgehog(0).Hat);
    94         dict  = dictContents(dicts[rand()%(dicts.size())]);
    93         dict  = dictContents(dicts[rand()%(dicts.size())]);
    95     }
    94     }
    96 
    95 
    97     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
    96     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
    98     {
    97     {
    99         if (((TypesHatnames[kind].size()) > 0) && (mode == HWNamegen::rtmEverything || mode == HWNamegen::rtmHats))
    98         if (mode == HWNamegen::rtmEverything && (TypesHatnames[kind].size()) > 0)
   100         {
    99         {
   101             HWHog hh = team.hedgehog(i);
   100             HWHog hh = team.hedgehog(i);
   102             hh.Hat = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())];
   101             hh.Hat = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())];
   103             team.setHedgehog(i,hh);
   102             team.setHedgehog(i,hh);
   104         }
   103         }
       
   104         else if (mode == HWNamegen::rtmHats)
       
   105         {
       
   106             HWNamegen::teamRandomHat(team,i);
       
   107         }
       
   108 
   105         // there is a chance that this hog has the same hat as the previous one
   109         // 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
   110         // let's reuse the hat-specific dict in this case
   107         if ((i == 0) || (team.hedgehog(i).Hat != team.hedgehog(i-1).Hat))
   111         if ( (mode == HWNamegen::rtmHogNames || mode == HWNamegen::rtmEverything) && ((i == 0) || (team.hedgehog(i).Hat != team.hedgehog(i-1).Hat)))
   108         {
   112         {
   109             dicts = dictsForHat(team.hedgehog(i).Hat);
   113             dicts = dictsForHat(team.hedgehog(i).Hat);
   110             dict  = dictContents(dicts[rand()%(dicts.size())]);
   114             dict  = dictContents(dicts[rand()%(dicts.size())]);
   111         }
   115         }
   112 
   116 
   113         // give each hedgehog a random name
   117         // give each hedgehog a random name
   114         if (mode == HWNamegen::rtmHogNames || mode == HWNamegen::rtmEverything)
   118         if (mode == HWNamegen::rtmHogNames || mode == HWNamegen::rtmEverything)
   115             HWNamegen::teamRandomHogName(team,i,dict);
   119             HWNamegen::teamRandomHogName(team,i,dict);
   116     }
   120     }
   117 
   121 
       
   122 }
       
   123 
       
   124 void HWNamegen::teamRandomHat(HWTeam & team, const int HedgehogNumber, bool withDLC)
       
   125 {
       
   126     HWHog hh = team.hedgehog(HedgehogNumber);
       
   127 
       
   128     hh.Hat = getRandomHat(withDLC);
       
   129 
       
   130     team.setHedgehog(HedgehogNumber, hh);
       
   131 }
       
   132 
       
   133 void HWNamegen::teamRandomHat(HWTeam & team, const int HedgehogNumber, const QStringList & dict)
       
   134 {
       
   135     HWHog hh = team.hedgehog(HedgehogNumber);
       
   136 
       
   137     hh.Name = dict[rand()%(dict.size())];
       
   138 
       
   139     team.setHedgehog(HedgehogNumber, hh);
   118 }
   140 }
   119 
   141 
   120 void HWNamegen::teamRandomHogName(HWTeam & team, const int HedgehogNumber)
   142 void HWNamegen::teamRandomHogName(HWTeam & team, const int HedgehogNumber)
   121 {
   143 {
   122     QStringList dicts = dictsForHat(team.hedgehog(HedgehogNumber).Hat);
   144     QStringList dicts = dictsForHat(team.hedgehog(HedgehogNumber).Hat);
   289         return TypesTeamnames[kind][rand()%(TypesTeamnames[kind].size())];
   311         return TypesTeamnames[kind][rand()%(TypesTeamnames[kind].size())];
   290     else
   312     else
   291         return QString();
   313         return QString();
   292 }
   314 }
   293 
   315 
       
   316 QString HWNamegen::getRandomHat(bool withDLC)
       
   317 {
       
   318     QStringList Hats;
       
   319 
       
   320     // list all available hats
       
   321     Hats.append(DataManager::instance().entryList(
       
   322                       "Graphics/Hats",
       
   323                       QDir::Files,
       
   324                       QStringList("*.png"),
       
   325                       withDLC
       
   326                   ).replaceInStrings(QRegExp("\\.png$"), "")
       
   327                  );
       
   328 
       
   329     if(Hats.size()==0)
       
   330     {
       
   331         // TODO do some serious error handling
       
   332         return "Error";
       
   333     }
       
   334 
       
   335     // pick a random hat
       
   336     return Hats[rand()%(Hats.size())];
       
   337 }
       
   338 
   294 QString HWNamegen::getRandomGrave(bool withDLC)
   339 QString HWNamegen::getRandomGrave(bool withDLC)
   295 {
   340 {
   296     QStringList Graves;
   341     QStringList Graves;
   297 
   342 
   298     //list all available Graves
   343     //list all available Graves