QTfrontend/team.cpp
branchhedgeroid
changeset 6224 42b256eca362
parent 6223 cc3eb9b7230f
child 6225 505643d4c23d
equal deleted inserted replaced
6055:88cfcd9161d3 6224:42b256eca362
    23 #include <QCryptographicHash>
    23 #include <QCryptographicHash>
    24 #include <QSettings>
    24 #include <QSettings>
    25 
    25 
    26 #include "team.h"
    26 #include "team.h"
    27 #include "hwform.h"
    27 #include "hwform.h"
    28 #include "pageeditteam.h"
       
    29 #include "hats.h"
    28 #include "hats.h"
    30 
    29 
    31 HWTeam::HWTeam(const QString & teamname) :
    30 HWTeam::HWTeam(const QString & teamname) :
    32     m_difficulty(0),
    31 	QObject(0)
    33     m_numHedgehogs(4),
    32 	, m_difficulty(0)
    34     m_isNetTeam(false)
    33 	, m_numHedgehogs(4)
       
    34 	, m_isNetTeam(false)
    35 {
    35 {
    36     m_name = teamname;
    36     m_name = teamname;
    37     OldTeamName = m_name;
    37     OldTeamName = m_name;
    38     for (int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
    38     for (int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
    39     {
    39     {
    44     m_fort = "Plane";
    44     m_fort = "Plane";
    45     m_voicepack = "Default";
    45     m_voicepack = "Default";
    46     m_flag = "hedgewars";
    46     m_flag = "hedgewars";
    47     for(int i = 0; i < BINDS_NUMBER; i++)
    47     for(int i = 0; i < BINDS_NUMBER; i++)
    48     {
    48     {
    49         binds[i].action = cbinds[i].action;
    49         m_binds[i].action = cbinds[i].action;
    50         binds[i].strbind = cbinds[i].strbind;
    50         m_binds[i].strbind = cbinds[i].strbind;
    51     }
    51     }
    52     m_rounds = 0;
    52     m_rounds = 0;
    53     m_wins = 0;
    53     m_wins = 0;
    54     m_campaignProgress = 0;
    54     m_campaignProgress = 0;
    55 }
    55 }
    56 
    56 
    57 HWTeam::HWTeam(const QStringList& strLst) :
    57 HWTeam::HWTeam(const QStringList& strLst) :
    58   m_numHedgehogs(4),
    58 	QObject(0)
    59   m_isNetTeam(true)
    59 	, m_numHedgehogs(4)
       
    60 	, m_isNetTeam(true)
    60 {
    61 {
    61     // net teams are configured from QStringList
    62     // net teams are configured from QStringList
    62     if(strLst.size() != 23) throw HWTeamConstructException();
    63     if(strLst.size() != 23) throw HWTeamConstructException();
    63     m_name = strLst[0];
    64     m_name = strLst[0];
    64     m_grave = strLst[1];
    65     m_grave = strLst[1];
    79     m_wins = 0;
    80     m_wins = 0;
    80     m_campaignProgress = 0;
    81     m_campaignProgress = 0;
    81 }
    82 }
    82 
    83 
    83 HWTeam::HWTeam() :
    84 HWTeam::HWTeam() :
    84   m_difficulty(0),
    85 	QObject(0)
    85   m_numHedgehogs(4),
    86   , m_difficulty(0)
    86   m_isNetTeam(false)
    87   , m_numHedgehogs(4)
       
    88   , m_isNetTeam(false)
    87 {
    89 {
    88     m_name = QString("Team");
    90     m_name = QString("Team");
    89     for (int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
    91     for (int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
    90     {
    92     {
    91         m_hedgehogs[i].Name.sprintf("hedgehog %d", i);
    93         m_hedgehogs[i].Name.sprintf("hedgehog %d", i);
    97     m_voicepack = "Default";
    99     m_voicepack = "Default";
    98     m_flag = "hedgewars";
   100     m_flag = "hedgewars";
    99 
   101 
   100     for(int i = 0; i < BINDS_NUMBER; i++)
   102     for(int i = 0; i < BINDS_NUMBER; i++)
   101     {
   103     {
   102         binds[i].action = cbinds[i].action;
   104         m_binds[i].action = cbinds[i].action;
   103         binds[i].strbind = cbinds[i].strbind;
   105         m_binds[i].strbind = cbinds[i].strbind;
   104     }
   106     }
   105     m_rounds = 0;
   107     m_rounds = 0;
   106     m_wins = 0;
   108     m_wins = 0;
   107     m_campaignProgress = 0;
   109     m_campaignProgress = 0;
   108 }
   110 }
   109 
   111 
       
   112 HWTeam::HWTeam(const HWTeam & other) :
       
   113 		QObject(0)
       
   114 		, OldTeamName(other.OldTeamName)
       
   115 		, m_name(other.m_name)
       
   116 		, m_grave(other.m_grave)
       
   117 		, m_fort(other.m_fort)
       
   118 		, m_flag(other.m_flag)
       
   119 		, m_voicepack(other.m_voicepack)
       
   120 		, m_hedgehogs(other.m_hedgehogs)
       
   121 		, m_difficulty(other.m_difficulty)
       
   122 		, m_binds(other.m_binds)
       
   123 		, m_numHedgehogs(other.m_numHedgehogs)
       
   124 		, m_color(other.m_color)
       
   125 		, m_isNetTeam(other.m_isNetTeam)
       
   126 		, m_owner(other.m_owner)
       
   127 		, m_campaignProgress(other.m_campaignProgress)
       
   128 		, m_rounds(other.m_rounds)
       
   129 		, m_wins(other.m_wins)
       
   130 //	  , AchievementProgress(other.AchievementProgress)
       
   131 {
       
   132 
       
   133 }
       
   134 
       
   135 HWTeam & HWTeam::operator = (const HWTeam & other)
       
   136 {
       
   137 	if(this != &other)
       
   138 	{
       
   139 		OldTeamName = other.OldTeamName;
       
   140 		m_name = other.m_name;
       
   141 		m_grave = other.m_grave;
       
   142 		m_fort = other.m_fort;
       
   143 		m_flag = other.m_flag;
       
   144 		m_voicepack = other.m_voicepack;
       
   145 //		m_hedgehogs = other.m_hedgehogs;
       
   146 		m_difficulty = other.m_difficulty;
       
   147 //		m_binds = other.m_binds;
       
   148 		m_numHedgehogs = other.m_numHedgehogs;
       
   149 		m_color = other.m_color;
       
   150 		m_isNetTeam = other.m_isNetTeam;
       
   151 		m_owner = other.m_owner;
       
   152 		m_campaignProgress = other.m_campaignProgress;
       
   153 		m_rounds = other.m_rounds;
       
   154 		m_wins = other.m_wins;
       
   155 	}
       
   156 
       
   157 	return *this;
       
   158 }
   110 
   159 
   111 bool HWTeam::loadFromFile()
   160 bool HWTeam::loadFromFile()
   112 {
   161 {
   113     QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + m_name + ".hwt", QSettings::IniFormat, 0);
   162     QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + m_name + ".hwt", QSettings::IniFormat, 0);
   114     teamfile.setIniCodec("UTF-8");
   163     teamfile.setIniCodec("UTF-8");
   130         m_hedgehogs[i].Kills = teamfile.value(hh + "Kills", 0).toInt();
   179         m_hedgehogs[i].Kills = teamfile.value(hh + "Kills", 0).toInt();
   131         m_hedgehogs[i].Deaths = teamfile.value(hh + "Deaths", 0).toInt();
   180         m_hedgehogs[i].Deaths = teamfile.value(hh + "Deaths", 0).toInt();
   132         m_hedgehogs[i].Suicides = teamfile.value(hh + "Suicides", 0).toInt();
   181         m_hedgehogs[i].Suicides = teamfile.value(hh + "Suicides", 0).toInt();
   133     }
   182     }
   134     for(int i = 0; i < BINDS_NUMBER; i++)
   183     for(int i = 0; i < BINDS_NUMBER; i++)
   135         binds[i].strbind = teamfile.value(QString("Binds/%1").arg(binds[i].action), cbinds[i].strbind).toString();
   184         m_binds[i].strbind = teamfile.value(QString("Binds/%1").arg(m_binds[i].action), cbinds[i].strbind).toString();
   136     for(int i = 0; i < MAX_ACHIEVEMENTS; i++)
   185     for(int i = 0; i < MAX_ACHIEVEMENTS; i++)
   137         if(achievements[i][0][0])
   186         if(achievements[i][0][0])
   138             AchievementProgress[i] = teamfile.value(QString("Achievements/%1").arg(achievements[i][0]), 0).toUInt();
   187             AchievementProgress[i] = teamfile.value(QString("Achievements/%1").arg(achievements[i][0]), 0).toUInt();
   139         else
   188         else
   140             break;
   189             break;
   184         teamfile.setValue(hh + "Kills", m_hedgehogs[i].Kills);
   233         teamfile.setValue(hh + "Kills", m_hedgehogs[i].Kills);
   185         teamfile.setValue(hh + "Deaths", m_hedgehogs[i].Deaths);
   234         teamfile.setValue(hh + "Deaths", m_hedgehogs[i].Deaths);
   186         teamfile.setValue(hh + "Suicides", m_hedgehogs[i].Suicides);
   235         teamfile.setValue(hh + "Suicides", m_hedgehogs[i].Suicides);
   187     }
   236     }
   188     for(int i = 0; i < BINDS_NUMBER; i++)
   237     for(int i = 0; i < BINDS_NUMBER; i++)
   189         teamfile.setValue(QString("Binds/%1").arg(binds[i].action), binds[i].strbind);
   238         teamfile.setValue(QString("Binds/%1").arg(m_binds[i].action), m_binds[i].strbind);
   190     for(int i = 0; i < MAX_ACHIEVEMENTS; i++)
   239     for(int i = 0; i < MAX_ACHIEVEMENTS; i++)
   191         if(achievements[i][0][0])
   240         if(achievements[i][0][0])
   192             teamfile.setValue(QString("Achievements/%1").arg(achievements[i][0]), AchievementProgress[i]);
   241             teamfile.setValue(QString("Achievements/%1").arg(achievements[i][0]), AchievementProgress[i]);
   193         else
   242         else
   194             break;
   243             break;
   195     return true;
   244     return true;
   196 }
   245 }
   197 
   246 
   198 void HWTeam::SetToPage(HWForm * hwform)
       
   199 {
       
   200     hwform->ui.pageEditTeam->TeamNameEdit->setText(m_name);
       
   201     hwform->ui.pageEditTeam->CBTeamLvl->setCurrentIndex(m_difficulty);
       
   202     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
       
   203     {
       
   204          hwform->ui.pageEditTeam->HHNameEdit[i]->setText(m_hedgehogs[i].Name);
       
   205          if (m_hedgehogs[i].Hat.startsWith("Reserved"))
       
   206             hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData("Reserved "+m_hedgehogs[i].Hat.remove(0,40), Qt::DisplayRole));
       
   207          else
       
   208             hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData(m_hedgehogs[i].Hat, Qt::DisplayRole));
       
   209     }
       
   210     hwform->ui.pageEditTeam->CBGrave->setCurrentIndex(hwform->ui.pageEditTeam->CBGrave->findText(m_grave));
       
   211     hwform->ui.pageEditTeam->CBFlag->setCurrentIndex(hwform->ui.pageEditTeam->CBFlag->findData(m_flag));
       
   212 
       
   213     hwform->ui.pageEditTeam->CBFort->setCurrentIndex(hwform->ui.pageEditTeam->CBFort->findText(m_fort));
       
   214     hwform->ui.pageEditTeam->CBVoicepack->setCurrentIndex(hwform->ui.pageEditTeam->CBVoicepack->findText(m_voicepack));
       
   215     //hwform->ui.pageEditTeam->CBFort_activated(Fort);
       
   216 
       
   217     for(int i = 0; i < BINDS_NUMBER; i++)
       
   218     {
       
   219         hwform->ui.pageEditTeam->CBBind[i]->setCurrentIndex(hwform->ui.pageEditTeam->CBBind[i]->findData(binds[i].strbind));
       
   220     }
       
   221 }
       
   222 
       
   223 void HWTeam::GetFromPage(HWForm * hwform)
       
   224 {
       
   225     m_name  = hwform->ui.pageEditTeam->TeamNameEdit->text();
       
   226     m_difficulty = hwform->ui.pageEditTeam->CBTeamLvl->currentIndex();
       
   227     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
       
   228     {
       
   229         m_hedgehogs[i].Name = hwform->ui.pageEditTeam->HHNameEdit[i]->text();
       
   230         if (hwform->ui.pageEditTeam->HHHats[i]->currentText().startsWith("Reserved"))
       
   231             m_hedgehogs[i].Hat = "Reserved"+playerHash+hwform->ui.pageEditTeam->HHHats[i]->currentText().remove(0,9);
       
   232         else
       
   233             m_hedgehogs[i].Hat = hwform->ui.pageEditTeam->HHHats[i]->currentText();
       
   234     }
       
   235 
       
   236     m_grave = hwform->ui.pageEditTeam->CBGrave->currentText();
       
   237     m_fort = hwform->ui.pageEditTeam->CBFort->currentText();
       
   238     m_voicepack = hwform->ui.pageEditTeam->CBVoicepack->currentText();
       
   239     m_flag = hwform->ui.pageEditTeam->CBFlag->itemData(hwform->ui.pageEditTeam->CBFlag->currentIndex()).toString();
       
   240     for(int i = 0; i < BINDS_NUMBER; i++)
       
   241     {
       
   242         binds[i].strbind = hwform->ui.pageEditTeam->CBBind[i]->itemData(hwform->ui.pageEditTeam->CBBind[i]->currentIndex()).toString();
       
   243     }
       
   244 }
       
   245 
       
   246 QStringList HWTeam::teamGameConfig(quint32 InitHealth) const
   247 QStringList HWTeam::teamGameConfig(quint32 InitHealth) const
   247 {
   248 {
   248     QStringList sl;
   249     QStringList sl;
   249     if (m_isNetTeam)
   250     if (m_isNetTeam)
   250     {
   251     {
   258     sl.push_back(QString("evoicepack " + m_voicepack));
   259     sl.push_back(QString("evoicepack " + m_voicepack));
   259     sl.push_back(QString("eflag " + m_flag));
   260     sl.push_back(QString("eflag " + m_flag));
   260 
   261 
   261     if (!m_isNetTeam)
   262     if (!m_isNetTeam)
   262         for(int i = 0; i < BINDS_NUMBER; i++)
   263         for(int i = 0; i < BINDS_NUMBER; i++)
   263             if(!binds[i].strbind.isEmpty())
   264             if(!m_binds[i].strbind.isEmpty())
   264                 sl.push_back(QString("ebind " + binds[i].strbind + " " + binds[i].action));
   265                 sl.push_back(QString("ebind " + m_binds[i].strbind + " " + m_binds[i].action));
   265 
   266 
   266     for (int t = 0; t < m_numHedgehogs; t++)
   267     for (int t = 0; t < m_numHedgehogs; t++)
   267     {
   268     {
   268       sl.push_back(QString("eaddhh %1 %2 %3")
   269       sl.push_back(QString("eaddhh %1 %2 %3")
   269                .arg(QString::number(m_difficulty),
   270                .arg(QString::number(m_difficulty),
   297 QString HWTeam::name() const { return m_name; }
   298 QString HWTeam::name() const { return m_name; }
   298    void HWTeam::setName(const QString & name) { m_name = name; }
   299    void HWTeam::setName(const QString & name) { m_name = name; }
   299 
   300 
   300 // single hedgehog
   301 // single hedgehog
   301 const HWHog & HWTeam::hedgehog(unsigned int idx) const { return m_hedgehogs[idx]; }
   302 const HWHog & HWTeam::hedgehog(unsigned int idx) const { return m_hedgehogs[idx]; }
   302          void HWTeam::setHedgehog(unsigned int idx, const HWHog & hh) { m_hedgehogs[idx] = hh; }
   303          void HWTeam::setHedgehog(unsigned int idx, HWHog hh) { m_hedgehogs[idx] = hh; }
   303 
   304 
   304 // owner
   305 // owner
   305 QString HWTeam::owner() const { return m_owner; }
   306 QString HWTeam::owner() const { return m_owner; }
   306 
   307 
   307 
   308 
   313 // color
   314 // color
   314 QColor HWTeam::color() const { return m_color; }
   315 QColor HWTeam::color() const { return m_color; }
   315   void HWTeam::setColor(const QColor & color) { m_color = color; }
   316   void HWTeam::setColor(const QColor & color) { m_color = color; }
   316 
   317 
   317 
   318 
       
   319 // binds
       
   320 QString HWTeam::keyBind(unsigned int idx) const { return m_binds[idx].strbind; }
       
   321    void HWTeam::bindKey(unsigned int idx, const QString & key) { m_binds[idx].strbind = key; }
   318 
   322 
   319 // flag
   323 // flag
   320 void    HWTeam::setFlag(const QString & flag) { m_flag = flag; }
   324 void    HWTeam::setFlag(const QString & flag) { m_flag = flag; }
   321 QString HWTeam::flag() const { return m_flag; }
   325 QString HWTeam::flag() const { return m_flag; }
   322 
   326