QTfrontend/team.cpp
changeset 1907 a104432e8301
parent 1840 4747f0232b88
child 2192 4763a778c033
equal deleted inserted replaced
1906:644f93d8f148 1907:a104432e8301
    21 #include <QApplication>
    21 #include <QApplication>
    22 #include <QStringList>
    22 #include <QStringList>
    23 #include <QLineEdit>
    23 #include <QLineEdit>
    24 #include "team.h"
    24 #include "team.h"
    25 #include "hwform.h"
    25 #include "hwform.h"
    26 #include "predefteams.h"
       
    27 #include "pages.h"
    26 #include "pages.h"
    28 #include "hwconsts.h"
    27 #include "hwconsts.h"
    29 #include "hats.h"
    28 #include "hats.h"
    30 
    29 
    31 HWTeam::HWTeam(const QString & teamname) :
    30 HWTeam::HWTeam(const QString & teamname) :
    32 	difficulty(0),
    31 	difficulty(0),
    33 	numHedgehogs(4),
    32 	numHedgehogs(4),
    34 	m_isNetTeam(false)
    33 	m_isNetTeam(false)
    35 {
    34 {
    36 	TypesLoad();
       
    37 
       
    38 	TeamName = teamname;
    35 	TeamName = teamname;
    39 	OldTeamName = TeamName;
    36 	OldTeamName = TeamName;
    40 	for (int i = 0; i < 8; i++)
    37 	for (int i = 0; i < 8; i++)
    41 	{
    38 	{
    42 		HHName[i].sprintf("hedgehog %d", i);
    39 		HHName[i].sprintf("hedgehog %d", i);
    54 
    51 
    55 HWTeam::HWTeam(const QStringList& strLst) :
    52 HWTeam::HWTeam(const QStringList& strLst) :
    56   numHedgehogs(4),
    53   numHedgehogs(4),
    57   m_isNetTeam(true)
    54   m_isNetTeam(true)
    58 {
    55 {
    59 	TypesLoad();
       
    60 
       
    61 	// net teams are configured from QStringList
    56 	// net teams are configured from QStringList
    62 	if(strLst.size() != 22) throw HWTeamConstructException();
    57 	if(strLst.size() != 22) throw HWTeamConstructException();
    63 	TeamName = strLst[0];
    58 	TeamName = strLst[0];
    64 	Grave = strLst[1];
    59 	Grave = strLst[1];
    65 	Fort = strLst[2];
    60 	Fort = strLst[2];
    71 		HHName[i]=strLst[i * 2 + 6];
    66 		HHName[i]=strLst[i * 2 + 6];
    72 		HHHat[i]=strLst[i * 2 + 7];
    67 		HHHat[i]=strLst[i * 2 + 7];
    73 	}
    68 	}
    74 }
    69 }
    75 
    70 
    76 HWTeam::HWTeam(quint8 num) :
    71 HWTeam::HWTeam() :
    77   difficulty(0),
    72   difficulty(0),
    78   numHedgehogs(4),
    73   numHedgehogs(4),
    79   m_isNetTeam(false)
    74   m_isNetTeam(false)
    80 {
    75 {
    81 	TypesLoad();
       
    82 
       
    83 	num %= PREDEFTEAMS_COUNT;
       
    84 /*
       
    85 	//This is now generated by TeamRandomNames(TRUE);
       
    86 	TeamName = QApplication::translate("teams", pteams[num].TeamName);
       
    87 	HHName[0] = QApplication::translate("teams", pteams[num].hh0name);
       
    88 	HHName[1] = QApplication::translate("teams", pteams[num].hh1name);
       
    89 	HHName[2] = QApplication::translate("teams", pteams[num].hh2name);
       
    90 	HHName[3] = QApplication::translate("teams", pteams[num].hh3name);
       
    91 	HHName[4] = QApplication::translate("teams", pteams[num].hh4name);
       
    92 	HHName[5] = QApplication::translate("teams", pteams[num].hh5name);
       
    93 	HHName[6] = QApplication::translate("teams", pteams[num].hh6name);
       
    94 	HHName[7] = QApplication::translate("teams", pteams[num].hh7name);
       
    95 	HHHat[0] = pteams[num].hh0hat;
       
    96 	HHHat[1] = pteams[num].hh1hat;
       
    97 	HHHat[2] = pteams[num].hh2hat;
       
    98 	HHHat[3] = pteams[num].hh3hat;
       
    99 	HHHat[4] = pteams[num].hh4hat;
       
   100 	HHHat[5] = pteams[num].hh5hat;
       
   101 	HHHat[6] = pteams[num].hh6hat;
       
   102 	HHHat[7] = pteams[num].hh7hat;
       
   103 */	
       
   104 
       
   105 	TeamName = QString("Team");
    76 	TeamName = QString("Team");
   106 	for (int i = 0; i < 8; i++)
    77 	for (int i = 0; i < 8; i++)
   107 	{
    78 	{
   108 		HHName[i].sprintf("hedgehog %d", i);
    79 		HHName[i].sprintf("hedgehog %d", i);
   109 		HHHat[i] = "NoHat";
    80 		HHHat[i] = "NoHat";
   110 	}
    81 	}
   111 
    82 
   112 	Grave = pteams[num].Grave;
    83 	Grave = QString("Simple"); // default
   113 	Fort = pteams[num].Fort;
    84 	Fort = QString("Island"); // default
       
    85 
   114 	for(int i = 0; i < BINDS_NUMBER; i++)
    86 	for(int i = 0; i < BINDS_NUMBER; i++)
   115 	{
    87 	{
   116 		binds[i].action = cbinds[i].action;
    88 		binds[i].action = cbinds[i].action;
   117 		binds[i].strbind = cbinds[i].strbind;
    89 		binds[i].strbind = cbinds[i].strbind;
   118 	}
    90 	}
   119 
       
   120 	TeamRandomNames(TRUE);
       
   121 }
    91 }
   122 
    92 
   123 
    93 
   124 bool HWTeam::LoadFromFile()
    94 bool HWTeam::LoadFromFile()
   125 {
    95 {
   292 		       .arg(HHHat[t]));
   262 		       .arg(HHHat[t]));
   293 	}
   263 	}
   294 	return sl;
   264 	return sl;
   295 }
   265 }
   296 
   266 
   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 
       
   353 bool HWTeam::isNetTeam() const
   267 bool HWTeam::isNetTeam() const
   354 {
   268 {
   355   return m_isNetTeam;
   269   return m_isNetTeam;
   356 }
   270 }
   357 
   271 
   362 
   276 
   363 bool HWTeam::operator<(const HWTeam& t1) const {
   277 bool HWTeam::operator<(const HWTeam& t1) const {
   364   return TeamName<t1.TeamName; // if names are equal - test if it is net team
   278   return TeamName<t1.TeamName; // if names are equal - test if it is net team
   365 }
   279 }
   366 
   280 
   367 void HWTeam::TypesLoad()
   281 
   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