- Small fix for AI
authorunc0rr
Sat, 09 Sep 2006 17:59:25 +0000
changeset 141 ac3680be1f4b
parent 140 50ccde437ea1
child 142 1ff0b02fe367
- Small fix for AI - Full-functional Multiplayer
QTfrontend/game.cpp
QTfrontend/game.h
hedgewars/uAIAmmoTests.pas
--- a/QTfrontend/game.cpp	Sat Sep 09 16:59:10 2006 +0000
+++ b/QTfrontend/game.cpp	Sat Sep 09 17:59:25 2006 +0000
@@ -90,6 +90,23 @@
 	SendIPC(QString("etheme %1").arg(config->GetRandomTheme()));
 	SENDIPC("TL");
 	SendIPC(QString("e$gmflags %1").arg(gamecfg->getGameFlags()));
+
+	for (int i = 0; i < TeamCount; i++)
+	{
+		SENDIPC("eaddteam");
+		LocalCFG(teams[i]);
+		SendIPC(QString("ecolor %1").arg(65535 << i * 8));
+		for (int t = 0; t < hdNum[teams[i]]; t++)
+			SendIPC(QString("eadd hh%1 0").arg(t));
+	}
+}
+
+void HWGame::SendQuickConfig()
+{
+	SendIPC(QString("eseed %1").arg(seed));
+	SendIPC(QString("etheme %1").arg(config->GetRandomTheme()));
+	SENDIPC("TL");
+	SendIPC(QString("e$gmflags %1").arg(gamecfg->getGameFlags()));
 	SENDIPC("eaddteam");
 	LocalCFG(0);
 	SENDIPC("ecolor 65535");
@@ -108,32 +125,31 @@
 
 void HWGame::ParseMessage(const QByteArray & msg)
 {
-	switch(msg.data()[1])
-	{
-		case '?':
-		{
+	switch(msg.data()[1]) {
+		case '?': {
 			if (gameType == gtNet)
 				emit SendNet(QByteArray("\x01""?"));
 			else
 				SENDIPC("!");
 			break;
 		}
-		case 'C':
-		{
-			if (gameType == gtNet)
-			{
-				SENDIPC("TN");
-				emit SendNet(QByteArray("\x01""C"));
-			}
-			else
-			{
-				if (gameType == gtLocal)
+		case 'C': {
+			switch (gameType) {
+				case gtLocal:
+				case gtQLocal: {
 				 	SendConfig();
+					break;
+				}
+				case gtDemo: break;
+				case gtNet: {
+					SENDIPC("TN");
+					emit SendNet(QByteArray("\x01""C"));
+					break;
+				}
 			}
 			break;
 		}
-		case 'E':
-		{
+		case 'E': {
 			QMessageBox::critical(0,
 					"Hedgewars: error message",
 					QString().append(msg.mid(2)).left(msg.size() - 6),
@@ -142,16 +158,14 @@
 					QMessageBox::NoButton);
 			return;
 		}
-		case '+':
-		{
+		case '+': {
 			if (gameType == gtNet)
 			{
 				emit SendNet(msg);
 			}
 			break;
 		}
-		default:
-		{
+		default: {
 			if (gameType == gtNet)
 			{
 				emit SendNet(msg);
@@ -321,7 +335,7 @@
 
 void HWGame::StartQuick()
 {
-	gameType = gtLocal;
+	gameType = gtQLocal;
 	seed = QUuid::createUuid().toString();
 	Start();
 }
--- a/QTfrontend/game.h	Sat Sep 09 16:59:10 2006 +0000
+++ b/QTfrontend/game.h	Sat Sep 09 17:59:25 2006 +0000
@@ -73,9 +73,10 @@
 
 private:
     enum GameType {
-        gtLocal = 1,
-        gtDemo  = 2,
-        gtNet   = 3
+        gtLocal  = 1,
+        gtQLocal = 2,
+        gtDemo   = 3,
+        gtNet    = 4
     };
     QTcpServer * IPCServer;
 	QTcpSocket * IPCSocket;
@@ -93,6 +94,7 @@
 
 	void Start();
 	void SendConfig();
+	void SendQuickConfig();
 	void SendTeamConfig(int index);
 	void ParseMessage(const QByteArray & msg);
 	void SendIPC(const char * msg, quint8 len);
--- a/hedgewars/uAIAmmoTests.pas	Sat Sep 09 16:59:10 2006 +0000
+++ b/hedgewars/uAIAmmoTests.pas	Sat Sep 09 17:59:25 2006 +0000
@@ -112,7 +112,7 @@
      if Result <= Score then
         begin
         r:= sqrt(r);
-        Angle:= DxDy2AttackAngle(Vx, Vy) + rndSign(random((Level - 1) * 8) + 1);
+        Angle:= DxDy2AttackAngle(Vx, Vy) + rndSign(random((Level - 1) * 8));
         Power:= round(r * cMaxPower) - random((Level - 1) * 15 + 1);
         ExplR:= 100;
         ExplX:= EX;