- Various fixes for ammo cases
authorunc0rr
Sun, 11 Sep 2005 21:02:11 +0000
changeset 16 b6f4b413dd41
parent 15 6200cca92480
child 17 a6bed8d31444
- Various fixes for ammo cases - Spawning case on turn end (max 5 cases)
hedgewars/GSHandlers.inc
hedgewars/HHHandlers.inc
hedgewars/uConsts.pas
hedgewars/uGears.pas
hedgewars/uIO.pas
--- a/hedgewars/GSHandlers.inc	Sun Sep 11 11:45:01 2005 +0000
+++ b/hedgewars/GSHandlers.inc	Sun Sep 11 21:02:11 2005 +0000
@@ -637,6 +637,6 @@
 if Gear.Damage > 0 then
    begin
    DeleteGear(Gear);
-   doMakeExplosion(round(Gear.X), round(Gear.Y), 50, EXPLAutoSound)
+   doMakeExplosion(round(Gear.X), round(Gear.Y), 20, EXPLAutoSound)
    end
 end;
--- a/hedgewars/HHHandlers.inc	Sun Sep 11 11:45:01 2005 +0000
+++ b/hedgewars/HHHandlers.inc	Sun Sep 11 21:02:11 2005 +0000
@@ -50,7 +50,7 @@
    end;
    
 // check for case with ammo
-t:= CheckGearNear(Gear, gtCase, 25, 25);
+t:= CheckGearNear(Gear, gtCase, 30, 30);
 if t <> nil then
    begin
    t.Message:= gm_Destroy;
--- a/hedgewars/uConsts.pas	Sun Sep 11 11:45:01 2005 +0000
+++ b/hedgewars/uConsts.pas	Sun Sep 11 21:02:11 2005 +0000
@@ -48,6 +48,7 @@
      TGearType  = (gtCloud, gtAmmo_Bomb, gtHedgehog, gtAmmo_Grenade, gtHealthTag,
                    gtGrave, gtUFO, gtShotgunShot, gtActionTimer, gtPickHammer, gtRope,
                    gtSmokeTrace, gtExplosion, gtMine, gtCase);
+     TGearsType = set of TGearType;
      TSound     = (sndGrenadeImpact, sndExplosion, sndThrowPowerUp, sndThrowRelease, sndSplash,
                    sndShotgunReload, sndShotgunFire, sndGraveImpact, sndMineTick);
      TAmmoType  = (amGrenade, amBazooka, amUFO, amShotgun, amPickHammer, amSkip, amRope,
--- a/hedgewars/uGears.pas	Sun Sep 11 11:45:01 2005 +0000
+++ b/hedgewars/uGears.pas	Sun Sep 11 21:02:11 2005 +0000
@@ -197,8 +197,8 @@
                 Result.Timer:= 3000;
                 end;
         gtCase: begin
-                Result.HalfWidth:= 10;
-                Result.HalfHeight:= 10;
+                Result.HalfWidth:= 14;
+                Result.HalfHeight:= 14;
                 Result.Elasticity:= 0.6
                 end;
      end;
@@ -463,7 +463,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);
-            gtCase: DrawSprite(sprCase, Round(Gear.X) - 12 + WorldDx, Round(Gear.Y) - 12 + WorldDy, 0, Surface);
+            gtCase: DrawSprite(sprCase, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, 0, Surface);
               end;
       Gear:= Gear.NextGear
       end;
@@ -489,17 +489,11 @@
 begin
 for i:= 0 to cCloudsNumber do AddGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -128, gtCloud, random(4), (0.5-random)*0.01);
 AddGear(0, 0, gtActionTimer, gtsStartGame, 0, 0, 2000).Health:= 3;
-for i:= 0 to 2 do
+for i:= 0 to 3 do
     begin
     GetHHPoint(x, y);
     AddGear(X, Y + 9, gtMine, 0);
     end;
-
-for i:= 0 to 0 do
-    begin
-    GetHHPoint(x, y);
-    AddGear(X, Y, gtCase, 0)
-    end;
 end;
 
 procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord);
@@ -572,8 +566,62 @@
 Result:= nil
 end;
 
+function CheckGearsNear(mX, mY: integer; Kind: TGearsType; rX, rY: integer): PGear;
+var t: PGear;
+begin
+t:= GearsList;
+rX:= sqr(rX);
+rY:= sqr(rY);
+while t <> nil do
+      begin
+      if t.Kind in Kind then
+         if sqr(mX - t.X) / rX + sqr(mY - t.Y) / rY <= 1 then
+            begin
+            Result:= t;
+            exit
+            end;
+      t:= t.NextGear
+      end;
+Result:= nil
+end;
+
+function CountGears(Kind: TGearType): Longword;
+var t: PGear;
+begin
+Result:= 0;
+t:= GearsList;
+while t <> nil do
+      begin
+      if t.Kind = Kind then inc(Result);
+      t:= t.NextGear
+      end;
+end;
+
 procedure SpawnBoxOfSmth;
+var i, x, y, k: integer;
+    b: boolean;
 begin
+if CountGears(gtCase) > 4 then exit;
+k:= 7;
+repeat
+  x:= getrandom(2000) + 24;
+  b:= false;
+  y:= -1;
+  while (y < 1024) and not b do
+        begin
+        inc(y);
+        i:= x - 14;
+        while (i <= x + 14) and not b do // 14 is gtCase HalfWidth
+              begin
+              if Land[y, i] <> 0 then b:= true;
+              inc(i)
+              end;
+        end;
+  if b then
+     b:= CheckGearsNear(x, y, [gtMine, gtHedgehog, gtCase], 70, 70) = nil;
+  dec(k)
+until (k = 0) or b;
+if b then FollowGear:= AddGear(x, -30, gtCase, 0)
 end;
 
 initialization
--- a/hedgewars/uIO.pas	Sun Sep 11 11:45:01 2005 +0000
+++ b/hedgewars/uIO.pas	Sun Sep 11 21:02:11 2005 +0000
@@ -199,7 +199,7 @@
              CursorPoint.Y:= extcmd[cmdcurpos].Y + WorldDy;
              end;
         '1'..'5': ParseCommand('/timer ' + extcmd[cmdcurpos].cmd);
-        #128..#131: ParseCommand('/slot ' + char(byte(extcmd[cmdcurpos].cmd) - 79))
+        #128..#134: ParseCommand('/slot ' + char(byte(extcmd[cmdcurpos].cmd) - 79))
         end;
    inc(cmdcurpos)
    end;