Disable gfMoreWind for land objects on turn end only after a fixed-time delay
authorWuzzy <Wuzzy2@mail.ru>
Sat, 06 Jun 2020 15:40:51 +0200
changeset 15620 6e72bd61002e
parent 15619 3409433a236a
child 15621 d275bb6b85b4
Disable gfMoreWind for land objects on turn end only after a fixed-time delay 15s sounds much, but it's the average amount for gfMineStrike mines to settle naturally. And it would be very confusing to see falling mines suddenly not caring about gfMoreWind for no apparent reason. Note this whole thing is a giant hack anyway, to prevent a turn being blocked by infinitely bouncing mines. The better solution would be to help gfMoreWind-affected land objects settle naturally more reliably even under extreme wind. But this commit is "good enough" for now. If you don't like the delay, you can always tweak the constant.
hedgewars/uConsts.pas
hedgewars/uGears.pas
hedgewars/uGearsHandlersMess.pas
hedgewars/uVariables.pas
--- a/hedgewars/uConsts.pas	Sat Jun 06 15:10:41 2020 +0200
+++ b/hedgewars/uConsts.pas	Sat Jun 06 15:40:51 2020 +0200
@@ -228,6 +228,7 @@
     cSeductionDist = 250; // effect distance of seduction
 
     ExtraTime = 30000; // amount of time (ms) given for using Extra Time
+    MaxMoreWindTime = 5000; // amount of time (ms) for land objects like gfMine to be affected after end of turn
 
     // do not change this value
     cDefaultZoomLevel = 2.0; // 100% zoom
--- a/hedgewars/uGears.pas	Sat Jun 06 15:10:41 2020 +0200
+++ b/hedgewars/uGears.pas	Sat Jun 06 15:40:51 2020 +0200
@@ -595,6 +595,11 @@
             dec(TurnTimeLeft)
         end;
 
+if (TurnTimeLeft = 0) and (ReadyTimeLeft = 0) then
+    inc(TimeNotInTurn)
+else
+    TimeNotInTurn:= 0;
+
 if skipFlag then
     begin
     if TagTurnTimeLeft = 0 then
--- a/hedgewars/uGearsHandlersMess.pas	Sat Jun 06 15:10:41 2020 +0200
+++ b/hedgewars/uGearsHandlersMess.pas	Sat Jun 06 15:40:51 2020 +0200
@@ -539,7 +539,11 @@
         Gear^.dY := Gear^.dY + cGravity;
         if ((GameFlags and gfMoreWind) <> 0) and
            // Disable gfMoreWind for land objects on turn end to prevent bouncing them forever
-           ((not (Gear^.Kind in [gtMine, gtAirMine, gtSMine, gtKnife, gtExplosives])) or (TurnTimeLeft > 0)) and
+           // This solution is rather ugly, in that it will occassionally suddenly wind physics
+           // while a gear is moving, this can be rather confusing.
+           // TODO: Find a way to make gfMoreWind-affected land objects settle more reliably
+           // and quickler without touching wind itselvs
+           ((not (Gear^.Kind in [gtMine, gtAirMine, gtSMine, gtKnife, gtExplosives])) or (TimeNotInTurn < MaxMoreWindTime)) and
            ((xland or land) = 0) and
            ((Gear^.dX.QWordValue + Gear^.dY.QWordValue) > _0_02.QWordValue) then
             Gear^.dX := Gear^.dX + cWindSpeed / Gear^.Density
--- a/hedgewars/uVariables.pas	Sat Jun 06 15:10:41 2020 +0200
+++ b/hedgewars/uVariables.pas	Sat Jun 06 15:40:51 2020 +0200
@@ -105,6 +105,7 @@
     TurnClockActive : boolean;
     TagTurnTimeLeft : Longword;
     ReadyTimeLeft   : Longword;
+    TimeNotInTurn   : Longword; // Milliseconds that passed while no turn is active
     IsGetAwayTime   : boolean;
     GameOver        : boolean;
     cSuddenDTurns   : LongInt;
@@ -2898,6 +2899,7 @@
     GameOver            := false;
     TurnClockActive     := true;
     TagTurnTimeLeft     := 0;
+    TimeNotInTurn       := 0;
     cSuddenDTurns       := 15;
     LastSuddenDWarn     := -2;
     cInitHealth         := 100;