QTfrontend/team.cpp
changeset 1840 4747f0232b88
parent 1683 af34da5726aa
child 1907 a104432e8301
equal deleted inserted replaced
1839:5dd4cb7fd7e5 1840:4747f0232b88
    31 HWTeam::HWTeam(const QString & teamname) :
    31 HWTeam::HWTeam(const QString & teamname) :
    32 	difficulty(0),
    32 	difficulty(0),
    33 	numHedgehogs(4),
    33 	numHedgehogs(4),
    34 	m_isNetTeam(false)
    34 	m_isNetTeam(false)
    35 {
    35 {
       
    36 	TypesLoad();
       
    37 
    36 	TeamName = teamname;
    38 	TeamName = teamname;
    37 	OldTeamName = TeamName;
    39 	OldTeamName = TeamName;
    38 	for (int i = 0; i < 8; i++)
    40 	for (int i = 0; i < 8; i++)
    39 	{
    41 	{
    40 		HHName[i].sprintf("hedgehog %d", i);
    42 		HHName[i].sprintf("hedgehog %d", i);
    52 
    54 
    53 HWTeam::HWTeam(const QStringList& strLst) :
    55 HWTeam::HWTeam(const QStringList& strLst) :
    54   numHedgehogs(4),
    56   numHedgehogs(4),
    55   m_isNetTeam(true)
    57   m_isNetTeam(true)
    56 {
    58 {
       
    59 	TypesLoad();
       
    60 
    57 	// net teams are configured from QStringList
    61 	// net teams are configured from QStringList
    58 	if(strLst.size() != 22) throw HWTeamConstructException();
    62 	if(strLst.size() != 22) throw HWTeamConstructException();
    59 	TeamName = strLst[0];
    63 	TeamName = strLst[0];
    60 	Grave = strLst[1];
    64 	Grave = strLst[1];
    61 	Fort = strLst[2];
    65 	Fort = strLst[2];
    72 HWTeam::HWTeam(quint8 num) :
    76 HWTeam::HWTeam(quint8 num) :
    73   difficulty(0),
    77   difficulty(0),
    74   numHedgehogs(4),
    78   numHedgehogs(4),
    75   m_isNetTeam(false)
    79   m_isNetTeam(false)
    76 {
    80 {
       
    81 	TypesLoad();
       
    82 
    77 	num %= PREDEFTEAMS_COUNT;
    83 	num %= PREDEFTEAMS_COUNT;
       
    84 /*
       
    85 	//This is now generated by TeamRandomNames(TRUE);
    78 	TeamName = QApplication::translate("teams", pteams[num].TeamName);
    86 	TeamName = QApplication::translate("teams", pteams[num].TeamName);
    79 	HHName[0] = QApplication::translate("teams", pteams[num].hh0name);
    87 	HHName[0] = QApplication::translate("teams", pteams[num].hh0name);
    80 	HHName[1] = QApplication::translate("teams", pteams[num].hh1name);
    88 	HHName[1] = QApplication::translate("teams", pteams[num].hh1name);
    81 	HHName[2] = QApplication::translate("teams", pteams[num].hh2name);
    89 	HHName[2] = QApplication::translate("teams", pteams[num].hh2name);
    82 	HHName[3] = QApplication::translate("teams", pteams[num].hh3name);
    90 	HHName[3] = QApplication::translate("teams", pteams[num].hh3name);
    90 	HHHat[3] = pteams[num].hh3hat;
    98 	HHHat[3] = pteams[num].hh3hat;
    91 	HHHat[4] = pteams[num].hh4hat;
    99 	HHHat[4] = pteams[num].hh4hat;
    92 	HHHat[5] = pteams[num].hh5hat;
   100 	HHHat[5] = pteams[num].hh5hat;
    93 	HHHat[6] = pteams[num].hh6hat;
   101 	HHHat[6] = pteams[num].hh6hat;
    94 	HHHat[7] = pteams[num].hh7hat;
   102 	HHHat[7] = pteams[num].hh7hat;
    95 	
   103 */	
       
   104 
       
   105 	TeamName = QString("Team");
       
   106 	for (int i = 0; i < 8; i++)
       
   107 	{
       
   108 		HHName[i].sprintf("hedgehog %d", i);
       
   109 		HHHat[i] = "NoHat";
       
   110 	}
       
   111 
    96 	Grave = pteams[num].Grave;
   112 	Grave = pteams[num].Grave;
    97 	Fort = pteams[num].Fort;
   113 	Fort = pteams[num].Fort;
    98 	for(int i = 0; i < BINDS_NUMBER; i++)
   114 	for(int i = 0; i < BINDS_NUMBER; i++)
    99 	{
   115 	{
   100 		binds[i].action = cbinds[i].action;
   116 		binds[i].action = cbinds[i].action;
   101 		binds[i].strbind = cbinds[i].strbind;
   117 		binds[i].strbind = cbinds[i].strbind;
   102 	}
   118 	}
       
   119 
       
   120 	TeamRandomNames(TRUE);
   103 }
   121 }
   104 
   122 
   105 
   123 
   106 bool HWTeam::LoadFromFile()
   124 bool HWTeam::LoadFromFile()
   107 {
   125 {
   274 		       .arg(HHHat[t]));
   292 		       .arg(HHHat[t]));
   275 	}
   293 	}
   276 	return sl;
   294 	return sl;
   277 }
   295 }
   278 
   296 
       
   297 void HWTeam::RandomNameByHat(const int &i)
       
   298 {
       
   299 
       
   300 
       
   301 
       
   302 	QStringList Dictionaries;
       
   303 	HatCfgLoad(HHHat[i],Dictionaries);
       
   304 
       
   305 
       
   306 /*
       
   307 
       
   308 "Dismissed",
       
   309 "Dragon",
       
   310 "Mindblower",
       
   311 */
       
   312 
       
   313 	QStringList Dictionary;
       
   314 	DictLoad(Dictionaries[rand()%(Dictionaries.size())],Dictionary);
       
   315 
       
   316 
       
   317 	HHName[i] = Dictionary[rand()%(Dictionary.size())];
       
   318 
       
   319 }
       
   320 
       
   321 void HWTeam::TeamRandomName(const int &i)
       
   322 {
       
   323 
       
   324 	RandomNameByHat(i);
       
   325 
       
   326 
       
   327 }
       
   328 
       
   329 void HWTeam::TeamRandomNames(bool changeteamname)
       
   330 {
       
   331 
       
   332 	if ((TypesHatnames.size() > 0) && TypesAvliable){
       
   333 
       
   334 		int kind = (rand()%(TypesHatnames.size()));
       
   335 
       
   336 		if (changeteamname){
       
   337 			if (TypesTeamnames[kind].size() > 0){
       
   338 				TeamName = TypesTeamnames[kind][rand()%(TypesTeamnames[kind].size())];
       
   339 			}
       
   340 		}
       
   341 
       
   342 		for(int i = 0; i < 8; i++)
       
   343 		{
       
   344 			if ((TypesHatnames[kind].size()) > 0){
       
   345 				HHHat[i] = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())];
       
   346 			}
       
   347 			RandomNameByHat(i);
       
   348 		}
       
   349 
       
   350 	}
       
   351 }
       
   352 
   279 bool HWTeam::isNetTeam() const
   353 bool HWTeam::isNetTeam() const
   280 {
   354 {
   281   return m_isNetTeam;
   355   return m_isNetTeam;
   282 }
   356 }
   283 
   357 
   287 }
   361 }
   288 
   362 
   289 bool HWTeam::operator<(const HWTeam& t1) const {
   363 bool HWTeam::operator<(const HWTeam& t1) const {
   290   return TeamName<t1.TeamName; // if names are equal - test if it is net team
   364   return TeamName<t1.TeamName; // if names are equal - test if it is net team
   291 }
   365 }
       
   366 
       
   367 void HWTeam::TypesLoad()
       
   368 {
       
   369 
       
   370      QFile file(QString("%1/Names/types.ini").arg(datadir->absolutePath()));
       
   371      if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
       
   372          TypesAvliable = FALSE;
       
   373 
       
   374      int counter = 0; //counter starts with 0 (teamnames mode)
       
   375      TypesTeamnames.append(QStringList());
       
   376      TypesHatnames.append(QStringList());
       
   377 
       
   378      QTextStream in(&file);
       
   379      while (!in.atEnd()) {
       
   380          QString line = in.readLine();
       
   381          if (line == QString("#####")){
       
   382              counter++; //toggle mode (teamnames || hats)
       
   383              if ((counter%2) == 0){
       
   384                  TypesTeamnames.append(QStringList());
       
   385                  TypesHatnames.append(QStringList());
       
   386              }
       
   387          } else if ((line == QString("*****")) || (line == QString("*END*"))){
       
   388              TypesAvliable = TRUE; return; // bye bye
       
   389          } else {
       
   390              if ((counter%2) == 0){ // even => teamnames mode
       
   391                  TypesTeamnames[(counter/2)].append(line);
       
   392              } else { // odd => hats mode
       
   393                  TypesHatnames[((counter-1)/2)].append(line);
       
   394              }
       
   395          }
       
   396 //         Types.append(line);
       
   397      }
       
   398          TypesAvliable = TRUE;
       
   399      return;
       
   400 }
       
   401 
       
   402 
       
   403 void HWTeam::DictLoad(const QString filename, QStringList &list)
       
   404 {
       
   405      list.clear();
       
   406 
       
   407      QFile file(QString("%1/Names/%2.txt").arg(datadir->absolutePath()).arg(filename));
       
   408      if (file.open(QIODevice::ReadOnly | QIODevice::Text))
       
   409      {
       
   410 
       
   411          QTextStream in(&file);
       
   412          while (!in.atEnd()) {
       
   413              QString line = in.readLine();
       
   414              if(line != QString(""))
       
   415                  {list.append(line);}
       
   416          }
       
   417      }
       
   418 
       
   419      if (list.size()==0)
       
   420          list.append(filename);
       
   421 
       
   422 }
       
   423 
       
   424 
       
   425 void HWTeam::HatCfgLoad(const QString hatname, QStringList &list)
       
   426 {
       
   427      list.clear();
       
   428 
       
   429      QFile file(QString("%1/Names/%2.cfg").arg(datadir->absolutePath()).arg(hatname));
       
   430      if (file.open(QIODevice::ReadOnly | QIODevice::Text))
       
   431      {
       
   432 
       
   433          QTextStream in(&file);
       
   434          while (!in.atEnd()) {
       
   435              QString line = in.readLine();
       
   436              if(line != QString(""))
       
   437                  {list.append(line);}
       
   438          }
       
   439      }
       
   440 
       
   441      if (list.size()==0)
       
   442          list.append(QString("generic"));
       
   443 
       
   444 }
       
   445 
       
   446