QTfrontend/game.cpp
branchexperimental3D
changeset 4004 b1c2c2f6fc5e
parent 3696 6009d8378422
parent 3943 9835060e5c01
child 4812 f924be23ffb4
equal deleted inserted replaced
3698:793386610068 4004:b1c2c2f6fc5e
    28 #include "KB.h"
    28 #include "KB.h"
    29 #include "proto.h"
    29 #include "proto.h"
    30 
    30 
    31 #include <QTextStream>
    31 #include <QTextStream>
    32 
    32 
    33 QString training; // TODO: Cleaner solution?
    33 QString training, campaign; // TODO: Cleaner solution?
    34 
    34 
    35 HWGame::HWGame(GameUIConfig * config, GameCFGWidget * gamecfg, QString ammo, TeamSelWidget* pTeamSelWidget) :
    35 HWGame::HWGame(GameUIConfig * config, GameCFGWidget * gamecfg, QString ammo, TeamSelWidget* pTeamSelWidget) :
    36   TCPBase(true),
    36   TCPBase(true),
    37   ammostr(ammo),
    37   ammostr(ammo),
    38   m_pTeamSelWidget(pTeamSelWidget)
    38   m_pTeamSelWidget(pTeamSelWidget)
    82     if (m_pTeamSelWidget)
    82     if (m_pTeamSelWidget)
    83     {
    83     {
    84         QList<HWTeam> teams = m_pTeamSelWidget->getPlayingTeams();
    84         QList<HWTeam> teams = m_pTeamSelWidget->getPlayingTeams();
    85         for(QList<HWTeam>::iterator it = teams.begin(); it != teams.end(); ++it)
    85         for(QList<HWTeam>::iterator it = teams.begin(); it != teams.end(); ++it)
    86         {
    86         {
    87             HWProto::addStringListToBuffer(buf,
       
    88                 (*it).TeamGameConfig(gamecfg->getInitHealth()));
       
    89             HWProto::addStringToBuffer(buf, QString("eammloadt %1").arg(ammostr.mid(0, cAmmoNumber)));
    87             HWProto::addStringToBuffer(buf, QString("eammloadt %1").arg(ammostr.mid(0, cAmmoNumber)));
    90             HWProto::addStringToBuffer(buf, QString("eammprob %1").arg(ammostr.mid(cAmmoNumber, cAmmoNumber)));
    88             HWProto::addStringToBuffer(buf, QString("eammprob %1").arg(ammostr.mid(cAmmoNumber, cAmmoNumber)));
    91             HWProto::addStringToBuffer(buf, QString("eammdelay %1").arg(ammostr.mid(2 * cAmmoNumber, cAmmoNumber)));
    89             HWProto::addStringToBuffer(buf, QString("eammdelay %1").arg(ammostr.mid(2 * cAmmoNumber, cAmmoNumber)));
    92             HWProto::addStringToBuffer(buf, QString("eammreinf %1").arg(ammostr.mid(3 * cAmmoNumber, cAmmoNumber)));
    90             HWProto::addStringToBuffer(buf, QString("eammreinf %1").arg(ammostr.mid(3 * cAmmoNumber, cAmmoNumber)));
    93             HWProto::addStringToBuffer(buf, QString("eammstore"));
    91             HWProto::addStringToBuffer(buf, QString("eammstore"));
       
    92             HWProto::addStringListToBuffer(buf,
       
    93                 (*it).TeamGameConfig(gamecfg->getInitHealth()));
    94         }
    94         }
    95     }
    95     }
    96     RawSendIPC(buf);
    96     RawSendIPC(buf);
    97 }
    97 }
    98 
    98 
   113     HWNamegen namegen;
   113     HWNamegen namegen;
   114 
   114 
   115     HWTeam * team1;
   115     HWTeam * team1;
   116     team1 = new HWTeam;
   116     team1 = new HWTeam;
   117     team1->difficulty = 0;
   117     team1->difficulty = 0;
   118     team1->teamColor = *color1;
   118     team1->teamColor = *colors[0];
   119     team1->numHedgehogs = 4;
   119     team1->numHedgehogs = 4;
   120     namegen.TeamRandomNames(team1,TRUE);
   120     namegen.TeamRandomNames(team1,TRUE);
   121     HWProto::addStringListToBuffer(teamscfg,
   121     HWProto::addStringListToBuffer(teamscfg,
   122             team1->TeamGameConfig(100));
   122             team1->TeamGameConfig(100));
   123 
   123 
   124     HWTeam * team2;
   124     HWTeam * team2;
   125     team2 = new HWTeam;
   125     team2 = new HWTeam;
   126     team2->difficulty = 4;
   126     team2->difficulty = 4;
   127     team2->teamColor = *color2;
   127     team2->teamColor = *colors[1];
   128     team2->numHedgehogs = 4;
   128     team2->numHedgehogs = 4;
   129 	do
   129 	do
   130         namegen.TeamRandomNames(team2,TRUE);
   130         namegen.TeamRandomNames(team2,TRUE);
   131 	while(!team2->TeamName.compare(team1->TeamName) || !team2->Hedgehogs[0].Hat.compare(team1->Hedgehogs[0].Hat));
   131 	while(!team2->TeamName.compare(team1->TeamName) || !team2->Hedgehogs[0].Hat.compare(team1->Hedgehogs[0].Hat));
   132     HWProto::addStringListToBuffer(teamscfg,
   132     HWProto::addStringListToBuffer(teamscfg,
   144 void HWGame::SendTrainingConfig()
   144 void HWGame::SendTrainingConfig()
   145 {
   145 {
   146     QByteArray traincfg;
   146     QByteArray traincfg;
   147     HWProto::addStringToBuffer(traincfg, "TL");
   147     HWProto::addStringToBuffer(traincfg, "TL");
   148 
   148 
   149     HWProto::addStringToBuffer(traincfg, "escript " + datadir->absolutePath() + "/Missions/Training/" + training + ".lua");
   149     HWProto::addStringToBuffer(traincfg, "escript " + training);
   150 
   150 
   151     RawSendIPC(traincfg);
   151     RawSendIPC(traincfg);
       
   152 }
       
   153 
       
   154 void HWGame::SendCampaignConfig()
       
   155 {
       
   156     QByteArray campaigncfg;
       
   157     HWProto::addStringToBuffer(campaigncfg, "TL");
       
   158 
       
   159     HWProto::addStringToBuffer(campaigncfg, "escript " + campaign);
       
   160 
       
   161     RawSendIPC(campaigncfg);
   152 }
   162 }
   153 
   163 
   154 void HWGame::SendNetConfig()
   164 void HWGame::SendNetConfig()
   155 {
   165 {
   156     commonConfig();
   166     commonConfig();
   178                     SendNetConfig();
   188                     SendNetConfig();
   179                     break;
   189                     break;
   180                 }
   190                 }
   181                 case gtTraining: {
   191                 case gtTraining: {
   182                     SendTrainingConfig();
   192                     SendTrainingConfig();
       
   193                     break;
       
   194                 }
       
   195                 case gtCampaign: {
       
   196                     SendCampaignConfig();
   183                     break;
   197                     break;
   184                 }
   198                 }
   185             }
   199             }
   186             break;
   200             break;
   187         }
   201         }
   275     arguments << QString::number(resolution.height());
   289     arguments << QString::number(resolution.height());
   276     arguments << QString::number(config->bitDepth()); // bpp
   290     arguments << QString::number(config->bitDepth()); // bpp
   277     arguments << QString("%1").arg(ipc_port);
   291     arguments << QString("%1").arg(ipc_port);
   278     arguments << (config->vid_Fullscreen() ? "1" : "0");
   292     arguments << (config->vid_Fullscreen() ? "1" : "0");
   279     arguments << (config->isSoundEnabled() ? "1" : "0");
   293     arguments << (config->isSoundEnabled() ? "1" : "0");
   280     arguments << "0"; //(config->isSoundHardware() ? "1" : "0");
   294     arguments << (config->isMusicEnabled() ? "1" : "0");
   281     arguments << "0"; //(config->isWeaponTooltip() ? "1" : "0");
       
   282     arguments << tr("en.txt");
       
   283     arguments << QString::number(config->volume()); // sound volume
   295     arguments << QString::number(config->volume()); // sound volume
   284     arguments << QString::number(config->timerInterval());
   296     arguments << QString::number(config->timerInterval());
   285     arguments << datadir->absolutePath();
   297     arguments << datadir->absolutePath();
   286     arguments << (config->isShowFPSEnabled() ? "1" : "0");
   298     arguments << (config->isShowFPSEnabled() ? "1" : "0");
   287     arguments << (config->isAltDamageEnabled() ? "1" : "0");
   299     arguments << (config->isAltDamageEnabled() ? "1" : "0");
   288     arguments << config->netNick().toUtf8().toBase64();
   300     arguments << config->netNick().toUtf8().toBase64();
   289     arguments << (config->isMusicEnabled() ? "1" : "0");
       
   290     arguments << QString::number(config->translateQuality());
   301     arguments << QString::number(config->translateQuality());
   291     arguments << QString::number(config->stereoMode());
   302     arguments << QString::number(config->stereoMode());
       
   303     arguments << tr("en.txt");
       
   304 
   292     return arguments;
   305     return arguments;
   293 }
   306 }
   294 
   307 
   295 void HWGame::AddTeam(const QString & teamname)
   308 void HWGame::AddTeam(const QString & teamname)
   296 {
   309 {
   343 }
   356 }
   344 
   357 
   345 void HWGame::StartTraining(const QString & file)
   358 void HWGame::StartTraining(const QString & file)
   346 {
   359 {
   347     gameType = gtTraining;
   360     gameType = gtTraining;
   348     training = file;
   361     training = "Missions/Training/" + file + ".lua";
       
   362     demo.clear();
       
   363     Start();
       
   364     SetGameState(gsStarted);
       
   365 }
       
   366 
       
   367 void HWGame::StartCampaign(const QString & file)
       
   368 {
       
   369     gameType = gtCampaign;
       
   370     campaign = "Missions/Campaign/" + file + ".lua";
   349     demo.clear();
   371     demo.clear();
   350     Start();
   372     Start();
   351     SetGameState(gsStarted);
   373     SetGameState(gsStarted);
   352 }
   374 }
   353 
   375