add rope layers
authoralfadur
Tue, 21 May 2019 23:04:50 +0300
changeset 15024 af2f6f4074de
parent 15023 9a8c678df7d9
child 15025 dc4a12a84c92
add rope layers
hedgewars/uConsts.pas
hedgewars/uGearsRender.pas
hedgewars/uLandObjects.pas
hedgewars/uVariables.pas
--- a/hedgewars/uConsts.pas	Tue May 21 16:45:16 2019 +0200
+++ b/hedgewars/uConsts.pas	Tue May 21 23:04:50 2019 +0300
@@ -155,6 +155,7 @@
 
     MAXNAMELEN = 192;
     MAXROPEPOINTS = 3840;
+    MAXROPELAYERS = 16;
 
     {$IFNDEF PAS2C}
     // some opengl headers do not have these macros
--- a/hedgewars/uGearsRender.pas	Tue May 21 16:45:16 2019 +0200
+++ b/hedgewars/uGearsRender.pas	Tue May 21 23:04:50 2019 +0300
@@ -95,7 +95,7 @@
 end;
 
 
-function DrawRopeLine(X1, Y1, X2, Y2, roplen: LongInt): LongInt;
+function DrawRopeLine(X1, Y1, X2, Y2, roplen: LongInt; LayerIndex: Longword): LongInt;
 var  eX, eY, dX, dY: LongInt;
     i, sX, sY, x, y, d: LongInt;
     b: boolean;
@@ -162,42 +162,46 @@
         if b then
             begin
             inc(roplen);
-            if (roplen mod cRopeNodeStep) = 0 then
+            if (roplen mod (cRopeNodeStep * cRopeLayers)) = (cRopeNodeStep * LayerIndex) then
                 DrawSpriteRotatedF(sprRopeNode, x, y, roplen div cRopeNodeStep, 1, angle);
             end
     end;
     DrawRopeLine:= roplen;
 end;
 
+procedure DrawRopeLayer(Gear: PGear; LayerIndex: LongWord);
+var roplen, i: LongInt;
+begin
+    roplen:= 0;
+    if RopePoints.Count > 0 then
+    begin
+        i:= 0;
+        while i < Pred(RopePoints.Count) do
+        begin
+            roplen:= DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy,
+                                  hwRound(RopePoints.ar[Succ(i)].X) + WorldDx, hwRound(RopePoints.ar[Succ(i)].Y) + WorldDy, roplen, LayerIndex);
+            inc(i)
+        end;
+        roplen:= DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy,
+                              hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, roplen, LayerIndex);
+        roplen:= DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy,
+                              hwRound(Gear^.Hedgehog^.Gear^.X) + WorldDx, hwRound(Gear^.Hedgehog^.Gear^.Y) + WorldDy, roplen, LayerIndex);
+    end
+    else
+        if Gear^.Elasticity.QWordValue > 0 then
+            roplen:= DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy,
+                                  hwRound(Gear^.Hedgehog^.Gear^.X) + WorldDx, hwRound(Gear^.Hedgehog^.Gear^.Y) + WorldDy, roplen, LayerIndex);
+end;
+
 procedure DrawRope(Gear: PGear);
-var roplen, i: LongInt;
+var i: LongInt;
 begin
     if Gear^.Hedgehog^.Gear = nil then exit;
     if (Gear^.Tag = 1) or ((cReducedQuality and rqSimpleRope) <> 0) then
         DrawRopeLinesRQ(Gear)
     else
-        begin
-        roplen:= 0;
-        if RopePoints.Count > 0 then
-            begin
-            i:= 0;
-            while i < Pred(RopePoints.Count) do
-                    begin
-                    roplen:= DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy,
-                                hwRound(RopePoints.ar[Succ(i)].X) + WorldDx, hwRound(RopePoints.ar[Succ(i)].Y) + WorldDy, roplen);
-                    inc(i)
-                    end;
-            roplen:= DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy,
-                        hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, roplen);
-            roplen:= DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy,
-                        hwRound(Gear^.Hedgehog^.Gear^.X) + WorldDx, hwRound(Gear^.Hedgehog^.Gear^.Y) + WorldDy, roplen);
-            end
-        else
-            if Gear^.Elasticity.QWordValue > 0 then
-            roplen:= DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy,
-                        hwRound(Gear^.Hedgehog^.Gear^.X) + WorldDx, hwRound(Gear^.Hedgehog^.Gear^.Y) + WorldDy, roplen);
-        end;
-
+        for i := 0 to cRopeLayers - 1 do
+            DrawRopeLayer(Gear, i);
 
 if RopePoints.Count > 0 then
     DrawSpriteRotated(sprRopeHook, hwRound(RopePoints.ar[0].X) + WorldDx, hwRound(RopePoints.ar[0].Y) + WorldDy, 1, RopePoints.HookAngle)
--- a/hedgewars/uLandObjects.pas	Tue May 21 16:45:16 2019 +0200
+++ b/hedgewars/uLandObjects.pas	Tue May 21 23:04:50 2019 +0300
@@ -1062,6 +1062,8 @@
         cSnow:= true
     else if key = 'rope-step' then
         cRopeNodeStep:= StrToInt(s)
+    else if key = 'rope-layers' then
+        cRopeLayers:= max(1, min(MAXROPELAYERS, StrToInt(s)))
     else if key = 'sd-water-top' then
         begin
         i:= Pos(',', s);
--- a/hedgewars/uVariables.pas	Tue May 21 16:45:16 2019 +0200
+++ b/hedgewars/uVariables.pas	Tue May 21 23:04:50 2019 +0300
@@ -117,6 +117,7 @@
     cMapGen         : TMapGen;
     cRopePercent    : LongWord;
     cRopeNodeStep   : LongWord;
+    cRopeLayers     : LongInt;
     cGetAwayTime    : LongWord;
 
     cAdvancedMapGenMode: boolean;
@@ -2883,6 +2884,7 @@
     cDamagePercent      := 100;
     cRopePercent        := 100;
     cRopeNodeStep       := 4;
+    cRopeLayers         := 1;
     cGetAwayTime        := 100;
     cMineDudPercent     := 0;
     cTemplateFilter     := 0;