Send run parameters by cmd line, game parameters by IPC... breaks network game
authorunc0rr
Sat, 21 Jan 2006 16:18:19 +0000
changeset 55 e09f7c952a40
parent 54 839fd258ae6f
child 56 a29135563e94
Send run parameters by cmd line, game parameters by IPC... breaks network game
QTfrontend/game.cpp
QTfrontend/game.h
hedgewars/CCHandlers.inc
hedgewars/hwengine.dpr
hedgewars/uConsole.pas
hedgewars/uConsts.pas
hedgewars/uMisc.pas
hedgewars/uStore.pas
--- a/QTfrontend/game.cpp	Fri Jan 20 19:02:50 2006 +0000
+++ b/QTfrontend/game.cpp	Sat Jan 21 16:18:19 2006 +0000
@@ -84,8 +84,11 @@
 
 void HWGame::SendConfig()
 {
+	SendIPC(QString("eseed %1").arg(seed));
+	SendIPC(QString("etheme %1").arg(GetThemeBySeed()));
+	//SENDIPC("emap test");
 	SENDIPC("TL");
-//	SENDIPC("e$gmflags 0");
+	SENDIPC("e$gmflags 0");
 	SENDIPC("eaddteam");
 	SendTeamConfig(0);
 	SENDIPC("ecolor 65535");
@@ -164,6 +167,11 @@
 	SendIPC(QByteArray::fromRawData(msg, len));
 }
 
+void HWGame::SendIPC(const QString & buf)
+{
+	SendIPC(QByteArray().append(buf));
+}
+
 void HWGame::SendIPC(const QByteArray & buf)
 {
 	if (buf.size() > MAXMSGCHARS) return;
@@ -221,15 +229,16 @@
 				.arg(IPCServer->errorString()));
 	}
 
+	demo = new QByteArray;
 	QProcess * process;
 	QStringList arguments;
 	process = new QProcess;
 	arguments << resolutions[0][vid_Resolution];
 	arguments << resolutions[1][vid_Resolution];
-	arguments << GetThemeBySeed();
+	arguments << "16";
 	arguments << "46631";
-	arguments << seed;
 	arguments << (vid_Fullscreen ? "1" : "0");
+	arguments << "1";
 	process->start("./hwengine", arguments);
 }
 
@@ -315,22 +324,7 @@
 	} while (readbytes > 0);
 	demofile.close();
 
-	// cut seed
-	quint32 index = toSendBuf.indexOf(10);
-	if ((index < 3) || (index > 20))
-	{
-		QMessageBox::critical(0,
-				tr("Error"),
-				tr("Corrupted demo file %1").arg(demofilename),
-				tr("Quit"));
-		return ;
-	}
-	seed = QString(toSendBuf.left(index++));
-	toSendBuf.remove(0, index);
-
-	toSendBuf = QByteArray::fromRawData("\x02TD", 3) + toSendBuf;
 	// run engine
-	demo = new QByteArray;
 	Start();
 }
 
@@ -339,8 +333,6 @@
 	gameType = gtNet;
 	seed = netseed;
 	demo = new QByteArray;
-	demo->append(seed.toLocal8Bit());
-	demo->append(10);
 	Start();
 }
 
@@ -349,9 +341,6 @@
 	gameType = gtLocal;
 	if (TeamCount < 2) return;
 	seedgen.GenRNDStr(seed, 10);
-	demo = new QByteArray;
-	demo->append(seed.toLocal8Bit());
-	demo->append(10);
 	Start();
 }
 
--- a/QTfrontend/game.h	Fri Jan 20 19:02:50 2006 +0000
+++ b/QTfrontend/game.h	Sat Jan 21 16:18:19 2006 +0000
@@ -91,6 +91,7 @@
 	void ParseMessage(const QByteArray & msg);
 	void SendIPC(const char * msg, quint8 len);
 	void SendIPC(const QByteArray & buf);
+	void SendIPC(const QString & buf);
 	void RawSendIPC(const QByteArray & buf);
 	void SaveDemo(const QString & filename);
 	QString GetThemeBySeed();
--- a/hedgewars/CCHandlers.inc	Fri Jan 20 19:02:50 2006 +0000
+++ b/hedgewars/CCHandlers.inc	Sat Jan 21 16:18:19 2006 +0000
@@ -340,3 +340,30 @@
 TurnTimeLeft:= 0
 end;
 
+procedure chSetMap(var s: shortstring);
+begin
+if isDeveloperMode then
+   begin
+   Pathz[ptMapCurrent]:= Pathz[ptMaps] + '/' + s;
+   InitStepsFlags:= InitStepsFlags or cifMap
+   end
+end;
+
+procedure chSetTheme(var s: shortstring);
+begin
+if isDeveloperMode then
+   begin
+   Pathz[ptThemeCurrent]:= Pathz[ptThemes] + '/' + s;
+   InitStepsFlags:= InitStepsFlags or cifTheme
+   end
+end;
+
+procedure chSetSeed(var s: shortstring);
+begin
+if isDeveloperMode then
+   begin
+   SetRandomParams(s, rndfillstr);
+   InitStepsFlags:= InitStepsFlags or cifRandomize
+   end
+end;
+
--- a/hedgewars/hwengine.dpr	Fri Jan 20 19:02:50 2006 +0000
+++ b/hedgewars/hwengine.dpr	Sat Jan 21 16:18:19 2006 +0000
@@ -157,7 +157,6 @@
 ////////////////////
 procedure GetParams;
 var c: integer;
