- Better blowtorch
authorunc0rr
Thu, 04 Jan 2007 16:27:45 +0000
changeset 306 7b61834edcf6
parent 305 1c1cd66ffcdc
child 307 96b428ac11f2
- Better blowtorch - Round statistics (only show winner now)
QTfrontend/game.cpp
QTfrontend/game.h
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/pages.cpp
QTfrontend/pages.h
QTfrontend/ui_hwform.cpp
QTfrontend/ui_hwform.h
hedgewars/GSHandlers.inc
hedgewars/uConsts.pas
hedgewars/uGears.pas
hedgewars/uMisc.pas
hedgewars/uTeams.pas
--- a/QTfrontend/game.cpp	Tue Dec 19 17:20:14 2006 +0000
+++ b/QTfrontend/game.cpp	Thu Jan 04 16:27:45 2007 +0000
@@ -44,6 +44,7 @@
 void HWGame::onClientDisconnect()
 {
 	SaveDemo(cfgdir->absolutePath() + "/Demos/LastRound.hwd_" + cProtoVer);
+	emit GameStateChanged(gsFinished);
 }
 
 void HWGame::SendTeamConfig(int index)
@@ -99,7 +100,7 @@
 
 void HWGame::ParseMessage(const QByteArray & msg)
 {
-	switch(msg.data()[1]) {
+	switch(msg.at(1)) {
 		case '?': {
 			if (gameType == gtNet)
 				emit SendNet(QByteArray("\x01""?"));
@@ -155,6 +156,10 @@
 			}
 			break;
 		}
+		case 'i': {
+			emit GameStats(msg.at(2), QString::fromUtf8(msg.mid(3)));
+			break;
+		}
 		default: {
 			if (gameType == gtNet)
 			{
@@ -257,6 +262,7 @@
 	// run engine
 	demo = new QByteArray;
 	Start();
+	emit GameStateChanged(gsStarted);
 }
 
 void HWGame::StartNet()
@@ -264,6 +270,7 @@
 	gameType = gtNet;
 	demo = new QByteArray;
 	Start();
+	emit GameStateChanged(gsStarted);
 }
 
 void HWGame::StartLocal()
@@ -273,6 +280,7 @@
 	seed = gamecfg->getCurrentSeed();
 	demo = new QByteArray;
 	Start();
+	emit GameStateChanged(gsStarted);
 }
 
 void HWGame::StartQuick()
@@ -281,6 +289,7 @@
 	seed = gamecfg->getCurrentSeed();
 	demo = new QByteArray;
 	Start();
+	emit GameStateChanged(gsStarted);
 }
 
 
--- a/QTfrontend/game.h	Tue Dec 19 17:20:14 2006 +0000
+++ b/QTfrontend/game.h	Thu Jan 04 16:27:45 2007 +0000
@@ -31,6 +31,13 @@
 class GameUIConfig;
 class GameCFGWidget;
 
+enum GameState {
+	gsNotStarted = 0,
+	gsStarted  = 1,
+	gsFinished = 2
+};
+
+
 class HWGame : public TCPBase
 {
 	Q_OBJECT
@@ -49,6 +56,8 @@
 
 signals:
 	void SendNet(const QByteArray & msg);
+	void GameStateChanged(GameState gameState);
+	void GameStats(char type, const QString & info);
 
 public slots:
 	void FromNet(const QByteArray & msg);
--- a/QTfrontend/hwform.cpp	Tue Dec 19 17:20:14 2006 +0000
+++ b/QTfrontend/hwform.cpp	Thu Jan 04 16:27:45 2007 +0000
@@ -83,6 +83,8 @@
 
 	connect(ui.pageInfo->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoBack()));
 
+	connect(ui.pageGameStats->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoBack()));
+
 	GoToPage(ID_PAGE_MAIN);
 }
 
@@ -199,7 +201,7 @@
 
 void HWForm::SimpleGame()
 {
-	game = new HWGame(config, ui.pageLocalGame->gameCFG);
+	CreateGame(ui.pageLocalGame->gameCFG);
 	game->StartQuick();
 }
 
@@ -214,7 +216,7 @@
 				tr("OK"));
 		return ;
 	}
-	game = new HWGame(config, 0);
+	CreateGame(0);
 	game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_" + cProtoVer);
 }
 
@@ -275,7 +277,8 @@
 
 void HWForm::StartMPGame()
 {
-	game = new HWGame(config, ui.pageMultiplayer->gameCFG);
+	CreateGame(ui.pageMultiplayer->gameCFG);
+
 	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);
