This should make bee/airstrikes play nicer with infinite attack mode
authornemo
Sun, 07 Aug 2011 11:18:49 -0400
changeset 5507 1040c0946ef8
parent 5505 a55aab592950
child 5509 3b344484883e
This should make bee/airstrikes play nicer with infinite attack mode
hedgewars/GSHandlers.inc
hedgewars/HHHandlers.inc
hedgewars/uGears.pas
hedgewars/uGearsRender.pas
hedgewars/uTypes.pas
--- a/hedgewars/GSHandlers.inc	Sat Aug 06 07:09:30 2011 +0200
+++ b/hedgewars/GSHandlers.inc	Sun Aug 07 11:18:49 2011 -0400
@@ -794,8 +794,8 @@
     begin
         if (GameTicks and $30) = 0 then
             AddVisualGear(gX, gY, vgtBeeTrace);
-        Gear^.dX := Gear^.Elasticity * (Gear^.dX + _0_000064 * (TargetPoint.X - gX));
-        Gear^.dY := Gear^.Elasticity * (Gear^.dY + _0_000064 * (TargetPoint.Y - gY));
+        Gear^.dX := Gear^.Elasticity * (Gear^.dX + _0_000064 * (Gear^.TargetX - gX));
+        Gear^.dY := Gear^.Elasticity * (Gear^.dY + _0_000064 * (Gear^.TargetY - gY));
         // make sure new speed isn't higher than original one (which we stored in Friction variable)
         t := Gear^.Friction / Distance(Gear^.dX, Gear^.dY);
         Gear^.dX := Gear^.dX * t;
@@ -2417,14 +2417,14 @@
     end;
 
     Gear^.Y := int2hwFloat(topY-300);
-    Gear^.dX := int2hwFloat(TargetPoint.X - 5 * Gear^.Tag * 15);
+    Gear^.dX := int2hwFloat(Gear^.TargetX - 5 * Gear^.Tag * 15);
 
     // calcs for Napalm Strike, so that it will hit the target (without wind at least :P)
     if (Gear^.State = 2) then
         Gear^.dX := Gear^.dX - cBombsSpeed * Gear^.Tag * 900 
     // calcs for regular falling gears
