first buggy hedgehogs num net change
authordisplacer
Sun, 21 Jan 2007 19:53:25 +0000
changeset 352 4665bfe25470
parent 351 29bc9c36ad5f
child 353 5ec611d702a0
first buggy hedgehogs num net change
QTfrontend/frameTeam.cpp
QTfrontend/frameTeam.h
QTfrontend/game.cpp
QTfrontend/hedgehogerWidget.cpp
QTfrontend/hedgehogerWidget.h
QTfrontend/hwform.cpp
QTfrontend/netserver.cpp
QTfrontend/netserver.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	Sun Jan 21 19:51:02 2007 +0000
+++ b/QTfrontend/frameTeam.cpp	Sun Jan 21 19:53:25 2007 +0000
@@ -62,6 +62,13 @@
   teamToWidget.erase(it);
 }
 
+void FrameTeams::setHHNum(const HWTeam& team)
+{
+  TeamShowWidget* pTeamShowWidget = dynamic_cast<TeamShowWidget*>(getTeamWidget(team));
+  if(!pTeamShowWidget) throw;
+  pTeamShowWidget->setHHNum(team.numHedgehogs);
+}
+
 QWidget* FrameTeams::getTeamWidget(HWTeam team)
 {
   tmapTeamToWidget::iterator it=teamToWidget.find(team);
--- a/QTfrontend/frameTeam.h	Sun Jan 21 19:51:02 2007 +0000
+++ b/QTfrontend/frameTeam.h	Sun Jan 21 19:53:25 2007 +0000
@@ -38,6 +38,7 @@
   QWidget* getTeamWidget(HWTeam team);
   bool isFullTeams() const;
   void resetColors();
+  void setHHNum(const HWTeam& team);
 
  public slots:
   void addTeam(HWTeam team, bool willPlay);
--- a/QTfrontend/game.cpp	Sun Jan 21 19:51:02 2007 +0000
+++ b/QTfrontend/game.cpp	Sun Jan 21 19:53:25 2007 +0000
@@ -77,11 +77,11 @@
 	if (m_pTeamSelWidget)
 	{
 		qDebug() << "adding teams from teamselwidget...";
-		QList<HWTeam> teams = QList<HWTeam>::fromStdList(m_pTeamSelWidget->getPlayingTeams());
+		QList<HWTeam> teams = m_pTeamSelWidget->getPlayingTeams();
 		for(QList<HWTeam>::iterator it = teams.begin(); it != teams.end(); ++it)
 		{
 			qDebug() << "a team...";
-			(*it).numHedgehogs = 4;
+			//(*it).numHedgehogs = 4;
 			HWProto::addStringListToBuffer(buf,
 				(*it).TeamGameConfig(gamecfg->getInitHealth()));
 		}
--- a/QTfrontend/hedgehogerWidget.cpp	Sun Jan 21 19:51:02 2007 +0000
+++ b/QTfrontend/hedgehogerWidget.cpp	Sun Jan 21 19:53:25 2007 +0000
@@ -47,12 +47,14 @@
     if(numHedgehogs < 8 && pOurFrameTeams->overallHedgehogs<18) {
       numHedgehogs++;
       pOurFrameTeams->overallHedgehogs++;
+      emit hedgehogsNumChanged();
     }
   } else if (event->button()==Qt::RightButton) {
     event->accept();
     if(numHedgehogs > 3) {
       numHedgehogs--;
       pOurFrameTeams->overallHedgehogs--;
+      emit hedgehogsNumChanged();
     }
   } else {
     event->ignore();
@@ -61,6 +63,14 @@
   repaint();
 }
 
+void CHedgehogerWidget::setHHNum(unsigned int num)
+{
+  unsigned int diff=numHedgehogs-num;
+  numHedgehogs=num;
+  pOurFrameTeams->overallHedgehogs+=diff;
+  repaint();
+}
+
 void CHedgehogerWidget::paintEvent(QPaintEvent* event)
 {
   QImage image(":/res/hh25x25.png");
--- a/QTfrontend/hedgehogerWidget.h	Sun Jan 21 19:51:02 2007 +0000
+++ b/QTfrontend/hedgehogerWidget.h	Sun Jan 21 19:53:25 2007 +0000
@@ -31,6 +31,10 @@
   CHedgehogerWidget(QWidget * parent);
   ~CHedgehogerWidget();
   unsigned char getHedgehogsNum() const;
+  void setHHNum (unsigned int num);
+
+ signals:
+  void hedgehogsNumChanged();
 
  protected:
   virtual void paintEvent(QPaintEvent* event);
--- a/QTfrontend/hwform.cpp	Sun Jan 21 19:51:02 2007 +0000
+++ b/QTfrontend/hwform.cpp	Sun Jan 21 19:53:25 2007 +0000
@@ -246,6 +246,8 @@
 	connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter()));
 	connect(hwnet, SIGNAL(AddNetTeam(const HWTeam&)), this, SLOT(AddNetTeam(const HWTeam&)));
 