@@ -283,3 +286,23 @@
 	}
 	game->StartLocal();
 }
+
+void HWForm::GameStateChanged(GameState gameState)
+{
+	if (gameState == gsStarted)
+		GoToPage(ID_PAGE_GAMESTATS);
+}
+
+void HWForm::GameStats(char type, const QString & info)
+{
+	switch(type) {
+		case 'r' : { ui.pageGameStats->labelGameResult->setText(info); break; }
+	}
+}
+
+void HWForm::CreateGame(GameCFGWidget * gamecfg)
+{
+	game = new HWGame(config, gamecfg);
+	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	Tue Dec 19 17:20:14 2006 +0000
+++ b/QTfrontend/hwform.h	Thu Jan 04 16:27:45 2007 +0000
@@ -24,6 +24,7 @@
 #include <QDir>
 #include <QStack>
 
+#include "game.h"
 #include "ui_hwform.h"
 
 class HWGame;
@@ -66,6 +67,8 @@
 	void NetStartGame();
 	void ChangeInNetTeams(const QStringList & teams);
 	void StartMPGame();
+	void GameStateChanged(GameState gameState);
+	void GameStats(char type, const QString & info);
 
 private:
 	void UpdateTeamsLists();
@@ -79,13 +82,16 @@
 		ID_PAGE_NETCHAT	= 6,
 		ID_PAGE_NETCFG	= 7,
 		ID_PAGE_INFO	= 8,
-		ID_PAGE_MAIN	= 9
+		ID_PAGE_MAIN	= 9,
+		ID_PAGE_GAMESTATS = 10
 		};
 	HWGame * game;
 	HWTeam * editedTeam;
 	HWNet * hwnet;
 	GameUIConfig * config;
 	QStack<quint8> PagesStack;
+
+	void CreateGame(GameCFGWidget * gamecfg);
 };
 
 #endif
--- a/QTfrontend/pages.cpp	Tue Dec 19 17:20:14 2006 +0000
+++ b/QTfrontend/pages.cpp	Thu Jan 04 16:27:45 2007 +0000
@@ -480,3 +480,21 @@
 	about = new About(this);
 	pageLayout->addWidget(about, 0, 0, 1, 3);
 }
+
+PageGameStats::PageGameStats(QWidget* parent) : QWidget(parent)
+{
+	QFont * font14 = new QFont("MS Shell Dlg", 14);
+	QGridLayout * pageLayout = new QGridLayout(this);
+	pageLayout->setColumnStretch(0, 1);
+	pageLayout->setColumnStretch(1, 1);
+	pageLayout->setColumnStretch(2, 1);
+
+	BtnBack = new QPushButton(this);
+	BtnBack->setFont(*font14);
+	BtnBack->setText(QPushButton::tr("Back"));
+	pageLayout->addWidget(BtnBack, 1, 0);
+
+	labelGameResult = new QLabel(this);
+	labelGameResult->setFont(*font14);
+	pageLayout->addWidget(labelGameResult, 0, 1);
+}
--- a/QTfrontend/pages.h	Tue Dec 19 17:20:14 2006 +0000
+++ b/QTfrontend/pages.h	Thu Jan 04 16:27:45 2007 +0000
@@ -201,4 +201,16 @@
 	About *about;
 };
 
+class PageGameStats : public QWidget
+{
+	Q_OBJECT
+
+public:
+	PageGameStats(QWidget* parent = 0);
+
+	QPushButton *BtnBack;
+	QLabel *labelGameResult;
+};
+
+
 #endif // PAGES_H
--- a/QTfrontend/ui_hwform.cpp	Tue Dec 19 17:20:14 2006 +0000
+++ b/QTfrontend/ui_hwform.cpp	Thu Jan 04 16:27:45 2007 +0000
@@ -79,4 +79,7 @@
 
 	pageMain = new PageMain();
 	Pages->addWidget(pageMain);
+
+	pageGameStats = new PageGameStats();
+	Pages->addWidget(pageGameStats);
 }
--- a/QTfrontend/ui_hwform.h	Tue Dec 19 17:20:14 2006 +0000
+++ b/QTfrontend/ui_hwform.h	Thu Jan 04 16:27:45 2007 +0000
@@ -46,6 +46,7 @@
 class PageNetChat;
 class PageNetGame;
 class PageInfo;
