added flake configuration also in sudden death and SDClouds for underwater
authorHenek
Sat, 01 Jan 2011 23:10:57 +0100
changeset 4806 48c1a395f0a7
parent 4805 01332828b568
child 4807 180dbfb13903
added flake configuration also in sudden death and SDClouds for underwater
hedgewars/VGSHandlers.inc
hedgewars/hwengine.pas
hedgewars/uGears.pas
hedgewars/uLandObjects.pas
hedgewars/uVariables.pas
hedgewars/uVisualGears.pas
share/hedgewars/Data/Themes/Underwater/SDClouds.png
--- a/hedgewars/VGSHandlers.inc	Sat Jan 01 19:41:58 2011 +0100
+++ b/hedgewars/VGSHandlers.inc	Sat Jan 01 23:10:57 2011 +0100
@@ -24,14 +24,23 @@
 with Gear^ do
     begin
     inc(FrameTicks, Steps);
-    if FrameTicks > vobFrameTicks then
+    if not SuddenDeathDmg and (FrameTicks > vobFrameTicks) then
         begin
         dec(FrameTicks, vobFrameTicks);
         inc(Frame);
         if Frame = vobFramesCount then Frame:= 0
+        end
+    else if SuddenDeathDmg and (FrameTicks > vobSDFrameTicks) then
+        begin
+        dec(FrameTicks, vobSDFrameTicks);
+        inc(Frame);
+        if Frame = vobSDFramesCount then Frame:= 0
         end;
     X:= X + (cWindSpeedf * 200 + dX + tdX) * Steps;
-    Y:= Y + (dY + tdY + cGravityf * vobFallSpeed) * Steps;
+    if SuddenDeathDmg then
+        Y:= Y + (dY + tdY + cGravityf * vobSDFallSpeed) * Steps
+    else
+        Y:= Y + (dY + tdY + cGravityf * vobFallSpeed) * Steps;
     Angle:= Angle + dAngle * Steps;
     if Angle > 360 then
         Angle:= Angle - 360
--- a/hedgewars/hwengine.pas	Sat Jan 01 19:41:58 2011 +0100
+++ b/hedgewars/hwengine.pas	Sat Jan 01 23:10:57 2011 +0100
@@ -60,6 +60,7 @@
         gsStart: begin
                 if HasBorder then DisableSomeWeapons;
                 AddClouds;
+                AddFlakes;
                 AssignHHCoords;
                 AddMiscGears;
                 StoreLoad;
--- a/hedgewars/uGears.pas	Sat Jan 01 19:41:58 2011 +0100
+++ b/hedgewars/uGears.pas	Sat Jan 01 23:10:57 2011 +0100
@@ -799,7 +799,8 @@
                     if cHealthDecrease <> 0 then
                         begin
                         SuddenDeathDmg:= true;
-                        ChangeToSDClouds
+                        ChangeToSDClouds;
+                        ChangeToSDFlakes;
                         end;
                     AddCaption(trmsg[sidSuddenDeath], cWhiteColor, capgrpGameState);
                     playSound(sndSuddenDeath);
--- a/hedgewars/uLandObjects.pas	Sat Jan 01 19:41:58 2011 +0100
+++ b/hedgewars/uLandObjects.pas	Sat Jan 01 23:10:57 2011 +0100
@@ -398,16 +398,16 @@
     if s[1] = ';' then continue;
 
     i:= Pos('=', s);
-    key:= Trim(Copy(s, 1, i - 1));
+    key:= Trim(Copy(s, 1, Pred(i)));
     Delete(s, 1, i);
 
     if key = 'sky' then
         begin
         i:= Pos(',', s);
-        c1.r:= StrToInt(Trim(Copy(s, 1, i - 1)));
+        c1.r:= StrToInt(Trim(Copy(s, 1, Pred(i))));
         Delete(s, 1, i);
         i:= Pos(',', s);
-        c1.g:= StrToInt(Trim(Copy(s, 1, i - 1)));
+        c1.g:= StrToInt(Trim(Copy(s, 1, Pred(i))));
         Delete(s, 1, i);
         c1.b:= StrToInt(Trim(s));
         glClearColor(c1.r / 255, c1.g / 255, c1.b / 255, 0.99);
@@ -415,10 +415,10 @@
     else if key = 'border' then
         begin
         i:= Pos(',', s);
-        c2.r:= StrToInt(Trim(Copy(s, 1, i - 1)));
+        c2.r:= StrToInt(Trim(Copy(s, 1, Pred(i))));
         Delete(s, 1, i);
         i:= Pos(',', s);