+	connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(hhogsNumChanged(const HWTeam&)),
+		hwnet, SLOT(onHedgehogsNumChanged(const HWTeam&)));
 	connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamWillPlay(HWTeam)), hwnet, SLOT(AddTeam(HWTeam)));
 	connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamNotPlaying(const HWTeam&)), hwnet, SLOT(RemoveTeam(const HWTeam&)));
 
@@ -262,6 +264,8 @@
 	connect(hwnet, SIGNAL(initHealthChanged(quint32)), ui.pageNetGame->pGameCFG, SLOT(setInitHealth(quint32)));
 	connect(hwnet, SIGNAL(turnTimeChanged(quint32)), ui.pageNetGame->pGameCFG, SLOT(setTurnTime(quint32)));
 	connect(hwnet, SIGNAL(fortsModeChanged(bool)), ui.pageNetGame->pGameCFG, SLOT(setFortsMode(bool)));
+	connect(hwnet, SIGNAL(hhnumChanged(const HWTeam&)), 
+		ui.pageNetGame->pNetTeamsWidget, SLOT(changeHHNum(const HWTeam&)));
 
 
 	hwnet->Connect(hostName, port, nick);
--- a/QTfrontend/netserver.cpp	Sun Jan 21 19:51:02 2007 +0000
+++ b/QTfrontend/netserver.cpp	Sun Jan 21 19:53:25 2007 +0000
@@ -241,27 +241,36 @@
   if(lst[0]=="ADDTEAM:") {
     if(lst.size()<10) return;
     lst.pop_front();
+    // add team ID
+    static unsigned int netTeamID=1;
+    lst.insert(1, QString::number(netTeamID++));
+
     m_teamsCfg.push_back(lst);
-    m_hwserver->sendOthers(this, msg);
+    m_hwserver->sendOthers(this, QString("ADDTEAM:")+delimeter+lst.join(QString(delimeter)));
     return;
   }
 
   if(lst[0]=="REMOVETEAM:") {
     if(lst.size()<2) return;
-    removeTeam(lst[1]);
+    unsigned int netID=removeTeam(lst[1]);
+    m_hwserver->sendOthers(this, QString("REMOVETEAM:")+delimeter+lst[1]+delimeter+QString::number(netID));
+    return;
   }
 
   m_hwserver->sendOthers(this, msg);
 }
 
-void HWConnectedClient::removeTeam(const QString& tname)
+unsigned int HWConnectedClient::removeTeam(const QString& tname)
 {
+  unsigned int netID=0;
   for(QList<QStringList>::iterator it=m_teamsCfg.begin(); it!=m_teamsCfg.end(); ++it) {
     if((*it)[0]==tname) {
+      netID=(*it)[1].toUInt();
       m_teamsCfg.erase(it);
       break;
     }
   }
+  return netID;
 }
 
 QList<QStringList> HWConnectedClient::getTeamNames() const
--- a/QTfrontend/netserver.h	Sun Jan 21 19:51:02 2007 +0000
+++ b/QTfrontend/netserver.h	Sun Jan 21 19:53:25 2007 +0000
@@ -53,7 +53,7 @@
 
   QString client_nick;
   void ParseLine(const QByteArray & line);
-  void removeTeam(const QString& tname);
+  unsigned int removeTeam(const QString& tname); // returns netID
 
   HWNetServer* m_hwserver;
   QTcpSocket* m_client;
--- a/QTfrontend/newnetclient.cpp	Sun Jan 21 19:51:02 2007 +0000
+++ b/QTfrontend/newnetclient.cpp	Sun Jan 21 19:53:25 2007 +0000
@@ -168,8 +168,8 @@
   }
 
   if (lst[0] == "REMOVETEAM:") {
-    if(lst.size()<2) return;
-    m_pTeamSelWidget->removeNetTeam(HWTeam(lst[1], true));
+    if(lst.size()<3) return;
+    m_pTeamSelWidget->removeNetTeam(HWTeam(lst[1], lst[2].toUInt()));
     return;
   }
 
