QTfrontend/namegen.cpp
changeset 5115 276410cc1178
parent 5114 a05081bc2769
child 5238 46ddaf14509d
equal deleted inserted replaced
5114:a05081bc2769 5115:276410cc1178
    58             team->Grave = GetRandomGrave();
    58             team->Grave = GetRandomGrave();
    59             team->Fort = GetRandomFort();
    59             team->Fort = GetRandomFort();
    60             team->Voicepack = "Default";
    60             team->Voicepack = "Default";
    61         }
    61         }
    62 
    62 
    63 		//give each hedgehog a random name:
    63         //give each hedgehog a random name:
    64 		//TODO: load the dictionary only once! (right now it's loaded once for each hedgehog)
    64         //TODO: load the dictionary only once! (right now it's loaded once for each hedgehog)
    65         for(int i = 0; i < 8; i++)
    65         for(int i = 0; i < 8; i++)
    66         {
    66         {
    67             if ((TypesHatnames[kind].size()) > 0){
    67             if ((TypesHatnames[kind].size()) > 0){
    68                 team->Hedgehogs[i].Hat = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())];
    68                 team->Hedgehogs[i].Hat = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())];
    69             }
    69             }
   167 
   167 
   168 
   168 
   169 
   169 
   170 QString HWNamegen::GetRandomGrave()
   170 QString HWNamegen::GetRandomGrave()
   171 {
   171 {
   172 	QStringList Graves;
   172     QStringList Graves;
   173 	
   173 
   174 	//list all available Graves
   174     //list all available Graves
   175 	QDir tmpdir;
   175     QDir tmpdir;
   176     tmpdir.cd(datadir->absolutePath());
   176     tmpdir.cd(datadir->absolutePath());
   177     tmpdir.cd("Graphics/Graves");
   177     tmpdir.cd("Graphics/Graves");
   178     tmpdir.setFilter(QDir::Files);
   178     tmpdir.setFilter(QDir::Files);
   179     Graves.append(tmpdir.entryList(QStringList("*.png")).replaceInStrings(QRegExp("^(.*)\\.png"), "\\1"));
   179     Graves.append(tmpdir.entryList(QStringList("*.png")).replaceInStrings(QRegExp("^(.*)\\.png"), "\\1"));
   180 
   180 
   181 	if(Graves.size()==0)
   181     if(Graves.size()==0)
   182 	{
   182     {
   183 		//do some serious error handling
   183         //do some serious error handling
   184 		return "Error";
   184         return "Error";
   185 	}
   185     }
   186 
   186 
   187 	//pick a random grave
   187     //pick a random grave
   188 	return Graves[rand()%(Graves.size())];
   188     return Graves[rand()%(Graves.size())];
   189 }
   189 }
   190 
   190 
   191 QString HWNamegen::GetRandomFort()
   191 QString HWNamegen::GetRandomFort()
   192 {
   192 {
   193 	QStringList Forts;
   193     QStringList Forts;
   194 
   194 
   195 	//list all available Forts
   195     //list all available Forts
   196 	QDir tmpdir;
   196     QDir tmpdir;
   197     tmpdir.cd(datadir->absolutePath());
   197     tmpdir.cd(datadir->absolutePath());
   198     tmpdir.cd("Forts");
   198     tmpdir.cd("Forts");
   199     tmpdir.setFilter(QDir::Files);
   199     tmpdir.setFilter(QDir::Files);
   200     Forts.append(tmpdir.entryList(QStringList("*L.png")).replaceInStrings(QRegExp("^(.*)L\\.png"), "\\1"));
   200     Forts.append(tmpdir.entryList(QStringList("*L.png")).replaceInStrings(QRegExp("^(.*)L\\.png"), "\\1"));
   201 
   201 
   202 	if(Forts.size()==0)
   202     if(Forts.size()==0)
   203 	{
   203     {
   204 		//do some serious error handling
   204         //do some serious error handling
   205 		return "Error";
   205         return "Error";
   206 	}
   206     }
   207 	
   207 
   208 	//pick a random fort
   208     //pick a random fort
   209 	return Forts[rand()%(Forts.size())];
   209     return Forts[rand()%(Forts.size())];
   210 }
   210 }