- Removed dark pixels on the corners of health case
authorunc0rr
Tue, 10 Jan 2006 19:53:18 +0000
changeset 43 e297fea1a2f3
parent 42 72ffe21f027c
child 44 1ef9546971ff
- Removed dark pixels on the corners of health case - Cleaned up dynamite code - Dynamite sprite - Frontend shows error messages from engine (except IPC-related :) ) - changed IPC-related stuff in frontend
QTfrontend/game.cpp
QTfrontend/game.h
QTfrontend/hwform.cpp
hedgewars/Data/Graphics/FirstAid.png
hedgewars/Data/Graphics/dynamite.png
hedgewars/GSHandlers.inc
hedgewars/uConsts.pas
hedgewars/uGears.pas
hedgewars/uMisc.pas
hedgewars/uStore.pas
--- a/QTfrontend/game.cpp	Mon Jan 09 20:33:12 2006 +0000
+++ b/QTfrontend/game.cpp	Tue Jan 10 19:53:18 2006 +0000
@@ -60,7 +60,6 @@
 		IPCSocket = client;
 		connect(client, SIGNAL(disconnected()), this, SLOT(ClientDisconnect()));
 		connect(client, SIGNAL(readyRead()), this, SLOT(ClientRead()));
-		msgsize = 0;
 		if (toSendBuf.size() > 0)
 			SENDIPC("?");
 	} else
@@ -105,9 +104,9 @@
 	SENDIPC("eadd hh4 1");
 }
 
-void HWGame::ParseMessage()
+void HWGame::ParseMessage(const QByteArray & msg)
 {
-	switch(msgbuf[0])
+	switch(msg.data()[1])
 	{
 		case '?':
 		{
@@ -131,23 +130,31 @@
 			}
 			break;
 		}
+		case 'E':
+		{
+			QMessageBox::critical(0,
+					"Hedgewars: error message",
+					QString().append(msg.mid(2)).left(msg.size() - 6),
+					QMessageBox::Ok,
+					QMessageBox::NoButton,
+					QMessageBox::NoButton);
+			return;
+		}
 		case '+':
 		{
 			if (gameType == gtNet)
 			{
-				QByteArray tmpbuf = QByteArray::fromRawData((char *)&msgsize, 1) + QByteArray::fromRawData(msgbuf, msgsize);
-				emit SendNet(tmpbuf);
+				emit SendNet(msg);
 			}
 			break;
 		}
 		default:
 		{
-			QByteArray tmpbuf = QByteArray::fromRawData((char *)&msgsize, 1) + QByteArray::fromRawData(msgbuf, msgsize);
 			if (gameType == gtNet)
 			{
-				emit SendNet(tmpbuf);
+				emit SendNet(msg);
 			}
-			demo->append(tmpbuf);
+			demo->append(msg);
 		}
 	}
 }
@@ -189,23 +196,15 @@
 
 void HWGame::ClientRead()
 {
-	qint64 readbytes = 1;
-	while (readbytes > 0)
+	readbuffer.append(IPCSocket->readAll());
+	quint8 msglen;
+	quint32 bufsize;
+	while (((bufsize = readbuffer.size()) > 0) &&
+			((msglen = readbuffer.data()[0]) < bufsize))
 	{
-		if (msgsize == 0)
-		{
-			msgbufsize = 0;
-			readbytes = IPCSocket->read((char *)&msgsize, 1);
-		} else
-		{
-			msgbufsize +=
-			readbytes = IPCSocket->read((char *)&msgbuf[msgbufsize], msgsize - msgbufsize);
-			if (msgbufsize = msgsize)
-			{
-				ParseMessage();
-				msgsize = 0;
-			}
-		}
+		QByteArray msg = readbuffer.left(msglen + 1);
+		readbuffer.remove(0, msglen + 1);
+		ParseMessage(msg);
 	}
 }
 
--- a/QTfrontend/game.h	Mon Jan 09 20:33:12 2006 +0000
+++ b/QTfrontend/game.h	Tue Jan 10 19:53:18 2006 +0000
@@ -73,8 +73,7 @@
     QTcpServer * IPCServer;
 	QTcpSocket * IPCSocket;
 	char msgbuf[MAXMSGCHARS];
-	quint8 msgbufsize;
-	quint8 msgsize;
+	QByteArray readbuffer;
 	QString teams[5];
 	QString seed;
 	int TeamCount;
@@ -89,7 +88,7 @@
 	void Start();
 	void SendConfig();
 	void SendTeamConfig(int index);
