Prevent wind bar from overflowing with high wind values
authorWuzzy <Wuzzy2@mail.ru>
Thu, 10 Jan 2019 19:09:06 +0100
changeset 14564 78363dbfd5dc
parent 14563 e68b91abbcf5
child 14565 3105881d5840
Prevent wind bar from overflowing with high wind values Wind flow overflow does not happen normally, but might be triggered when calling SetWind with extreme values (>100 or <-100). Allows for silly wind experiments in scripts.
hedgewars/uVisualGearsHandlers.pas
--- a/hedgewars/uVisualGearsHandlers.pas	Thu Jan 10 18:45:04 2019 +0100
+++ b/hedgewars/uVisualGearsHandlers.pas	Thu Jan 10 19:09:06 2019 +0100
@@ -900,6 +900,7 @@
     currwindbar: PVisualGear = nil;
 
 procedure doStepSmoothWindBarWork(Gear: PVisualGear; Steps: Longword);
+const maxWindBarWidth = 73;
 begin
     if currwindbar = Gear then
     begin
@@ -912,6 +913,11 @@
             inc(WindBarWidth)
         else if WindBarWidth > Gear^.Tag then
             dec(WindBarWidth);
+        // Prevent wind bar from overflowing
+        if WindBarWidth > maxWindBarWidth then
+            WindBarWidth:= maxWindBarWidth;
+        if WindBarWidth < - maxWindBarWidth then
+            WindBarWidth:= - maxWindBarWidth;
         end;
     if cWindspeedf > Gear^.dAngle then
         begin
@@ -925,7 +931,7 @@
         end;
     end;
 
-    if ((WindBarWidth = Gear^.Tag) and (cWindspeedf = Gear^.dAngle)) or (currwindbar <> Gear) then
+    if (((WindBarWidth = Gear^.Tag) or (Abs(WindBarWidth) >= maxWindBarWidth)) and (cWindspeedf = Gear^.dAngle)) or (currwindbar <> Gear) then
     begin
         if currwindbar = Gear then currwindbar:= nil;
         DeleteVisualGear(Gear)