Cleanup gtAirAttack behaviour in weWrap
authorWuzzy <Wuzzy2@mail.ru>
Thu, 11 Jul 2019 19:14:54 +0200
changeset 15254 b189d6a2ecda
parent 15253 a9a1f5824076
child 15255 186c3f272187
Cleanup gtAirAttack behaviour in weWrap Fixed bugs: - Gear position was not wrapped properly, messing up repeat rendering - Gear spawned outside of map bounds
hedgewars/uGearsHandlersMess.pas
hedgewars/uGearsList.pas
--- a/hedgewars/uGearsHandlersMess.pas	Thu Jul 11 17:15:30 2019 +0200
+++ b/hedgewars/uGearsHandlersMess.pas	Thu Jul 11 19:14:54 2019 +0200
@@ -3083,10 +3083,14 @@
     tmpFloat: hwFloat;
 begin
     AllInactive := false;
+    if (WorldEdge = weWrap) then
+        if (WorldWrap(Gear)) then
+            inc(Gear^.Power);
     Gear^.X := Gear^.X + cAirPlaneSpeed * Gear^.Tag;
-    if (Gear^.Health > 0) and (not (Gear^.X < Gear^.dX)) and (Gear^.X < Gear^.dX + cAirPlaneSpeed) then
+    if (Gear^.Health > 0) and (Gear^.Power >= Gear^.WDTimer) and (((Gear^.Tag = 1) and (not (Gear^.X < Gear^.dX))) or ((Gear^.Tag = -1) and (not (Gear^.X > Gear^.dX)))) then
         begin
         dec(Gear^.Health);
+        Gear^.FlightTime:= 0;
         // Spawn missile
         case Gear^.State of
             0: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtAirBomb, 0, cBombsSpeed * Gear^.Tag, _0, 0);
@@ -3094,7 +3098,14 @@
             2: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtNapalmBomb, 0, cBombsSpeed * Gear^.Tag, _0, 0);
             3: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtDrill, gsttmpFlag, cBombsSpeed * Gear^.Tag, _0, Gear^.Timer + 1);
         end;
-        Gear^.dX := Gear^.dX + int2hwFloat(Gear^.Damage * Gear^.Tag);
+        Gear^.dX := Gear^.X + int2hwFloat(Gear^.Damage * Gear^.Tag);
+        if (WorldEdge = weWrap) then
+            begin
+            Gear^.dX := int2hwFloat(CalcWorldWrap(hwRound(Gear^.dX), 0));
+            if (((Gear^.Tag = 1) and (not (Gear^.X < Gear^.dX))) or ((Gear^.Tag = -1) and (not (Gear^.X > Gear^.dX)))) then
+                inc(Gear^.WDTimer);
+            end;
+
         if CheckCoordInWater(hwRound(Gear^.X), hwRound(Gear^.Y)) then
             FollowGear^.State:= FollowGear^.State or gstSubmersible;
         if (Gear^.SoundChannel <> -1) and (WorldEdge <> weSea) then
@@ -3104,6 +3115,9 @@
             end;
         end;
 
+    if (Gear^.Health = 0) then
+        inc(Gear^.FlightTime);
+
     // Particles
     if (GameTicks and $3F) = 0 then
         if CheckCoordInWater(hwRound(Gear^.X), hwRound(Gear^.Y)) then
@@ -3112,7 +3126,8 @@
             AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace);
 
     // Get rid of gear and cleanup
-    if (hwRound(Gear^.X) > (max(LAND_WIDTH,4096)+2048)) or (hwRound(Gear^.X) < -2048) or ((Gear^.Message and gmDestroy) > 0) then
+    if ((WorldEdge = weWrap) and (Gear^.FlightTime >= 4000)) or
+        ((WorldEdge <> weWrap) and ((hwRound(Gear^.X) > (max(LAND_WIDTH,4096)+2048)) or (hwRound(Gear^.X) < -2048) or ((Gear^.Message and gmDestroy) > 0))) then
         begin
         // fail-safe: instanly stop sound if it wasn't disabled before
         if (Gear^.SoundChannel <> -1) then
@@ -3169,12 +3184,18 @@
     if Gear^.X.QWordValue = 0 then
         begin
         Gear^.Tag :=  1;
-        Gear^.X := -_2048;
+        if (WorldEdge = weWrap) then
+            Gear^.X := int2hwFloat(CalcWorldWrap(Gear^.Target.X + max(384, LAND_WIDTH shr 2), 0))
+        else
+            Gear^.X := -_2048;
         end
     else
         begin
         Gear^.Tag := -1;
-        Gear^.X := int2hwFloat(max(LAND_WIDTH,4096) + 2048);
+        if (WorldEdge = weWrap) then
+            Gear^.X := int2hwFloat(CalcWorldWrap(Gear^.Target.X - max(384, LAND_WIDTH shr 2), 0))
+        else
+            Gear^.X := int2hwFloat(max(LAND_WIDTH,4096) + 2048);
         end;
 
     Gear^.Y := int2hwFloat(topY - 300);
@@ -3193,6 +3214,13 @@
             Gear^.dX := Gear^.dX - cBombsSpeed * hwSqrt((int2hwFloat(Gear^.Target.Y) - Gear^.Y) * 2 /
                 cGravity) * Gear^.Tag;
 
+    if (WorldEdge = weWrap) then
+        begin
+        Gear^.dX := int2hwFloat(CalcWorldWrap(hwRound(Gear^.dX), 0));
+        if (((Gear^.Tag = 1) and (not (Gear^.X < Gear^.dX))) or ((Gear^.Tag = -1) and (not (Gear^.X > Gear^.dX)))) then
+            Gear^.WDTimer:= 1;
+        end;
+
     Gear^.doStep := @doStepAirAttackWork;
 
     if (WorldEdge = weSea) then
@@ -3200,6 +3228,11 @@
         Gear^.SoundChannel := LoopSound(sndPlaneWater, 4000);
         Gear^.Karma := 1;
         end
+    else if  (WorldEdge = weWrap) then
+        begin
+        Gear^.SoundChannel := LoopSound(sndPlane);
+        Gear^.Karma := 0;
+        end
     else
         begin
         Gear^.SoundChannel := LoopSound(sndPlane, 4000);
--- a/hedgewars/uGearsList.pas	Thu Jul 11 17:15:30 2019 +0200
+++ b/hedgewars/uGearsList.pas	Thu Jul 11 19:14:54 2019 +0200
@@ -609,6 +609,9 @@
                 gear^.Z:= cHHZ+2;
                 gear^.Karma:= 0; // for sound effect: 0 = normal, 1 = underwater
                 gear^.Radius:= 150;
+                gear^.FlightTime:= 0; // for timeout in weWrap
+                gear^.Power:= 0; // count number of wraps in weWrap
+                gear^.WDTimer:= 0; // number of required wraps
                 gear^.Density:= _19;
                 gear^.Tint:= gear^.Hedgehog^.Team^.Clan^.Color shl 8 or $FF
                 end;