QTfrontend/game.cpp
changeset 341 184230eb4151
parent 339 7535ab6c3820
child 352 4665bfe25470
equal deleted inserted replaced
340:f5d4db927eba 341:184230eb4151
    22 #include <QString>
    22 #include <QString>
    23 #include <QByteArray>
    23 #include <QByteArray>
    24 #include <QFile>
    24 #include <QFile>
    25 #include <QTextStream>
    25 #include <QTextStream>
    26 #include <QUuid>
    26 #include <QUuid>
       
    27 #include <QDebug>
    27 
    28 
    28 #include "game.h"
    29 #include "game.h"
    29 #include "hwconsts.h"
    30 #include "hwconsts.h"
    30 #include "gameuiconfig.h"
    31 #include "gameuiconfig.h"
    31 #include "gamecfgwidget.h"
    32 #include "gamecfgwidget.h"
    55 }
    56 }
    56 
    57 
    57 void HWGame::commonConfig()
    58 void HWGame::commonConfig()
    58 {
    59 {
    59 	QByteArray buf;
    60 	QByteArray buf;
       
    61 	QString gt;
       
    62 	switch (gameType) {
       
    63 		case gtDemo:
       
    64 			gt = "TD";
       
    65 			break;
       
    66 		case gtNet:
       
    67 			gt = "TN";
       
    68 			break;
       
    69 		default:
       
    70 			gt = "TL";
       
    71 	}
       
    72 	HWProto::addStringToBuffer(buf, gt);
       
    73 	qDebug() << "game type" << gt;
    60 	HWProto::addStringListToBuffer(buf, gamecfg->getFullConfig());
    74 	HWProto::addStringListToBuffer(buf, gamecfg->getFullConfig());
    61 	HWProto::addStringToBuffer(buf, "TL");
    75 	qDebug() << "config" << gamecfg->getFullConfig();
       
    76 
       
    77 	if (m_pTeamSelWidget)
       
    78 	{
       
    79 		qDebug() << "adding teams from teamselwidget...";
       
    80 		QList<HWTeam> teams = QList<HWTeam>::fromStdList(m_pTeamSelWidget->getPlayingTeams());
       
    81 		for(QList<HWTeam>::iterator it = teams.begin(); it != teams.end(); ++it)
       
    82 		{
       
    83 			qDebug() << "a team...";
       
    84 			(*it).numHedgehogs = 4;
       
    85 			HWProto::addStringListToBuffer(buf,
       
    86 				(*it).TeamGameConfig(gamecfg->getInitHealth()));
       
    87 		}
       
    88 	}
    62 	RawSendIPC(buf);
    89 	RawSendIPC(buf);
    63 }
    90 }
    64 
    91 
    65 void HWGame::SendConfig()
    92 void HWGame::SendConfig()
    66 {
    93 {
    67 	commonConfig();
    94 	commonConfig();
    68 
       
    69 	for (int i = 0; i < TeamCount; i++)
       
    70 	{
       
    71 		HWTeam team(teams[i]);
       
    72 		team.LoadFromFile();
       
    73 
       
    74 		QColor clr = m_teamsParams[teams[i]].teamColor;
       
    75 		QByteArray buf;
       
    76 		QStringList sl = team.TeamGameConfig(clr.rgb()&0xFFFFFF,
       
    77 				m_teamsParams[teams[i]].numHedgehogs,
       
    78 				gamecfg->getInitHealth());
       
    79 		HWProto::addStringListToBuffer(buf, sl);
       
    80 		RawSendIPC(buf);
       
    81 	}
       
    82 }
    95 }
    83 
    96 
    84 void HWGame::SendQuickConfig()
    97 void HWGame::SendQuickConfig()
    85 {
    98 {
    86 	commonConfig();
    99 	commonConfig();
    87 
   100 
    88 	QByteArray teamscfg;
   101 	QByteArray teamscfg;
    89 	HWTeam team1(0);
   102 	HWTeam team1(0);
    90 	team1.difficulty = 0;
   103 	team1.difficulty = 0;
       
   104 	team1.teamColor = QColor(65535);
       
   105 	team1.numHedgehogs = 4;
    91 	HWProto::addStringListToBuffer(teamscfg,
   106 	HWProto::addStringListToBuffer(teamscfg,
    92 			team1.TeamGameConfig(65535, 4, gamecfg->getInitHealth()));
   107 			team1.TeamGameConfig(gamecfg->getInitHealth()));
    93 
   108 
    94 	HWTeam team2(2);
   109 	HWTeam team2(2);
    95 	team2.difficulty = 4;
   110 	team2.difficulty = 4;
       
   111 	team2.teamColor = QColor(16776960);
       
   112 	team2.numHedgehogs = 4;
    96 	RawSendIPC(HWProto::addStringListToBuffer(teamscfg,
   113 	RawSendIPC(HWProto::addStringListToBuffer(teamscfg,
    97 			team2.TeamGameConfig(16776960, 4, gamecfg->getInitHealth())));
   114 			team2.TeamGameConfig(gamecfg->getInitHealth())));
       
   115 }
       
   116 
       
   117 void HWGame::SendNetConfig()
       
   118 {
       
   119 	commonConfig();
    98 }
   120 }
    99 
   121 
   100 void HWGame::ParseMessage(const QByteArray & msg)
   122 void HWGame::ParseMessage(const QByteArray & msg)
   101 {
   123 {
   102 	switch(msg.at(1)) {
   124 	switch(msg.at(1)) {
   106 			else
   128 			else
   107 				SendIPC("!");
   129 				SendIPC("!");
   108 			break;
   130 			break;
   109 		}
   131 		}
   110 		case 'C': {
   132 		case 'C': {
       
   133 			qDebug("ASK Config");
   111 			switch (gameType) {
   134 			switch (gameType) {
   112 				case gtLocal: {
   135 				case gtLocal: {
   113 				 	SendConfig();
   136 				 	SendConfig();
   114 					break;
   137 					break;
   115 				}
   138 				}
   117 				 	SendQuickConfig();
   140 				 	SendQuickConfig();
   118 					break;
   141 					break;
   119 				}
   142 				}
   120 				case gtDemo: break;
   143 				case gtDemo: break;
   121 				case gtNet: {
   144 				case gtNet: {
   122 					SendIPC("TN");
       
   123 					emit SendNet(QByteArray("\x01""C"));
   145 					emit SendNet(QByteArray("\x01""C"));
       
   146 					SendNetConfig();
   124 					break;
   147 					break;
   125 				}
   148 				}
   126 			}
   149 			}
   127 			break;
   150 			break;
   128 		}
   151 		}
   210 	arguments << datadir->absolutePath();
   233 	arguments << datadir->absolutePath();
   211 	arguments << (config->isShowFPSEnabled() ? "1" : "0");
   234 	arguments << (config->isShowFPSEnabled() ? "1" : "0");
   212 	return arguments;
   235 	return arguments;
   213 }
   236 }
   214 
   237 
   215 void HWGame::AddTeam(const QString & teamname, HWTeamTempParams teamParams)
   238 void HWGame::AddTeam(const QString & teamname)
   216 {
   239 {
   217 	if (TeamCount == 5) return;
   240 	if (TeamCount == 5) return;
   218 	teams[TeamCount] = teamname;
   241 	teams[TeamCount] = teamname;
   219 	TeamCount++;
   242 	TeamCount++;
   220 	m_teamsParams[teamname]=teamParams;
       
   221 }
   243 }
   222 
   244 
   223 void HWGame::SaveDemo(const QString & filename)
   245 void HWGame::SaveDemo(const QString & filename)
   224 {
   246 {
   225 	demo->replace(QByteArray("\x02TL"), QByteArray("\x02TD"));
   247 	demo->replace(QByteArray("\x02TL"), QByteArray("\x02TD"));
   281 }
   303 }
   282 
   304 
   283 void HWGame::StartLocal()
   305 void HWGame::StartLocal()
   284 {
   306 {
   285 	gameType = gtLocal;
   307 	gameType = gtLocal;
   286 	if (TeamCount < 2) return;
       
   287 	seed = gamecfg->getCurrentSeed();
   308 	seed = gamecfg->getCurrentSeed();
   288 	demo = new QByteArray;
   309 	demo = new QByteArray;
   289 	Start();
   310 	Start();
   290 	emit GameStateChanged(gsStarted);
   311 	emit GameStateChanged(gsStarted);
   291 }
   312 }
   300 }
   321 }
   301 
   322 
   302 
   323 
   303 void HWGame::LocalCFG(const QString & teamname)
   324 void HWGame::LocalCFG(const QString & teamname)
   304 {
   325 {
   305 	QByteArray teamcfg;
   326 	qDebug("HWGame::LocalCFG is UNIMPLEMENTED");
       
   327 /*	QByteArray teamcfg;
   306 	HWTeam team(teamname);
   328 	HWTeam team(teamname);
   307 	team.LoadFromFile();
   329 	team.LoadFromFile();
   308 	RawSendIPC(HWProto::addStringListToBuffer(teamcfg,
   330 	RawSendIPC(HWProto::addStringListToBuffer(teamcfg,
   309 			team.TeamGameConfig(16776960, 4, gamecfg->getInitHealth())));
   331 			team.TeamGameConfig(16776960, 4, gamecfg->getInitHealth())));
   310 }
   332 */
   311 
   333 }
       
   334