-	void ParseMessage();
+	void ParseMessage(const QByteArray & msg);
 	void SendIPC(const char * msg, quint8 len);
 	void SendIPC(const QByteArray & buf);
 	void RawSendIPC(const QByteArray & buf);
--- a/QTfrontend/hwform.cpp	Mon Jan 09 20:33:12 2006 +0000
+++ b/QTfrontend/hwform.cpp	Tue Jan 10 19:53:18 2006 +0000
@@ -107,7 +107,7 @@
 		{
 			QMessageBox::critical(this,
 					tr("Error"),
-					tr("Cannot create directory %s").arg("/.hedgewars"),
+					tr("Cannot create directory %1").arg("/.hedgewars"),
 					tr("Quit"));
 			return ;
 		}
@@ -275,7 +275,7 @@
 	{
 		QMessageBox::critical(this,
 				tr("Error"),
-				tr("Cannot save options to file %s").arg(settings.fileName()),
+				tr("Cannot save options to file %1").arg(settings.fileName()),
 				tr("Quit"));
 		return ;
 	}
Binary file hedgewars/Data/Graphics/FirstAid.png has changed
Binary file hedgewars/Data/Graphics/dynamite.png has changed
--- a/hedgewars/GSHandlers.inc	Mon Jan 09 20:33:12 2006 +0000
+++ b/hedgewars/GSHandlers.inc	Tue Jan 10 19:53:18 2006 +0000
@@ -642,30 +642,16 @@
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepDynamite(Gear: PGear);
 begin
-if (Gear.dX <> 0) or (Gear.dY <> 0) {or not TestCollisionY(Gear, 1)} then
+doStepFallingGear(Gear);
+AllInactive:= false;
+if Gear.Timer mod 166 = 0 then inc(Gear.Tag);
+if Gear.Timer = 0 then
    begin
-   doStepFallingGear(Gear);
-   if Gear.Active = false then
-      begin
-      Gear.dX:= 0;
-      Gear.dY:= 0
-      end;
-//   CalcRotationDirAngle(Gear);
-   AllInactive:= false
+   doMakeExplosion(round(Gear.X), round(Gear.Y), 85, EXPLAutoSound);
+   DeleteGear(Gear);
+   exit
    end;
-//if ((Gear.State and gsttmpFlag) <> 0) then
-//   if ((Gear.State  and gstAttacking) = 0) then
-      begin
-  //    AllInactive:= true;
-      if (Gear.Timer and $FF) = 0 then PlaySound(sndMineTick);
-      if Gear.Timer = 0 then
-         begin
-         doMakeExplosion(round(Gear.X), round(Gear.Y), 85, EXPLAutoSound);
-         DeleteGear(Gear)
-         end;
-      dec(Gear.Timer);
-      end;{ else // gsttmpFlag = 0
-   if TurnTimeLeft = 0 then Gear.State:= Gear.State or gsttmpFlag;}
+dec(Gear.Timer);
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
--- a/hedgewars/uConsts.pas	Mon Jan 09 20:33:12 2006 +0000
+++ b/hedgewars/uConsts.pas	Tue Jan 10 19:53:18 2006 +0000
@@ -44,7 +44,7 @@
      TSprite    = (sprWater, sprCloud, sprBomb, sprBigDigit, sprFrame,
                    sprLag, sprArrow, sprGrenade, sprTargetP, sprUFO,
                    sprSmokeTrace, sprRopeHook, sprExplosion50, sprMineOff,
-                   sprMineOn, sprCase, sprFAid);
+                   sprMineOn, sprCase, sprFAid, sprDynamite);
      TGearType  = (gtCloud, gtAmmo_Bomb, gtHedgehog, gtAmmo_Grenade, gtHealthTag,
                    gtGrave, gtUFO, gtShotgunShot, gtActionTimer, gtPickHammer, gtRope,
                    gtSmokeTrace, gtExplosion, gtMine, gtCase, gtDEagleShot, gtDynamite);
@@ -69,7 +69,7 @@
 
 
 resourcestring
-      errmsgCreateSurface   = 'Error creating DirectDraw7 surface';
+      errmsgCreateSurface   = 'Error creating SDL surface';
       errmsgNoDesc          = 'Unknown error';
       errmsgTransparentSet  = 'Error setting transparent color';
       errmsgUnknownCommand  = 'Unknown command';
@@ -237,7 +237,8 @@
                      (FileName:   'MineOff.png'; Path: ptGraphics; Width:  16; Height: 16; hasAlpha: false),// sprMineOff
                      (FileName:    'MineOn.png'; Path: ptGraphics; Width:  16; Height: 16; hasAlpha: false),// sprMineOn
                      (FileName:      'Case.png'; Path: ptGraphics; Width:  32; Height: 32; hasAlpha: false),// sprCase
