hedgewars/uLandGraphics.pas
changeset 8624 12bdc51a6790
parent 8612 f7c194533d45
child 8628 627e76986a08
equal deleted inserted replaced
8623:93645b4ba0de 8624:12bdc51a6790
   262         begin
   262         begin
   263         if (i < 0) or
   263         if (i < 0) or
   264            (i > LAND_WIDTH - 1) or
   264            (i > LAND_WIDTH - 1) or
   265            (j < 0) or
   265            (j < 0) or
   266            (j > LAND_HEIGHT -1) then
   266            (j > LAND_HEIGHT -1) then
   267                begin               
   267            begin               
   268                 result := 0;
   268            result := 0;
   269                 exit;
   269            exit;
   270                end;
   270            end;
   271 
   271 
   272         if ((Land[j, i] and $FF00) = 0) and ((Land[j, i] and lfIce) = 0) then
   272         if Land[j, i] and $FF00 and not lfIce = 0 then
   273            begin
       
   274            result := result + 1;
   273            result := result + 1;
   275            end;
       
   276         end;
   274         end;
   277 end;
   275 end;
   278 
   276 
   279 procedure drawIcePixel(y, x:Longint);
   277 procedure drawIcePixel(y, x:Longint);
   280 var
   278 var
   286 begin
   284 begin
   287     // So. 3 parameters here. Ice colour, Ice opacity, and a bias on the greyscaled pixel towards lightness
   285     // So. 3 parameters here. Ice colour, Ice opacity, and a bias on the greyscaled pixel towards lightness
   288     iceSurface:= SpritesData[sprIceTexture].Surface;
   286     iceSurface:= SpritesData[sprIceTexture].Surface;
   289     icePixels := iceSurface^.pixels;
   287     icePixels := iceSurface^.pixels;
   290     w:= LandPixels[y, x];
   288     w:= LandPixels[y, x];
   291     w:= round(((w shr RShift and $FF) * RGB_LUMINANCE_RED +
   289     if w > 0 then
   292           (w shr BShift and $FF) * RGB_LUMINANCE_GREEN +
   290         begin
   293           (w shr GShift and $FF) * RGB_LUMINANCE_BLUE));
   291         w:= round(((w shr RShift and $FF) * RGB_LUMINANCE_RED +
   294     if w < 128 then w:= w+128;
   292               (w shr BShift and $FF) * RGB_LUMINANCE_GREEN +
   295     if w > 255 then w:= 255;
   293               (w shr GShift and $FF) * RGB_LUMINANCE_BLUE));
   296     w:= (w shl RShift) or (w shl BShift) or (w shl GShift) or (LandPixels[y,x] and AMask);
   294         if w < 128 then w:= w+128;
   297     //LandPixels[y, x]:= w;
   295         if w > 255 then w:= 255;
   298     LandPixels[y, x]:= addBgColor(w, IceColor);
   296         w:= (w shl RShift) or (w shl BShift) or (w shl GShift) or (LandPixels[y,x] and AMask);
   299     LandPixels[y, x]:= addBgColor(LandPixels[y, x], icePixels^[iceSurface^.w * (y mod iceSurface^.h) + (x mod iceSurface^.w)]);
   297         LandPixels[y, x]:= addBgColor(w, IceColor);
       
   298         LandPixels[y, x]:= addBgColor(LandPixels[y, x], icePixels^[iceSurface^.w * (y mod iceSurface^.h) + (x mod iceSurface^.w)])
       
   299         end
       
   300     else 
       
   301         begin
       
   302         LandPixels[y, x]:= IceColor and not AMask or $E8 shl AShift;
       
   303         LandPixels[y, x]:= addBgColor(LandPixels[y, x], icePixels^[iceSurface^.w * (y mod iceSurface^.h) + (x mod iceSurface^.w)]);
       
   304         // silly workaround to avoid having to make background erasure a tadb it smarter about sea ice
       
   305         if LandPixels[y, x] and AMask shr AShift = 255 then 
       
   306             LandPixels[y, x]:= LandPixels[y, x] and not AMask or 254 shl AShift;
       
   307         end;
   300 end;
   308 end;
   301 
   309 
   302 function getIncrementInquarter(dx, dy, quarter: Longint): Longint; inline;
   310 function getIncrementInquarter(dx, dy, quarter: Longint): Longint; inline;
   303 const directionX : array [0..3] of Longint = (0, 0, 1, -1);
   311 const directionX : array [0..3] of Longint = (0, 0, 1, -1);
   304 const directionY : array [0..3] of Longint = (1, -1, 0, 0);
   312 const directionY : array [0..3] of Longint = (1, -1, 0, 0);
   383 begin
   391 begin
   384 for i := min(max(x - iceRadius, 0), LAND_WIDTH - 1) to min(max(x + iceRadius, 0), LAND_WIDTH - 1) do
   392 for i := min(max(x - iceRadius, 0), LAND_WIDTH - 1) to min(max(x + iceRadius, 0), LAND_WIDTH - 1) do
   385     begin
   393     begin
   386     for j := min(max(y, 0), LAND_HEIGHT - 1) to min(max(y + iceHeight, 0), LAND_HEIGHT - 1) do
   394     for j := min(max(y, 0), LAND_HEIGHT - 1) to min(max(y + iceHeight, 0), LAND_HEIGHT - 1) do
   387         begin
   395         begin
   388         if land[j, i] = 0 then
   396         if Land[j, i] = 0 then
   389             begin
   397             begin
   390                 land[j, i] := lfIce;                
   398             Land[j, i] := lfIce;                
   391                 drawIcePixel(j, i);
   399             drawIcePixel(j, i);
   392             end;
   400             end;
   393         end;        
   401         end;        
   394     end;
   402     end;
   395 landRect.x := min(max(x - iceRadius, 0), LAND_WIDTH - 1);
   403 landRect.x := min(max(x - iceRadius, 0), LAND_WIDTH - 1);
   396 landRect.y := min(max(y, 0), LAND_HEIGHT - 1);
   404 landRect.y := min(max(y, 0), LAND_HEIGHT - 1);