Disallow placement of piano beyond bounce world edge
authorWuzzy <Wuzzy2@mail.ru>
Sun, 13 Jan 2019 17:28:33 +0100
changeset 14587 85921db6f7c3
parent 14586 833ab5b359e5
child 14588 5de4d470dafe
Disallow placement of piano beyond bounce world edge
ChangeLog.txt
hedgewars/uGearsHandlersMess.pas
hedgewars/uGearsHedgehog.pas
hedgewars/uVariables.pas
--- a/ChangeLog.txt	Sun Jan 13 17:02:15 2019 +0100
+++ b/ChangeLog.txt	Sun Jan 13 17:28:33 2019 +0100
@@ -13,6 +13,9 @@
  * Fix poison damage not working in first round
  * Use player-chosen team identity in campaigns and singleplayer missions
  * Fix player-chosen teams ignoring custom team controls in campaigns
+ * Fix broken behaviour of airborne attacks when placed near bounce world edge
+ * Deny placement of airborne attack in “impossible” places in maps with bounce world edge
+ * Deny placement of piano beyond bounce world edge
 
 Styles and schemes:
  + The Specialists: Unlock game scheme
--- a/hedgewars/uGearsHandlersMess.pas	Sun Jan 13 17:02:15 2019 +0100
+++ b/hedgewars/uGearsHandlersMess.pas	Sun Jan 13 17:28:33 2019 +0100
@@ -115,6 +115,7 @@
 procedure doStepMovingPortal(Gear: PGear);
 procedure doStepPortalShot(newPortal: PGear);
 procedure doStepPiano(Gear: PGear);
+procedure doStepPianoWork(Gear: PGear);
 procedure doStepSineGunShotWork(Gear: PGear);
 procedure doStepSineGunShot(Gear: PGear);
 procedure doStepFlamethrowerWork(Gear: PGear);
@@ -5330,8 +5331,51 @@
     newPortal^.doStep := @doStepMovingPortal;
 end;
 
+procedure doStepPiano(Gear: PGear);
+var valid: boolean;
+    HHGear: PGear;
+begin
+    AllInactive := false;
+    valid := true;
+
+    if (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.Gear <> nil) then
+        HHGear := Gear^.Hedgehog^.Gear;
+
+    if (WorldEdge = weBounce) then
+        if (hwRound(Gear^.X) - Gear^.Radius < leftX) then
+            valid := false
+        else if (hwRound(Gear^.X) - Gear^.Radius > rightX) then
+            valid := false;
+
+    if (not valid) then
+        begin
+        if (HHGear <> nil) then
+            begin
+            HHGear^.Message := HHGear^.Message and (not gmAttack);
+            HHGear^.State := HHGear^.State and (not gstAttacking);
+            HHGear^.State := HHGear^.State or gstChooseTarget;
+            isCursorVisible := true;
+            end;
+        DeleteGear(Gear);
+        PlaySound(sndDenied);
+        exit;
+        end;
+
+    isCursorVisible := false;
+    if (HHGear <> nil) then
+        begin
+        PlaySoundV(sndIncoming, Gear^.Hedgehog^.Team^.voicepack);
+        // Tuck the hedgehog away until the piano attack is completed
+        Gear^.Hedgehog^.Unplaced:= true;
+        HHGear^.X:= _0;
+        HHGear^.Y:= _0;
+        end;
+
+    PauseMusic;
+    Gear^.doStep:= @doStepPianoWork;
+end;
 ////////////////////////////////////////////////////////////////////////////////
-procedure doStepPiano(Gear: PGear);
+procedure doStepPianoWork(Gear: PGear);
 var
     r0, r1: LongInt;
     odY: hwFloat;
--- a/hedgewars/uGearsHedgehog.pas	Sun Jan 13 17:02:15 2019 +0100
+++ b/hedgewars/uGearsHedgehog.pas	Sun Jan 13 17:28:33 2019 +0100
@@ -487,14 +487,7 @@
                                  PlaySoundV(sndOw1, Team^.voicepack);
                                  cVampiric:= true;
                                  end;
-                        amPiano: begin
-                                 // Tuck the hedgehog away until the piano attack is completed
-                                 Unplaced:= true;
-                                 X:= _0;
-                                 Y:= _0;
-                                 newGear:= AddGear(TargetPoint.X, -1024, gtPiano, 0, _0, _0, 0);
-                                 PauseMusic
-                                 end;
+                        amPiano: newGear:= AddGear(TargetPoint.X, -1024, gtPiano, 0, _0, _0, 0);
                  amFlamethrower: newGear:= AddGear(hwRound(X), hwRound(Y), gtFlamethrower,  0, xx * _0_5, yy * _0_5, 0);
                       amLandGun: newGear:= AddGear(hwRound(X), hwRound(Y), gtLandGun,  0, xx * _0_5, yy * _0_5, 0);
                   amResurrector: begin
--- a/hedgewars/uVariables.pas	Sun Jan 13 17:02:15 2019 +0100
+++ b/hedgewars/uVariables.pas	Sun Jan 13 17:28:33 2019 +0100
@@ -2027,7 +2027,7 @@
             NumberInCase: 1;
             Ammo: (Propz: ammoprop_NoCrosshair or
                             ammoprop_NeedTarget or
-                            ammoprop_NoTargetAfter or
+                            // NoTargetAfter is handled manually in doStepPiano
                             ammoprop_AttackingPut or
                             ammoprop_DontHold or
                             ammoprop_NotBorder or
@@ -2037,7 +2037,7 @@
                 Timer: 0;
                 Pos: 0;
                 AmmoType: amPiano;
-                AttackVoice: sndIncoming;
+                AttackVoice: sndNone; // handled in doStepPiano
                 Bounciness: defaultBounciness);
             Slot: 5;
             TimeAfterTurn: 0;