QTfrontend/game.cpp
branchwebgl
changeset 9521 8054d9d775fd
parent 9197 e4e366013e9a
parent 9466 8b48c27201af
child 9950 2759212a27de
equal deleted inserted replaced
9282:92af50454cf2 9521:8054d9d775fd
    15  * along with this program; if not, write to the Free Software
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    17  */
    17  */
    18 
    18 
    19 #include <QString>
    19 #include <QString>
       
    20 #include <QCheckBox>
    20 #include <QByteArray>
    21 #include <QByteArray>
    21 #include <QUuid>
    22 #include <QUuid>
    22 #include <QColor>
    23 #include <QColor>
    23 #include <QStringListModel>
    24 #include <QStringListModel>
    24 #include <QTextStream>
    25 #include <QTextStream>
    86                 emit HaveRecord(rtNeither, demo);
    87                 emit HaveRecord(rtNeither, demo);
    87     }
    88     }
    88     SetGameState(gsStopped);
    89     SetGameState(gsStopped);
    89 }
    90 }
    90 
    91 
    91 void HWGame::addKeyBindings(QByteArray * buf)
       
    92 {
       
    93     for(int i = 0; i < BINDS_NUMBER; i++)
       
    94     {
       
    95         QString value = config->value(QString("Binds/%1").arg(cbinds[i].action), cbinds[i].strbind).toString();
       
    96         if (value.isEmpty() || value == "default") continue;
       
    97 
       
    98         QString bind = QString("edbind " + value + " " + cbinds[i].action);
       
    99         HWProto::addStringToBuffer(*buf, bind);
       
   100     }
       
   101 }
       
   102 
       
   103 void HWGame::commonConfig()
    92 void HWGame::commonConfig()
   104 {
    93 {
   105     QByteArray buf;
    94     QByteArray buf;
   106     QString gt;
    95     QString gt;
   107     switch (gameType)
    96     switch (gameType)
   114             break;
   103             break;
   115         default:
   104         default:
   116             gt = "TL";
   105             gt = "TL";
   117     }
   106     }
   118     HWProto::addStringToBuffer(buf, gt);
   107     HWProto::addStringToBuffer(buf, gt);
   119 
       
   120     addKeyBindings(&buf);
       
   121 
   108 
   122     buf += gamecfg->getFullConfig();
   109     buf += gamecfg->getFullConfig();
   123 
   110 
   124     if (m_pTeamSelWidget)
   111     if (m_pTeamSelWidget)
   125     {
   112     {
   129             HWProto::addStringToBuffer(buf, QString("eammprob %1").arg(ammostr.mid(cAmmoNumber, cAmmoNumber)));
   116             HWProto::addStringToBuffer(buf, QString("eammprob %1").arg(ammostr.mid(cAmmoNumber, cAmmoNumber)));
   130             HWProto::addStringToBuffer(buf, QString("eammdelay %1").arg(ammostr.mid(2 * cAmmoNumber, cAmmoNumber)));
   117             HWProto::addStringToBuffer(buf, QString("eammdelay %1").arg(ammostr.mid(2 * cAmmoNumber, cAmmoNumber)));
   131             HWProto::addStringToBuffer(buf, QString("eammreinf %1").arg(ammostr.mid(3 * cAmmoNumber, cAmmoNumber)));
   118             HWProto::addStringToBuffer(buf, QString("eammreinf %1").arg(ammostr.mid(3 * cAmmoNumber, cAmmoNumber)));
   132             if(gamecfg->schemeData(15).toBool() || !gamecfg->schemeData(21).toBool()) HWProto::addStringToBuffer(buf, QString("eammstore"));
   119             if(gamecfg->schemeData(15).toBool() || !gamecfg->schemeData(21).toBool()) HWProto::addStringToBuffer(buf, QString("eammstore"));
   133             HWProto::addStringListToBuffer(buf,
   120             HWProto::addStringListToBuffer(buf,
   134                                            team.teamGameConfig(gamecfg->getInitHealth(), config));
   121                                            team.teamGameConfig(gamecfg->getInitHealth()));
   135             ;
   122             ;
   136         }
   123         }
   137     }
   124     }
   138 
   125 
   139     RawSendIPC(buf);
   126     RawSendIPC(buf);
   146 
   133 
   147 void HWGame::SendQuickConfig()
   134 void HWGame::SendQuickConfig()
   148 {
   135 {
   149     QByteArray teamscfg;
   136     QByteArray teamscfg;
   150     ThemeModel * themeModel = DataManager::instance().themeModel();
   137     ThemeModel * themeModel = DataManager::instance().themeModel();
   151 
       
   152     addKeyBindings(&teamscfg);
       
   153 
   138 
   154     HWProto::addStringToBuffer(teamscfg, "TL");
   139     HWProto::addStringToBuffer(teamscfg, "TL");
   155     HWProto::addStringToBuffer(teamscfg, QString("etheme %1")
   140     HWProto::addStringToBuffer(teamscfg, QString("etheme %1")
   156                                .arg((themeModel->rowCount() > 0) ? themeModel->index(rand() % themeModel->rowCount()).data(ThemeModel::ActualNameRole).toString() : "steel"));
   141                                .arg((themeModel->rowCount() > 0) ? themeModel->index(rand() % themeModel->rowCount()).data(ThemeModel::ActualNameRole).toString() : "steel"));
   157     HWProto::addStringToBuffer(teamscfg, "eseed " + QUuid::createUuid().toString());
   142     HWProto::addStringToBuffer(teamscfg, "eseed " + QUuid::createUuid().toString());
   162     team1.setDifficulty(0);
   147     team1.setDifficulty(0);
   163     team1.setColor(0);
   148     team1.setColor(0);
   164     team1.setNumHedgehogs(4);
   149     team1.setNumHedgehogs(4);
   165     HWNamegen::teamRandomNames(team1,true);
   150     HWNamegen::teamRandomNames(team1,true);
   166     HWProto::addStringListToBuffer(teamscfg,
   151     HWProto::addStringListToBuffer(teamscfg,
   167                                    team1.teamGameConfig(100, config));
   152                                    team1.teamGameConfig(100));
   168 
   153 
   169     HWTeam team2;
   154     HWTeam team2;
   170     team2.setDifficulty(4);
   155     team2.setDifficulty(4);
   171     team2.setColor(1);
   156     team2.setColor(1);
   172     team2.setNumHedgehogs(4);
   157     team2.setNumHedgehogs(4);
   173     do
   158     do
   174         HWNamegen::teamRandomNames(team2,true);
   159         HWNamegen::teamRandomNames(team2,true);
   175     while(!team2.name().compare(team1.name()) || !team2.hedgehog(0).Hat.compare(team1.hedgehog(0).Hat));
   160     while(!team2.name().compare(team1.name()) || !team2.hedgehog(0).Hat.compare(team1.hedgehog(0).Hat));
   176     HWProto::addStringListToBuffer(teamscfg,
   161     HWProto::addStringListToBuffer(teamscfg,
   177                                    team2.teamGameConfig(100, config));
   162                                    team2.teamGameConfig(100));
   178 
   163 
   179     HWProto::addStringToBuffer(teamscfg, QString("eammloadt %1").arg(cDefaultAmmoStore->mid(0, cAmmoNumber)));
   164     HWProto::addStringToBuffer(teamscfg, QString("eammloadt %1").arg(cDefaultAmmoStore->mid(0, cAmmoNumber)));
   180     HWProto::addStringToBuffer(teamscfg, QString("eammprob %1").arg(cDefaultAmmoStore->mid(cAmmoNumber, cAmmoNumber)));
   165     HWProto::addStringToBuffer(teamscfg, QString("eammprob %1").arg(cDefaultAmmoStore->mid(cAmmoNumber, cAmmoNumber)));
   181     HWProto::addStringToBuffer(teamscfg, QString("eammdelay %1").arg(cDefaultAmmoStore->mid(2 * cAmmoNumber, cAmmoNumber)));
   166     HWProto::addStringToBuffer(teamscfg, QString("eammdelay %1").arg(cDefaultAmmoStore->mid(2 * cAmmoNumber, cAmmoNumber)));
   182     HWProto::addStringToBuffer(teamscfg, QString("eammreinf %1").arg(cDefaultAmmoStore->mid(3 * cAmmoNumber, cAmmoNumber)));
   167     HWProto::addStringToBuffer(teamscfg, QString("eammreinf %1").arg(cDefaultAmmoStore->mid(3 * cAmmoNumber, cAmmoNumber)));
   191     QByteArray traincfg;
   176     QByteArray traincfg;
   192     HWProto::addStringToBuffer(traincfg, "TL");
   177     HWProto::addStringToBuffer(traincfg, "TL");
   193     HWProto::addStringToBuffer(traincfg, "eseed " + QUuid::createUuid().toString());
   178     HWProto::addStringToBuffer(traincfg, "eseed " + QUuid::createUuid().toString());
   194     HWProto::addStringToBuffer(traincfg, "escript " + training);
   179     HWProto::addStringToBuffer(traincfg, "escript " + training);
   195 
   180 
   196     addKeyBindings(&traincfg);
       
   197 
       
   198     RawSendIPC(traincfg);
   181     RawSendIPC(traincfg);
   199 }
   182 }
   200 
   183 
   201 void HWGame::SendCampaignConfig()
   184 void HWGame::SendCampaignConfig()
   202 {
   185 {
   203     QByteArray campaigncfg;
   186     QByteArray campaigncfg;
   204     HWProto::addStringToBuffer(campaigncfg, "TL");
   187     HWProto::addStringToBuffer(campaigncfg, "TL");
   205     HWProto::addStringToBuffer(campaigncfg, "eseed " + QUuid::createUuid().toString());
   188     HWProto::addStringToBuffer(campaigncfg, "eseed " + QUuid::createUuid().toString());
   206 
   189 
   207     HWProto::addStringToBuffer(campaigncfg, "escript " + campaignScript);
   190     HWProto::addStringToBuffer(campaigncfg, "escript " + campaignScript);
   208 
       
   209     addKeyBindings(&campaigncfg);
       
   210 
   191 
   211     RawSendIPC(campaigncfg);
   192     RawSendIPC(campaigncfg);
   212 }
   193 }
   213 
   194 
   214 void HWGame::SendNetConfig()
   195 void HWGame::SendNetConfig()
   413     if (!nick.isEmpty()) {
   394     if (!nick.isEmpty()) {
   414         arguments << "--nick";
   395         arguments << "--nick";
   415         arguments << nick;
   396         arguments << nick;
   416     }
   397     }
   417 
   398 
       
   399     if (!config->Form->ui.pageOptions->CBTeamTag->isChecked())
       
   400         arguments << "--no-teamtag";
       
   401     if (!config->Form->ui.pageOptions->CBHogTag->isChecked())
       
   402         arguments << "--no-hogtag";
       
   403     if (!config->Form->ui.pageOptions->CBHealthTag->isChecked())
       
   404         arguments << "--no-healthtag";
       
   405     if (config->Form->ui.pageOptions->CBTagOpacity->isChecked())
       
   406         arguments << "--translucent-tags";
       
   407 
   418     return arguments;
   408     return arguments;
   419 }
   409 }
   420 
   410 
   421 void HWGame::PlayDemo(const QString & demofilename, bool isSave)
   411 void HWGame::PlayDemo(const QString & demofilename, bool isSave)
   422 {
   412 {