QTfrontend/game.cpp
changeset 788 00720357601f
parent 759 8da05b316d81
child 883 07a568ba44e0
equal deleted inserted replaced
787:5064d72fa0e2 788:00720357601f
    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 <QByteArray>
    20 #include <QByteArray>
       
    21 #include <QUuid>
    21 
    22 
    22 #include "game.h"
    23 #include "game.h"
    23 #include "hwconsts.h"
    24 #include "hwconsts.h"
    24 #include "gameuiconfig.h"
    25 #include "gameuiconfig.h"
    25 #include "gamecfgwidget.h"
    26 #include "gamecfgwidget.h"
    35   ammostr(ammo)
    36   ammostr(ammo)
    36 {
    37 {
    37 	this->config = config;
    38 	this->config = config;
    38 	this->gamecfg = gamecfg;
    39 	this->gamecfg = gamecfg;
    39 	TeamCount = 0;
    40 	TeamCount = 0;
    40 	seed = "";
       
    41 }
    41 }
    42 
    42 
    43 HWGame::~HWGame()
    43 HWGame::~HWGame()
    44 {
    44 {
    45 	SetGameState(gsDestroyed);
    45 	SetGameState(gsDestroyed);
    71 			break;
    71 			break;
    72 		default:
    72 		default:
    73 			gt = "TL";
    73 			gt = "TL";
    74 	}
    74 	}
    75 	HWProto::addStringToBuffer(buf, gt);
    75 	HWProto::addStringToBuffer(buf, gt);
       
    76 
    76 	HWProto::addStringListToBuffer(buf, gamecfg->getFullConfig());
    77 	HWProto::addStringListToBuffer(buf, gamecfg->getFullConfig());
    77 
    78 
    78 	if (m_pTeamSelWidget)
    79 	if (m_pTeamSelWidget)
    79 	{
    80 	{
    80 		QList<HWTeam> teams = m_pTeamSelWidget->getPlayingTeams();
    81 		QList<HWTeam> teams = m_pTeamSelWidget->getPlayingTeams();
    93 	commonConfig();
    94 	commonConfig();
    94 }
    95 }
    95 
    96 
    96 void HWGame::SendQuickConfig()
    97 void HWGame::SendQuickConfig()
    97 {
    98 {
    98 	commonConfig();
       
    99 
       
   100 	QByteArray teamscfg;
    99 	QByteArray teamscfg;
       
   100 
       
   101 	HWProto::addStringToBuffer(teamscfg, "TL");
       
   102 	HWProto::addStringToBuffer(teamscfg, QString("etheme %1")
       
   103 			.arg((Themes->size() > 0) ? Themes->at(rand() % Themes->size()) : "steel"));
       
   104 	HWProto::addStringToBuffer(teamscfg, "eseed " + QUuid::createUuid().toString());
       
   105 
   101 	HWTeam team1(0);
   106 	HWTeam team1(0);
   102 	team1.difficulty = 0;
   107 	team1.difficulty = 0;
   103 	team1.teamColor = *color1;
   108 	team1.teamColor = *color1;
   104 	team1.numHedgehogs = 4;
   109 	team1.numHedgehogs = 4;
   105 	HWProto::addStringListToBuffer(teamscfg,
   110 	HWProto::addStringListToBuffer(teamscfg,
   106 			team1.TeamGameConfig(gamecfg->getInitHealth()));
   111 			team1.TeamGameConfig(100));
   107 
   112 
   108 	HWTeam team2(2);
   113 	HWTeam team2(2);
   109 	team2.difficulty = 4;
   114 	team2.difficulty = 4;
   110 	team2.teamColor = *color2;
   115 	team2.teamColor = *color2;
   111 	team2.numHedgehogs = 4;
   116 	team2.numHedgehogs = 4;
   112 	HWProto::addStringListToBuffer(teamscfg,
   117 	HWProto::addStringListToBuffer(teamscfg,
   113 			team2.TeamGameConfig(gamecfg->getInitHealth()));
   118 			team2.TeamGameConfig(100));
   114 
   119 
   115 	HWProto::addStringToBuffer(teamscfg, *cDefaultAmmoStore);
   120 	HWProto::addStringToBuffer(teamscfg, *cDefaultAmmoStore);
   116 	HWProto::addStringToBuffer(teamscfg, *cDefaultAmmoStore);
   121 	HWProto::addStringToBuffer(teamscfg, *cDefaultAmmoStore);
   117 	RawSendIPC(teamscfg);
   122 	RawSendIPC(teamscfg);
   118 }
   123 }
   119 
   124 
   120 void HWGame::SendTrainingConfig()
   125 void HWGame::SendTrainingConfig()
   121 {
   126 {
   122 	QByteArray teamscfg;
   127 	QByteArray traincfg;
   123 	HWProto::addStringToBuffer(teamscfg, "TL");
   128 	HWProto::addStringToBuffer(traincfg, "TL");
   124 
   129 
   125 	HWTeam team1(0);
   130 	HWTeam team1(0);
   126 	team1.difficulty = 0;
   131 	team1.difficulty = 0;
   127 	team1.teamColor = *color1;
   132 	team1.teamColor = *color1;
   128 	team1.numHedgehogs = 1;
   133 	team1.numHedgehogs = 1;
   129 	HWProto::addStringListToBuffer(teamscfg,
   134 	HWProto::addStringListToBuffer(traincfg,
   130 			team1.TeamGameConfig(100));
   135 			team1.TeamGameConfig(100));
   131 
   136 
   132 	QFile file(datadir->absolutePath() + "/Trainings/001_Shotgun.txt");
   137 	QFile file(datadir->absolutePath() + "/Trainings/001_Shotgun.txt");
   133 	if(!file.open(QFile::ReadOnly))
   138 	if(!file.open(QFile::ReadOnly))
   134 	{
   139 	{
   137 	}
   142 	}
   138 	
   143 	
   139 	QTextStream stream(&file);
   144 	QTextStream stream(&file);
   140 	while(!stream.atEnd())
   145 	while(!stream.atEnd())
   141 	{
   146 	{
   142 		HWProto::addStringToBuffer(teamscfg, "e" + stream.readLine());
   147 		HWProto::addStringToBuffer(traincfg, "e" + stream.readLine());
   143 	}
   148 	}
   144 
   149 
   145 	RawSendIPC(teamscfg);
   150 	RawSendIPC(traincfg);
   146 }
   151 }
   147 
   152 
   148 void HWGame::SendNetConfig()
   153 void HWGame::SendNetConfig()
   149 {
   154 {
   150 	commonConfig();
   155 	commonConfig();
   299 }
   304 }
   300 
   305 
   301 void HWGame::StartLocal()
   306 void HWGame::StartLocal()
   302 {
   307 {
   303 	gameType = gtLocal;
   308 	gameType = gtLocal;
   304 	seed = gamecfg->getCurrentSeed();
       
   305 	demo.clear();
   309 	demo.clear();
   306 	Start();
   310 	Start();
   307 	SetGameState(gsStarted);
   311 	SetGameState(gsStarted);
   308 }
   312 }
   309 
   313 
   310 void HWGame::StartQuick()
   314 void HWGame::StartQuick()
   311 {
   315 {
   312 	gameType = gtQLocal;
   316 	gameType = gtQLocal;
   313 	seed = gamecfg->getCurrentSeed();
       
   314 	demo.clear();
   317 	demo.clear();
   315 	Start();
   318 	Start();
   316 	SetGameState(gsStarted);
   319 	SetGameState(gsStarted);
   317 }
   320 }
   318 
   321 
   319 void HWGame::StartTraining()
   322 void HWGame::StartTraining()
   320 {
   323 {
   321 	gameType = gtTraining;
   324 	gameType = gtTraining;
   322 	seed = "training";
       
   323 	demo.clear();
   325 	demo.clear();
   324 	Start();
   326 	Start();
   325 	SetGameState(gsStarted);
   327 	SetGameState(gsStarted);
   326 }
   328 }
   327 
   329