QTfrontend/game.cpp
changeset 8346 3443e0de2c9d
parent 8325 ecd51650d5d8
child 8350 14b938faec69
equal deleted inserted replaced
8344:3d18f7f71d65 8346:3443e0de2c9d
    27 #include "hwconsts.h"
    27 #include "hwconsts.h"
    28 #include "gameuiconfig.h"
    28 #include "gameuiconfig.h"
    29 #include "gamecfgwidget.h"
    29 #include "gamecfgwidget.h"
    30 #include "teamselect.h"
    30 #include "teamselect.h"
    31 #include "proto.h"
    31 #include "proto.h"
       
    32 #include "binds.h"
    32 #include "campaign.h"
    33 #include "campaign.h"
    33 
    34 
    34 #include <QTextStream>
    35 #include <QTextStream>
    35 #include "ThemeModel.h"
    36 #include "ThemeModel.h"
    36 
    37 
    71                 emit HaveRecord(rtNeither, demo);
    72                 emit HaveRecord(rtNeither, demo);
    72     }
    73     }
    73     SetGameState(gsStopped);
    74     SetGameState(gsStopped);
    74 }
    75 }
    75 
    76 
       
    77 void HWGame::addKeyBindings(QByteArray * buf)
       
    78 {
       
    79     for(int i = 0; i < BINDS_NUMBER; i++)
       
    80     {
       
    81         QString value = config->value(QString("Binds/%1").arg(cbinds[i].action), cbinds[i].strbind).toString();
       
    82         if (value.isEmpty() || value == "default") continue;
       
    83         
       
    84         QString bind = QString("edbind " + value + " " + cbinds[i].action);
       
    85         HWProto::addStringToBuffer(*buf, bind);
       
    86     }
       
    87 }
       
    88 
    76 void HWGame::commonConfig()
    89 void HWGame::commonConfig()
    77 {
    90 {
    78     QByteArray buf;
    91     QByteArray buf;
    79     QString gt;
    92     QString gt;
    80     switch (gameType)
    93     switch (gameType)
    87             break;
   100             break;
    88         default:
   101         default:
    89             gt = "TL";
   102             gt = "TL";
    90     }
   103     }
    91     HWProto::addStringToBuffer(buf, gt);
   104     HWProto::addStringToBuffer(buf, gt);
       
   105 
       
   106     addKeyBindings(&buf);
    92 
   107 
    93     buf += gamecfg->getFullConfig();
   108     buf += gamecfg->getFullConfig();
    94 
   109 
    95     if (m_pTeamSelWidget)
   110     if (m_pTeamSelWidget)
    96     {
   111     {
   100             HWProto::addStringToBuffer(buf, QString("eammprob %1").arg(ammostr.mid(cAmmoNumber, cAmmoNumber)));
   115             HWProto::addStringToBuffer(buf, QString("eammprob %1").arg(ammostr.mid(cAmmoNumber, cAmmoNumber)));
   101             HWProto::addStringToBuffer(buf, QString("eammdelay %1").arg(ammostr.mid(2 * cAmmoNumber, cAmmoNumber)));
   116             HWProto::addStringToBuffer(buf, QString("eammdelay %1").arg(ammostr.mid(2 * cAmmoNumber, cAmmoNumber)));
   102             HWProto::addStringToBuffer(buf, QString("eammreinf %1").arg(ammostr.mid(3 * cAmmoNumber, cAmmoNumber)));
   117             HWProto::addStringToBuffer(buf, QString("eammreinf %1").arg(ammostr.mid(3 * cAmmoNumber, cAmmoNumber)));
   103             if(gamecfg->schemeData(15).toBool() || !gamecfg->schemeData(21).toBool()) HWProto::addStringToBuffer(buf, QString("eammstore"));
   118             if(gamecfg->schemeData(15).toBool() || !gamecfg->schemeData(21).toBool()) HWProto::addStringToBuffer(buf, QString("eammstore"));
   104             HWProto::addStringListToBuffer(buf,
   119             HWProto::addStringListToBuffer(buf,
   105                                            team.teamGameConfig(gamecfg->getInitHealth()));
   120                                            team.teamGameConfig(gamecfg->getInitHealth(), config));
   106             ;
   121             ;
   107         }
   122         }
   108     }
   123     }
       
   124     
   109     RawSendIPC(buf);
   125     RawSendIPC(buf);
   110 }
   126 }
   111 
   127 
   112 void HWGame::SendConfig()
   128 void HWGame::SendConfig()
   113 {
   129 {
   116 
   132 
   117 void HWGame::SendQuickConfig()
   133 void HWGame::SendQuickConfig()
   118 {
   134 {
   119     QByteArray teamscfg;
   135     QByteArray teamscfg;
   120     ThemeModel * themeModel = DataManager::instance().themeModel();
   136     ThemeModel * themeModel = DataManager::instance().themeModel();
       
   137 
       
   138     addKeyBindings(&teamscfg);
   121 
   139 
   122     HWProto::addStringToBuffer(teamscfg, "TL");
   140     HWProto::addStringToBuffer(teamscfg, "TL");
   123     HWProto::addStringToBuffer(teamscfg, QString("etheme %1")
   141     HWProto::addStringToBuffer(teamscfg, QString("etheme %1")
   124                                .arg((themeModel->rowCount() > 0) ? themeModel->index(rand() % themeModel->rowCount()).data().toString() : "steel"));
   142                                .arg((themeModel->rowCount() > 0) ? themeModel->index(rand() % themeModel->rowCount()).data().toString() : "steel"));
   125     HWProto::addStringToBuffer(teamscfg, "eseed " + QUuid::createUuid().toString());
   143     HWProto::addStringToBuffer(teamscfg, "eseed " + QUuid::createUuid().toString());
   130     team1.setDifficulty(0);
   148     team1.setDifficulty(0);
   131     team1.setColor(0);
   149     team1.setColor(0);
   132     team1.setNumHedgehogs(4);
   150     team1.setNumHedgehogs(4);
   133     HWNamegen::teamRandomNames(team1,true);
   151     HWNamegen::teamRandomNames(team1,true);
   134     HWProto::addStringListToBuffer(teamscfg,
   152     HWProto::addStringListToBuffer(teamscfg,
   135                                    team1.teamGameConfig(100));
   153                                    team1.teamGameConfig(100, config));
   136 
   154 
   137     HWTeam team2;
   155     HWTeam team2;
   138     team2.setDifficulty(4);
   156     team2.setDifficulty(4);
   139     team2.setColor(1);
   157     team2.setColor(1);
   140     team2.setNumHedgehogs(4);
   158     team2.setNumHedgehogs(4);
   141     do
   159     do
   142         HWNamegen::teamRandomNames(team2,true);
   160         HWNamegen::teamRandomNames(team2,true);
   143     while(!team2.name().compare(team1.name()) || !team2.hedgehog(0).Hat.compare(team1.hedgehog(0).Hat));
   161     while(!team2.name().compare(team1.name()) || !team2.hedgehog(0).Hat.compare(team1.hedgehog(0).Hat));
   144     HWProto::addStringListToBuffer(teamscfg,
   162     HWProto::addStringListToBuffer(teamscfg,
   145                                    team2.teamGameConfig(100));
   163                                    team2.teamGameConfig(100, config));
   146 
   164 
   147     HWProto::addStringToBuffer(teamscfg, QString("eammloadt %1").arg(cDefaultAmmoStore->mid(0, cAmmoNumber)));
   165     HWProto::addStringToBuffer(teamscfg, QString("eammloadt %1").arg(cDefaultAmmoStore->mid(0, cAmmoNumber)));
   148     HWProto::addStringToBuffer(teamscfg, QString("eammprob %1").arg(cDefaultAmmoStore->mid(cAmmoNumber, cAmmoNumber)));
   166     HWProto::addStringToBuffer(teamscfg, QString("eammprob %1").arg(cDefaultAmmoStore->mid(cAmmoNumber, cAmmoNumber)));
   149     HWProto::addStringToBuffer(teamscfg, QString("eammdelay %1").arg(cDefaultAmmoStore->mid(2 * cAmmoNumber, cAmmoNumber)));
   167     HWProto::addStringToBuffer(teamscfg, QString("eammdelay %1").arg(cDefaultAmmoStore->mid(2 * cAmmoNumber, cAmmoNumber)));
   150     HWProto::addStringToBuffer(teamscfg, QString("eammreinf %1").arg(cDefaultAmmoStore->mid(3 * cAmmoNumber, cAmmoNumber)));
   168     HWProto::addStringToBuffer(teamscfg, QString("eammreinf %1").arg(cDefaultAmmoStore->mid(3 * cAmmoNumber, cAmmoNumber)));
   151     HWProto::addStringToBuffer(teamscfg, QString("eammstore"));
   169     HWProto::addStringToBuffer(teamscfg, QString("eammstore"));
   152     HWProto::addStringToBuffer(teamscfg, QString("eammstore"));
   170     HWProto::addStringToBuffer(teamscfg, QString("eammstore"));
       
   171     
   153     RawSendIPC(teamscfg);
   172     RawSendIPC(teamscfg);
   154 }
   173 }
   155 
   174 
   156 void HWGame::SendTrainingConfig()
   175 void HWGame::SendTrainingConfig()
   157 {
   176 {
   158     QByteArray traincfg;
   177     QByteArray traincfg;
   159     HWProto::addStringToBuffer(traincfg, "TL");
   178     HWProto::addStringToBuffer(traincfg, "TL");
   160     HWProto::addStringToBuffer(traincfg, "eseed " + QUuid::createUuid().toString());
   179     HWProto::addStringToBuffer(traincfg, "eseed " + QUuid::createUuid().toString());
   161     HWProto::addStringToBuffer(traincfg, "escript " + training);
   180     HWProto::addStringToBuffer(traincfg, "escript " + training);
   162 
   181 
       
   182     addKeyBindings(&traincfg);
       
   183 
   163     RawSendIPC(traincfg);
   184     RawSendIPC(traincfg);
   164 }
   185 }
   165 
   186 
   166 void HWGame::SendCampaignConfig()
   187 void HWGame::SendCampaignConfig()
   167 {
   188 {
   168     QByteArray campaigncfg;
   189     QByteArray campaigncfg;
   169     HWProto::addStringToBuffer(campaigncfg, "TL");
   190     HWProto::addStringToBuffer(campaigncfg, "TL");
   170     HWProto::addStringToBuffer(campaigncfg, "eseed " + QUuid::createUuid().toString());
   191     HWProto::addStringToBuffer(campaigncfg, "eseed " + QUuid::createUuid().toString());
   171 
   192 
   172     HWProto::addStringToBuffer(campaigncfg, "escript " + campaignScript);
   193     HWProto::addStringToBuffer(campaigncfg, "escript " + campaignScript);
       
   194 
       
   195     addKeyBindings(&campaigncfg);
   173 
   196 
   174     RawSendIPC(campaigncfg);
   197     RawSendIPC(campaigncfg);
   175 }
   198 }
   176 
   199 
   177 void HWGame::SendNetConfig()
   200 void HWGame::SendNetConfig()