Predefined teams, 'simple game' doesn't need to create team
authorunc0rr
Tue, 25 Jul 2006 20:19:46 +0000
changeset 86 664b536a1c27
parent 85 44d9045b26ff
child 87 ff213e443336
Predefined teams, 'simple game' doesn't need to create team
QTfrontend/CMakeLists.txt
QTfrontend/game.cpp
QTfrontend/game.h
QTfrontend/hedgewars.pro
QTfrontend/hwform.cpp
QTfrontend/predefteams.h
QTfrontend/team.cpp
QTfrontend/team.h
QTfrontend/teamselhelper.cpp
--- a/QTfrontend/CMakeLists.txt	Tue Jul 25 13:32:11 2006 +0000
+++ b/QTfrontend/CMakeLists.txt	Tue Jul 25 20:19:46 2006 +0000
@@ -32,7 +32,8 @@
 	vertScrollArea.h
 	gameuiconfig.h
 	ui_hwform.h
-	gamecfgwidget.h)
+	gamecfgwidget.h
+	predefteams.h)
 
 
 set(hwfr_rez
--- a/QTfrontend/game.cpp	Tue Jul 25 13:32:11 2006 +0000
+++ b/QTfrontend/game.cpp	Tue Jul 25 20:19:46 2006 +0000
@@ -36,8 +36,9 @@
 #include <QTimer>
 #include <QString>
 #include <QByteArray>
+#include <QFile>
 #include <QTextStream>
-#include <QFile>
+
 #include "game.h"
 #include "hwconsts.h"
 #include "gameuiconfig.h"
@@ -85,42 +86,22 @@
 {
 	SendIPC(QString("eseed %1").arg(seed));
 	SendIPC(QString("etheme %1").arg(GetThemeBySeed()));
-	//SENDIPC("emap test");
 	SENDIPC("TL");
 	SendIPC(QString("e$gmflags %1").arg(gamecfg->getGameFlags()));
 	SENDIPC("eaddteam");
-	SendTeamConfig(0);
+	LocalCFG(0);
 	SENDIPC("ecolor 65535");
-	SENDIPC("eadd hh0 1");
-	SENDIPC("eadd hh1 1");
-	SENDIPC("eadd hh2 1");
-	SENDIPC("eadd hh3 1");
-	SENDIPC("eadd hh4 1");
-	SENDIPC("eadd hh5 1");
-	SENDIPC("eadd hh6 1");
-	SENDIPC("eadd hh7 1");
+	SENDIPC("eadd hh0 0");
+	SENDIPC("eadd hh1 0");
+	SENDIPC("eadd hh2 0");
+	SENDIPC("eadd hh3 0");
 	SENDIPC("eaddteam");
-	SendTeamConfig(1);
+	LocalCFG(1);
 	SENDIPC("ecolor 16776960");
 	SENDIPC("eadd hh0 1");
 	SENDIPC("eadd hh1 1");
 	SENDIPC("eadd hh2 1");
 	SENDIPC("eadd hh3 1");
-	SENDIPC("eadd hh4 1");
-	SENDIPC("eadd hh5 1");
-	SENDIPC("eadd hh6 1");
-	SENDIPC("eadd hh7 1");
-	SENDIPC("eaddteam");
-	SendTeamConfig(1);
-	SENDIPC("ecolor 255");
-	SENDIPC("eadd hh0 1");
-	SENDIPC("eadd hh1 1");
-	SENDIPC("eadd hh2 1");
-	SENDIPC("eadd hh3 1");
-	SENDIPC("eadd hh4 1");
-	SENDIPC("eadd hh5 1");
-	SENDIPC("eadd hh6 1");
-	SENDIPC("eadd hh7 1");
 }
 
 void HWGame::ParseMessage(const QByteArray & msg)
@@ -361,23 +342,31 @@
 	Start();
 }
 