-    s: string;
 {$IFDEF DEBUGFILE}
     i: integer;
 begin
@@ -170,13 +169,10 @@
    begin
    val(ParamStr(1), cScreenWidth, c);
    val(ParamStr(2), cScreenHeight, c);
-   // "/mapname" is map, "avematan" is theme
-   s:= ParamStr(3);
-   if (Length(s) > 0) and (s[1] = '/') then Pathz[ptMapCurrent]:= Pathz[ptMaps] + s
-                                       else Pathz[ptThemeCurrent]:= Pathz[ptThemes] + '/' + ParamStr(3);
+   val(ParamStr(3), cBits, c);
    val(ParamStr(4), ipcPort, c);
-   SetRandomParams(ParamStr(5), rndfillstr);
-   cFullScreen:= ParamStr(6)[1] = '1'
+   cFullScreen:= ParamStr(5) = '1';
+   isSoundEnabled:= ParamStr(6) = '1';
    end else OutError(errmsgShouldntRun, true);
 end;
 
@@ -224,6 +220,10 @@
 
 isDeveloperMode:= false;
 
+TryDo(InitStepsFlags = cifAllInited,
+      'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')',
+      true);
+
 MainLoop
 
 end.
--- a/hedgewars/uConsole.pas	Fri Jan 20 19:02:50 2006 +0000
+++ b/hedgewars/uConsole.pas	Sat Jan 21 16:18:19 2006 +0000
@@ -48,7 +48,7 @@
 
 implementation
 {$J+}
-uses uMisc, uStore, Types, uConsts, uGears, uTeams, uIO, uKeys, uSound, uWorld, uLand;
+uses uMisc, uStore, Types, uConsts, uGears, uTeams, uIO, uKeys, uSound, uWorld, uLand, uRandom;
 const cLineWidth: integer = 0;
       cLinesCount = 256;
       
@@ -275,12 +275,13 @@
 RegisterVariable('capture' , vtCommand, @chCapture      );
 RegisterVariable('addteam' , vtCommand, @chAddTeam      );
 RegisterVariable('rdriven' , vtCommand, @chTeamLocal    );
-//RegisterVariable('gravity' , vtReal   , @cGravity       ); гравитация не должна быть доступна вообще
+RegisterVariable('map'     , vtCommand, @chSetMap       );
+RegisterVariable('theme'   , vtCommand, @chSetTheme     );
+RegisterVariable('seed'    , vtCommand, @chSetSeed      );
 RegisterVariable('c_height', vtInteger, @cConsoleHeight );
 RegisterVariable('gmflags' , vtInteger, @GameFlags      );
 RegisterVariable('turntime', vtInteger, @cHedgehogTurnTime);
 RegisterVariable('showfps' , vtBoolean, @cShowFPS       );
-RegisterVariable('sound'   , vtBoolean, @isSoundEnabled );
 RegisterVariable('name'    , vtCommand, @chName         );
 RegisterVariable('fort'    , vtCommand, @chFort         );
 RegisterVariable('grave'   , vtCommand, @chGrave        );
--- a/hedgewars/uConsts.pas	Fri Jan 20 19:02:50 2006 +0000
+++ b/hedgewars/uConsts.pas	Sat Jan 21 16:18:19 2006 +0000
@@ -84,12 +84,17 @@
       msgGettingConfig     = 'Getting game config...';
 
 const
-      cAppName  = 'hw';
-      cAppTitle = 'hw';
       cNetProtoVersion = 1;
 
       rndfillstr = 'hw';
 
+      cifRandomize = $00000001;
+      cifTheme     = $00000002;
+      cifMap       = $00000002; // either theme or map (or map+theme)
+      cifAllInited = cifRandomize or
+                     cifTheme or
+                     cifMap;
+
       cTransparentColor: Cardinal = $000000;
 
       cMaxHHIndex      = 9;
--- a/hedgewars/uMisc.pas	Fri Jan 20 19:02:50 2006 +0000
+++ b/hedgewars/uMisc.pas	Sat Jan 21 16:18:19 2006 +0000
@@ -90,6 +90,8 @@
 
     flagMakeCapture: boolean = false;
 
+    InitStepsFlags: Longword = 0;
+
     AttackBar     : integer = 0; // 0 - отсутствует, 1 - внизу, 2 - как в wwp
 
 function Sign(r: real): integer;
--- a/hedgewars/uStore.pas	Fri Jan 20 19:02:50 2006 +0000
+++ b/hedgewars/uStore.pas	Sat Jan 21 16:18:19 2006 +0000
@@ -73,7 +73,6 @@
 TryDo(  TempSurface <> nil, errmsgCreateSurface + ': temp'  , true);
 
 TryDo(SDL_SetColorKey( StoreSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
-//TryDo(SDL_SetColorKey(SpriteSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
 TryDo(SDL_SetColorKey(  TempSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
 end;