QTfrontend/util/namegen.cpp
changeset 12295 ac57d564efce
parent 12248 07f67ee424dc
child 12499 d97050a7c074
equal deleted inserted replaced
12294:0deabf747b8f 12295:ac57d564efce
    38     QString newName = getRandomTeamName(-1);
    38     QString newName = getRandomTeamName(-1);
    39     if(!newName.isNull())
    39     if(!newName.isNull())
    40         team.setName(newName);
    40         team.setName(newName);
    41 }
    41 }
    42 
    42 
    43 void HWNamegen::teamRandomFlag(HWTeam & team)
    43 void HWNamegen::teamRandomFlag(HWTeam & team, bool withDLC)
    44 {
    44 {
    45     team.setFlag(getRandomFlag());
    45     team.setFlag(getRandomFlag(withDLC));
    46 }
    46 }
    47 
    47 
    48 void HWNamegen::teamRandomVoice(HWTeam & team)
    48 void HWNamegen::teamRandomVoice(HWTeam & team, bool withDLC)
    49 {
    49 {
    50     team.setVoicepack(getRandomVoice());
    50     team.setVoicepack(getRandomVoice(withDLC));
    51 }
    51 }
    52 
    52 
    53 void HWNamegen::teamRandomGrave(HWTeam & team)
    53 void HWNamegen::teamRandomGrave(HWTeam & team, bool withDLC)
    54 {
    54 {
    55     team.setGrave(getRandomGrave());
    55     team.setGrave(getRandomGrave(withDLC));
    56 }
    56 }
    57 
    57 
    58 void HWNamegen::teamRandomFort(HWTeam & team)
    58 void HWNamegen::teamRandomFort(HWTeam & team, bool withDLC)
    59 {
    59 {
    60     team.setFort(getRandomFort());
    60     team.setFort(getRandomFort(withDLC));
    61 }
    61 }
    62 
    62 
    63 void HWNamegen::teamRandomEverything(HWTeam & team, const RandomTeamMode mode)
    63 void HWNamegen::teamRandomEverything(HWTeam & team, const RandomTeamMode mode)
    64 {
    64 {
    65     // load types if not already loaded
    65     // load types if not already loaded
   278         return TypesTeamnames[kind][rand()%(TypesTeamnames[kind].size())];
   278         return TypesTeamnames[kind][rand()%(TypesTeamnames[kind].size())];
   279     else
   279     else
   280         return QString();
   280         return QString();
   281 }
   281 }
   282 
   282 
   283 QString HWNamegen::getRandomGrave()
   283 QString HWNamegen::getRandomGrave(bool withDLC)
   284 {
   284 {
   285     QStringList Graves;
   285     QStringList Graves;
   286 
   286 
   287     //list all available Graves
   287     //list all available Graves
   288     Graves.append(DataManager::instance().entryList(
   288     Graves.append(DataManager::instance().entryList(
   289                       "Graphics/Graves",
   289                       "Graphics/Graves",
   290                       QDir::Files,
   290                       QDir::Files,
   291                       QStringList("*.png")
   291                       QStringList("*.png"),
       
   292                       withDLC
   292                   ).replaceInStrings(QRegExp("\\.png$"), "")
   293                   ).replaceInStrings(QRegExp("\\.png$"), "")
   293                  );
   294                  );
   294 
   295 
   295     if(Graves.size()==0)
   296     if(Graves.size()==0)
   296     {
   297     {
   300 
   301 
   301     //pick a random grave
   302     //pick a random grave
   302     return Graves[rand()%(Graves.size())];
   303     return Graves[rand()%(Graves.size())];
   303 }
   304 }
   304 
   305 
   305 QString HWNamegen::getRandomFlag()
   306 QString HWNamegen::getRandomFlag(bool withDLC)
   306 {
   307 {
   307     QStringList Flags;
   308     QStringList Flags;
   308 
   309 
   309     //list all available flags
   310     //list all available flags
   310     Flags.append(DataManager::instance().entryList(
   311     Flags.append(DataManager::instance().entryList(
   311                       "Graphics/Flags",
   312                       "Graphics/Flags",
   312                       QDir::Files,
   313                       QDir::Files,
   313                       QStringList("*.png")
   314                       QStringList("*.png"),
       
   315                       withDLC
   314                   ).replaceInStrings(QRegExp("\\.png$"), "")
   316                   ).replaceInStrings(QRegExp("\\.png$"), "")
   315                  );
   317                  );
   316     //remove internal flags
   318     //remove internal flags
   317     Flags.removeAll("cpu");
   319     Flags.removeAll("cpu");
   318     Flags.removeAll("cpu_plain");
   320     Flags.removeAll("cpu_plain");
   325 
   327 
   326     //pick a random flag
   328     //pick a random flag
   327     return Flags[rand()%(Flags.size())];
   329     return Flags[rand()%(Flags.size())];
   328 }
   330 }
   329 
   331 
   330 QString HWNamegen::getRandomFort()
   332 QString HWNamegen::getRandomFort(bool withDLC)
   331 {
   333 {
   332     QStringList Forts;
   334     QStringList Forts;
   333 
   335 
   334     //list all available Forts
   336     //list all available Forts
   335     Forts.append(DataManager::instance().entryList(
   337     Forts.append(DataManager::instance().entryList(
   336                      "Forts",
   338                      "Forts",
   337                      QDir::Files,
   339                      QDir::Files,
   338                      QStringList("*L.png")
   340                      QStringList("*L.png"),
       
   341                      withDLC
   339                  ).replaceInStrings(QRegExp("L\\.png$"), "")
   342                  ).replaceInStrings(QRegExp("L\\.png$"), "")
   340                 );
   343                 );
   341 
   344 
   342     if(Forts.size()==0)
   345     if(Forts.size()==0)
   343     {
   346     {
   347 
   350 
   348     //pick a random fort
   351     //pick a random fort
   349     return Forts[rand()%(Forts.size())];
   352     return Forts[rand()%(Forts.size())];
   350 }
   353 }
   351 
   354 
   352 QString HWNamegen::getRandomVoice()
   355 QString HWNamegen::getRandomVoice(bool withDLC)
   353 {
   356 {
   354     QStringList Voices;
   357     QStringList Voices;
   355 
   358 
   356     //list all available voices 
   359     //list all available voices 
   357     Voices.append(DataManager::instance().entryList(
   360     Voices.append(DataManager::instance().entryList(
   358                      "Sounds/voices",
   361                      "Sounds/voices",
   359                      QDir::Dirs | QDir::NoDotAndDotDot,
   362                      QDir::Dirs | QDir::NoDotAndDotDot,
   360                      QStringList("*")));
   363                      QStringList("*"),
       
   364                      withDLC));
   361 
   365 
   362     if(Voices.size()==0)
   366     if(Voices.size()==0)
   363     {
   367     {
   364         // TODO do some serious error handling
   368         // TODO do some serious error handling
   365         return "Error";
   369         return "Error";