QTfrontend/team.cpp
changeset 352 4665bfe25470
parent 348 c91b983de18f
child 353 5ec611d702a0
equal deleted inserted replaced
351:29bc9c36ad5f 352:4665bfe25470
    27 #include "hwconsts.h"
    27 #include "hwconsts.h"
    28 
    28 
    29 #include <QStringList>
    29 #include <QStringList>
    30 #include <QDebug>
    30 #include <QDebug>
    31 
    31 
    32 HWTeam::HWTeam(const QString & teamname, bool isNet) :
    32 HWTeam::HWTeam(const QString & teamname, unsigned int netID) :
    33   difficulty(0),
    33   difficulty(0),
    34   netTeam(isNet)
    34   m_netID(netID)
    35 {
    35 {
    36 	TeamName = teamname;
    36 	TeamName = teamname;
    37 	OldTeamName = TeamName;
    37 	OldTeamName = TeamName;
    38 	for (int i = 0; i < 8; i++) HHName[i].sprintf("hedgehog %d", i);
    38 	for (int i = 0; i < 8; i++) HHName[i].sprintf("hedgehog %d", i);
    39 	Grave = "Simple";
    39 	Grave = "Simple";
    43 		binds[i].action = cbinds[i].action;
    43 		binds[i].action = cbinds[i].action;
    44 		binds[i].strbind = cbinds[i].strbind;
    44 		binds[i].strbind = cbinds[i].strbind;
    45 	}
    45 	}
    46 }
    46 }
    47 
    47 
    48 HWTeam::HWTeam(const QStringList& strLst) :
    48 HWTeam::HWTeam(const QStringList& strLst)
    49   netTeam(true)
       
    50 {
    49 {
    51   // net teams are configured from QStringList
    50   // net teams are configured from QStringList
    52   if(strLst.size()<9) throw HWTeamConstructException();
    51   if(strLst.size()<10) throw HWTeamConstructException();
    53   TeamName=strLst[0];
    52   TeamName=strLst[0];
    54   for(int i = 0; i < 8; i++) HHName[i]=strLst[i+1];
    53   m_netID=strLst[1].toUInt();
       
    54   for(int i = 0; i < 8; i++) HHName[i]=strLst[i+2];
    55 }
    55 }
    56 
    56 
    57 HWTeam::HWTeam(quint8 num) :
    57 HWTeam::HWTeam(quint8 num) :
    58   difficulty(0),
    58   difficulty(0),
    59   netTeam(false)
    59   m_netID(0)
    60 {
    60 {
    61 	num %= PREDEFTEAMS_COUNT;
    61 	num %= PREDEFTEAMS_COUNT;
    62 	TeamName = QApplication::translate("teams", pteams[num].TeamName);
    62 	TeamName = QApplication::translate("teams", pteams[num].TeamName);
    63 	HHName[0] = QApplication::translate("teams", pteams[num].hh0name);
    63 	HHName[0] = QApplication::translate("teams", pteams[num].hh0name);
    64 	HHName[1] = QApplication::translate("teams", pteams[num].hh1name);
    64 	HHName[1] = QApplication::translate("teams", pteams[num].hh1name);
   205 
   205 
   206 QStringList HWTeam::TeamGameConfig(quint32 InitHealth) const
   206 QStringList HWTeam::TeamGameConfig(quint32 InitHealth) const
   207 {
   207 {
   208 	QStringList sl;
   208 	QStringList sl;
   209 	sl.push_back("eaddteam");
   209 	sl.push_back("eaddteam");
   210 	if (netTeam)
   210 	if (m_netID)
   211 		sl.push_back("erdriven");
   211 		sl.push_back("erdriven");
   212 	sl.push_back(QString("ecolor %1").arg(teamColor.rgb() & 0xffffff));
   212 	sl.push_back(QString("ecolor %1").arg(teamColor.rgb() & 0xffffff));
   213 	sl.push_back("ename team " + TeamName);
   213 	sl.push_back("ename team " + TeamName);
   214 
   214 
   215 	for (int i = 0; i < numHedgehogs; i++)
   215 	for (int i = 0; i < numHedgehogs; i++)
   216 		sl.push_back(QString("ename hh%1 ").arg(i).append(HHName[i]));
   216 		sl.push_back(QString("ename hh%1 ").arg(i).append(HHName[i]));
   217 
   217 
   218 	sl.push_back(QString("egrave " + Grave));
   218 	sl.push_back(QString("egrave " + Grave));
   219 	sl.push_back(QString("efort " + Fort));
   219 	sl.push_back(QString("efort " + Fort));
   220 
   220 
   221 	if (!netTeam)
   221 	if (!m_netID)
   222 		for(int i = 0; i < BINDS_NUMBER; i++)
   222 		for(int i = 0; i < BINDS_NUMBER; i++)
   223 			sl.push_back(QString("ebind " + binds[i].strbind + " " + binds[i].action));
   223 			sl.push_back(QString("ebind " + binds[i].strbind + " " + binds[i].action));
   224 
   224 
   225 	for (int t = 0; t < numHedgehogs; t++)
   225 	for (int t = 0; t < numHedgehogs; t++)
   226 	  sl.push_back(QString("eaddhh %1 %2")
   226 	  sl.push_back(QString("eaddhh %1 %2")
   227 		       .arg(QString::number(difficulty),
   227 		       .arg(QString::number(difficulty),
   228 			    QString::number(InitHealth)));
   228 			    QString::number(InitHealth)));
   229 	return sl;
   229 	return sl;
   230 }
   230 }
   231 
   231 
       
   232 bool HWTeam::isNetTeam() const
       
   233 {
       
   234   return m_netID!=0;
       
   235 }
       
   236 
       
   237 unsigned int HWTeam::getNetID() const
       
   238 {
       
   239   return m_netID;
       
   240 }
       
   241 
   232 bool HWTeam::operator==(const HWTeam& t1) const {
   242 bool HWTeam::operator==(const HWTeam& t1) const {
   233   return TeamName==t1.TeamName && netTeam==t1.netTeam;
   243   return TeamName==t1.TeamName && m_netID==t1.m_netID;
   234 }
   244 }
   235 
   245 
   236 bool HWTeam::operator<(const HWTeam& t1) const {
   246 bool HWTeam::operator<(const HWTeam& t1) const {
   237   return TeamName<t1.TeamName || (netTeam < t1.netTeam); // if names are equal - test if it is net team
   247   return m_netID<t1.m_netID || TeamName<t1.TeamName; // if names are equal - test if it is net team
   238 }
   248 }