Small fixes to bring engine to life
authorunc0rr
Sun, 21 Jan 2007 21:31:10 +0000
changeset 355 40c68869899e
parent 354 60e4af0a4375
child 356 ca3a5dfcae75
Small fixes to bring engine to life
hedgewars/GSHandlers.inc
hedgewars/hwengine.dpr
hedgewars/uFloat.pas
hedgewars/uGears.pas
hedgewars/uSound.pas
hedgewars/uStore.pas
--- a/hedgewars/GSHandlers.inc	Sun Jan 21 21:27:07 2007 +0000
+++ b/hedgewars/GSHandlers.inc	Sun Jan 21 21:31:10 2007 +0000
@@ -442,8 +442,8 @@
 
 if (HHGear^.Angle <> BTPrevAngle) then
    begin
-   Gear^.dX:= hwSign(HHGear^.dX) * _0_5;//hwSign(HHGear^.dX) * Sin(HHGear^.Angle * pi / cMaxAngle) * _0_5;
-   Gear^.dY:= 0;//Cos(HHGear^.Angle * pi / cMaxAngle) * (-0.5);
+   Gear^.dX:= hwSign(HHGear^.dX) * AngleSin(HHGear^.Angle) * _0_5;
+   Gear^.dY:= AngleCos(HHGear^.Angle) * ( - _0_5);
    BTPrevAngle:= HHGear^.Angle;
    b:= true
    end;
--- a/hedgewars/hwengine.dpr	Sun Jan 21 21:27:07 2007 +0000
+++ b/hedgewars/hwengine.dpr	Sun Jan 21 21:31:10 2007 +0000
@@ -16,6 +16,10 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  *)
 
+{$IFNDEF FPC}
+WriteLn('Only Freepascal supported');
+{$ENDIF}
+
 program hwengine;
 {$APPTYPE CONSOLE}
 uses
--- a/hedgewars/uFloat.pas	Sun Jan 21 21:27:07 2007 +0000
+++ b/hedgewars/uFloat.pas	Sun Jan 21 21:31:10 2007 +0000
@@ -171,7 +171,7 @@
 begin
 z.isNegative:= z1.isNegative xor (z2 < 0);
 z2:= abs(z2);
-z.QWordValue:= z.QWordValue * z2
+z.QWordValue:= z1.QWordValue * z2
 end;
 
 operator / (z1, z2: hwFloat) z : hwFloat;
@@ -260,7 +260,7 @@
 function AngleSin(angle: Longword): hwFloat;
 begin
 AngleSin.isNegative:= false;
-AngleSin:= Round(Sin(Angle * pi / cMaxAngle) * 4294967296)
+AngleSin.QWordValue:= Round(Sin(Angle * pi / cMaxAngle) * 4294967296)
 end;
 
 function AngleCos(angle: Longword): hwFloat;
@@ -268,7 +268,7 @@
 begin
 CosVal:= Cos(Angle * pi / cMaxAngle);
 AngleCos.isNegative:= CosVal < 0;
-AngleCos:= Round(Cosval * 4294967296)
+AngleCos.QWordValue:= Round(Abs(Cosval) * 4294967296)
 end;
 
 {$ENDIF}
--- a/hedgewars/uGears.pas	Sun Jan 21 21:27:07 2007 +0000
+++ b/hedgewars/uGears.pas	Sun Jan 21 21:31:10 2007 +0000
@@ -653,7 +653,7 @@
 {$IFDEF DEBUGFILE}if Radius > 3 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');{$ENDIF}
 if (Mask and EXPLDontDraw) = 0 then DrawExplosion(X, Y, Radius);
 if Radius = 50 then AddGear(X, Y, gtExplosion, 0, 0, 0, 0);
-if (Mask and EXPLAutoSound)<>0 then PlaySound(sndExplosion, false);
+if (Mask and EXPLAutoSound) <> 0 then PlaySound(sndExplosion, false);
 if (Mask and EXPLAllDamageInRadius)=0 then Radius:= Radius shl 1;
 Gear:= GearsList;
 while Gear <> nil do
@@ -661,17 +661,20 @@
       dmg:= Radius - hwRound(Distance(Gear^.X - X, Gear^.Y - Y));
       if dmg > 0 then
          begin
-         dmg:= dmg shr 1;
+         dmg:= dmg div 2;
          case Gear^.Kind of
               gtHedgehog,
                   gtMine,
                   gtCase,
                  gtFlame: begin