-    else if (int2hwFloat(TargetPoint.Y) - Gear^.Y > _0) then
-            Gear^.dX := Gear^.dX - cBombsSpeed * hwSqrt((int2hwFloat(TargetPoint.Y) - Gear^.Y) * 2 /
+    else if (int2hwFloat(Gear^.TargetY) - Gear^.Y > _0) then
+            Gear^.dX := Gear^.dX - cBombsSpeed * hwSqrt((int2hwFloat(Gear^.TargetY) - Gear^.Y) * 2 /
                 cGravity) * Gear^.Tag;
 
     Gear^.Health := 6;
@@ -2460,14 +2460,14 @@
     AllInactive := false;
 
     HHGear := Gear^.Hedgehog^.Gear;
-    tx := int2hwFloat(TargetPoint.X);
-    ty := int2hwFloat(TargetPoint.Y);
+    tx := int2hwFloat(Gear^.TargetX);
+    ty := int2hwFloat(Gear^.TargetY);
     x := HHGear^.X;
     y := HHGear^.Y;
 
     if (Distance(tx - x, ty - y) > _256) or
-       not TryPlaceOnLand(TargetPoint.X - SpritesData[sprAmGirder].Width div 2,
-       TargetPoint.Y - SpritesData[sprAmGirder].Height div 2,
+       not TryPlaceOnLand(Gear^.TargetX - SpritesData[sprAmGirder].Width div 2,
+       Gear^.TargetY - SpritesData[sprAmGirder].Height div 2,
        sprAmGirder, Gear^.State, true, false) then
     begin
         PlaySound(sndDenied);
@@ -2486,7 +2486,6 @@
 
     HHGear^.State := HHGear^.State and not (gstAttacking or gstAttacked);
     HHGear^.Message := HHGear^.Message and not gmAttack;
-    TargetPoint.X := NoPointX
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -2527,8 +2526,8 @@
     AllInactive := false;
 
     HHGear := Gear^.Hedgehog^.Gear;
-    if not TryPlaceOnLand(TargetPoint.X - SpritesData[sprHHTelepMask].Width div 2,
-       TargetPoint.Y - SpritesData[sprHHTelepMask].Height div 2,
+    if not TryPlaceOnLand(Gear^.TargetX - SpritesData[sprHHTelepMask].Width div 2,
+       Gear^.TargetY - SpritesData[sprHHTelepMask].Height div 2,
        sprHHTelepMask, 0, false, false) then
     begin
         HHGear^.Message := HHGear^.Message and not gmAttack;
@@ -2550,12 +2549,12 @@
         HHGear^.dX.isNegative := (Gear^.X.QWordValue <> 0);
         Gear^.X := HHGear^.X;
         Gear^.Y := HHGear^.Y;
-        HHGear^.X := int2hwFloat(TargetPoint.X);
-        HHGear^.Y := int2hwFloat(TargetPoint.Y);
+        HHGear^.X := int2hwFloat(Gear^.TargetX);
+        HHGear^.Y := int2hwFloat(Gear^.TargetY);
         HHGear^.State := HHGear^.State or gstMoving;
         playSound(sndWarp)
     end;
-    TargetPoint.X := NoPointX;
+    Gear^.TargetX:= NoPointX
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
--- a/hedgewars/HHHandlers.inc	Sat Aug 06 07:09:30 2011 +0200
+++ b/hedgewars/HHHandlers.inc	Sun Aug 07 11:18:49 2011 -0400
@@ -373,6 +373,12 @@
                   amResurrector, amStructure,
                        amTardis: CurAmmoGear:= newGear;
                   end;
+        if Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0 then
+            begin
+            newGear^.TargetX:= TargetPoint.X;
+            newGear^.TargetY:= TargetPoint.Y;
+            TargetPoint.X := NoPointX
+            end;
 
         // Clear FollowGear if using on a rope/parachute/saucer etc so focus stays with the hog's movement
         if altUse then FollowGear:= nil;
--- a/hedgewars/uGears.pas	Sat Aug 06 07:09:30 2011 +0200
+++ b/hedgewars/uGears.pas	Sun Aug 07 11:18:49 2011 -0400
@@ -207,6 +207,7 @@
 FillChar(gear^, sizeof(TGear), 0);
 gear^.X:= int2hwFloat(X);
 gear^.Y:= int2hwFloat(Y);
+gear^.TargetX:= NoPointX;
 gear^.Kind := Kind;
 gear^.State:= State;
 gear^.Active:= true;
@@ -915,7 +916,14 @@
         dec(delay2);
 
         if ((delay2 mod cInactDelay) = 0) and (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) then
+            begin
+            if (CurrentHedgehog^.Gear^.State and gstAttacked <> 0) and (Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0) then
+                begin
+                CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State or gstHHChooseTarget;
+                isCursorVisible := true
+                end;
             CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State and not gstAttacked;
+            end;
         if delay2 = 0 then
             begin
             if (CurrentHedgehog^.Gear <> nil) and (CurrentHedgehog^.Gear^.State and gstAttacked = 0) then SweepDirty;
@@ -1214,7 +1222,6 @@
     vg: PVisualGear;
     i, cnt: LongInt;
 begin
-TargetPoint.X:= NoPointX;
 if Radius > 4 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');
 if Radius > 25 then KickFlakes(Radius, X, Y);
 
--- a/hedgewars/uGearsRender.pas	Sat Aug 06 07:09:30 2011 +0200
+++ b/hedgewars/uGearsRender.pas	Sun Aug 07 11:18:49 2011 -0400
@@ -877,6 +877,12 @@
     i: Longword;
     startX, endX, startY, endY: LongInt;
 begin
+    if Gear^.TargetX <> NoPointX then
+        if Gear^.AmmoType = amBee then
+            DrawRotatedF(sprTargetBee, Gear^.TargetX + WorldDx, Gear^.TargetY + WorldDy, 0, 0, (RealTicks shr 3) mod 360)
+        else
+            DrawRotatedF(sprTargetP, Gear^.TargetX + WorldDx, Gear^.TargetY + WorldDy, 0, 0, (RealTicks shr 3) mod 360);
+
     case Gear^.Kind of
           gtGrenade: DrawRotated(sprBomb, x, y, 0, Gear^.DirAngle);
       gtSnowball: DrawRotated(sprSnowball, x, y, 0, Gear^.DirAngle);
--- a/hedgewars/uTypes.pas	Sat Aug 06 07:09:30 2011 +0200
+++ b/hedgewars/uTypes.pas	Sun Aug 07 11:18:49 2011 -0400
@@ -228,6 +228,8 @@
             Y : hwFloat;
             dX: hwFloat;
             dY: hwFloat;
+            TargetX : LongInt;
+            TargetY : LongInt;
             Kind: TGearType;
             Pos: Longword;
             doStep: TGearStepProcedure;