hedgewars/uLand.pas
changeset 10017 de822cd3df3a
parent 10015 4feced261c68
child 10040 4ac87acbaed9
equal deleted inserted replaced
10015:4feced261c68 10017:de822cd3df3a
    35 
    35 
    36 var digest: shortstring;
    36 var digest: shortstring;
    37 
    37 
    38 procedure ResizeLand(width, height: LongWord);
    38 procedure ResizeLand(width, height: LongWord);
    39 var potW, potH: LongInt;
    39 var potW, potH: LongInt;
    40 begin 
    40 begin
    41 potW:= toPowerOf2(width);
    41 potW:= toPowerOf2(width);
    42 potH:= toPowerOf2(height);
    42 potH:= toPowerOf2(height);
    43 if (potW <> LAND_WIDTH) or (potH <> LAND_HEIGHT) then
    43 if (potW <> LAND_WIDTH) or (potH <> LAND_HEIGHT) then
    44     begin
    44     begin
    45     LAND_WIDTH:= potW;
    45     LAND_WIDTH:= potW;
   118     c1:= AMask;
   118     c1:= AMask;
   119     c2:= AMask or RMask or GMask;
   119     c2:= AMask or RMask or GMask;
   120 
   120 
   121     // vertical
   121     // vertical
   122     s:= LAND_HEIGHT;
   122     s:= LAND_HEIGHT;
   123     
   123 
   124     for x:= 0 to LAND_WIDTH - 1 do
   124     for x:= 0 to LAND_WIDTH - 1 do
   125         for y:= 0 to LAND_HEIGHT - 1 do
   125         for y:= 0 to LAND_HEIGHT - 1 do
   126             if Land[y, x] = 0 then
   126             if Land[y, x] = 0 then
   127                 if s < y then
   127                 if s < y then
   128                     begin
   128                     begin
   129                     for i:= max(s, y - 8) to y - 1 do
   129                     for i:= max(s, y - 8) to y - 1 do
   130                         begin
   130                         begin
   131                         if ((x + i) and 16) = 0 then c:= c1 else c:= c2;
   131                         if ((x + i) and 16) = 0 then c:= c1 else c:= c2;
   132                         
   132 
   133                         if (cReducedQuality and rqBlurryLand) = 0 then
   133                         if (cReducedQuality and rqBlurryLand) = 0 then
   134                             LandPixels[i, x]:= c
   134                             LandPixels[i, x]:= c
   135                         else
   135                         else
   136                             LandPixels[i div 2, x div 2]:= c
   136                             LandPixels[i div 2, x div 2]:= c
   137                         end;
   137                         end;
   142                 begin
   142                 begin
   143                 if s > y then s:= y;
   143                 if s > y then s:= y;
   144                 if s + 8 > y then
   144                 if s + 8 > y then
   145                     begin
   145                     begin
   146                     if ((x + y) and 16) = 0 then c:= c1 else c:= c2;
   146                     if ((x + y) and 16) = 0 then c:= c1 else c:= c2;
   147                     
   147 
   148                     if (cReducedQuality and rqBlurryLand) = 0 then
   148                     if (cReducedQuality and rqBlurryLand) = 0 then
   149                         LandPixels[y, x]:= c
   149                         LandPixels[y, x]:= c
   150                     else
   150                     else
   151                         LandPixels[y div 2, x div 2]:= c
   151                         LandPixels[y div 2, x div 2]:= c
   152                     end;            
   152                     end;
   153                 end;
   153                 end;
   154                 
   154 
   155     // horizontal
   155     // horizontal
   156     s:= LAND_WIDTH;
   156     s:= LAND_WIDTH;
   157     
   157 
   158     for y:= 0 to LAND_HEIGHT - 1 do
   158     for y:= 0 to LAND_HEIGHT - 1 do
   159         for x:= 0 to LAND_WIDTH - 1 do
   159         for x:= 0 to LAND_WIDTH - 1 do
   160             if Land[y, x] = 0 then
   160             if Land[y, x] = 0 then
   161                 if s < x then
   161                 if s < x then
   162                     begin
   162                     begin
   163                     for i:= max(s, x - 8) to x - 1 do
   163                     for i:= max(s, x - 8) to x - 1 do
   164                         begin
   164                         begin
   165                         if ((y + i) and 16) = 0 then c:= c1 else c:= c2;
   165                         if ((y + i) and 16) = 0 then c:= c1 else c:= c2;
   166                         
   166 
   167                         if (cReducedQuality and rqBlurryLand) = 0 then
   167                         if (cReducedQuality and rqBlurryLand) = 0 then
   168                             LandPixels[y, i]:= c
   168                             LandPixels[y, i]:= c
   169                         else
   169                         else
   170                             LandPixels[y div 2, i div 2]:= c
   170                             LandPixels[y div 2, i div 2]:= c
   171                         end;
   171                         end;
   176                 begin
   176                 begin
   177                 if s > x then s:= x;
   177                 if s > x then s:= x;
   178                 if s + 8 > x then
   178                 if s + 8 > x then
   179                     begin
   179                     begin
   180                     if ((x + y) and 16) = 0 then c:= c1 else c:= c2;
   180                     if ((x + y) and 16) = 0 then c:= c1 else c:= c2;
   181                     
   181 
   182                     if (cReducedQuality and rqBlurryLand) = 0 then
   182                     if (cReducedQuality and rqBlurryLand) = 0 then
   183                         LandPixels[y, x]:= c
   183                         LandPixels[y, x]:= c
   184                     else
   184                     else
   185                         LandPixels[y div 2, x div 2]:= c
   185                         LandPixels[y div 2, x div 2]:= c
   186                     end;            
   186                     end;
   187                 end
   187                 end
   188 end;
   188 end;
   189 
   189 
   190 procedure ColorizeLand(Surface: PSDL_Surface);
   190 procedure ColorizeLand(Surface: PSDL_Surface);
   191 var tmpsurf: PSDL_Surface;
   191 var tmpsurf: PSDL_Surface;
   373             repeat
   373             repeat
   374                 inc(cTemplateFilter);
   374                 inc(cTemplateFilter);
   375                 dec(l, TemplateCounts[cTemplateFilter]);
   375                 dec(l, TemplateCounts[cTemplateFilter]);
   376             until l < 0;
   376             until l < 0;
   377             end else getRandom(1);
   377             end else getRandom(1);
   378         
   378 
   379         case cTemplateFilter of
   379         case cTemplateFilter of
   380         0: OutError('Ask unC0Rr about what you did wrong', true);
   380         0: OutError('Ask unC0Rr about what you did wrong', true);
   381         1: SelectTemplate:= SmallTemplates[getrandom(TemplateCounts[cTemplateFilter])];
   381         1: SelectTemplate:= SmallTemplates[getrandom(TemplateCounts[cTemplateFilter])];
   382         2: SelectTemplate:= MediumTemplates[getrandom(TemplateCounts[cTemplateFilter])];
   382         2: SelectTemplate:= MediumTemplates[getrandom(TemplateCounts[cTemplateFilter])];
   383         3: SelectTemplate:= LargeTemplates[getrandom(TemplateCounts[cTemplateFilter])];
   383         3: SelectTemplate:= LargeTemplates[getrandom(TemplateCounts[cTemplateFilter])];
   434     if gameFlags and gfShoppaBorder = 0 then DrawBorderFromImage(tmpsurf);
   434     if gameFlags and gfShoppaBorder = 0 then DrawBorderFromImage(tmpsurf);
   435     AddOnLandObjects(tmpsurf);
   435     AddOnLandObjects(tmpsurf);
   436 
   436 
   437     LandSurface2LandPixels(tmpsurf);
   437     LandSurface2LandPixels(tmpsurf);
   438     SDL_FreeSurface(tmpsurf);
   438     SDL_FreeSurface(tmpsurf);
   439     
   439 
   440     if gameFlags and gfShoppaBorder <> 0 then DrawShoppaBorder;
   440     if gameFlags and gfShoppaBorder <> 0 then DrawShoppaBorder;
   441     
   441 
   442     for x:= leftX+2 to rightX-2 do
   442     for x:= leftX+2 to rightX-2 do
   443         for y:= topY+2 to LAND_HEIGHT-3 do
   443         for y:= topY+2 to LAND_HEIGHT-3 do
   444             if (Land[y, x] = 0) and 
   444             if (Land[y, x] = 0) and
   445                (((Land[y, x-1] = lfBasic) and ((Land[y+1,x] = lfBasic)) or (Land[y-1,x] = lfBasic)) or
   445                (((Land[y, x-1] = lfBasic) and ((Land[y+1,x] = lfBasic)) or (Land[y-1,x] = lfBasic)) or
   446                ((Land[y, x+1] = lfBasic) and ((Land[y-1,x] = lfBasic) or (Land[y+1,x] = lfBasic)))) then
   446                ((Land[y, x+1] = lfBasic) and ((Land[y-1,x] = lfBasic) or (Land[y+1,x] = lfBasic)))) then
   447             begin
   447             begin
   448                 if (cReducedQuality and rqBlurryLand) = 0 then
   448                 if (cReducedQuality and rqBlurryLand) = 0 then
   449                     begin
   449                     begin
   450                     if (Land[y, x-1] = lfBasic) and (LandPixels[y, x-1] and AMask <> 0) then
   450                     if (Land[y, x-1] = lfBasic) and (LandPixels[y, x-1] and AMask <> 0) then
   451                         LandPixels[y, x]:= LandPixels[y, x-1]
   451                         LandPixels[y, x]:= LandPixels[y, x-1]
   452                         
   452 
   453                     else if (Land[y, x+1] = lfBasic) and (LandPixels[y, x+1] and AMask <> 0) then
   453                     else if (Land[y, x+1] = lfBasic) and (LandPixels[y, x+1] and AMask <> 0) then
   454                         LandPixels[y, x]:= LandPixels[y, x+1]
   454                         LandPixels[y, x]:= LandPixels[y, x+1]
   455                         
   455 
   456                     else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1, x] and AMask <> 0) then
   456                     else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1, x] and AMask <> 0) then
   457                         LandPixels[y, x]:= LandPixels[y-1, x]
   457                         LandPixels[y, x]:= LandPixels[y-1, x]
   458                         
   458 
   459                     else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1, x] and AMask <> 0) then
   459                     else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1, x] and AMask <> 0) then
   460                         LandPixels[y, x]:= LandPixels[y+1, x];
   460                         LandPixels[y, x]:= LandPixels[y+1, x];
   461                         
   461 
   462                     if (((LandPixels[y,x] and AMask) shr AShift) > 10) then
   462                     if (((LandPixels[y,x] and AMask) shr AShift) > 10) then
   463                         LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (128 shl AShift)
   463                         LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (128 shl AShift)
   464                     end;
   464                     end;
   465                 Land[y,x]:= lfObject
   465                 Land[y,x]:= lfObject
   466             end
   466             end
   471                     ((Land[y, x+1] = lfBasic) and (Land[y-1,x+1] = lfBasic) and (Land[y-2,x] = lfBasic)) or
   471                     ((Land[y, x+1] = lfBasic) and (Land[y-1,x+1] = lfBasic) and (Land[y-2,x] = lfBasic)) or
   472                     ((Land[y+1, x] = lfBasic) and (Land[y+1,x+1] = lfBasic) and (Land[y,x+2] = lfBasic)) or
   472                     ((Land[y+1, x] = lfBasic) and (Land[y+1,x+1] = lfBasic) and (Land[y,x+2] = lfBasic)) or
   473                     ((Land[y-1, x] = lfBasic) and (Land[y-1,x+1] = lfBasic) and (Land[y,x+2] = lfBasic)) or
   473                     ((Land[y-1, x] = lfBasic) and (Land[y-1,x+1] = lfBasic) and (Land[y,x+2] = lfBasic)) or
   474                     ((Land[y+1, x] = lfBasic) and (Land[y+1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic)) or
   474                     ((Land[y+1, x] = lfBasic) and (Land[y+1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic)) or
   475                     ((Land[y-1, x] = lfBasic) and (Land[y-1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic))) then
   475                     ((Land[y-1, x] = lfBasic) and (Land[y-1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic))) then
   476                     
   476 
   477                 begin
   477                 begin
   478                 
   478 
   479                 if (cReducedQuality and rqBlurryLand) = 0 then
   479                 if (cReducedQuality and rqBlurryLand) = 0 then
   480                 
   480 
   481                     begin
   481                     begin
   482                     
   482 
   483                     if (Land[y, x-1] = lfBasic) and (LandPixels[y,x-1] and AMask <> 0) then
   483                     if (Land[y, x-1] = lfBasic) and (LandPixels[y,x-1] and AMask <> 0) then
   484                         LandPixels[y, x]:= LandPixels[y, x-1]
   484                         LandPixels[y, x]:= LandPixels[y, x-1]
   485                         
   485 
   486                     else if (Land[y, x+1] = lfBasic) and (LandPixels[y,x+1] and AMask <> 0) then
   486                     else if (Land[y, x+1] = lfBasic) and (LandPixels[y,x+1] and AMask <> 0) then
   487                         LandPixels[y, x]:= LandPixels[y, x+1]
   487                         LandPixels[y, x]:= LandPixels[y, x+1]
   488                         
   488 
   489                     else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1,x] and AMask <> 0) then
   489                     else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1,x] and AMask <> 0) then
   490                         LandPixels[y, x]:= LandPixels[y+1, x]
   490                         LandPixels[y, x]:= LandPixels[y+1, x]
   491                         
   491 
   492                     else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1,x] and AMask <> 0) then
   492                     else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1,x] and AMask <> 0) then
   493                         LandPixels[y, x]:= LandPixels[y-1, x];
   493                         LandPixels[y, x]:= LandPixels[y-1, x];
   494                         
   494 
   495                     if (((LandPixels[y,x] and AMask) shr AShift) > 10) then
   495                     if (((LandPixels[y,x] and AMask) shr AShift) > 10) then
   496                         LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (64 shl AShift)
   496                         LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (64 shl AShift)
   497                     end;
   497                     end;
   498                 Land[y,x]:= lfObject
   498                 Land[y,x]:= lfObject
   499             end;
   499             end;
   776 if (GameFlags and gfDisableGirders) <> 0 then
   776 if (GameFlags and gfDisableGirders) <> 0 then
   777     hasGirders:= false;
   777     hasGirders:= false;
   778 
   778 
   779 if (GameFlags and gfForts = 0) and (maskOnly or (cPathz[ptMapCurrent] = '')) then
   779 if (GameFlags and gfForts = 0) and (maskOnly or (cPathz[ptMapCurrent] = '')) then
   780     AddObjects
   780     AddObjects
   781     
   781 
   782 else
   782 else
   783     AddProgress();
   783     AddProgress();
   784 
   784 
   785 FreeLandObjects;
   785 FreeLandObjects;
   786 
   786 
   832     if rw < rh*2 then
   832     if rw < rh*2 then
   833         begin
   833         begin
   834         rw:= rh*2;
   834         rw:= rh*2;
   835         end;
   835         end;
   836     if rh < rw div 2 then rh:= rw * 2;
   836     if rh < rw div 2 then rh:= rw * 2;
   837     
   837 
   838     ox:= (rw-LAND_WIDTH) div 2;
   838     ox:= (rw-LAND_WIDTH) div 2;
   839     oy:= rh-LAND_HEIGHT;
   839     oy:= rh-LAND_HEIGHT;
   840 
   840 
   841     lh:= rh div 128;
   841     lh:= rh div 128;
   842     lw:= rw div 32;
   842     lw:= rw div 32;
   848             begin
   848             begin
   849                 t:= 0;
   849                 t:= 0;
   850                 cbit:= bit * 8;
   850                 cbit:= bit * 8;
   851                 for yy:= y * lh to y * lh + 7 do
   851                 for yy:= y * lh to y * lh + 7 do
   852                     for xx:= x * lw + cbit to x * lw + cbit + 7 do
   852                     for xx:= x * lw + cbit to x * lw + cbit + 7 do
   853                         if ((yy-oy) and LAND_HEIGHT_MASK = 0) and ((xx-ox) and LAND_WIDTH_MASK = 0) 
   853                         if ((yy-oy) and LAND_HEIGHT_MASK = 0) and ((xx-ox) and LAND_WIDTH_MASK = 0)
   854                            and (Land[yy-oy, xx-ox] <> 0) then
   854                            and (Land[yy-oy, xx-ox] <> 0) then
   855                             inc(t);
   855                             inc(t);
   856                 if t > 8 then
   856                 if t > 8 then
   857                     Preview[y, x]:= Preview[y, x] or ($80 shr bit);
   857                     Preview[y, x]:= Preview[y, x] or ($80 shr bit);
   858             end;
   858             end;