+                          {$IFDEF DEBUGFILE}AddFileLog('Damage: ' + inttostr(dmg));{$ENDIF}
                           if (Mask and EXPLNoDamage) = 0 then inc(Gear^.Damage, dmg);
                           if ((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog) then
                              begin
-                             Gear^.dX:= Gear^.dX + (_0_005 * dmg + cHHKick)* hwSign(Gear^.X - X);
-                             Gear^.dY:= Gear^.dY + (_0_005 * dmg + cHHKick)* hwSign(Gear^.Y - Y);
+                             Gear^.dX:= Gear^.dX + (_0_005 * dmg + cHHKick) * hwSign(Gear^.X - X);
+                             addfilelog(' >> _0_005 * dmg = '+floattostr(_0_005 * dmg));
+                             addfilelog(' >> dx = '+floattostr(Gear^.dX));
+                             Gear^.dY:= Gear^.dY + (_0_005 * dmg + cHHKick) * hwSign(Gear^.Y - Y);
                              Gear^.Active:= true;
                              FollowGear:= Gear
                              end;
--- a/hedgewars/uSound.pas	Sun Jan 21 21:27:07 2007 +0000
+++ b/hedgewars/uSound.pas	Sun Jan 21 21:31:10 2007 +0000
@@ -63,14 +63,14 @@
 
 procedure SoundLoad;
 var i: TSound;
-    s: array[byte] of char;
+    s: shortstring;
 begin
 if not isSoundEnabled then exit;
 for i:= Low(TSound) to High(TSound) do
     begin
     s:= Pathz[Soundz[i].Path] + '/' + Soundz[i].FileName;
-    WriteToConsole(msgLoading + string(s) + ' ');
-    Soundz[i].id:= Mix_LoadWAV_RW(SDL_RWFromFile(@s, 'rb'), 1);
+    WriteToConsole(msgLoading + s + ' ');
+    Soundz[i].id:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1);
     TryDo(Soundz[i].id <> nil, msgFailed, true);
     WriteLnToConsole(msgOK);
     end;
--- a/hedgewars/uStore.pas	Sun Jan 21 21:27:07 2007 +0000
+++ b/hedgewars/uStore.pas	Sun Jan 21 21:31:10 2007 +0000
@@ -100,10 +100,8 @@
     tmpsurf: PSDL_Surface;
     clr: TSDL_Color;
     Result: TSDL_Rect;
-    ps: array[byte] of char;
 begin
-ps:= s;
-TTF_SizeUTF8(Fontz[Font].Handle, @ps, w, h);
+TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h);
 Result.x:= X;
 Result.y:= Y;
 Result.w:= w + FontBorder * 2 + 4;
@@ -112,7 +110,7 @@
 clr.r:= Color shr 16;
 clr.g:= (Color shr 8) and $FF;
 clr.b:= Color and $FF;
-tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, @ps, clr.value);
+tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr.value);
 Result.x:= X + FontBorder + 2;
 Result.y:= Y + FontBorder;
 SDLTry(tmpsurf <> nil, true);
@@ -253,16 +251,13 @@
     AdjustColor(cExplosionBorderColor);
     end;
 
-var ps: array[byte] of char;
-
 begin
 for fi:= Low(THWFont) to High(THWFont) do
     with Fontz[fi] do
          begin
          s:= Pathz[ptFonts] + '/' + Name;
          WriteToConsole(msgLoading + s + '... ');
-         ps:= s;
-         Handle:= TTF_OpenFont(@ps, Height);
+         Handle:= TTF_OpenFont(Str2PChar(s), Height);
          SDLTry(Handle <> nil, true);
          TTF_SetFontStyle(Handle, style);
          WriteLnToConsole(msgOK)
@@ -379,15 +374,13 @@
 var clr: TSDL_Color;
     tmpsurf: PSDL_Surface;
     r: TSDL_Rect;
-    ps: array[byte] of Char;
 begin
 r.x:= X;
 r.y:= Y;
 clr.r:= $FF;
 clr.g:= $FF;
 clr.b:= $FF;
-ps:= s;
-tmpsurf:= TTF_RenderUTF8_Solid(Fontz[Font].Handle, @ps, clr.value);
+tmpsurf:= TTF_RenderUTF8_Solid(Fontz[Font].Handle, Str2PChar(s), clr.value);
 if tmpsurf = nil then
    begin
    SetKB(1);
@@ -446,11 +439,9 @@
 
 function  RenderString(s: string; Color: Longword; font: THWFont): PSDL_Surface;
 var w, h: Longint;
-    ps: array[byte] of Char;
     Result: PSDL_Surface;
 begin
-ps:= s;
-TTF_SizeUTF8(Fontz[font].Handle, @ps, w, h);
+TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h);
 Result:= SDL_CreateRGBSurface(SDL_HWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2,
          cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask);
 TryDo(Result <> nil, 'RenderString: fail to create surface', true);
@@ -495,17 +486,17 @@
 
 function  LoadImage(filename: string; hasAlpha: boolean; critical, setTransparent: boolean): PSDL_Surface;
 var tmpsurf: PSDL_Surface;
-    ps: array[byte] of char;
     Result: PSDL_Surface;
+    s: shortstring;
 begin
 WriteToConsole(msgLoading + filename + '... ');
-ps:= filename + '.' + cBitsStr + '.png';
-tmpsurf:= IMG_Load(@ps);
+s:= filename + '.' + cBitsStr + '.png';
+tmpsurf:= IMG_Load(Str2PChar(s));
 
 if tmpsurf = nil then
    begin
-   ps:= filename + '.png';
-   tmpsurf:= IMG_Load(ps);
+   s:= filename + '.png';
+   tmpsurf:= IMG_Load(Str2PChar(s));
    end;
 
 if tmpsurf = nil then