-        c2.g:= StrToInt(Trim(Copy(s, 1, i - 1)));
+        c2.g:= StrToInt(Trim(Copy(s, 1, Pred(i))));
         Delete(s, 1, i);
         c2.b:= StrToInt(Trim(s));
         cExplosionBorderColor:= c2.value or AMask;
@@ -426,10 +426,10 @@
     else if key = 'water-top' then
         begin
         i:= Pos(',', s);
-        WaterColorArray[0].r:= StrToInt(Trim(Copy(s, 1, i - 1)));
+        WaterColorArray[0].r:= StrToInt(Trim(Copy(s, 1, Pred(i))));
         Delete(s, 1, i);
         i:= Pos(',', s);
-        WaterColorArray[0].g:= StrToInt(Trim(Copy(s, 1, i - 1)));
+        WaterColorArray[0].g:= StrToInt(Trim(Copy(s, 1, Pred(i))));
         Delete(s, 1, i);
         WaterColorArray[0].b:= StrToInt(Trim(s));
         WaterColorArray[0].a := 255;
@@ -438,16 +438,20 @@
     else if key = 'water-bottom' then
         begin
         i:= Pos(',', s);
-        WaterColorArray[2].r:= StrToInt(Trim(Copy(s, 1, i - 1)));
+        WaterColorArray[2].r:= StrToInt(Trim(Copy(s, 1, Pred(i))));
         Delete(s, 1, i);
         i:= Pos(',', s);
-        WaterColorArray[2].g:= StrToInt(Trim(Copy(s, 1, i - 1)));
+        WaterColorArray[2].g:= StrToInt(Trim(Copy(s, 1, Pred(i))));
         Delete(s, 1, i);
         WaterColorArray[2].b:= StrToInt(Trim(s));
         WaterColorArray[2].a := 255;
         WaterColorArray[3]:= WaterColorArray[2];
         end
-    else if key = 'water-opacity' then cWaterOpacity:= StrToInt(Trim(s))
+    else if key = 'water-opacity' then
+        begin
+        cWaterOpacity:= StrToInt(Trim(s));
+        cSDWaterOpacity:= cWaterOpacity
+        end
     else if key = 'music' then MusicFN:= Trim(s)
     else if key = 'clouds' then
         begin
@@ -460,50 +464,50 @@
         with ThemeObjects.objs[Pred(ThemeObjects.Count)] do
             begin
             i:= Pos(',', s);
-            Surf:= LoadImage(Pathz[ptCurrTheme] + '/' + Trim(Copy(s, 1, i - 1)), ifCritical or ifTransparent or ifIgnoreCaps);
+            Surf:= LoadImage(Pathz[ptCurrTheme] + '/' + Trim(Copy(s, 1, Pred(i))), ifCritical or ifTransparent or ifIgnoreCaps);
             Width:= Surf^.w;
             Height:= Surf^.h;
             Delete(s, 1, i);
             i:= Pos(',', s);
-            Maxcnt:= StrToInt(Trim(Copy(s, 1, i - 1)));
+            Maxcnt:= StrToInt(Trim(Copy(s, 1, Pred(i))));
             Delete(s, 1, i);
             if (Maxcnt < 1) or (Maxcnt > MAXTHEMEOBJECTS) then OutError('Object''s max count should be between 1 and '+ inttostr(MAXTHEMEOBJECTS) +' (it was '+ inttostr(Maxcnt) +').', true);
             with inland do
                 begin
                 i:= Pos(',', s);
-                x:= StrToInt(Trim(Copy(s, 1, i - 1)));
+                x:= StrToInt(Trim(Copy(s, 1, Pred(i))));
                 Delete(s, 1, i);
                 i:= Pos(',', s);
-                y:= StrToInt(Trim(Copy(s, 1, i - 1)));
+                y:= StrToInt(Trim(Copy(s, 1, Pred(i))));
                 Delete(s, 1, i);
                 i:= Pos(',', s);
-                w:= StrToInt(Trim(Copy(s, 1, i - 1)));
+                w:= StrToInt(Trim(Copy(s, 1, Pred(i))));
                 Delete(s, 1, i);
                 i:= Pos(',', s);
-                h:= StrToInt(Trim(Copy(s, 1, i - 1)));
+                h:= StrToInt(Trim(Copy(s, 1, Pred(i))));
                 Delete(s, 1, i);
                 CheckRect(Width, Height, x, y, w, h)
                 end;
             i:= Pos(',', s);
