- Store more team specific values in HWTeam
authorunc0rr
Mon, 15 Jan 2007 21:20:36 +0000
changeset 341 184230eb4151
parent 340 f5d4db927eba
child 342 0a21586b3f1d
- Store more team specific values in HWTeam - Use list<HWTeam> to get all teams config, nothing else - Get rid of HWTeamTempParams
QTfrontend/frameTeam.cpp
QTfrontend/game.cpp
QTfrontend/game.h
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/newnetclient.cpp
QTfrontend/newnetclient.h
QTfrontend/team.cpp
QTfrontend/team.h
QTfrontend/teamselect.cpp
QTfrontend/teamselect.h
QTfrontend/teamselhelper.cpp
QTfrontend/teamselhelper.h
--- a/QTfrontend/frameTeam.cpp	Mon Jan 15 19:11:31 2007 +0000
+++ b/QTfrontend/frameTeam.cpp	Mon Jan 15 21:20:36 2007 +0000
@@ -46,7 +46,7 @@
 
 void FrameTeams::addTeam(HWTeam team, bool willPlay)
 {
-  TeamShowWidget* pTeamShowWidget =new TeamShowWidget(team, willPlay, this);
+  TeamShowWidget* pTeamShowWidget = new TeamShowWidget(team, willPlay, this);
 //  int hght=teamToWidget.empty() ? 0 : teamToWidget.begin()->second->size().height();
   teamToWidget.insert(make_pair(team, pTeamShowWidget));
   mainLayout.addWidget(pTeamShowWidget);
--- a/QTfrontend/game.cpp	Mon Jan 15 19:11:31 2007 +0000
+++ b/QTfrontend/game.cpp	Mon Jan 15 21:20:36 2007 +0000
@@ -24,6 +24,7 @@
 #include <QFile>
 #include <QTextStream>
 #include <QUuid>
+#include <QDebug>
 
 #include "game.h"
 #include "hwconsts.h"
@@ -57,28 +58,40 @@
 void HWGame::commonConfig()
 {
 	QByteArray buf;
+	QString gt;
+	switch (gameType) {
+		case gtDemo:
+			gt = "TD";
+			break;
+		case gtNet:
+			gt = "TN";
+			break;
+		default:
+			gt = "TL";
+	}
+	HWProto::addStringToBuffer(buf, gt);
+	qDebug() << "game type" << gt;
 	HWProto::addStringListToBuffer(buf, gamecfg->getFullConfig());
-	HWProto::addStringToBuffer(buf, "TL");
+	qDebug() << "config" << gamecfg->getFullConfig();
+
+	if (m_pTeamSelWidget)
+	{
+		qDebug() << "adding teams from teamselwidget...";
+		QList<HWTeam> teams = QList<HWTeam>::fromStdList(m_pTeamSelWidget->getPlayingTeams());
+		for(QList<HWTeam>::iterator it = teams.begin(); it != teams.end(); ++it)
+		{
+			qDebug() << "a team...";
+			(*it).numHedgehogs = 4;
+			HWProto::addStringListToBuffer(buf,
+				(*it).TeamGameConfig(gamecfg->getInitHealth()));
+		}
+	}
 	RawSendIPC(buf);
 }
 
 void HWGame::SendConfig()
 {
 	commonConfig();
-
-	for (int i = 0; i < TeamCount; i++)
-	{
-		HWTeam team(teams[i]);
-		team.LoadFromFile();
-
-		QColor clr = m_teamsParams[teams[i]].teamColor;
-		QByteArray buf;
-		QStringList sl = team.TeamGameConfig(clr.rgb()&0xFFFFFF,
-				m_teamsParams[teams[i]].numHedgehogs,
-				gamecfg->getInitHealth());
-		HWProto::addStringListToBuffer(buf, sl);
-		RawSendIPC(buf);
-	}
 }
 
 void HWGame::SendQuickConfig()
@@ -88,13 +101,22 @@
 	QByteArray teamscfg;
 	HWTeam team1(0);
 	team1.difficulty = 0;
+	team1.teamColor = QColor(65535);
+	team1.numHedgehogs = 4;
 	HWProto::addStringListToBuffer(teamscfg,
-			team1.TeamGameConfig(65535, 4, gamecfg->getInitHealth()));
+			team1.TeamGameConfig(gamecfg->getInitHealth()));
 
 	HWTeam team2(2);
 	team2.difficulty = 4;
