huh. how'd we end up needing a merge here... icegun
authornemo
Tue, 26 Feb 2013 20:26:49 -0500
branchicegun
changeset 8588 47084c6fcb4e
parent 8584 ea20d9cc8515 (diff)
parent 8587 6319accfa04a (current diff)
child 8589 3bb505fc707e
huh. how'd we end up needing a merge here...
hedgewars/GSHandlers.inc
hedgewars/uLandGraphics.pas
--- a/hedgewars/GSHandlers.inc	Tue Feb 26 17:04:40 2013 +0200
+++ b/hedgewars/GSHandlers.inc	Tue Feb 26 20:26:49 2013 -0500
@@ -5125,13 +5125,57 @@
         end;
 end;
 
+
+procedure drawIcePixel(x, y:Longint);
+var 
+    iceSurface: PSDL_Surface;
+    icePixels: PLongwordArray;
+    pictureX, pictureY: LongInt;
+    w, c: LongWord;
+begin
+    if Land[y, x] and lfIce <> 0 then exit;
+// So. 3 parameters here. Ice colour, Ice opacity, and a bias on the greyscaled pixel towards lightness
+    iceSurface:= SpritesData[sprIceTexture].Surface;
+    pictureX := x mod iceSurface^.w;
+    pictureY := y mod iceSurface^.h;
+    icePixels := iceSurface^.pixels;
+    w:= LandPixels[y, x];
+    w:= round(((w shr RShift and $FF) * RGB_LUMINANCE_RED +
+          (w shr BShift and $FF) * RGB_LUMINANCE_GREEN +
+          (w shr GShift and $FF) * RGB_LUMINANCE_BLUE));
+    if w < 128 then w:= w+128;
+    if w > 255 then w:= 255;
+    w:= (w shl RShift) or (w shl BShift) or (w shl GShift) or (LandPixels[y,x] and AMask);
+    //LandPixels[y, x]:= w;
+    LandPixels[y, x]:= addBgColor(w, IceColor);
+    LandPixels[y, x]:= addBgColor(LandPixels[y, x], icePixels^[iceSurface^.w * (y mod iceSurface^.h) + (x mod iceSurface^.w)]);
+
+    Land[y, x] := Land[y, x] or lfIce;
+end;
+
+procedure DrawIce(x, y: Longint); 
+    const iceRadius :Longint = 32;
+var
+    i, j: Longint;
+    weight: Longint;
+    landRect : TSDL_RECT;
+begin
+    FillRoundInLandWithIce(x, y, iceRadius);
+    SetAllHHToActive; 
+    landRect.x := min(max(x - iceRadius, 0), LAND_WIDTH - 1);
+    landRect.y := min(max(y - iceRadius, 0), LAND_HEIGHT - 1);
+    landRect.w := min(2*iceRadius, LAND_WIDTH - landRect.x - 1);
+    landRect.h := min(2*iceRadius, LAND_HEIGHT - landRect.y - 1);
+    UpdateLandTexture(landRect.x, landRect.w, landRect.y, landRect.h, true);
+end;
+
+
 procedure doStepIceGun(Gear: PGear);
 const iceWaitCollision:Longint = 0;
 const iceCollideWithGround:Longint = 1;
 const iceWaitNextTarget:Longint = 2;
 const iceCollideWithHog:Longint = 4;
 const groundFreezingTime:Longint = 1000;
-const iceRadius:Longint = 32;
 var
     HHGear: PGear;
     ndX, ndY: hwFloat;
@@ -5193,8 +5237,7 @@
 
                 if (IceState = iceCollideWithGround) and ((GameTicks - IceTime) > groundFreezingTime) then
                 begin 
-                    FillRoundInLandWithIce(Target.X, Target.Y, iceRadius);                                        
-                    SetAllHHToActive; 
+                    DrawIce(Target.X, Target.Y);                                        
                     IceState := iceWaitNextTarget;
                 end;
 
--- a/hedgewars/uLandGraphics.pas	Tue Feb 26 17:04:40 2013 +0200
+++ b/hedgewars/uLandGraphics.pas	Tue Feb 26 20:26:49 2013 -0500
@@ -247,21 +247,33 @@
 end;
 
 
+function isLandscapeEdge(weight:Longint):boolean;
+begin
+    result := (weight < 8) and (weight >= 2);
+end;
 