-            rectcnt:= StrToInt(Trim(Copy(s, 1, i - 1)));
+            rectcnt:= StrToInt(Trim(Copy(s, 1, Pred(i))));
             Delete(s, 1, i);
             for ii:= 1 to rectcnt do
                 with outland[ii] do
                     begin
                     i:= Pos(',', s);
-                    x:= StrToInt(Trim(Copy(s, 1, i - 1)));
+                    x:= StrToInt(Trim(Copy(s, 1, Pred(i))));
                     Delete(s, 1, i);
                     i:= Pos(',', s);
-                    y:= StrToInt(Trim(Copy(s, 1, i - 1)));
+                    y:= StrToInt(Trim(Copy(s, 1, Pred(i))));
                     Delete(s, 1, i);
                     i:= Pos(',', s);
-                    w:= StrToInt(Trim(Copy(s, 1, i - 1)));
+                    w:= StrToInt(Trim(Copy(s, 1, Pred(i))));
                     Delete(s, 1, i);
                     if ii = rectcnt then h:= StrToInt(Trim(s))
                     else
                         begin
                         i:= Pos(',', s);
-                        h:= StrToInt(Trim(Copy(s, 1, i - 1)));
+                        h:= StrToInt(Trim(Copy(s, 1, Pred(i))));
                         Delete(s, 1, i)
                         end;
                     CheckRect(Width, Height, x, y, w, h)
@@ -516,7 +520,7 @@
         with SprayObjects.objs[Pred(SprayObjects.Count)] do
             begin
             i:= Pos(',', s);
-            Surf:= LoadImage(Pathz[ptCurrTheme] + '/' + Trim(Copy(s, 1, i - 1)), ifCritical or ifTransparent or ifIgnoreCaps);
+            Surf:= LoadImage(Pathz[ptCurrTheme] + '/' + Trim(Copy(s, 1, Pred(i))), ifCritical or ifTransparent or ifIgnoreCaps);
             Width:= Surf^.w;
             Height:= Surf^.h;
             Delete(s, 1, i);
@@ -526,29 +530,30 @@
     else if key = 'flakes' then
         begin
         i:= Pos(',', s);
-        vobCount:= StrToInt(Trim(Copy(s, 1, i - 1)));
+        vobCount:= StrToInt(Trim(Copy(s, 1, Pred(i))));
         Delete(s, 1, i);
         if vobCount > 0 then
             begin
             i:= Pos(',', s);
-            vobFramesCount:= StrToInt(Trim(Copy(s, 1, i - 1)));
+            vobFramesCount:= StrToInt(Trim(Copy(s, 1, Pred(i))));
             Delete(s, 1, i);
             i:= Pos(',', s);
-            vobFrameTicks:= StrToInt(Trim(Copy(s, 1, i - 1)));
+            vobFrameTicks:= StrToInt(Trim(Copy(s, 1, Pred(i))));
             Delete(s, 1, i);
             i:= Pos(',', s);
-            vobVelocity:= StrToInt(Trim(Copy(s, 1, i - 1)));
+            vobVelocity:= StrToInt(Trim(Copy(s, 1, Pred(i))));
             Delete(s, 1, i);
             vobFallSpeed:= StrToInt(Trim(s));
+            vobCount:= vobCount * cScreenSpace div LAND_WIDTH;
             end;
         end
     else if key = 'sd-water-top' then
         begin
         i:= Pos(',', s);
-        SDWaterColorArray[0].r:= StrToInt(Trim(Copy(s, 1, i - 1)));
+        SDWaterColorArray[0].r:= StrToInt(Trim(Copy(s, 1, Pred(i))));
         Delete(s, 1, i);
         i:= Pos(',', s);
-        SDWaterColorArray[0].g:= StrToInt(Trim(Copy(s, 1, i - 1)));
+        SDWaterColorArray[0].g:= StrToInt(Trim(Copy(s, 1, Pred(i))));
         Delete(s, 1, i);
         SDWaterColorArray[0].b:= StrToInt(Trim(s));
         SDWaterColorArray[0].a := 255;
@@ -557,10 +562,10 @@
     else if key = 'sd-water-bottom' then
         begin
         i:= Pos(',', s);