+	team2.teamColor = QColor(16776960);
+	team2.numHedgehogs = 4;
 	RawSendIPC(HWProto::addStringListToBuffer(teamscfg,
-			team2.TeamGameConfig(16776960, 4, gamecfg->getInitHealth())));
+			team2.TeamGameConfig(gamecfg->getInitHealth())));
+}
+
+void HWGame::SendNetConfig()
+{
+	commonConfig();
 }
 
 void HWGame::ParseMessage(const QByteArray & msg)
@@ -108,6 +130,7 @@
 			break;
 		}
 		case 'C': {
+			qDebug("ASK Config");
 			switch (gameType) {
 				case gtLocal: {
 				 	SendConfig();
@@ -119,8 +142,8 @@
 				}
 				case gtDemo: break;
 				case gtNet: {
-					SendIPC("TN");
 					emit SendNet(QByteArray("\x01""C"));
+					SendNetConfig();
 					break;
 				}
 			}
@@ -212,12 +235,11 @@
 	return arguments;
 }
 
-void HWGame::AddTeam(const QString & teamname, HWTeamTempParams teamParams)
+void HWGame::AddTeam(const QString & teamname)
 {
 	if (TeamCount == 5) return;
 	teams[TeamCount] = teamname;
 	TeamCount++;
-	m_teamsParams[teamname]=teamParams;
 }
 
 void HWGame::SaveDemo(const QString & filename)
@@ -283,7 +305,6 @@
 void HWGame::StartLocal()
 {
 	gameType = gtLocal;
-	if (TeamCount < 2) return;
 	seed = gamecfg->getCurrentSeed();
 	demo = new QByteArray;
 	Start();
@@ -302,10 +323,12 @@
 
 void HWGame::LocalCFG(const QString & teamname)
 {
-	QByteArray teamcfg;
+	qDebug("HWGame::LocalCFG is UNIMPLEMENTED");
+/*	QByteArray teamcfg;
 	HWTeam team(teamname);
 	team.LoadFromFile();
 	RawSendIPC(HWProto::addStringListToBuffer(teamcfg,
 			team.TeamGameConfig(16776960, 4, gamecfg->getInitHealth())));
+*/
 }
 
--- a/QTfrontend/game.h	Mon Jan 15 19:11:31 2007 +0000
+++ b/QTfrontend/game.h	Mon Jan 15 21:20:36 2007 +0000
@@ -45,8 +45,8 @@
 {
 	Q_OBJECT
 public:
-	HWGame(GameUIConfig * config, GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget=0);
-	void AddTeam(const QString & team, HWTeamTempParams teamParams);
+	HWGame(GameUIConfig * config, GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget = 0);
+	void AddTeam(const QString & team);
 	void PlayDemo(const QString & demofilename);
 	void StartLocal();
 	void StartQuick();
@@ -75,7 +75,6 @@
     };
 	char msgbuf[MAXMSGCHARS];
 	QString teams[5];
-	std::map<QString, HWTeamTempParams> m_teamsParams;
 	QString seed;
 	int TeamCount;
 	GameUIConfig * config;
@@ -86,6 +85,7 @@
 	void commonConfig();
 	void SendConfig();
 	void SendQuickConfig();
+	void SendNetConfig();
 	void SendTeamConfig(int index);
 	void ParseMessage(const QByteArray & msg);
 	void SaveDemo(const QString & filename);
--- a/QTfrontend/hwform.cpp	Mon Jan 15 19:11:31 2007 +0000
+++ b/QTfrontend/hwform.cpp	Mon Jan 15 21:20:36 2007 +0000
@@ -217,7 +217,7 @@
 
 void HWForm::SimpleGame()
 {
-	CreateGame(ui.pageLocalGame->gameCFG);
+	CreateGame(ui.pageLocalGame->gameCFG, 0);
 	game->StartQuick();
 }
 
@@ -232,7 +232,7 @@
 				tr("OK"));
 		return ;
 	}
-	CreateGame(0);
+	CreateGame(0, 0);
 	game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_" + cProtoVer);
 }
 
@@ -321,13 +321,8 @@
 
 void HWForm::StartMPGame()
 {
-	CreateGame(ui.pageMultiplayer->gameCFG);
+	CreateGame(ui.pageMultiplayer->gameCFG, ui.pageMultiplayer->teamsSelect);
 
-	list<HWTeam> teamslist=ui.pageMultiplayer->teamsSelect->getPlayingTeams();
-	for (list<HWTeam>::const_iterator it = teamslist.begin(); it != teamslist.end(); ++it ) {
-	  HWTeamTempParams params=ui.pageMultiplayer->teamsSelect->getTeamParams(it->TeamName);
-	  game->AddTeam(it->TeamName, params);
-	}
 	game->StartLocal();
 }
 