+void HWGame::StartQuick()
+{
+	gameType = gtLocal;
+	seedgen.GenRNDStr(seed, 10);
+	Start();
+}
+
+
 void HWGame::LocalCFG(const QString & teamname)
 {
-	QFile teamcfg(config->cfgdir.absolutePath() + "/" + teamname + ".cfg");
-	if (!teamcfg.open(QIODevice::ReadOnly))
-	{
-		return ;
+	HWTeam team(teamname, config);
+	if (!team.LoadFromFile()) {
+		QMessageBox::critical(0,
+				"Error",
+				QString("Cannot load team config ""%1""").arg(teamname),
+				QMessageBox::Ok,
+				QMessageBox::NoButton,
+				QMessageBox::NoButton);
+		return;
 	}
-	QTextStream stream(&teamcfg);
-	stream.setCodec("UTF-8");
-	QString str;
+	RawSendIPC(team.IPCTeamInfo());
+}
 
-	while (!stream.atEnd())
-	{
-		str = stream.readLine();
-		if (str.startsWith(";") || (str.length() > 254)) continue;
-		str.prepend("e");
-		SendIPC(str.toUtf8());
-	}
-	teamcfg.close();
+void HWGame::LocalCFG(quint8 num)
+{
+	HWTeam team(num, config);
+	RawSendIPC(team.IPCTeamInfo());
 }
--- a/QTfrontend/game.h	Tue Jul 25 13:32:11 2006 +0000
+++ b/QTfrontend/game.h	Tue Jul 25 20:19:46 2006 +0000
@@ -58,6 +58,7 @@
 	void AddTeam(const QString & team);
 	void PlayDemo(const QString & demofilename);
 	void StartLocal();
+	void StartQuick();
 	void StartNet(const QString & netseed);
 
 signals:
@@ -66,6 +67,7 @@
 public slots:
 	void FromNet(const QByteArray & msg);
 	void LocalCFG(const QString & teamname);
+	void LocalCFG(quint8 num);
 
 private:
     enum GameType {
--- a/QTfrontend/hedgewars.pro	Tue Jul 25 13:32:11 2006 +0000
+++ b/QTfrontend/hedgewars.pro	Tue Jul 25 20:19:46 2006 +0000
@@ -24,7 +24,8 @@
            vertScrollArea.h \
            gameuiconfig.h \
            ui_hwform.h \
-           gamecfgwidget.h
+           gamecfgwidget.h \
+           predefteams.h
            
 SOURCES += game.cpp \
            main.cpp \
--- a/QTfrontend/hwform.cpp	Tue Jul 25 13:32:11 2006 +0000
+++ b/QTfrontend/hwform.cpp	Tue Jul 25 20:19:46 2006 +0000
@@ -105,10 +105,9 @@
 	QStringList teamslist = config->GetTeamsList();
 
 	if(teamslist.empty()) {
-	  HWTeam defaultTeam("DefaultTeam");
-	  defaultTeam.SetCfgDir(config->cfgdir.absolutePath());
-	  defaultTeam.SaveToFile();
-	  teamslist.push_back("DefaultTeam");
+		HWTeam defaultTeam("DefaultTeam", config);
+		defaultTeam.SaveToFile();
+		teamslist.push_back("DefaultTeam");
 	}
 
 	for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it )
@@ -190,16 +189,14 @@
 
 void HWForm::NewTeam()
 {
-	tmpTeam = new HWTeam("unnamed");
-	tmpTeam->SetCfgDir(config->cfgdir.absolutePath());
-	tmpTeam->SetToPage(this);
+	tmpTeam = new HWTeam("unnamed", config);
+
 	ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
 }
 
 void HWForm::EditTeam()
 {
-	tmpTeam = new HWTeam(ui.CBTeamName->currentText());
-	tmpTeam->SetCfgDir(config->cfgdir.absolutePath());
+	tmpTeam = new HWTeam(ui.CBTeamName->currentText(), config);
 	tmpTeam->LoadFromFile();
 	tmpTeam->SetToPage(this);
 	ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
@@ -221,9 +218,7 @@
 void HWForm::SimpleGame()
 {
 	game = new HWGame(config, ui.pageLGGameCFG);
-	game->AddTeam("DefaultTeam");
-	game->AddTeam("DefaultTeam");
-	game->StartLocal();
+	game->StartQuick();
 }
 
 void HWForm::CBGrave_activated(const QString & gravename)
@@ -291,8 +286,7 @@
 
 void HWForm::NetAddTeam()
 {
-	HWTeam team("DefaultTeam");
-	team.SetCfgDir(config->cfgdir.absolutePath());
+	HWTeam team("DefaultTeam", config);
 	team.LoadFromFile();
 	hwnet->AddTeam(team);
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/predefteams.h	Tue Jul 25 20:19:46 2006 +0000
@@ -0,0 +1,77 @@
+/*
+ * Hedgewars, a worms-like game
+ * Copyright (c) 2006 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * Distributed under the terms of the BSD-modified licence:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * with the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef PREDEFTEAMS_H
+#define PREDEFTEAMS_H
+
+#include <QtGlobal>
+
+#define PREDEFTEAMS_COUNT 2
+
+struct PredefinedTeam
+{
+	QString TeamName;
+	QString hh0name;
+	QString hh1name;
+	QString hh2name;
+	QString hh3name;
+	QString hh4name;
+	QString hh5name;
+	QString hh6name;
+	QString hh7name;
+	QString Grave;
+	QString Fort;
+};
+
+
+const PredefinedTeam pteams[PREDEFTEAMS_COUNT] =
+{
+	{
+		QT_TR_NOOP("Hedgehogs"),
+		QT_TR_NOOP("hedgehog 1"), QT_TR_NOOP("hedgehog 2"),
+		QT_TR_NOOP("hedgehog 3"), QT_TR_NOOP("hedgehog 4"),
+		QT_TR_NOOP("hedgehog 5"), QT_TR_NOOP("hedgehog 6"),
+		QT_TR_NOOP("hedgehog 7"), QT_TR_NOOP("hedgehog 8"),
+		"Simple", "Island"
+	},
+	{
+		QT_TR_NOOP("Goddess"),
+		QT_TR_NOOP("Isis"), QT_TR_NOOP("Astarte"),
+		QT_TR_NOOP("Diana"), QT_TR_NOOP("Aphrodite"),
+		QT_TR_NOOP("Hecate"), QT_TR_NOOP("Demeter"),
+		QT_TR_NOOP("Kali"), QT_TR_NOOP("Inanna"),
+		"Bone", "Island"
+	}
+};
+
+#endif // PREDEFTEAMS_H
--- a/QTfrontend/team.cpp	Tue Jul 25 13:32:11 2006 +0000
+++ b/QTfrontend/team.cpp	Tue Jul 25 20:19:46 2006 +0000
@@ -35,9 +35,12 @@
 #include <QTextStream>
 #include "team.h"
 #include "hwform.h"
+#include "gameuiconfig.h"
+#include "predefteams.h"
 
-HWTeam::HWTeam(const QString & teamname)
+HWTeam::HWTeam(const QString & teamname, GameUIConfig * config)
 {
+	this->config = config;
 	TeamName = teamname;
 	for (int i = 0; i < 8; i++) HHName[i].sprintf("hedgehog %d", i);
 	Grave = "Simple";
@@ -47,12 +50,29 @@
 		binds[i].action = cbinds[i].action;
 		binds[i].strbind = cbinds[i].strbind;
 	}
-	dir = "";
 }
 
+HWTeam::HWTeam(quint8 num, GameUIConfig * config)
+{
+	this->config = config;
+	num %= PREDEFTEAMS_COUNT;
+	TeamName = pteams[num].TeamName;
+	HHName[0] = pteams[num].hh0name;
+	HHName[1] = pteams[num].hh1name;
+	HHName[2] = pteams[num].hh2name;
+	HHName[3] = pteams[num].hh3name;
+	HHName[4] = pteams[num].hh4name;
+	HHName[5] = pteams[num].hh5name;
+	HHName[6] = pteams[num].hh6name;
+	HHName[7] = pteams[num].hh7name;
+	Grave = pteams[num].Grave;
+	Fort = pteams[num].Fort;
+}
+
+
 bool HWTeam::LoadFromFile()
 {
-	QFile cfgfile(dir + "/" + TeamName + ".cfg");
+	QFile cfgfile(config->cfgdir.absolutePath() + "/" + TeamName + ".cfg");
 	if (!cfgfile.open(QIODevice::ReadOnly)) return false;
 	QTextStream stream(&cfgfile);
 	stream.setCodec("UTF-8");
@@ -106,7 +126,7 @@
 
 bool HWTeam::SaveToFile()
 {
-	QFile cfgfile(dir + "/" + TeamName + ".cfg");
+	QFile cfgfile(config->cfgdir.absolutePath() + "/" + TeamName + ".cfg");
 	if (!cfgfile.open(QIODevice::WriteOnly)) return false;
 	QTextStream stream(&cfgfile);
 	stream.setCodec("UTF-8");
@@ -159,7 +179,26 @@
 	}
 }
 
-void HWTeam::SetCfgDir(const QString & dir)
+QByteArray HWTeam::IPCTeamInfo() const
 {
-	this->dir = dir;
+	QByteArray buf;
+	#define ADD(a) { \
+					QByteArray strmsg = a.toUtf8(); \
+					quint8 sz = strmsg.size(); \
+					buf.append(QByteArray((char *)&sz, 1)); \
+					buf.append(strmsg); \
+					}
+
+	ADD(QString("ename team " + TeamName));
+	for (int i = 0; i < 8; i++)
+		ADD(QString("ename hh%1 ").arg(i).append(HHName[i]));
+	ADD(QString("egrave " + Grave));
+	ADD(QString("efort " + Fort));
+	for(int i = 0; i < BINDS_NUMBER; i++)
+	{
+		ADD(QString("ebind " + binds[i].strbind + " " + binds[i].action));
+	}
+	#undef ADD
+	return buf;
 }
+
--- a/QTfrontend/team.h	Tue Jul 25 13:32:11 2006 +0000
+++ b/QTfrontend/team.h	Tue Jul 25 20:19:46 2006 +0000
@@ -1,61 +1,64 @@
-/*
- * Hedgewars, a worms-like game
- * Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
- *
- * Distributed under the terms of the BSD-modified licence:
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * with the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
- * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef TEAM_H
-#define TEAM_H
-
-#include <QString>
-#include "binds.h"
-
-class HWForm;
-class HWTeam
-{
-	public:
-		HWTeam(const QString & teamname);
-		
-		QString TeamName;
-		QString HHName[8];
-		QString	Grave;
-		QString Fort;
-		QString dir;
-		BindAction binds[BINDS_NUMBER];
-		
-		void SetCfgDir(const QString & dir);
-		bool LoadFromFile();
-		bool SaveToFile();
-		void SetToPage(HWForm * hwform);
-		void GetFromPage(HWForm * hwform);
-	private:
-};
-
-#endif
+/*
+ * Hedgewars, a worms-like game
+ * Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * Distributed under the terms of the BSD-modified licence:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * with the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TEAM_H
+#define TEAM_H
+
+#include <QString>
+#include "binds.h"
+
+class HWForm;
+class GameUIConfig;
+
+class HWTeam
+{
+	public:
+		HWTeam(const QString & teamname, GameUIConfig * config);
+		HWTeam(quint8 num, GameUIConfig * config);
+
+		QString TeamName;
+		QString HHName[8];
+		QString	Grave;
+		QString Fort;
+		BindAction binds[BINDS_NUMBER];
+
+		bool LoadFromFile();
+		bool SaveToFile();
+		void SetToPage(HWForm * hwform);
+		void GetFromPage(HWForm * hwform);
+		QByteArray IPCTeamInfo() const;
+	private:
+		GameUIConfig * config;
+};
+
+#endif
--- a/QTfrontend/teamselhelper.cpp	Tue Jul 25 13:32:11 2006 +0000
+++ b/QTfrontend/teamselhelper.cpp	Tue Jul 25 20:19:46 2006 +0000
@@ -11,7 +11,7 @@
 TeamShowWidget::TeamShowWidget(tmprop team, QWidget * parent) :
   QWidget(parent), mainLayout(this), m_team(team)
 {
-  this->setMaximumHeight(30);
+  this->setMaximumHeight(40);
   QLabel* pixlbl=new QLabel();
   pixlbl->setPixmap(QPixmap("./Data/Graphics/thinking.png"));
   mainLayout.addWidget(pixlbl);
@@ -21,7 +21,7 @@
 
   QPushButton* butt=new QPushButton("o");
   butt->setGeometry(0, 0, 25, 25);
-  butt->setMaximumWidth(25);
+  butt->setMaximumWidth(30);
   mainLayout.addWidget(butt);
 
   QObject::connect(butt, SIGNAL(clicked()), this, SLOT(activateTeam()));