+function isLandscape(weight:Longint):boolean;
+begin
+    result := weight < 2;
+end;
 
+function isEmptySpace(weight:Longint):boolean;
+begin
+    result := not isLandscape(weight) and not isLandscapeEdge(weight);
+end;
 
 function getPixelWeight(x, y:Longint): Longint;
 var
     i, j:Longint;
-begin    
+begin
     result := 0;
     for i := x - 1 to x + 1 do
-        for j := y - 1 to y + 1 do 
+        for j := y - 1 to y + 1 do
         begin
-        if (i < 0) or 
-           (i > LAND_WIDTH - 1) or 
-           (j < 0) or 
-           (j > LAND_HEIGHT -1) or 
+        if (i < 0) or
+           (i > LAND_WIDTH - 1) or
+           (j < 0) or
+           (j > LAND_HEIGHT -1) or
            ((Land[j, i] and $FF00) = 0) then
            begin
            result := result + 1;
@@ -270,56 +282,52 @@
 end;
 
 procedure drawIcePixel(y, x:Longint);
-var 
+var
     iceSurface: PSDL_Surface;
     icePixels: PLongwordArray;
     pictureX, pictureY: LongInt;
     w, c: LongWord;
     weight: Longint;
 begin
-weight := getPixelWeight(x, y);
-if (land[y, x] and lfIce) <> 0 then
-    exit;
-//pixel in landscape
-if weight < 2 then
-    begin
-    // So. 3 parameters here. Ice colour, Ice opacity, and a bias on the greyscaled pixel towards lightness
-    c:= $7dc1ccff;
-    // FIXME should be a global value, not set every single pixel.  Just for test purposes
-    c:= ($44 shl RShift) or ($97 shl GShift) or ($A9 shl BShift) or ($A0 shl AShift);
-    iceSurface:= SpritesData[sprIceTexture].Surface;
-    pictureX := x mod iceSurface^.w;
-    pictureY := y mod iceSurface^.h;
-    icePixels := iceSurface^.pixels;
-    w:= LandPixels[y, x];
-    w:= round(((w shr RShift and $FF) * RGB_LUMINANCE_RED +
-          (w shr BShift and $FF) * RGB_LUMINANCE_GREEN +
-          (w shr GShift and $FF) * RGB_LUMINANCE_BLUE));
-    if w < 128 then w:= w+128;
-    if w > 255 then w:= 255;
-    w:= (w shl RShift) or (w shl BShift) or (w shl GShift) or (LandPixels[y,x] and AMask);
-    //LandPixels[y, x]:= w;
-    LandPixels[y, x]:= addBgColor(w, c);
-    LandPixels[y, x]:= addBgColor(LandPixels[y, x], icePixels^[iceSurface^.w * (y mod iceSurface^.h) + (x mod iceSurface^.w)]);
-    end
-//pixel is on edge of lanscape
-else if (weight < 8) then
-    begin
-        LandPixels[y, x] := $FFB2AF8A;                    
-    end;
+    weight := getPixelWeight(x, y);
+    if isLandscape(weight) then
+        begin
+        // So. 3 parameters here. Ice colour, Ice opacity, and a bias on the greyscaled pixel towards lightness
+        iceSurface:= SpritesData[sprIceTexture].Surface;
+        pictureX := x mod iceSurface^.w;
+        pictureY := y mod iceSurface^.h;
+        icePixels := iceSurface^.pixels;
+        w:= LandPixels[y, x];
+        w:= round(((w shr RShift and $FF) * RGB_LUMINANCE_RED +
+              (w shr BShift and $FF) * RGB_LUMINANCE_GREEN +
+              (w shr GShift and $FF) * RGB_LUMINANCE_BLUE));
+        if w < 128 then w:= w+128;
+        if w > 255 then w:= 255;
+        w:= (w shl RShift) or (w shl BShift) or (w shl GShift) or (LandPixels[y,x] and AMask);
+        //LandPixels[y, x]:= w;
+        LandPixels[y, x]:= addBgColor(w, IceColor);
+        LandPixels[y, x]:= addBgColor(LandPixels[y, x], icePixels^[iceSurface^.w * (y mod iceSurface^.h) + (x mod iceSurface^.w)]);
+        Land[y, x] := land[y, x] or lfIce;
+        end
+    else if (isLandscapeEdge(weight)) then
+        begin
+        LandPixels[y, x] := $FFB2AF8A;
+        if Land[y, x] > 255 then Land[y, x] := Land[y, x] or lfIce;
+        end;
+
 end;
 
 function getIncrementInquarter(dx, dy, quarter: Longint): Longint;
 const directionX : array [0..3] of Longint = (0, 0, 1, -1);
 const directionY : array [0..3] of Longint = (1, -1, 0, 0);