@@ -229,6 +229,12 @@
 	  emit fortsModeChanged(lst[2].toInt() != 0);
 	  return;
   	}
+  	if (lst[1] == "HHNUM") {
+	  HWTeam tmptm(lst[2], lst[3].toUInt());
+	  tmptm.numHedgehogs=lst[4].toUInt();
+	  emit hhnumChanged(tmptm);
+	  return;
+  	}
   	qDebug() << "unknow config param: " << lst[1];
     return;
   }
@@ -265,6 +271,12 @@
   game->StartNet();
 }
 
+void HWNewNet::onHedgehogsNumChanged(const HWTeam& team)
+{
+  qDebug() << team.getNetID() << ":" << team.numHedgehogs;
+  RawSendNet(QString("CONFIG_PARAM%1HHNUM%1%2%1%3%1%4").arg(delimeter).arg(team.TeamName).arg(team.getNetID()).arg(team.numHedgehogs));
+}
+
 void HWNewNet::onSeedChanged(const QString & seed)
 {
   RawSendNet(QString("CONFIG_PARAM%1SEED%1%2").arg(delimeter).arg(seed));
--- a/QTfrontend/newnetclient.h	Sun Jan 21 19:51:02 2007 +0000
+++ b/QTfrontend/newnetclient.h	Sun Jan 21 19:53:25 2007 +0000
@@ -94,6 +94,7 @@
   void initHealthChanged(quint32 health);
   void turnTimeChanged(quint32 time);
   void fortsModeChanged(bool value);
+  void hhnumChanged(const HWTeam&);
 
  public slots:
   void SendNet(const QByteArray & buf);
@@ -105,6 +106,7 @@
   void onInitHealthChanged(quint32 health);
   void onTurnTimeChanged(quint32 time);
   void onFortsModeChanged(bool value);
+  void onHedgehogsNumChanged(const HWTeam& team);
 
  private slots:
   void ClientRead();
--- a/QTfrontend/team.cpp	Sun Jan 21 19:51:02 2007 +0000
+++ b/QTfrontend/team.cpp	Sun Jan 21 19:53:25 2007 +0000
@@ -29,9 +29,9 @@
 #include <QStringList>
 #include <QDebug>
 
-HWTeam::HWTeam(const QString & teamname, bool isNet) :
+HWTeam::HWTeam(const QString & teamname, unsigned int netID) :
   difficulty(0),
-  netTeam(isNet)
+  m_netID(netID)
 {
 	TeamName = teamname;
 	OldTeamName = TeamName;
@@ -45,18 +45,18 @@
 	}
 }
 
-HWTeam::HWTeam(const QStringList& strLst) :
-  netTeam(true)
+HWTeam::HWTeam(const QStringList& strLst)
 {
   // net teams are configured from QStringList
-  if(strLst.size()<9) throw HWTeamConstructException();
+  if(strLst.size()<10) throw HWTeamConstructException();
   TeamName=strLst[0];
-  for(int i = 0; i < 8; i++) HHName[i]=strLst[i+1];
+  m_netID=strLst[1].toUInt();
+  for(int i = 0; i < 8; i++) HHName[i]=strLst[i+2];
 }
 
 HWTeam::HWTeam(quint8 num) :
   difficulty(0),