+class PageGameStats;
 
 class Ui_HWForm
 {
@@ -62,6 +63,7 @@
 	PageNetChat *pageNetChat;
 	PageNetGame *pageNetGame;
 	PageInfo *pageInfo;
+	PageGameStats *pageGameStats;
 
 	QStackedLayout *Pages;
 	QFont *font14;
--- a/hedgewars/GSHandlers.inc	Tue Dec 19 17:20:14 2006 +0000
+++ b/hedgewars/GSHandlers.inc	Thu Jan 04 16:27:45 2007 +0000
@@ -454,7 +454,7 @@
    HedgehogStep(HHGear);
 
    inc(BTSteps);
-   if BTSteps = 8 then
+   if BTSteps = 11 then
       begin
       BTSteps:= 0;
       Gear.X:= HHGear.X + Gear.dX * cHHRadius * 2;
@@ -470,7 +470,7 @@
 if b then
    DrawTunnel(HHGear.X - Gear.dX * cHHRadius, HHGear.Y - 4 - Gear.dY * cHHRadius + abs(Gear.dY) * 7,
               Gear.dX, Gear.dY,
-              cHHRadius * 6, cHHRadius * 2 + 6);
+              cHHRadius * 5, cHHRadius * 2 + 6);
 
 if (Gear.Timer = 0) or ((HHGear.Message and gm_Attack) <> 0) then
    begin
--- a/hedgewars/uConsts.pas	Tue Dec 19 17:20:14 2006 +0000
+++ b/hedgewars/uConsts.pas	Thu Jan 04 16:27:45 2007 +0000
@@ -62,6 +62,8 @@
 
      TCapGroup  = (capgrpGameState, capgrpAmmoinfo, capgrpNetSay, capgrpVolume);
 
+     TStatInfoType = (siGameResult);
+
      THHFont    = record
                   Handle: PTTF_Font;
                   Height: integer;
--- a/hedgewars/uGears.pas	Tue Dec 19 17:20:14 2006 +0000
+++ b/hedgewars/uGears.pas	Thu Jan 04 16:27:45 2007 +0000
@@ -266,7 +266,7 @@
                 Result.Radius:= 10;
                 end;
    gtBlowTorch: begin
-                Result.Radius:= cHHRadius + 6;
+                Result.Radius:= cHHRadius;
                 Result.Timer:= 7500;
                 end;
      end;
--- a/hedgewars/uMisc.pas	Tue Dec 19 17:20:14 2006 +0000
+++ b/hedgewars/uMisc.pas	Thu Jan 04 16:27:45 2007 +0000
@@ -101,6 +101,7 @@
 procedure SetKB(n: Longword);
 procedure SendKB;
 procedure SetLittle(var r: Double);
+procedure SendStat(sit: TStatInfoType; s: shortstring);
 
 var CursorPoint: TPoint;
     TargetPoint: TPoint = (X: NoPointX; Y: 0);
@@ -218,6 +219,12 @@
 Result:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')'
 end;
 
+procedure SendStat(sit: TStatInfoType; s: shortstring);
+const stc: array [TStatInfoType] of char = 'r';
+begin
+SendIPC('i' + stc[sit] + s)
+end;
+
 initialization
 AssignFile(f, 'debug.txt');
 rewrite(f);
--- a/hedgewars/uTeams.pas	Tue Dec 19 17:20:14 2006 +0000
+++ b/hedgewars/uTeams.pas	Thu Jan 04 16:27:45 2007 +0000
@@ -77,6 +77,7 @@
 function CheckForWin: boolean;
 var team, AliveTeam: PTeam;
     AliveCount: Longword;
+    s: shortstring;
 begin
 Result:= false;
 AliveCount:= 0;
@@ -99,10 +100,13 @@
 if AliveCount = 0 then
    begin // draw
    AddCaption(trmsg[sidDraw], $FFFFFF, capgrpGameState);
+   SendStat(siGameResult, trmsg[sidDraw]);
    AddGear(0, 0, gtATFinishGame, 0, 0, 0, 2000)
    end else // win
    begin
-   AddCaption(Format(trmsg[sidWinner], AliveTeam.TeamName), $FFFFFF, capgrpGameState);
+   s:= Format(trmsg[sidWinner], AliveTeam.TeamName);
+   AddCaption(s, $FFFFFF, capgrpGameState);
+   SendStat(siGameResult, s);
    AddGear(0, 0, gtATFinishGame, 0, 0, 0, 2000)
    end;
 end;