wrap explosions!
authorsheepluva
Thu, 11 Dec 2014 10:22:51 +0100
changeset 10653 ae9ad7735690
parent 10652 4456836514ed
child 10654 cdce07f5a011
wrap explosions!
hedgewars/uGearsUtils.pas
--- a/hedgewars/uGearsUtils.pas	Thu Dec 11 09:50:31 2014 +0100
+++ b/hedgewars/uGearsUtils.pas	Thu Dec 11 10:22:51 2014 +0100
@@ -81,6 +81,7 @@
     fX, fY, tdX, tdY: hwFloat;
     vg: PVisualGear;
     i, cnt: LongInt;
+    wrap: boolean;
 begin
 if Radius > 4 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');
 if Radius > 25 then KickFlakes(Radius, X, Y);
@@ -104,6 +105,11 @@
 fX:= int2hwFloat(X);
 fY:= int2hwFloat(Y);
 Gear:= GearsList;
+
+// we might have to run twice if weWrap is enabled
+wrap:= false;
+repeat;
+
 while Gear <> nil do
     begin
     dmg:= 0;
@@ -188,6 +194,27 @@
                 AddVisualGear(X, Y, vgtChunk)
         end;
 
+if (WorldEdge = weWrap) then
+    begin
+    // already wrapped? let's not wrap again!
+    if wrap then
+        break;
+
+    // Radius + 5 because that's the actual radius the explosion changes graphically
+    if X + (Radius + 5) > LongInt(rightX) then
+        begin
+        dec(X, playWidth);
+        wrap:= true;
+        end
+    else if X - (Radius + 5) < LongInt(leftX) then
+        begin
+        inc(X, playWidth);
+        wrap:= true;
+        end;
+    end;
+
+until (not wrap);
+
 uAIMisc.AwareOfExplosion(0, 0, 0)
 end;