-  netTeam(false)
+  m_netID(0)
 {
 	num %= PREDEFTEAMS_COUNT;
 	TeamName = QApplication::translate("teams", pteams[num].TeamName);
@@ -207,7 +207,7 @@
 {
 	QStringList sl;
 	sl.push_back("eaddteam");
-	if (netTeam)
+	if (m_netID)
 		sl.push_back("erdriven");
 	sl.push_back(QString("ecolor %1").arg(teamColor.rgb() & 0xffffff));
 	sl.push_back("ename team " + TeamName);
@@ -218,7 +218,7 @@
 	sl.push_back(QString("egrave " + Grave));
 	sl.push_back(QString("efort " + Fort));
 
-	if (!netTeam)
+	if (!m_netID)
 		for(int i = 0; i < BINDS_NUMBER; i++)
 			sl.push_back(QString("ebind " + binds[i].strbind + " " + binds[i].action));
 
@@ -229,10 +229,20 @@
 	return sl;
 }
 
+bool HWTeam::isNetTeam() const
+{
+  return m_netID!=0;
+}
+
+unsigned int HWTeam::getNetID() const
+{
+  return m_netID;
+}
+
 bool HWTeam::operator==(const HWTeam& t1) const {
-  return TeamName==t1.TeamName && netTeam==t1.netTeam;
+  return TeamName==t1.TeamName && m_netID==t1.m_netID;
 }
 
 bool HWTeam::operator<(const HWTeam& t1) const {
-  return TeamName<t1.TeamName || (netTeam < t1.netTeam); // if names are equal - test if it is net team
+  return m_netID<t1.m_netID || TeamName<t1.TeamName; // if names are equal - test if it is net team
 }
--- a/QTfrontend/team.h	Sun Jan 21 19:51:02 2007 +0000
+++ b/QTfrontend/team.h	Sun Jan 21 19:53:25 2007 +0000
@@ -33,10 +33,13 @@
 class HWTeam
 {
 	public:
-		HWTeam(const QString & teamname, bool isNet=false);
+		HWTeam(const QString & teamname, unsigned int netID=0);
 		HWTeam(const QStringList& strLst);
 		HWTeam(quint8 num);
 
+		bool isNetTeam() const;
+		unsigned int getNetID() const;
+
 		QString TeamName;
 		QString HHName[8];
 		QString	Grave;
@@ -44,7 +47,6 @@
 		unsigned int difficulty;
 		BindAction binds[BINDS_NUMBER];
 
-		bool netTeam;
 		unsigned char numHedgehogs;
 		QColor teamColor;
 
@@ -57,6 +59,7 @@
 		bool operator==(const HWTeam& t1) const;
 		bool operator<(const HWTeam& t1) const;
 	private:
+		unsigned int m_netID;
 		QString OldTeamName;
 };
 
--- a/QTfrontend/teamselect.cpp	Sun Jan 21 19:51:02 2007 +0000
+++ b/QTfrontend/teamselect.cpp	Sun Jan 21 19:53:25 2007 +0000
@@ -28,10 +28,10 @@
 
 void TeamSelWidget::addTeam(HWTeam team)
 {
-  if(team.netTeam) {
+  if(team.isNetTeam()) {
     framePlaying->addTeam(team, true);
     curPlayingTeams.push_back(team);
-    QObject::connect(framePlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
+    connect(framePlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
 		     this, SLOT(netTeamStatusChanged(const HWTeam&)));
   } else {
     frameDontPlaying->addTeam(team, false);
@@ -41,12 +41,27 @@
   }
 }
 
+void TeamSelWidget::hhNumChanged(const HWTeam& team)
+{
+  QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
+  itPlay->numHedgehogs=team.numHedgehogs;
+  emit hhogsNumChanged(team);
+}
+
+void TeamSelWidget::changeHHNum(const HWTeam& team)
+{
+  QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
+  itPlay->numHedgehogs=team.numHedgehogs;
+
+  framePlaying->setHHNum(team);
+}
+
 void TeamSelWidget::removeNetTeam(const HWTeam& team)
 {
   for(;;) {
-    list<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
+    QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
     if(itPlay==curPlayingTeams.end()) break;
-    if(itPlay->netTeam) {
+    if(itPlay->isNetTeam()) {
       QObject::disconnect(framePlaying->getTeamWidget(*itPlay), SIGNAL(teamStatusChanged(HWTeam)));
       framePlaying->removeTeam(team);
       curPlayingTeams.erase(itPlay);
@@ -57,7 +72,7 @@
 
 void TeamSelWidget::netTeamStatusChanged(const HWTeam& team)
 {
-  list<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
+  QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
   
 }
 
@@ -68,8 +83,8 @@
 
 void TeamSelWidget::changeTeamStatus(HWTeam team)
 {
-  list<HWTeam>::iterator itDontPlay=std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team);
-  list<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
+  QList<HWTeam>::iterator itDontPlay=std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team);
+  QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
 
   bool willBePlaying=itDontPlay!=curDontPlayingTeams.end();
 
@@ -101,6 +116,8 @@
   pRemoveTeams->removeTeam(team);
   QObject::connect(pAddTeams->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
 		   this, SLOT(changeTeamStatus(HWTeam)));
+  if(willBePlaying) connect(framePlaying->getTeamWidget(team), SIGNAL(hhNmChanged(const HWTeam&)), 
+			    this, SLOT(hhNumChanged(const HWTeam&)));
 
   QSize szh=pAddTeams->sizeHint();
   QSize szh1=pRemoveTeams->sizeHint();
@@ -138,7 +155,7 @@
 
 void TeamSelWidget::resetPlayingTeams(const QList<HWTeam>& teamslist)
 {
-  list<HWTeam>::iterator it;
+  QList<HWTeam>::iterator it;
   for(it=curPlayingTeams.begin(); it!=curPlayingTeams.end(); it++) {
     framePlaying->removeTeam(*it);
   }
@@ -159,7 +176,7 @@
   return std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team)!=curPlayingTeams.end();
 }
 
-list<HWTeam> TeamSelWidget::getPlayingTeams() const
+QList<HWTeam> TeamSelWidget::getPlayingTeams() const
 {
   return curPlayingTeams;
 }
--- a/QTfrontend/teamselect.h	Sun Jan 21 19:51:02 2007 +0000
+++ b/QTfrontend/teamselect.h	Sun Jan 21 19:53:25 2007 +0000
@@ -43,20 +43,23 @@
   void removeNetTeam(const HWTeam& team);
   void resetPlayingTeams(const QList<HWTeam>& teamslist);
   bool isPlaying(HWTeam team) const;
-  list<HWTeam> getPlayingTeams() const;
+  QList<HWTeam> getPlayingTeams() const;
 
  public slots:
   void addTeam(HWTeam team);
   void netTeamStatusChanged(const HWTeam& team);
+  void changeHHNum(const HWTeam&);
   
  signals:
   void NewTeam();
   void teamWillPlay(HWTeam team);
   void teamNotPlaying(const HWTeam& team);
+  void hhogsNumChanged(const HWTeam&);
   
  private slots:
   void changeTeamStatus(HWTeam team);
   void newTeamClicked();
+  void hhNumChanged(const HWTeam& team);
 
  private:
   void addScrArea(FrameTeams* pfteams, QColor color, int maxHeight);
@@ -66,8 +69,8 @@
   QVBoxLayout mainLayout;
   QPushButton * newTeam;
 
-  list<HWTeam> curPlayingTeams;
-  list<HWTeam> curDontPlayingTeams;
+  QList<HWTeam> curPlayingTeams;
+  QList<HWTeam> curDontPlayingTeams;
 };
 
 #endif // _TEAM_SELECT_INCLUDED
--- a/QTfrontend/teamselhelper.cpp	Sun Jan 21 19:51:02 2007 +0000
+++ b/QTfrontend/teamselhelper.cpp	Sun Jan 21 19:53:25 2007 +0000
@@ -36,7 +36,7 @@
   mainLayout.setSpacing(1);
   mainLayout.setMargin(2);
   this->setMaximumHeight(35);
-  QIcon difficultyIcon=team.netTeam ? QIcon(QString(":/res/net.png"))
+  QIcon difficultyIcon=team.isNetTeam() ? QIcon(QString(":/res/net.png"))
     : QIcon(QString(":/res/botlevels/%1.png").arg(m_team.difficulty));
 
   QPalette newPalette = palette();
@@ -68,6 +68,7 @@
 
     // hedgehogs num
     phhoger=new CHedgehogerWidget(this);
+    connect(phhoger, SIGNAL(hedgehogsNumChanged()), this, SLOT(hhNumChanged()));
     mainLayout.addWidget(phhoger);
   }
 
@@ -75,6 +76,17 @@
   QObject::connect(bText, SIGNAL(clicked()), this, SLOT(activateTeam()));
 }
 
+void TeamShowWidget::setHHNum(unsigned int num)
+{
+  phhoger->setHHNum(num);
+}
+
+void TeamShowWidget::hhNumChanged()
+{
+  m_team.numHedgehogs=phhoger->getHedgehogsNum();
+  emit hhNmChanged(m_team);
+}
+
 void TeamShowWidget::activateTeam()
 {
   emit teamStatusChanged(m_team);
--- a/QTfrontend/teamselhelper.h	Sun Jan 21 19:51:02 2007 +0000
+++ b/QTfrontend/teamselhelper.h	Sun Jan 21 19:53:25 2007 +0000
@@ -53,6 +53,7 @@
  public:
  TeamShowWidget(HWTeam team, bool isPlaying, QWidget * parent);
  void setPlaying(bool isPlaying);
+ void setHHNum(unsigned int num);
 
  private:
  TeamShowWidget();
@@ -62,8 +63,12 @@
  CHedgehogerWidget* phhoger;
  QPushButton* colorButt;
 
+ private slots:
+  void hhNumChanged();
+
  signals:
  void teamStatusChanged(HWTeam team);
+ void hhNmChanged(const HWTeam&);
 };
 
 #endif // _TEAMSEL_HELPER_INCLUDED