equal
deleted
inserted
replaced
19 #include <QString> |
19 #include <QString> |
20 #include <QByteArray> |
20 #include <QByteArray> |
21 #include <QUuid> |
21 #include <QUuid> |
22 #include <QColor> |
22 #include <QColor> |
23 #include <QStringListModel> |
23 #include <QStringListModel> |
|
24 #include <QMessageBox> |
24 |
25 |
25 #include "game.h" |
26 #include "game.h" |
26 #include "hwconsts.h" |
27 #include "hwconsts.h" |
27 #include "gameuiconfig.h" |
28 #include "gameuiconfig.h" |
28 #include "gamecfgwidget.h" |
29 #include "gamecfgwidget.h" |
29 #include "teamselect.h" |
30 #include "teamselect.h" |
30 #include "KB.h" |
31 #include "KB.h" |
31 #include "proto.h" |
32 #include "proto.h" |
|
33 #include "campaign.h" |
32 |
34 |
33 #include <QTextStream> |
35 #include <QTextStream> |
34 |
36 |
35 QString training, campaign; // TODO: Cleaner solution? |
37 QString training, campaign, campaignScript, campaignTeam; // TODO: Cleaner solution? |
36 |
38 |
37 HWGame::HWGame(GameUIConfig * config, GameCFGWidget * gamecfg, QString ammo, TeamSelWidget* pTeamSelWidget) : |
39 HWGame::HWGame(GameUIConfig * config, GameCFGWidget * gamecfg, QString ammo, TeamSelWidget* pTeamSelWidget) : |
38 TCPBase(true), |
40 TCPBase(true), |
39 ammostr(ammo), |
41 ammostr(ammo), |
40 m_pTeamSelWidget(pTeamSelWidget) |
42 m_pTeamSelWidget(pTeamSelWidget) |
163 { |
165 { |
164 QByteArray campaigncfg; |
166 QByteArray campaigncfg; |
165 HWProto::addStringToBuffer(campaigncfg, "TL"); |
167 HWProto::addStringToBuffer(campaigncfg, "TL"); |
166 HWProto::addStringToBuffer(campaigncfg, "eseed " + QUuid::createUuid().toString()); |
168 HWProto::addStringToBuffer(campaigncfg, "eseed " + QUuid::createUuid().toString()); |
167 |
169 |
168 HWProto::addStringToBuffer(campaigncfg, "escript " + campaign); |
170 HWProto::addStringToBuffer(campaigncfg, "escript " + campaignScript); |
169 |
171 |
170 RawSendIPC(campaigncfg); |
172 RawSendIPC(campaigncfg); |
171 } |
173 } |
172 |
174 |
173 void HWGame::SendNetConfig() |
175 void HWGame::SendNetConfig() |
273 case 'b': |
275 case 'b': |
274 { |
276 { |
275 int size = msg.size(); |
277 int size = msg.size(); |
276 QString msgbody = QString::fromUtf8(msg.mid(2).left(size - 4)); |
278 QString msgbody = QString::fromUtf8(msg.mid(2).left(size - 4)); |
277 emit SendTeamMessage(msgbody); |
279 emit SendTeamMessage(msgbody); |
|
280 break; |
|
281 } |
|
282 case 'V': |
|
283 { |
|
284 if (msg.at(2) == '?') |
|
285 sendCampaignVar(msg.right(msg.size() - 3)); |
|
286 else if (msg.at(2) == '!') |
|
287 writeCampaignVar(msg.right(msg.size() - 3)); |
278 break; |
288 break; |
279 } |
289 } |
280 default: |
290 default: |
281 { |
291 { |
282 if (gameType == gtNet && !netSuspend) |
292 if (gameType == gtNet && !netSuspend) |
389 demo.clear(); |
399 demo.clear(); |
390 Start(); |
400 Start(); |
391 SetGameState(gsStarted); |
401 SetGameState(gsStarted); |
392 } |
402 } |
393 |
403 |
394 void HWGame::StartCampaign(const QString & file) |
404 void HWGame::StartCampaign(const QString & camp, const QString & campScript, const QString & campTeam) |
395 { |
405 { |
396 gameType = gtCampaign; |
406 gameType = gtCampaign; |
397 campaign = "Missions/Campaign/" + file + ".lua"; |
407 campaign = camp; |
|
408 campaignScript = "Missions/Campaign/" + camp + "/" + campScript; |
|
409 campaignTeam = campTeam; |
398 demo.clear(); |
410 demo.clear(); |
399 Start(); |
411 Start(); |
400 SetGameState(gsStarted); |
412 SetGameState(gsStarted); |
401 } |
413 } |
402 |
414 |
410 { |
422 { |
411 QByteArray buf; |
423 QByteArray buf; |
412 HWProto::addStringToBuffer(buf, QString("efinish")); |
424 HWProto::addStringToBuffer(buf, QString("efinish")); |
413 RawSendIPC(buf); |
425 RawSendIPC(buf); |
414 } |
426 } |
|
427 |
|
428 void HWGame::sendCampaignVar(QByteArray varToSend) |
|
429 { |
|
430 QString varToFind(varToSend); |
|
431 QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + campaignTeam + ".hwt", QSettings::IniFormat, 0); |
|
432 teamfile.setIniCodec("UTF-8"); |
|
433 QString varValue = teamfile.value("Campaign " + campaign + "/" + varToFind, "").toString(); |
|
434 QByteArray command; |
|
435 HWProto::addStringToBuffer(command, "V." + varValue); |
|
436 RawSendIPC(command); |
|
437 } |
|
438 |
|
439 void HWGame::writeCampaignVar(QByteArray varVal) |
|
440 { |
|
441 QString varToWrite(""); |
|
442 QString varValue(""); |
|
443 unsigned int i = 0; |
|
444 while (i < varVal.size() && varVal.at(i) != ' ') |
|
445 { |
|
446 varToWrite.append(varVal.at(i)); |
|
447 i++; |
|
448 } |
|
449 i++; |
|
450 while (i < varVal.size() && varVal.at(i) != '\0') |
|
451 { |
|
452 varValue.append(varVal.at(i)); |
|
453 i++; |
|
454 } |
|
455 |
|
456 QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + campaignTeam + ".hwt", QSettings::IniFormat, 0); |
|
457 teamfile.setIniCodec("UTF-8"); |
|
458 teamfile.setValue("Campaign " + campaign + "/" + varToWrite, varValue); |
|
459 } |
|
460 |