-        SDWaterColorArray[2].r:= StrToInt(Trim(Copy(s, 1, i - 1)));
+        SDWaterColorArray[2].r:= StrToInt(Trim(Copy(s, 1, Pred(i))));
         Delete(s, 1, i);
         i:= Pos(',', s);
-        SDWaterColorArray[2].g:= StrToInt(Trim(Copy(s, 1, i - 1)));
+        SDWaterColorArray[2].g:= StrToInt(Trim(Copy(s, 1, Pred(i))));
         Delete(s, 1, i);
         SDWaterColorArray[2].b:= StrToInt(Trim(s));
         SDWaterColorArray[2].a := 255;
@@ -568,23 +573,28 @@
         end
     else if key = 'sd-water-opacity' then cSDWaterOpacity:= StrToInt(Trim(s))
     else if key = 'sd-clouds' then cSDCloudsNumber:= StrToInt(Trim(s)) * cScreenSpace div LAND_WIDTH
-    else if key = 'sd-flakes' then continue //TODO: make :P
+    else if key = 'sd-flakes' then
+        begin
+        i:= Pos(',', s);
+        vobSDCount:= StrToInt(Trim(Copy(s, 1, Pred(i))));
+        Delete(s, 1, i);
+        if vobSDCount > 0 then
+            begin
+            i:= Pos(',', s);
+            vobSDFramesCount:= StrToInt(Trim(Copy(s, 1, Pred(i))));
+            Delete(s, 1, i);
+            i:= Pos(',', s);
+            vobSDFrameTicks:= StrToInt(Trim(Copy(s, 1, Pred(i))));
+            Delete(s, 1, i);
+            i:= Pos(',', s);
+            vobSDVelocity:= StrToInt(Trim(Copy(s, 1, Pred(i))));
+            Delete(s, 1, i);
+            vobSDFallSpeed:= StrToInt(Trim(s));
+            vobSDCount:= vobSDCount * cScreenSpace div LAND_WIDTH;
+            end;
+        end
     end;
 
-// adjust amount of flakes scaled by screen space
-vobCount:= longint(vobCount);
-numFlakes:= vobCount * cScreenSpace div LAND_WIDTH;
-
-if (cReducedQuality and rqKillFlakes) <> 0 then
-    numFlakes:= 0;
-
-if ((GameFlags and gfBorder) <> 0) or ((Theme <> 'Snow') and (Theme <> 'Christmas')) then
-    for i:= 0 to Pred(numFlakes) do
-        AddVisualGear(cLeftScreenBorder + random(cScreenSpace), random(1024+200) - 100 + LAND_HEIGHT, vgtFlake)
-else
-    for i:= 0 to Pred(numFlakes div 3) do
-        AddVisualGear(cLeftScreenBorder + random(cScreenSpace), random(1024+200) - 100 + LAND_HEIGHT, vgtFlake);
-
 Close(f);
 {$I+}
 TryDo(IOResult = 0, 'Bad data or cannot access file ' + cThemeCFGFilename, true);
--- a/hedgewars/uVariables.pas	Sat Jan 01 19:41:58 2011 +0100
+++ b/hedgewars/uVariables.pas	Sat Jan 01 23:10:57 2011 +0100
@@ -2107,6 +2107,8 @@
     lastVisualGearByUID: PVisualGear;
     vobFrameTicks, vobFramesCount, vobCount: Longword;
     vobVelocity, vobFallSpeed: LongInt;
+    vobSDFrameTicks, vobSDFramesCount, vobSDCount: Longword;
+    vobSDVelocity, vobSDFallSpeed: LongInt;
 
 
     hideAmmoMenu: boolean;
@@ -2127,6 +2129,7 @@
     DefaultBinds, CurrentBinds: TBinds;
 
     coeff: LongInt;
+
 {$IFDEF HWLIBRARY}
     leftClick: boolean;
     middleClick: boolean;
@@ -2293,6 +2296,12 @@
         cMaxCaptions:= 3
     else
         cMaxCaptions:= 4;
+
+    vobSDFrameTicks:= 0;
+    vobSDFramesCount:= 0;
+    vobSDCount:= 30 * cScreenSpace div LAND_WIDTH;
+    vobSDVelocity:= 0;
+    vobSDFallSpeed:= 0;
 end;
 
 procedure freeModule;
--- a/hedgewars/uVisualGears.pas	Sat Jan 01 19:41:58 2011 +0100
+++ b/hedgewars/uVisualGears.pas	Sat Jan 01 23:10:57 2011 +0100
@@ -33,6 +33,8 @@
 function  VisualGearByUID(uid : Longword) : PVisualGear;
 procedure AddClouds;
 procedure ChangeToSDClouds;
