hedgewars/GSHandlers.inc
changeset 7093 2d7f1fb73335
parent 7092 c9ca770fd7fc
child 7098 f8c453ade379
--- a/hedgewars/GSHandlers.inc	Fri May 18 13:35:22 2012 -0400
+++ b/hedgewars/GSHandlers.inc	Sun May 20 01:00:00 2012 -0400
@@ -5437,16 +5437,36 @@
 var 
     HHGear, iter: PGear;
     ndX, ndY: hwFloat;
-    gX, gY: LongInt;
+    t, gX, gY: LongInt;
 begin
+    HHGear := Gear^.Hedgehog^.Gear;
+    if (Gear^.Health = 0) or (HHGear = nil) or (HHGear^.Damage <> 0) then
+        begin
+        DeleteGear(Gear);
+        AfterAttack;
+        exit
+        end
+    else
+        begin
+        t:= Gear^.Health div 10;
+        if (t <> Gear^.Damage) and ((GameTicks and $3F) = 0) then
+            begin
+            Gear^.Damage:= t;
+            FreeTexture(Gear^.Tex);
+            Gear^.Tex := RenderStringTex(trmsg[sidFuel] + ': ' + inttostr(t) +
+                         '%', cWhiteColor, fntSmall)
+            end
+        end;
+    if GameTicks mod 10 = 0 then dec(Gear^.Health);
     with Gear^ do
         begin
-        HHGear := Hedgehog^.Gear;
         HedgehogChAngle(HHGear);
-        ndX:= SignAs(AngleSin(HHGear^.Angle), HHGear^.dX);
-        ndY:= -AngleCos(HHGear^.Angle);
+        ndX:= SignAs(AngleSin(HHGear^.Angle), HHGear^.dX) * _4;
+        ndY:= -AngleCos(HHGear^.Angle) * _4;
         if (ndX <> dX) or (ndY <> dY) then
             begin
+            dX:= ndX;
+            dY:= ndY;
             Pos:= 0;
             Target.X:= NoPointX;
             LastDamage:= nil;
@@ -5459,28 +5479,46 @@
                 if (iter^.Kind = gtHedgehog) and 
                    (iter^.Hedgehog^.Effects[heFrozen] < 0) then 
                     iter^.Hedgehog^.Effects[heFrozen]:= 0;
-                iter:= iter^.NextGear;
-                end;
+                iter:= iter^.NextGear
+                end
             end
         else
             begin
-            gX:= hwRound(X);
-            gY:= hwRound(Y);
             X:= X + dX;
             Y:= Y + dY;
+            gX:= hwRound(X);
+            gY:= hwRound(Y);
+            if Target.X = NoPointX then t:= hwRound(hwSqr(X-HHGear^.X)+hwSqr(Y-HHGear^.Y));
             if Target.X <> NoPointX then
                 inc(Pos)
-            else if (gY > cWaterLine) or 
+            else if (gY > cWaterLine) or
                     (((gX and LAND_WIDTH_MASK = 0) and (gY and LAND_HEIGHT_MASK = 0))
                         and ((Land[gY, gX] and $FF00 and not lfIce <> 0) or
-                             (Land[gY, gX] and $00FF <> 0))) then
+                             ((Land[gY, gX] and $00FF <> 0) and (t > 400)))) then
                 begin
                 Target.X:= gX;
                 Target.Y:= gY;
-                if Land[gY, gX] and $00FF <> 0 then // locate and tag hogs
+                if (gX and LAND_WIDTH_MASK = 0) and (gY and LAND_HEIGHT_MASK = 0) then
                     begin
-                //GearsNear(X, Y, gtHedgehog, Radius);
+                    LandPixels[gY, gX]:= $FFFFFFFF; // just testing
+                    UpdateLandTexture(gX, 1, gY, 1);
+                    if Land[gY, gX] and $00FF <> 0 then // locate and tag hogs
+                        begin
+                    //GearsNear(X, Y, gtHedgehog, Radius);
+                        end
                     end;
+                X:= HHGear^.X;
+                Y:= HHGear^.Y
+                end;
+            if (gX > LAND_WIDTH*2) or
+                    (gX < -LAND_WIDTH) or
+                    (gY < -LAND_HEIGHT) or
+                    (gY > LAND_HEIGHT+512) or
+                    (((gX and LAND_WIDTH_MASK = 0) and (gY and LAND_HEIGHT_MASK = 0))
+                     and (Land[gy, gX] > $FF)) then
+                begin
+                X:= HHGear^.X;
+                Y:= HHGear^.Y
                 end
         end
     end;