hedgewars/uLand.pas
changeset 10162 38dbf26475d8
parent 10142 adb804cb2638
child 10163 b994afa40326
equal deleted inserted replaced
10161:c092f92aee23 10162:38dbf26475d8
    25 procedure initModule;
    25 procedure initModule;
    26 procedure freeModule;
    26 procedure freeModule;
    27 procedure DrawBottomBorder;
    27 procedure DrawBottomBorder;
    28 procedure GenMap;
    28 procedure GenMap;
    29 procedure GenPreview(out Preview: TPreview);
    29 procedure GenPreview(out Preview: TPreview);
       
    30 procedure GenPreviewAlpha(out Preview: TPreviewAlpha);
    30 
    31 
    31 implementation
    32 implementation
    32 uses uConsole, uStore, uRandom, uLandObjects, uIO, uLandTexture, SysUtils,
    33 uses uConsole, uStore, uRandom, uLandObjects, uIO, uLandTexture, SysUtils,
    33      uVariables, uUtils, uCommands, adler32, uDebug, uLandPainted, uTextures,
    34      uVariables, uUtils, uCommands, adler32, uDebug, uLandPainted, uTextures,
    34      uLandGenMaze, uLandOutline, uPhysFSLayer, uScript;
    35      uLandGenMaze, uLandOutline, uPhysFSLayer, uScript;
   867             end;
   868             end;
   868         end;
   869         end;
   869 end;
   870 end;
   870 
   871 
   871 
   872 
       
   873 procedure GenPreviewAlpha(out Preview: TPreviewAlpha);
       
   874 var rh, rw, ox, oy, x, y, xx, yy, t, lh, lw: LongInt;
       
   875 begin
       
   876     WriteLnToConsole('Generating preview...');
       
   877     case cMapGen of
       
   878         0: GenBlank(EdgeTemplates[SelectTemplate]);
       
   879         1: begin ResizeLand(4096,2048); GenMaze; end;
       
   880         2: GenDrawnMap;
       
   881     else
       
   882         OutError('Unknown mapgen', true);
       
   883     end;
       
   884 
       
   885     // strict scaling needed here since preview assumes a rectangle
       
   886     rh:= max(LAND_HEIGHT, 2048);
       
   887     rw:= max(LAND_WIDTH, 4096);
       
   888     ox:= 0;
       
   889     if rw < rh*2 then
       
   890         begin
       
   891         rw:= rh*2;
       
   892         end;
       
   893     if rh < rw div 2 then rh:= rw * 2;
       
   894 
       
   895     ox:= (rw-LAND_WIDTH) div 2;
       
   896     oy:= rh-LAND_HEIGHT;
       
   897 
       
   898     lh:= rh div 128;
       
   899     lw:= rw div 256;
       
   900     for y:= 0 to 127 do
       
   901         for x:= 0 to 255 do
       
   902             begin
       
   903             t:= 0;
       
   904 
       
   905             for yy:= y * lh - oy to y * lh + 7 - oy do
       
   906                 for xx:= x * lw - ox to x * lw + 7 - ox do
       
   907                     if (yy and LAND_HEIGHT_MASK = 0) and (xx and LAND_WIDTH_MASK = 0)
       
   908                         and (Land[yy, xx] <> 0) then
       
   909                         inc(t);
       
   910 
       
   911             Preview[y, x]:= t * 1023 div 256;
       
   912             if t > 8 then Preview[y, x]:= 255 else Preview[y, x]:= 0
       
   913             end;
       
   914 end;
       
   915 
   872 procedure chLandCheck(var s: shortstring);
   916 procedure chLandCheck(var s: shortstring);
   873 begin
   917 begin
   874     AddFileLog('CheckLandDigest: ' + s + ' digest : ' + digest);
   918     AddFileLog('CheckLandDigest: ' + s + ' digest : ' + digest);
   875     if digest = '' then
   919     if digest = '' then
   876         digest:= s
   920         digest:= s