QTfrontend/game.cpp
changeset 127 ca70467bd0a8
parent 116 00d3d6d2e699
child 128 223522298250
equal deleted inserted replaced
126:93df479aa1b9 127:ca70467bd0a8
    36 #include <QTimer>
    36 #include <QTimer>
    37 #include <QString>
    37 #include <QString>
    38 #include <QByteArray>
    38 #include <QByteArray>
    39 #include <QFile>
    39 #include <QFile>
    40 #include <QTextStream>
    40 #include <QTextStream>
       
    41 #include <QUuid>
    41 
    42 
    42 #include "game.h"
    43 #include "game.h"
    43 #include "hwconsts.h"
    44 #include "hwconsts.h"
    44 #include "gameuiconfig.h"
    45 #include "gameuiconfig.h"
    45 #include "gamecfgwidget.h"
    46 #include "gamecfgwidget.h"
    84 }
    85 }
    85 
    86 
    86 void HWGame::SendConfig()
    87 void HWGame::SendConfig()
    87 {
    88 {
    88 	SendIPC(QString("eseed %1").arg(seed));
    89 	SendIPC(QString("eseed %1").arg(seed));
    89 	SendIPC(QString("etheme %1").arg(GetThemeBySeed()));
    90 	SendIPC(QString("etheme %1").arg(config->GetRandomTheme()));
    90 	SENDIPC("TL");
    91 	SENDIPC("TL");
    91 	SendIPC(QString("e$gmflags %1").arg(gamecfg->getGameFlags()));
    92 	SendIPC(QString("e$gmflags %1").arg(gamecfg->getGameFlags()));
    92 	SENDIPC("eaddteam");
    93 	SENDIPC("eaddteam");
    93 	LocalCFG(0);
    94 	LocalCFG(0);
    94 	SENDIPC("ecolor 65535");
    95 	SENDIPC("ecolor 65535");
   254 	if (TeamCount == 5) return;
   255 	if (TeamCount == 5) return;
   255 	teams[TeamCount] = teamname;
   256 	teams[TeamCount] = teamname;
   256 	TeamCount++;
   257 	TeamCount++;
   257 }
   258 }
   258 
   259 
   259 QString HWGame::GetThemeBySeed()
       
   260 {
       
   261 	QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
       
   262 	QStringList themes;
       
   263 	if (themesfile.open(QIODevice::ReadOnly))
       
   264 	{
       
   265 		QTextStream stream(&themesfile);
       
   266 		QString str;
       
   267 		while (!stream.atEnd())
       
   268 		{
       
   269 			themes << stream.readLine();
       
   270 		}
       
   271 		themesfile.close();
       
   272 	}
       
   273 	quint32 len = themes.size();
       
   274 	if (len == 0)
       
   275 	{
       
   276 		QMessageBox::critical(0, "Error", "Cannot access themes.cfg or bad data", "OK");
       
   277 		return "avematan";
       
   278 	}
       
   279 	if (seed.isEmpty())
       
   280 	{
       
   281 		QMessageBox::critical(0, "Error", "seed not defined", "OK");
       
   282 		return "avematan";
       
   283 	}
       
   284 	quint32 k = 0;
       
   285 	for (int i = 0; i < seed.length(); i++)
       
   286 	{
       
   287 		k += seed[i].cell();
       
   288 	}
       
   289 	return themes[k % len];
       
   290 }
       
   291 
       
   292 void HWGame::SaveDemo(const QString & filename)
   260 void HWGame::SaveDemo(const QString & filename)
   293 {
   261 {
   294 	QFile demofile(filename);
   262 	QFile demofile(filename);
   295 	if (!demofile.open(QIODevice::WriteOnly))
   263 	if (!demofile.open(QIODevice::WriteOnly))
   296 	{
   264 	{
   344 
   312 
   345 void HWGame::StartLocal()
   313 void HWGame::StartLocal()
   346 {
   314 {
   347 	gameType = gtLocal;
   315 	gameType = gtLocal;
   348 	if (TeamCount < 2) return;
   316 	if (TeamCount < 2) return;
   349 	seedgen.GenRNDStr(seed, 10);
   317 	seed = QUuid::createUuid().toString();
   350 	Start();
   318 	Start();
   351 }
   319 }
   352 
   320 
   353 void HWGame::StartQuick()
   321 void HWGame::StartQuick()
   354 {
   322 {
   355 	gameType = gtLocal;
   323 	gameType = gtLocal;
   356 	seedgen.GenRNDStr(seed, 10);
   324 	seed = QUuid::createUuid().toString();
   357 	Start();
   325 	Start();
   358 }
   326 }
   359 
   327 
   360 
   328 
   361 void HWGame::LocalCFG(const QString & teamname)
   329 void HWGame::LocalCFG(const QString & teamname)