+procedure AddFlakes;
+procedure ChangeToSDFlakes;
 procedure AddDamageTag(X, Y, Damage, Color: LongWord);
 
 implementation
@@ -144,13 +146,22 @@
                 Timer:= 0;
                 tdX:= 0;
                 tdY:= 0;
-                FrameTicks:= random(vobFrameTicks);
-                Frame:= random(vobFramesCount);
+                if SuddenDeathDmg then
+                    begin
+                    FrameTicks:= random(vobSDFrameTicks);
+                    Frame:= random(vobSDFramesCount);
+                    end
+                else
+                    begin
+                    FrameTicks:= random(vobFrameTicks);
+                    Frame:= random(vobFramesCount);
+                    end;
                 Angle:= random * 360;
                 dx:= 0.0000038654705 * random(10000);
                 dy:= 0.000003506096 * random(7000);
                 if random(2) = 0 then dx := -dx;
-                dAngle:= (random(2) * 2 - 1) * (1 + random) * vobVelocity / 1000
+                if SuddenDeathDmg then dAngle:= (random(2) * 2 - 1) * (1 + random) * vobSDVelocity / 1000
+                else dAngle:= (random(2) * 2 - 1) * (1 + random) * vobVelocity / 1000
                 end;
     vgtCloud: begin
                 Frame:= random(4);
@@ -385,14 +396,14 @@
         begin
         if Gear^.Tint <> $FFFFFFFF then Tint(Gear^.Tint);
         case Gear^.Kind of
-            vgtFlake: if vobVelocity = 0 then
-                        if SuddenDeathDmg then
+            vgtFlake: if SuddenDeathDmg then
+                        if vobSDVelocity = 0 then
                             DrawSprite(sprSDFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame)
                         else
-                            DrawSprite(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame)
+                            DrawRotatedF(sprSDFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle)
                       else
-                        if SuddenDeathDmg then
-                            DrawRotatedF(sprSDFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle)
+                        if vobVelocity = 0 then
+                            DrawSprite(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame)
                         else
                             DrawRotatedF(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle);
             vgtCloud: if SuddenDeathDmg then
@@ -577,6 +588,42 @@
     AddVisualGear(cLeftScreenBorder + i * cScreenSpace div (cSDCloudsNumber + 1), LAND_HEIGHT-1184, vgtCloud)
 end;
 
+procedure AddFlakes;
+var i: LongInt;
+begin
+if (cReducedQuality and rqKillFlakes) <> 0 then exit;
+
+if ((GameFlags and gfBorder) <> 0) or ((Theme <> 'Snow') and (Theme <> 'Christmas')) then
+    for i:= 0 to Pred(vobCount) do
+        AddVisualGear(cLeftScreenBorder + random(cScreenSpace), random(1024+200) - 100 + LAND_HEIGHT, vgtFlake)
+else
+    for i:= 0 to Pred(vobCount div 3) do
+        AddVisualGear(cLeftScreenBorder + random(cScreenSpace), random(1024+200) - 100 + LAND_HEIGHT, vgtFlake);
+end;
+
+procedure ChangeToSDFlakes;
+var       i: LongInt;
+    vg, tmp: PVisualGear;
+begin
+if (cReducedQuality and rqKillFlakes) <> 0 then exit;
+if vobCount = vobSDCount then exit;
+vg:= VisualGearsList;
+while vg <> nil do
+    if vg^.Kind = vgtFlake then
+        begin
+        tmp:= vg^.NextGear;
+        DeleteVisualGear(vg);
+        vg:= tmp
+        end
+    else vg:= vg^.NextGear;
+if ((GameFlags and gfBorder) <> 0) or ((Theme <> 'Snow') and (Theme <> 'Christmas')) then
+    for i:= 0 to Pred(vobSDCount) do
+        AddVisualGear(cLeftScreenBorder + random(cScreenSpace), random(1024+200) - 100 + LAND_HEIGHT, vgtFlake)
+else
+    for i:= 0 to Pred(vobSDCount div 3) do
+        AddVisualGear(cLeftScreenBorder + random(cScreenSpace), random(1024+200) - 100 + LAND_HEIGHT, vgtFlake);
+end;
+
 procedure initModule;
 begin
     VisualGearsList:= nil;
Binary file share/hedgewars/Data/Themes/Underwater/SDClouds.png has changed