- Better AI thinking behavior
authorunc0rr
Sat, 10 Feb 2007 15:07:35 +0000
changeset 425 a7e1dabc8fb7
parent 424 4598c21bb421
child 426 7523417d84d6
- Better AI thinking behavior - Fix segfaul + more messageboxes with HWForm as parent instead of parent being 0
QTfrontend/game.cpp
QTfrontend/game.h
QTfrontend/hwform.cpp
QTfrontend/hwform.h
hedgewars/uAI.pas
--- a/QTfrontend/game.cpp	Sat Feb 10 13:14:41 2007 +0000
+++ b/QTfrontend/game.cpp	Sat Feb 10 15:07:35 2007 +0000
@@ -145,24 +145,14 @@
 			break;
 		}
 		case 'E': {
-			QMessageBox::critical(0,
-					"Hedgewars: error message",
-					QString().append(msg.mid(2)).left(msg.size() - 6),
-					QMessageBox::Ok,
-					QMessageBox::NoButton,
-					QMessageBox::NoButton);
+			emit ErrorMessage(QString().append(msg.mid(2)).left(msg.size() - 6));
 			return;
 		}
 		case 'K': {
 			ulong kb = msg.mid(2).toULong();
 			if (kb && kb <= KBmsgsCount)
 			{
-				QMessageBox::information(0,
-						"Hedgewars: information",
-						KBMessages[kb - 1],
-						QMessageBox::Ok,
-						QMessageBox::NoButton,
-						QMessageBox::NoButton);
+				emit ErrorMessage(KBMessages[kb - 1]);
 			}
 			return;
 		}
@@ -245,10 +235,7 @@
 	QFile demofile(filename);
 	if (!demofile.open(QIODevice::WriteOnly))
 	{
-		QMessageBox::critical(0,
-				tr("Error"),
-				tr("Cannot save demo to file %1").arg(filename),
-				tr("Quit"));
+		emit ErrorMessage(tr("Cannot save demo to file %1").arg(filename));
 		return ;
 	}
 	QDataStream stream(&demofile);
@@ -264,10 +251,7 @@
 	QFile demofile(demofilename);
 	if (!demofile.open(QIODevice::ReadOnly))
 	{
-		QMessageBox::critical(0,
-				tr("Error"),
-				tr("Cannot open demofile %1").arg(demofilename),
-				tr("Quit"));
+		emit ErrorMessage(tr("Cannot open demofile %1").arg(demofilename));
 		return ;
 	}
 
--- a/QTfrontend/game.h	Sat Feb 10 13:14:41 2007 +0000
+++ b/QTfrontend/game.h	Sat Feb 10 15:07:35 2007 +0000
@@ -62,6 +62,7 @@
 	void SendNet(const QByteArray & msg);
 	void GameStateChanged(GameState gameState);
 	void GameStats(char type, const QString & info);
+	void ErrorMessage(const QString &);
 
 public slots:
 	void FromNet(const QByteArray & msg);
--- a/QTfrontend/hwform.cpp	Sat Feb 10 13:14:41 2007 +0000
+++ b/QTfrontend/hwform.cpp	Sat Feb 10 15:07:35 2007 +0000
@@ -287,9 +287,9 @@
 	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&)), 
+	connect(hwnet, SIGNAL(hhnumChanged(const HWTeam&)),
 		ui.pageNetGame->pNetTeamsWidget, SLOT(changeHHNum(const HWTeam&)));
-	connect(hwnet, SIGNAL(teamColorChanged(const HWTeam&)), 
+	connect(hwnet, SIGNAL(teamColorChanged(const HWTeam&)),
 		ui.pageNetGame->pNetTeamsWidget, SLOT(changeTeamColor(const HWTeam&)));
 
 	hwnet->Connect(hostName, port, nick);
@@ -330,7 +330,7 @@
   if (hwnet) {
     hwnet->deleteLater();
     hwnet=0;
-    QMessageBox::warning(this, QMessageBox::tr("Network"), 
+    QMessageBox::warning(this, QMessageBox::tr("Network"),
 			 QMessageBox::tr("Connection to server is lost"));
   }
   GoBack();
@@ -422,4 +422,12 @@
 	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 &)));
+	connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection);
 }
+
+void HWForm::ShowErrorMessage(const QString & msg)
+{
+	QMessageBox::warning(this,
+			"Hedgewars",
+			msg);
+}
--- a/QTfrontend/hwform.h	Sat Feb 10 13:14:41 2007 +0000
+++ b/QTfrontend/hwform.h	Sat Feb 10 15:07:35 2007 +0000
@@ -73,6 +73,7 @@
 	void GameStateChanged(GameState gameState);
 	void GameStats(char type, const QString & info);
 	void ForcedDisconnect();
+	void ShowErrorMessage(const QString &);
 
 private:
 	void _NetConnect(const QString & hostName, quint16 port, const QString & nick);
--- a/hedgewars/uAI.pas	Sat Feb 10 13:14:41 2007 +0000
+++ b/hedgewars/uAI.pas	Sat Feb 10 15:07:35 2007 +0000
@@ -163,7 +163,7 @@
            and ((steps mod 4) = 0) then
            begin
            TestAmmos(Actions, Me);
-           if SDL_GetTicks - AIThinkStart >= cTimerInterval then
+           if SDL_GetTicks - AIThinkStart >= Pred(cTimerInterval) then
               begin
               dec(Actions.Count, 3);
               Push(ticks, Actions, Me^, Me^.Message);