@@ -375,9 +370,9 @@
 	}
 }
 
-void HWForm::CreateGame(GameCFGWidget * gamecfg)
+void HWForm::CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget)
 {
-	game = new HWGame(config, gamecfg);
+	game = new HWGame(config, gamecfg, pTeamSelWidget);
 	connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState)));
 	connect(game, SIGNAL(GameStats(char, const QString &)), this, SLOT(GameStats(char, const QString &)));
 }
--- a/QTfrontend/hwform.h	Mon Jan 15 19:11:31 2007 +0000
+++ b/QTfrontend/hwform.h	Mon Jan 15 21:20:36 2007 +0000
@@ -74,7 +74,7 @@
 private:
 	void _NetConnect(const QString & hostName, quint16 port, const QString & nick);
 	void UpdateTeamsLists();
-	void CreateGame(GameCFGWidget * gamecfg);
+	void CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget);
 	enum PageIDs {
 		ID_PAGE_SINGLEPLAYER	= 0,
 		ID_PAGE_SETUP_TEAM	= 1,
--- a/QTfrontend/newnetclient.cpp	Mon Jan 15 19:11:31 2007 +0000
+++ b/QTfrontend/newnetclient.cpp	Mon Jan 15 21:20:36 2007 +0000
@@ -70,11 +70,20 @@
   RawSendNet(QString("START:"));
 }
 
+void HWNewNet::SendConfigToEngine()
+{
+
+}
+
 void HWNewNet::SendNet(const QByteArray & buf)
 {
   QString msg = QString(buf.toBase64());
   qDebug() << "to net:" << buf << ":" << msg;
 
+  if(msg == "AUM=") {
+    SendConfigToEngine();
+    return ;
+  }
   //NetBuffer += buf;
   RawSendNet(QString("GAMEMSG:%1%2").arg(delimeter).arg(msg));
 }
--- a/QTfrontend/newnetclient.h	Mon Jan 15 19:11:31 2007 +0000
+++ b/QTfrontend/newnetclient.h	Mon Jan 15 21:20:36 2007 +0000
@@ -54,6 +54,7 @@
 
   void ConfigAsked();
   void RunGame();
+  void SendConfigToEngine();
 
   template <typename T>
   void SendCfgStrNet(T a) {
--- a/QTfrontend/team.cpp	Mon Jan 15 19:11:31 2007 +0000
+++ b/QTfrontend/team.cpp	Mon Jan 15 21:20:36 2007 +0000
@@ -203,23 +203,26 @@
 	}
 }
 
-QStringList HWTeam::TeamGameConfig(quint32 color, int hedgehogs, quint32 InitHealth, bool netTeam) const
+QStringList HWTeam::TeamGameConfig(quint32 InitHealth) const
 {
 	QStringList sl;
 	sl.push_back("eaddteam");
-	sl.push_back(QString("ecolor %1").arg(color));
+	if (netTeam)
+		sl.push_back("erdriven");
+	sl.push_back(QString("ecolor %1").arg(teamColor.rgb() & 0xffffff));
 	sl.push_back("ename team " + TeamName);
-	for (int i = 0; i < hedgehogs; i++)
+
+	for (int i = 0; i < numHedgehogs; i++)
 		sl.push_back(QString("ename hh%1 ").arg(i).append(HHName[i]));
-	if(!netTeam) {
-	  sl.push_back(QString("egrave " + Grave));
-	  sl.push_back(QString("efort " + Fort));
-	  for(int i = 0; i < BINDS_NUMBER; i++)
-	    {
-	      sl.push_back(QString("ebind " + binds[i].strbind + " " + binds[i].action));
-	    }
-	}
-	for (int t = 0; t < hedgehogs; t++)
+
+	sl.push_back(QString("egrave " + Grave));
+	sl.push_back(QString("efort " + Fort));
+
+	if (!netTeam)
+		for(int i = 0; i < BINDS_NUMBER; i++)
+			sl.push_back(QString("ebind " + binds[i].strbind + " " + binds[i].action));
+
+	for (int t = 0; t < numHedgehogs; t++)
 	  sl.push_back(QString("eaddhh %1 %2")
 		       .arg(QString::number(difficulty),
 			    QString::number(InitHealth)));
--- a/QTfrontend/team.h	Mon Jan 15 19:11:31 2007 +0000
+++ b/QTfrontend/team.h	Mon Jan 15 21:20:36 2007 +0000
@@ -43,13 +43,16 @@
 		QString Fort;
 		unsigned int difficulty;
 		BindAction binds[BINDS_NUMBER];
+
 		bool netTeam;
+		unsigned char numHedgehogs;
+		QColor teamColor;
 
 		bool LoadFromFile();
 		bool SaveToFile();
 		void SetToPage(HWForm * hwform);
 		void GetFromPage(HWForm * hwform);
-		QStringList TeamGameConfig(quint32 color, int hedgehogs, quint32 InitHealth, bool netTeam=false) const;
+		QStringList TeamGameConfig(quint32 InitHealth) const;
 
 		bool operator==(const HWTeam& t1) const;
 		bool operator<(const HWTeam& t1) const;
@@ -57,11 +60,4 @@
 		QString OldTeamName;
 };
 
