QTfrontend/util/namegen.cpp
branchflibqtfrontend
changeset 8103 c247346d296f
parent 8049 133e22b5c410
child 8126 5bfa1b2025d6
equal deleted inserted replaced
8100:0e6fadf81a2c 8103:c247346d296f
    62     QStringList dicts;
    62     QStringList dicts;
    63     QStringList dict;
    63     QStringList dict;
    64 
    64 
    65     if ((TypesHatnames[kind].size()) <= 0)
    65     if ((TypesHatnames[kind].size()) <= 0)
    66     {
    66     {
    67         dicts = dictsForHat(team.hedgehog(0).Hat);
    67         dicts = dictsForHat(team.hedgehogHat(0));
    68         dict  = dictContents(dicts[rand()%(dicts.size())]);
    68         dict  = dictContents(dicts[rand()%(dicts.size())]);
    69     }
    69     }
    70 
    70 
    71     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
    71     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
    72     {
    72     {
    73         if ((TypesHatnames[kind].size()) > 0)
    73         if ((TypesHatnames[kind].size()) > 0)
    74         {
    74             team.setHedgehogHat(i, TypesHatnames[kind][rand()%(TypesHatnames[kind].size())]);
    75             HWHog hh = team.hedgehog(i);
       
    76             hh.Hat = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())];
       
    77             team.setHedgehog(i,hh);
       
    78         }
       
    79 
    75 
    80         // there is a chance that this hog has the same hat as the previous one
    76         // there is a chance that this hog has the same hat as the previous one
    81         // let's reuse the hat-specific dict in this case
    77         // let's reuse the hat-specific dict in this case
    82         if ((i == 0) || (team.hedgehog(i).Hat != team.hedgehog(i-1).Hat))
    78         if ((i == 0) || (team.hedgehogHat(i) != team.hedgehogHat(i-1)))
    83         {
    79         {
    84             dicts = dictsForHat(team.hedgehog(i).Hat);
    80             dicts = dictsForHat(team.hedgehogHat(i));
    85             dict  = dictContents(dicts[rand()%(dicts.size())]);
    81             dict  = dictContents(dicts[rand()%(dicts.size())]);
    86         }
    82         }
    87 
    83 
    88         // give each hedgehog a random name
    84         // give each hedgehog a random name
    89         HWNamegen::teamRandomName(team,i,dict);
    85         HWNamegen::teamRandomName(team,i,dict);
    91 
    87 
    92 }
    88 }
    93 
    89 
    94 void HWNamegen::teamRandomName(HWTeam & team, const int HedgehogNumber)
    90 void HWNamegen::teamRandomName(HWTeam & team, const int HedgehogNumber)
    95 {
    91 {
    96     QStringList dicts = dictsForHat(team.hedgehog(HedgehogNumber).Hat);
    92     QStringList dicts = dictsForHat(team.hedgehogHat(HedgehogNumber));
    97 
    93 
    98     QStringList dict = dictContents(dicts[rand()%(dicts.size())]);
    94     QStringList dict = dictContents(dicts[rand()%(dicts.size())]);
    99 
    95 
   100     teamRandomName(team, HedgehogNumber, dict);
    96     teamRandomName(team, HedgehogNumber, dict);
   101 }
    97 }
   104 {
   100 {
   105     QStringList namesDict = dict;
   101     QStringList namesDict = dict;
   106 
   102 
   107     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
   103     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
   108     {
   104     {
   109         namesDict.removeOne(team.hedgehog(i).Name);
   105         namesDict.removeOne(team.hedgehogName(i));
   110     }
   106     }
   111 
   107 
   112     // if our dict doesn't have any new names we'll have to use duplicates
   108     // if our dict doesn't have any new names we'll have to use duplicates
   113     if (namesDict.size() < 1)
   109     if (namesDict.size() < 1)
   114         namesDict = dict;
   110         namesDict = dict;
   115 
   111 
   116     HWHog hh = team.hedgehog(HedgehogNumber);
   112     team.setHedgehogName(HedgehogNumber, namesDict[rand()%(namesDict.size())]);
   117 
       
   118     hh.Name = namesDict[rand()%(namesDict.size())];
       
   119 
       
   120     team.setHedgehog(HedgehogNumber, hh);
       
   121 }
   113 }
   122 
   114 
   123 QStringList HWNamegen::dictContents(const QString filename)
   115 QStringList HWNamegen::dictContents(const QString filename)
   124 {
   116 {
   125     QStringList list;
   117     QStringList list;