QTfrontend/game.cpp
changeset 239 f9adf3c73bed
parent 228 7298aaee99b4
child 247 07605d2a2024
equal deleted inserted replaced
238:85949b945906 239:f9adf3c73bed
    28 #include "game.h"
    28 #include "game.h"
    29 #include "hwconsts.h"
    29 #include "hwconsts.h"
    30 #include "gameuiconfig.h"
    30 #include "gameuiconfig.h"
    31 #include "gamecfgwidget.h"
    31 #include "gamecfgwidget.h"
    32 #include "KB.h"
    32 #include "KB.h"
       
    33 #include "proto.h"
    33 
    34 
    34 HWGame::HWGame(GameUIConfig * config, GameCFGWidget * gamecfg) :
    35 HWGame::HWGame(GameUIConfig * config, GameCFGWidget * gamecfg) :
    35   TCPBase(true)
    36   TCPBase(true)
    36 {
    37 {
    37 	this->config = config;
    38 	this->config = config;
    58 	SendIPC("TL");
    59 	SendIPC("TL");
    59 	SendIPC(QString("e$gmflags %1").arg(gamecfg->getGameFlags()).toAscii());
    60 	SendIPC(QString("e$gmflags %1").arg(gamecfg->getGameFlags()).toAscii());
    60 
    61 
    61 	for (int i = 0; i < TeamCount; i++)
    62 	for (int i = 0; i < TeamCount; i++)
    62 	{
    63 	{
    63 		SendIPC("eaddteam");
    64 		HWTeam team(teams[i]);
    64 		LocalCFG(teams[i]);
    65 		team.LoadFromFile();
    65 		QColor clr=m_teamsParams[teams[i]].teamColor;
    66 
    66 		SendIPC(QString("ecolor %1").arg(clr.rgb()&0xFFFFFF).toAscii());
    67 		QColor clr = m_teamsParams[teams[i]].teamColor;
    67 		for (int t = 0; t < m_teamsParams[teams[i]].numHedgehogs; t++)
    68 		QByteArray buf;
    68 			SendIPC(QString("eadd hh%1 0").arg(t).toAscii());
    69 		QStringList sl = team.TeamGameConfig(clr.rgb()&0xFFFFFF, m_teamsParams[teams[i]].numHedgehogs);
       
    70 		HWProto::addStringListToBuffer(buf, sl);
       
    71 		RawSendIPC(buf);
    69 	}
    72 	}
    70 }
    73 }
    71 
    74 
    72 void HWGame::SendQuickConfig()
    75 void HWGame::SendQuickConfig()
    73 {
    76 {
    74 	SendIPC(QString("eseed %1").arg(seed).toAscii());
    77 	SendIPC(QString("eseed %1").arg(seed).toAscii());
    75 	SendIPC(QString("etheme %1").arg(config->GetRandomTheme()).toAscii());
    78 	SendIPC(QString("etheme %1").arg(config->GetRandomTheme()).toAscii());
    76 	SendIPC("TL");
    79 	SendIPC("TL");
    77 	SendIPC(QString("e$gmflags %1").arg(gamecfg->getGameFlags()).toAscii());
    80 	SendIPC(QString("e$gmflags %1").arg(gamecfg->getGameFlags()).toAscii());
    78 	SendIPC("eaddteam");
    81 
    79 	LocalCFG(0);
    82 	QByteArray teamscfg;
    80 	SendIPC("ecolor 65535");
    83 	HWTeam team1(0);
    81 	SendIPC("eadd hh0 0");
    84 	team1.difficulty = 0;
    82 	SendIPC("eadd hh1 0");
    85 	HWProto::addStringListToBuffer(teamscfg, team1.TeamGameConfig(65535, 4));
    83 	SendIPC("eadd hh2 0");
    86 
    84 	SendIPC("eadd hh3 0");
    87 	HWTeam team2(2);
    85 	SendIPC("eaddteam");
    88 	team2.difficulty = 4;
    86 	LocalCFG(2);
    89 	RawSendIPC(HWProto::addStringListToBuffer(teamscfg, team2.TeamGameConfig(16776960, 4)));
    87 	SendIPC("ecolor 16776960");
       
    88 	SendIPC("eadd hh0 5");
       
    89 	SendIPC("eadd hh1 4");
       
    90 	SendIPC("eadd hh2 4");
       
    91 	SendIPC("eadd hh3 3");
       
    92 }
    90 }
    93 
    91 
    94 void HWGame::ParseMessage(const QByteArray & msg)
    92 void HWGame::ParseMessage(const QByteArray & msg)
    95 {
    93 {
    96 	switch(msg.data()[1]) {
    94 	switch(msg.data()[1]) {
   259 
   257 
   260 void HWGame::StartLocal()
   258 void HWGame::StartLocal()
   261 {
   259 {
   262 	gameType = gtLocal;
   260 	gameType = gtLocal;
   263 	if (TeamCount < 2) return;
   261 	if (TeamCount < 2) return;
   264 	seed = gamecfg->getCurrentSeed();//QUuid::createUuid().toString();
   262 	seed = gamecfg->getCurrentSeed();
   265 	demo = new QByteArray;
   263 	demo = new QByteArray;
   266 	Start();
   264 	Start();
   267 }
   265 }
   268 
   266 
   269 void HWGame::StartQuick()
   267 void HWGame::StartQuick()
   270 {
   268 {
   271 	gameType = gtQLocal;
   269 	gameType = gtQLocal;
   272 	seed = gamecfg->getCurrentSeed();//QUuid::createUuid().toString();
   270 	seed = gamecfg->getCurrentSeed();
   273 	demo = new QByteArray;
   271 	demo = new QByteArray;
   274 	Start();
   272 	Start();
   275 }
   273 }
   276 
   274 
   277 
   275 
   278 void HWGame::LocalCFG(const QString & teamname)
   276 void HWGame::LocalCFG(const QString & teamname)
   279 {
   277 {
       
   278 	QByteArray teamcfg;
   280 	HWTeam team(teamname);
   279 	HWTeam team(teamname);
   281 	if (!team.LoadFromFile()) {
   280 	RawSendIPC(HWProto::addStringListToBuffer(teamcfg, team.TeamGameConfig(16776960, 4)));
   282 		QMessageBox::critical(0,
   281 }
   283 				"Error",
   282 
   284 				QString("Cannot load team config ""%1""").arg(teamname),
       
   285 				QMessageBox::Ok,
       
   286 				QMessageBox::NoButton,
       
   287 				QMessageBox::NoButton);
       
   288 		return;
       
   289 	}
       
   290 	RawSendIPC(team.IPCTeamInfo());
       
   291 }
       
   292 
       
   293 void HWGame::LocalCFG(quint8 num)
       
   294 {
       
   295 	HWTeam team(num);
       
   296 	RawSendIPC(team.IPCTeamInfo());
       
   297 }