QTfrontend/util/namegen.cpp
changeset 12252 a6e0977be914
parent 12250 5206f9a803d1
child 12253 07f67ee424dc
equal deleted inserted replaced
12251:4c717a69a7a6 12252:a6e0977be914
    33 QList<QStringList> HWNamegen::TypesHatnames;
    33 QList<QStringList> HWNamegen::TypesHatnames;
    34 bool HWNamegen::typesAvailable = false;
    34 bool HWNamegen::typesAvailable = false;
    35 
    35 
    36 void HWNamegen::teamRandomTeamName(HWTeam & team)
    36 void HWNamegen::teamRandomTeamName(HWTeam & team)
    37 {
    37 {
    38     QString newName = getRandomTeamName();
    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)
    75     int kind = (rand()%(TypesHatnames.size()));
    75     int kind = (rand()%(TypesHatnames.size()));
    76 
    76 
    77     // pick team name based on hat
    77     // pick team name based on hat
    78     if (changeteamname)
    78     if (changeteamname)
    79     {
    79     {
    80         team.setName(getRandomTeamName());
    80         team.setName(getRandomTeamName(kind));
    81         team.setGrave(getRandomGrave());
    81         team.setGrave(getRandomGrave());
    82         team.setFort(getRandomFort());
    82         team.setFort(getRandomFort());
    83         team.setFlag(getRandomFlag());
    83         team.setFlag(getRandomFlag());
    84         team.setVoicepack(getRandomVoice());
    84         team.setVoicepack(getRandomVoice());
    85     }
    85     }
   254     delete file;
   254     delete file;
   255 
   255 
   256     return typesAvailable;
   256     return typesAvailable;
   257 }
   257 }
   258 
   258 
   259 QString HWNamegen::getRandomTeamName()
   259 /* Generates a random team name.
       
   260 kind: Use to select a team name out of a group (types.ini).
       
   261 Use a negative value if you don't care.
       
   262 This function may return a null QString on error(this should never happen). */
       
   263 QString HWNamegen::getRandomTeamName(int kind)
   260 {
   264 {
   261     // load types if not already loaded
   265     // load types if not already loaded
   262     if (!typesAvailable)
   266     if (!typesAvailable)
   263         if (!loadTypes())
   267         if (!loadTypes())
   264             return QString(); // abort if loading failed
   268             return QString(); // abort if loading failed
   265 
   269 
   266     // abort if there are no hat types
   270     // abort if there are no hat types
   267     if (TypesHatnames.size() <= 0)
   271     if (TypesHatnames.size() <= 0)
   268         return QString();
   272         return QString();
   269 
   273 
   270     int kind = (rand()%(TypesHatnames.size()));
   274     if(kind < 0)
       
   275         kind = (rand()%(TypesHatnames.size()));
       
   276 
   271     if (TypesTeamnames[kind].size() > 0)
   277     if (TypesTeamnames[kind].size() > 0)
   272         return TypesTeamnames[kind][rand()%(TypesTeamnames[kind].size())];
   278         return TypesTeamnames[kind][rand()%(TypesTeamnames[kind].size())];
   273     else
   279     else
   274         return QString();
   280         return QString();
   275 }
   281 }