-                     (FileName:  'FirstAid.png'; Path: ptGraphics; Width:  32; Height: 32; hasAlpha: false) // sprFAid
+                     (FileName:  'FirstAid.png'; Path: ptGraphics; Width:  32; Height: 32; hasAlpha: false),// sprFAid
+                     (FileName:  'dynamite.png'; Path: ptGraphics; Width:  32; Height: 32; hasAlpha: false) // sprDynamite
                      );
       Soundz: array[TSound] of record
                                        FileName: String[31];
--- a/hedgewars/uGears.pas	Mon Jan 09 20:33:12 2006 +0000
+++ b/hedgewars/uGears.pas	Tue Jan 10 19:53:18 2006 +0000
@@ -493,11 +493,7 @@
             gtMine: if ((Gear.State and gstAttacking) = 0)or((Gear.Timer and $3FF) < 420)
                        then DrawSprite(sprMineOff , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface)
                        else DrawSprite(sprMineOn  , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface);
-        //!!!              ACHTUNG!!!!
-        gtDynamite: if ((Gear.State and gstAttacking) = 0)or((Gear.Timer and $3FF) < 420)
-                       then DrawSprite(sprMineOff , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface)
-                       else DrawSprite(sprMineOn  , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface);
-        //!!!              ACHTUNG!!!!                     
+        gtDynamite: DrawSprite2(sprDynamite, Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, Gear.Tag and 1, Gear.Tag shr 1, Surface);
             gtCase: case Gear.Pos of
                          posCaseAmmo  : DrawSprite(sprCase, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, 0, Surface);
                          posCaseHealth: DrawSprite(sprFAid, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, (GameTicks shr 6) and $F, Surface);
@@ -660,7 +656,7 @@
 var i, x, y, k: integer;
     b: boolean;
 begin
-if CountGears(gtCase) > 2 then exit;
+if (CountGears(gtCase) > 1) or (getrandom(3) <> 0) then exit;
 k:= 7;
 repeat
   x:= getrandom(2000) + 24;
--- a/hedgewars/uMisc.pas	Mon Jan 09 20:33:12 2006 +0000
+++ b/hedgewars/uMisc.pas	Tue Jan 10 19:53:18 2006 +0000
@@ -111,7 +111,7 @@
     TargetPoint: TPoint = (X: NoPointX; Y: 0);
 
 implementation
-uses uConsole, uStore;
+uses uConsole, uStore, uIO;
 {$IFDEF DEBUGFILE}
 var f: textfile;
 {$ENDIF}
@@ -137,6 +137,7 @@
 {$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF}
 if isFatalError then
    begin
+   SendIPC('E' + Msg);
    WriteLn(Msg);
    SDL_Quit;
 //   Readln;
--- a/hedgewars/uStore.pas	Mon Jan 09 20:33:12 2006 +0000
+++ b/hedgewars/uStore.pas	Tue Jan 10 19:53:18 2006 +0000
@@ -47,6 +47,7 @@
 procedure DrawGear(Stuff : TStuff; X, Y: integer; Surface: PSDL_Surface);
 procedure DrawSpriteFromRect(r: TSDL_Rect; X, Y, Height, Position: integer; Surface: PSDL_Surface);
 procedure DrawSprite (Sprite: TSprite; X, Y, Position: integer; Surface: PSDL_Surface);
+procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: integer; Surface: PSDL_Surface);
 procedure DrawLand (X, Y: integer; Surface: PSDL_Surface);
 procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface);
 procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface; const fromTempSurf: boolean = false);
@@ -531,7 +532,7 @@
 rr.h:= r.h;
 if SDL_UpperBlit(SourceSurface, r, DestSurface, @rr) < 0 then
    begin
-   Writeln('Blit: ', SDL_GetError);
+   OutError('Blit: ' + SDL_GetError, true);
    exit
    end;
 end;
@@ -558,6 +559,16 @@
 DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface)
 end;
 
+procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: integer; Surface: PSDL_Surface);
+var r: TSDL_Rect;
+begin
+r.x:= FrameX * SpritesData[Sprite].Width;
+r.w:= SpritesData[Sprite].Width;
+r.y:= FrameY * SpritesData[Sprite].Height;
+r.h:= SpritesData[Sprite].Height;
+DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface)
+end;
+
 procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface);
 var clr: TSDL_Color;
     tmpsurf: PSDL_Surface;