-class HWTeamTempParams
-{
- public:
-  unsigned char numHedgehogs;
-  QColor teamColor;
-};
-
 #endif
--- a/QTfrontend/teamselect.cpp	Mon Jan 15 19:11:31 2007 +0000
+++ b/QTfrontend/teamselect.cpp	Mon Jan 15 21:20:36 2007 +0000
@@ -141,13 +141,6 @@
   return curPlayingTeams;
 }
 
-HWTeamTempParams TeamSelWidget::getTeamParams(HWTeam team) const
-{
-  const TeamShowWidget* tsw=dynamic_cast<TeamShowWidget*>(framePlaying->getTeamWidget(team));
-  if(!tsw) throw;
-  return tsw->getTeamParams();
-}
-
 void TeamSelWidget::newTeamClicked()
 {
 	emit NewTeam();
--- a/QTfrontend/teamselect.h	Mon Jan 15 19:11:31 2007 +0000
+++ b/QTfrontend/teamselect.h	Mon Jan 15 21:20:36 2007 +0000
@@ -43,7 +43,6 @@
   //void removeTeam(HWTeam team);
   void resetPlayingTeams(const QList<HWTeam>& teamslist);
   bool isPlaying(HWTeam team) const;
-  HWTeamTempParams getTeamParams(HWTeam team) const;
   list<HWTeam> getPlayingTeams() const;
 
  public slots:
@@ -52,7 +51,7 @@
  signals:
   void NewTeam();
   void teamWillPlay(HWTeam team);
-  
+
  private slots:
   void changeTeamStatus(HWTeam team);
   void newTeamClicked();
--- a/QTfrontend/teamselhelper.cpp	Mon Jan 15 19:11:31 2007 +0000
+++ b/QTfrontend/teamselhelper.cpp	Mon Jan 15 21:20:36 2007 +0000
@@ -80,14 +80,14 @@
   emit teamStatusChanged(m_team);
 }
 
-HWTeamTempParams TeamShowWidget::getTeamParams() const
+/*HWTeamTempParams TeamShowWidget::getTeamParams() const
 {
   if(!phhoger) throw;
   HWTeamTempParams params;
   params.numHedgehogs=phhoger->getHedgehogsNum();
   params.teamColor=colorButt->palette().color(QPalette::Button);
   return params;
-}
+}*/
 
 void TeamShowWidget::changeTeamColor()
 {
@@ -95,7 +95,7 @@
   if(++pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.end()) {
     pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.begin();
   }
-  
+
   QPalette newPalette = palette();
   newPalette.setColor(QPalette::Button, QColor(*pOurFrameTeams->currentColor));
   //colorButt->setStyleSheet(QString("background-color : ")+pOurFrameTeams->currentColor->name());
--- a/QTfrontend/teamselhelper.h	Mon Jan 15 19:11:31 2007 +0000
+++ b/QTfrontend/teamselhelper.h	Mon Jan 15 21:20:36 2007 +0000
@@ -53,8 +53,7 @@
  public:
  TeamShowWidget(HWTeam team, bool isPlaying, QWidget * parent);
  void setPlaying(bool isPlaying);
- HWTeamTempParams getTeamParams() const;
- 
+
  private:
  TeamShowWidget();
  QHBoxLayout mainLayout;