-begin    
+begin
     getIncrementInquarter := directionX[quarter] * dx + directionY[quarter] * dy;
 end;
 
 function getIncrementInquarter2(dx, dy, quarter: Longint): Longint;
 const directionY : array [0..3] of Longint = (0, 0, 1, 1);
 const directionX : array [0..3] of Longint = (1, 1, 0, 0);
-begin    
+begin
     getIncrementInquarter2 := directionX[quarter] * dx + directionY[quarter] * dy;
 end;
 
@@ -331,44 +339,34 @@
         t:= y + getIncrementInquarter(dx, dy, q);
         if (t and LAND_HEIGHT_MASK) = 0 then
             for i:= Max(x - getIncrementInquarter2(dx, dy, q), 0) to Min(x + getIncrementInquarter2(dx, dy, q), LAND_WIDTH - 1) do
-                if ((Land[t, i] and lfIndestructible) = 0) and (not disableLandBack or (Land[t, i] > 255))  then
-                begin
+                if (Land[t, i] and (lfIndestructible or lfIce) = 0) and (not disableLandBack or (Land[t, i] > 255))  then
                     if (cReducedQuality and rqBlurryLand) = 0 then
                        drawIcePixel(t, i)
                     else
-                       drawIcePixel(t div 2, i div 2) ;        
-                    if Land[y, x] > 255 then Land[y, x] := Land[y, x] or lfIce;
-                end;
+                       drawIcePixel(t div 2, i div 2) ;
     end;
 end;
 
 procedure FillRoundInLandWithIce(X, Y, Radius: LongInt);
 var dx, dy, d: LongInt;
-    landRect : TSDL_RECT;
 begin
 dx:= 0;
 dy:= Radius;
 d:= 3 - 2 * Radius;
-while (dx < dy) do
-    begin
-    FillLandCircleLinesIce(x, y, dx, dy);
-    if (d < 0) then
-        d:= d + 4 * dx + 6
-    else
+    while (dx < dy) do
         begin
-        d:= d + 4 * (dx - dy) + 10;
-        dec(dy)
+        FillLandCircleLinesIce(x, y, dx, dy);
+        if (d < 0) then
+            d:= d + 4 * dx + 6
+        else
+            begin
+            d:= d + 4 * (dx - dy) + 10;
+            dec(dy)
+            end;
+        inc(dx)
         end;
-    inc(dx)
-    end;
-if (dx = dy) then
-    FillLandCircleLinesIce(x, y, dx, dy);
-
-landRect.x := min(max(x - Radius, 0), LAND_WIDTH - 1);
-landRect.y := min(max(y - Radius, 0), LAND_HEIGHT - 1);
-landRect.w := min(2*Radius, LAND_WIDTH - landRect.x - 1);
-landRect.h := min(2*Radius, LAND_HEIGHT - landRect.y - 1);
-UpdateLandTexture(landRect.x, landRect.w, landRect.y, landRect.h, true);
+    if (dx = dy) then
+        FillLandCircleLinesIce(x, y, dx, dy);
 end;
 
 
--- a/hedgewars/uVariables.pas	Tue Feb 26 17:04:40 2013 +0200
+++ b/hedgewars/uVariables.pas	Tue Feb 26 20:26:49 2013 -0500
@@ -115,6 +115,7 @@
 
     // originally typed consts
     ExplosionBorderColor: LongWord;
+    IceColor            : LongWord;
     WaterOpacity: byte;
     SDWaterOpacity: byte;
     GrayScale: Boolean;
@@ -2409,6 +2410,7 @@
     SDWaterOpacity:= $80;
     SDTint:= $80;
     ExplosionBorderColor:= $FF808080;
+    IceColor:= ($44 shl RShift) or ($97 shl GShift) or ($A9 shl BShift) or ($A0 shl AShift);
     WaterOpacity:= $80;
 
     cDrownSpeed.QWordValue  := 257698038;       // 0.06