hedgewars/uLand.pas
changeset 6580 6155187bf599
parent 6491 736479f3d348
child 6626 a447993f2ad7
equal deleted inserted replaced
6579:fc52f7c22c9b 6580:6155187bf599
    65     begin
    65     begin
    66         yd:= LAND_HEIGHT - 1;
    66         yd:= LAND_HEIGHT - 1;
    67         repeat
    67         repeat
    68             while (yd > 0) and (Land[yd, x] =  0) do dec(yd);
    68             while (yd > 0) and (Land[yd, x] =  0) do dec(yd);
    69 
    69 
    70             if (yd < 0) then yd:= 0;
    70             if (yd < 0) then
    71 
    71                 yd:= 0;
    72             while (yd < LAND_HEIGHT) and (Land[yd, x] <> 0) do inc(yd);
    72 
       
    73             while (yd < LAND_HEIGHT) and (Land[yd, x] <> 0) do
       
    74                 inc(yd);
    73             dec(yd);
    75             dec(yd);
    74             yu:= yd;
    76             yu:= yd;
    75 
    77 
    76             while (yu > 0  ) and (Land[yu, x] <> 0) do dec(yu);
    78             while (yu > 0  ) and (Land[yu, x] <> 0) do dec(yu);
    77             while (yu < yd ) and (Land[yu, x] =  0) do inc(yu);
    79             while (yu < yd ) and (Land[yu, x] =  0) do inc(yu);
    78 
    80 
    79             if (yd < LAND_HEIGHT - 1) and ((yd - yu) >= 16) then
    81             if (yd < LAND_HEIGHT - 1) and ((yd - yu) >= 16) then
    80             begin
    82                 begin
    81                 rr.x:= x;
    83                 rr.x:= x;
    82                 rr.y:= yd - 15;
    84                 rr.y:= yd - 15;
    83                 r.x:= x mod tmpsurf^.w;
    85                 r.x:= x mod tmpsurf^.w;
    84                 r.y:= 16;
    86                 r.y:= 16;
    85                 r.w:= 1;
    87                 r.w:= 1;
    86                 r.h:= 16;
    88                 r.h:= 16;
    87                 SDL_UpperBlit(tmpsurf, @r, Surface, @rr);
    89                 SDL_UpperBlit(tmpsurf, @r, Surface, @rr);
    88             end;
    90                 end;
    89             if (yu > 0) then
    91             if (yu > 0) then
    90             begin
    92                 begin
    91                 rr.x:= x;
    93                 rr.x:= x;
    92                 rr.y:= yu;
    94                 rr.y:= yu;
    93                 r.x:= x mod tmpsurf^.w;
    95                 r.x:= x mod tmpsurf^.w;
    94                 r.y:= 0;
    96                 r.y:= 0;
    95                 r.w:= 1;
    97                 r.w:= 1;
    96                 r.h:= Min(16, yd - yu + 1);
    98                 r.h:= Min(16, yd - yu + 1);
    97                 SDL_UpperBlit(tmpsurf, @r, Surface, @rr);
    99                 SDL_UpperBlit(tmpsurf, @r, Surface, @rr);
    98             end;
   100                 end;
    99             yd:= yu - 1;
   101             yd:= yu - 1;
   100         until yd < 0;
   102         until yd < 0;
   101     end;
   103     end;
   102     SDL_FreeSurface(tmpsurf);
   104     SDL_FreeSurface(tmpsurf);
   103 end;
   105 end;
   104 
   106 
   105 procedure SetPoints(var Template: TEdgeTemplate; var pa: TPixAr);
   107 procedure SetPoints(var Template: TEdgeTemplate; var pa: TPixAr);
   106 var i: LongInt;
   108 var i: LongInt;
   107 begin
   109 begin
   108 with Template do
   110 with Template do
   109      begin
   111     begin
   110      pa.Count:= BasePointsCount;
   112     pa.Count:= BasePointsCount;
   111      for i:= 0 to pred(pa.Count) do
   113     for i:= 0 to pred(pa.Count) do
   112          begin
   114         begin
   113          pa.ar[i].x:= BasePoints^[i].x + LongInt(GetRandom(BasePoints^[i].w));
   115         pa.ar[i].x:= BasePoints^[i].x + LongInt(GetRandom(BasePoints^[i].w));
   114          if pa.ar[i].x <> NTPX then
   116         if pa.ar[i].x <> NTPX then
   115             pa.ar[i].x:= pa.ar[i].x + ((LAND_WIDTH - Template.TemplateWidth) div 2);
   117            pa.ar[i].x:= pa.ar[i].x + ((LAND_WIDTH - Template.TemplateWidth) div 2);
   116          pa.ar[i].y:= BasePoints^[i].y + LongInt(GetRandom(BasePoints^[i].h)) + LAND_HEIGHT - LongInt(Template.TemplateHeight)
   118         pa.ar[i].y:= BasePoints^[i].y + LongInt(GetRandom(BasePoints^[i].h)) + LAND_HEIGHT - LongInt(Template.TemplateHeight)
   117          end;
   119         end;
   118 
   120 
   119      if canMirror then
   121     if canMirror then
   120         if getrandom(2) = 0 then
   122         if getrandom(2) = 0 then
   121            begin
   123             begin
   122            for i:= 0 to pred(BasePointsCount) do
   124             for i:= 0 to pred(BasePointsCount) do
   123              if pa.ar[i].x <> NTPX then
   125                if pa.ar[i].x <> NTPX then
   124                pa.ar[i].x:= LAND_WIDTH - 1 - pa.ar[i].x;
   126                    pa.ar[i].x:= LAND_WIDTH - 1 - pa.ar[i].x;
   125            for i:= 0 to pred(FillPointsCount) do
   127             for i:= 0 to pred(FillPointsCount) do
   126                FillPoints^[i].x:= LAND_WIDTH - 1 - FillPoints^[i].x;
   128                 FillPoints^[i].x:= LAND_WIDTH - 1 - FillPoints^[i].x;
   127            end;
   129             end;
   128 
   130 
   129 (*  Experiment in making this option more useful
   131 (*  Experiment in making this option more useful
   130      if ((not isNegative) and (cTemplateFilter = 4)) or
   132      if ((not isNegative) and (cTemplateFilter = 4)) or
   131         (canFlip and (getrandom(2) = 0)) then
   133         (canFlip and (getrandom(2) = 0)) then
   132            begin
   134            begin
   144                end;
   146                end;
   145            end;
   147            end;
   146      end
   148      end
   147 *)
   149 *)
   148 // template recycling.  Pull these off the floor a bit
   150 // template recycling.  Pull these off the floor a bit
   149      if (not isNegative) and (cTemplateFilter = 4) then
   151     if (not isNegative) and (cTemplateFilter = 4) then
   150            begin
   152         begin
   151            for i:= 0 to pred(BasePointsCount) do
   153         for i:= 0 to pred(BasePointsCount) do
   152                begin
   154             begin
   153                dec(pa.ar[i].y, 100);
   155             dec(pa.ar[i].y, 100);
   154                if pa.ar[i].y < 0 then
   156             if pa.ar[i].y < 0 then
   155                    pa.ar[i].y:= 0;
   157                 pa.ar[i].y:= 0;
   156                end;
   158             end;
   157            for i:= 0 to pred(FillPointsCount) do
   159         for i:= 0 to pred(FillPointsCount) do
   158                begin
   160             begin
   159                dec(FillPoints^[i].y, 100);
   161             dec(FillPoints^[i].y, 100);
   160                if FillPoints^[i].y < 0 then
   162             if FillPoints^[i].y < 0 then
   161                    FillPoints^[i].y:= 0;
   163                 FillPoints^[i].y:= 0;
   162                end;
   164             end;
   163            end;
   165         end;
   164 
   166 
   165      if (canFlip and (getrandom(2) = 0)) then
   167     if (canFlip and (getrandom(2) = 0)) then
   166            begin
   168         begin
   167            for i:= 0 to pred(BasePointsCount) do
   169         for i:= 0 to pred(BasePointsCount) do
   168                pa.ar[i].y:= LAND_HEIGHT - 1 - pa.ar[i].y;
   170             pa.ar[i].y:= LAND_HEIGHT - 1 - pa.ar[i].y;
   169            for i:= 0 to pred(FillPointsCount) do
   171         for i:= 0 to pred(FillPointsCount) do
   170                FillPoints^[i].y:= LAND_HEIGHT - 1 - FillPoints^[i].y;
   172             FillPoints^[i].y:= LAND_HEIGHT - 1 - FillPoints^[i].y;
   171            end;
   173         end;
   172      end
   174     end
   173 end;
   175 end;
   174 
   176 
   175 
   177 
   176 procedure GenBlank(var Template: TEdgeTemplate);
   178 procedure GenBlank(var Template: TEdgeTemplate);
   177 var pa: TPixAr;
   179 var pa: TPixAr;
   188         begin
   190         begin
   189         BezierizeEdge(pa, _0_5);
   191         BezierizeEdge(pa, _0_5);
   190         RandomizePoints(pa);
   192         RandomizePoints(pa);
   191         RandomizePoints(pa)
   193         RandomizePoints(pa)
   192         end;
   194         end;
   193     for i:= 1 to Template.RandPassesCount do RandomizePoints(pa);
   195     for i:= 1 to Template.RandPassesCount do
       
   196         RandomizePoints(pa);
   194     BezierizeEdge(pa, _0_1);
   197     BezierizeEdge(pa, _0_1);
   195 
   198 
   196 
   199 
   197     DrawEdge(pa, 0);
   200     DrawEdge(pa, 0);
   198 
   201 
   210     leftX:= ((LAND_WIDTH - playWidth) div 2);
   213     leftX:= ((LAND_WIDTH - playWidth) div 2);
   211     rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1;
   214     rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1;
   212     topY:= LAND_HEIGHT - playHeight;
   215     topY:= LAND_HEIGHT - playHeight;
   213 
   216 
   214     // HACK: force to only cavern even if a cavern map is invertable if cTemplateFilter = 4 ?
   217     // HACK: force to only cavern even if a cavern map is invertable if cTemplateFilter = 4 ?
   215     if (cTemplateFilter = 4) or
   218     if (cTemplateFilter = 4)
   216     (Template.canInvert and (getrandom(2) = 0)) or
   219     or (Template.canInvert and (getrandom(2) = 0))
   217         (not Template.canInvert and Template.isNegative) then
   220     or (not Template.canInvert and Template.isNegative) then
   218         begin
   221         begin
   219         hasBorder:= true;
   222         hasBorder:= true;
   220         for y:= 0 to LAND_HEIGHT - 1 do
   223         for y:= 0 to LAND_HEIGHT - 1 do
   221             for x:= 0 to LAND_WIDTH - 1 do
   224             for x:= 0 to LAND_WIDTH - 1 do
   222                 if (y < topY) or (x < leftX) or (x > rightX) then
   225                 if (y < topY) or (x < leftX) or (x > rightX) then
   223                     Land[y, x]:= 0
   226                     Land[y, x]:= 0
   224                 else
   227                 else
   225                 begin
   228                     begin
   226                 if Land[y, x] = 0 then
   229                     if Land[y, x] = 0 then
   227                     Land[y, x]:= lfBasic
   230                         Land[y, x]:= lfBasic
   228                 else if Land[y, x] = lfBasic then
   231                     else if Land[y, x] = lfBasic then
   229                     Land[y, x]:= 0;
   232                         Land[y, x]:= 0;
   230                 end;
   233                     end;
   231         end;
   234         end;
   232 end;
   235 end;
   233 
   236 
   234 procedure GenDrawnMap;
   237 procedure GenDrawnMap;
   235 begin
   238 begin
   274 for y:= 0 to LAND_HEIGHT - 1 do
   277 for y:= 0 to LAND_HEIGHT - 1 do
   275     begin
   278     begin
   276     for x:= 0 to LAND_WIDTH - 1 do
   279     for x:= 0 to LAND_WIDTH - 1 do
   277     if Land[y, x] <> 0 then
   280     if Land[y, x] <> 0 then
   278         if (cReducedQuality and rqBlurryLand) = 0 then
   281         if (cReducedQuality and rqBlurryLand) = 0 then
   279              LandPixels[y, x]:= p^[x] or AMask
   282             LandPixels[y, x]:= p^[x] or AMask
   280         else
   283         else
   281              LandPixels[y div 2, x div 2]:= p^[x] or AMask;
   284             LandPixels[y div 2, x div 2]:= p^[x] or AMask;
   282 
   285 
   283     p:= @(p^[Surface^.pitch div 4]);
   286     p:= @(p^[Surface^.pitch div 4]);
   284     end;
   287     end;
   285 
   288 
   286 if SDL_MustLock(Surface) then
   289 if SDL_MustLock(Surface) then
   316                (((Land[y, x-1] = lfBasic) and ((Land[y+1,x] = lfBasic)) or (Land[y-1,x] = lfBasic)) or
   319                (((Land[y, x-1] = lfBasic) and ((Land[y+1,x] = lfBasic)) or (Land[y-1,x] = lfBasic)) or
   317                ((Land[y, x+1] = lfBasic) and ((Land[y-1,x] = lfBasic) or (Land[y+1,x] = lfBasic)))) then
   320                ((Land[y, x+1] = lfBasic) and ((Land[y-1,x] = lfBasic) or (Land[y+1,x] = lfBasic)))) then
   318             begin
   321             begin
   319                 if (cReducedQuality and rqBlurryLand) = 0 then
   322                 if (cReducedQuality and rqBlurryLand) = 0 then
   320                     begin
   323                     begin
   321                     if (Land[y, x-1] = lfBasic) and (LandPixels[y, x-1] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y, x-1]
   324                     if (Land[y, x-1] = lfBasic) and (LandPixels[y, x-1] and AMask <> 0) then
   322                     else if (Land[y, x+1] = lfBasic) and (LandPixels[y, x+1] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y, x+1]
   325                         LandPixels[y, x]:= LandPixels[y, x-1]
   323                     else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1, x] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y-1, x]
   326                         
   324                     else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1, x] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y+1, x];
   327                     else if (Land[y, x+1] = lfBasic) and (LandPixels[y, x+1] and AMask <> 0) then
   325                     if (((LandPixels[y,x] and AMask) shr AShift) > 10) then LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (128 shl AShift)
   328                         LandPixels[y, x]:= LandPixels[y, x+1]
       
   329                         
       
   330                     else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1, x] and AMask <> 0) then
       
   331                         LandPixels[y, x]:= LandPixels[y-1, x]
       
   332                         
       
   333                     else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1, x] and AMask <> 0) then
       
   334                         LandPixels[y, x]:= LandPixels[y+1, x];
       
   335                         
       
   336                     if (((LandPixels[y,x] and AMask) shr AShift) > 10) then
       
   337                         LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (128 shl AShift)
   326                     end;
   338                     end;
   327                 Land[y,x]:= lfObject
   339                 Land[y,x]:= lfObject
   328             end
   340             end
   329             else if (Land[y, x] = 0) and
   341             else if (Land[y, x] = 0) and
   330                     (((Land[y, x-1] = lfBasic) and (Land[y+1,x-1] = lfBasic) and (Land[y+2,x] = lfBasic)) or
   342                     (((Land[y, x-1] = lfBasic) and (Land[y+1,x-1] = lfBasic) and (Land[y+2,x] = lfBasic)) or
   333                     ((Land[y, x+1] = lfBasic) and (Land[y-1,x+1] = lfBasic) and (Land[y-2,x] = lfBasic)) or
   345                     ((Land[y, x+1] = lfBasic) and (Land[y-1,x+1] = lfBasic) and (Land[y-2,x] = lfBasic)) or
   334                     ((Land[y+1, x] = lfBasic) and (Land[y+1,x+1] = lfBasic) and (Land[y,x+2] = lfBasic)) or
   346                     ((Land[y+1, x] = lfBasic) and (Land[y+1,x+1] = lfBasic) and (Land[y,x+2] = lfBasic)) or
   335                     ((Land[y-1, x] = lfBasic) and (Land[y-1,x+1] = lfBasic) and (Land[y,x+2] = lfBasic)) or
   347                     ((Land[y-1, x] = lfBasic) and (Land[y-1,x+1] = lfBasic) and (Land[y,x+2] = lfBasic)) or
   336                     ((Land[y+1, x] = lfBasic) and (Land[y+1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic)) or
   348                     ((Land[y+1, x] = lfBasic) and (Land[y+1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic)) or
   337                     ((Land[y-1, x] = lfBasic) and (Land[y-1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic))) then
   349                     ((Land[y-1, x] = lfBasic) and (Land[y-1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic))) then
   338             begin
   350                     
       
   351                 begin
       
   352                 
   339                 if (cReducedQuality and rqBlurryLand) = 0 then
   353                 if (cReducedQuality and rqBlurryLand) = 0 then
       
   354                 
   340                     begin
   355                     begin
   341                     if (Land[y, x-1] = lfBasic) and (LandPixels[y,x-1] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y, x-1]
   356                     
   342                     else if (Land[y, x+1] = lfBasic) and (LandPixels[y,x+1] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y, x+1]
   357                     if (Land[y, x-1] = lfBasic) and (LandPixels[y,x-1] and AMask <> 0) then
   343                     else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1,x] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y+1, x]
   358                         LandPixels[y, x]:= LandPixels[y, x-1]
   344                     else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1,x] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y-1, x];
   359                         
   345                     if (((LandPixels[y,x] and AMask) shr AShift) > 10) then LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (64 shl AShift)
   360                     else if (Land[y, x+1] = lfBasic) and (LandPixels[y,x+1] and AMask <> 0) then
       
   361                         LandPixels[y, x]:= LandPixels[y, x+1]
       
   362                         
       
   363                     else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1,x] and AMask <> 0) then
       
   364                         LandPixels[y, x]:= LandPixels[y+1, x]
       
   365                         
       
   366                     else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1,x] and AMask <> 0) then
       
   367                         LandPixels[y, x]:= LandPixels[y-1, x];
       
   368                         
       
   369                     if (((LandPixels[y,x] and AMask) shr AShift) > 10) then
       
   370                         LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (64 shl AShift)
   346                     end;
   371                     end;
   347                 Land[y,x]:= lfObject
   372                 Land[y,x]:= lfObject
   348             end;
   373             end;
   349 
   374 
   350     AddProgress();
   375     AddProgress();
   362 topY:= LAND_HEIGHT - playHeight;
   387 topY:= LAND_HEIGHT - playHeight;
   363 
   388 
   364 WriteLnToConsole('Generating forts land...');
   389 WriteLnToConsole('Generating forts land...');
   365 
   390 
   366 tmpsurf:= LoadImage(UserPathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifTransparent or ifIgnoreCaps);
   391 tmpsurf:= LoadImage(UserPathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifTransparent or ifIgnoreCaps);
   367 if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
   392 if tmpsurf = nil then
       
   393     tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
   368 BlitImageAndGenerateCollisionInfo(leftX+150, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
   394 BlitImageAndGenerateCollisionInfo(leftX+150, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
   369 SDL_FreeSurface(tmpsurf);
   395 SDL_FreeSurface(tmpsurf);
   370 
   396 
   371 tmpsurf:= LoadImage(UserPathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifTransparent or ifIgnoreCaps);
   397 tmpsurf:= LoadImage(UserPathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifTransparent or ifIgnoreCaps);
   372 if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
   398 if tmpsurf = nil then
       
   399     tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
   373 BlitImageAndGenerateCollisionInfo(rightX - 150 - tmpsurf^.w, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
   400 BlitImageAndGenerateCollisionInfo(rightX - 150 - tmpsurf^.w, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
   374 SDL_FreeSurface(tmpsurf);
   401 SDL_FreeSurface(tmpsurf);
   375 end;
   402 end;
   376 
   403 
   377 // Loads Land[] from an image, allowing overriding standard collision
   404 // Loads Land[] from an image, allowing overriding standard collision
   379 var tmpsurf: PSDL_Surface;
   406 var tmpsurf: PSDL_Surface;
   380     p: PLongwordArray;
   407     p: PLongwordArray;
   381     x, y, cpX, cpY: Longword;
   408     x, y, cpX, cpY: Longword;
   382 begin
   409 begin
   383 tmpsurf:= LoadImage(UserPathz[ptMapCurrent] + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
   410 tmpsurf:= LoadImage(UserPathz[ptMapCurrent] + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
   384 if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
   411 if tmpsurf = nil then
       
   412     tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
   385 if tmpsurf = nil then
   413 if tmpsurf = nil then
   386     begin
   414     begin
   387     mapName:= ExtractFileName(Pathz[ptMapCurrent]);
   415     mapName:= ExtractFileName(Pathz[ptMapCurrent]);
   388     tmpsurf:= LoadImage(UserPathz[ptMissionMaps] + '/' + mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
   416     tmpsurf:= LoadImage(UserPathz[ptMissionMaps] + '/' + mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
   389     if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptMissionMaps] + '/' + mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
   417     if tmpsurf = nil then
       
   418         tmpsurf:= LoadImage(Pathz[ptMissionMaps] + '/' + mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
   390     end;
   419     end;
   391 
   420 
   392 
   421 
   393 if (tmpsurf <> nil) and (tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT) and (tmpsurf^.format^.BytesPerPixel = 4) then
   422 if (tmpsurf <> nil) and (tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT) and (tmpsurf^.format^.BytesPerPixel = 4) then
   394 begin
   423     begin
   395     disableLandBack:= true;
   424     disableLandBack:= true;
   396 
   425 
   397     cpX:= (LAND_WIDTH - tmpsurf^.w) div 2;
   426     cpX:= (LAND_WIDTH - tmpsurf^.w) div 2;
   398     cpY:= LAND_HEIGHT - tmpsurf^.h;
   427     cpY:= LAND_HEIGHT - tmpsurf^.h;
   399     if SDL_MustLock(tmpsurf) then
   428     if SDL_MustLock(tmpsurf) then
   425         SDL_UnlockSurface(tmpsurf);
   454         SDL_UnlockSurface(tmpsurf);
   426     if not disableLandBack then
   455     if not disableLandBack then
   427         begin
   456         begin
   428         // freed in freeModule() below
   457         // freed in freeModule() below
   429         LandBackSurface:= LoadImage(UserPathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent);
   458         LandBackSurface:= LoadImage(UserPathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent);
   430         if LandBackSurface = nil then LandBackSurface:= LoadImage(Pathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent);
   459         if LandBackSurface = nil then
   431         if (LandBackSurface <> nil) and cGrayScale then Surface2GrayScale(LandBackSurface)
   460             LandBackSurface:= LoadImage(Pathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent);
       
   461         if (LandBackSurface <> nil) and cGrayScale then
       
   462             Surface2GrayScale(LandBackSurface)
   432         end;
   463         end;
   433 end;
   464 end;
   434 if (tmpsurf <> nil) then
   465 if (tmpsurf <> nil) then
   435     SDL_FreeSurface(tmpsurf);
   466     SDL_FreeSurface(tmpsurf);
   436 tmpsurf:= nil;
   467 tmpsurf:= nil;
   444 begin
   475 begin
   445 isMap:= true;
   476 isMap:= true;
   446 WriteLnToConsole('Loading land from file...');
   477 WriteLnToConsole('Loading land from file...');
   447 AddProgress;
   478 AddProgress;
   448 tmpsurf:= LoadImage(UserPathz[ptMapCurrent] + '/map', ifAlpha or ifTransparent or ifIgnoreCaps);
   479 tmpsurf:= LoadImage(UserPathz[ptMapCurrent] + '/map', ifAlpha or ifTransparent or ifIgnoreCaps);
   449 if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/map', ifAlpha or ifTransparent or ifIgnoreCaps);
   480 if tmpsurf = nil then
       
   481     tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/map', ifAlpha or ifTransparent or ifIgnoreCaps);
   450 if tmpsurf = nil then
   482 if tmpsurf = nil then
   451     begin
   483     begin
   452     mapName:= ExtractFileName(Pathz[ptMapCurrent]);
   484     mapName:= ExtractFileName(Pathz[ptMapCurrent]);
   453     tmpsurf:= LoadImage(UserPathz[ptMissionMaps] + '/' + mapName + '/map', ifAlpha or ifTransparent or ifIgnoreCaps);
   485     tmpsurf:= LoadImage(UserPathz[ptMissionMaps] + '/' + mapName + '/map', ifAlpha or ifTransparent or ifIgnoreCaps);
   454     if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptMissionMaps] + '/' + mapName + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
   486     if tmpsurf = nil then
       
   487         tmpsurf:= LoadImage(Pathz[ptMissionMaps] + '/' + mapName + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
   455     end;
   488     end;
   456 TryDo((tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT), 'Map dimensions too big!', true);
   489 TryDo((tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT), 'Map dimensions too big!', true);
   457 
   490 
   458 // unC0Rr - should this be passed from the GUI? I am not sure which layer does what
   491 // unC0Rr - should this be passed from the GUI? I am not sure which layer does what
   459 s:= UserPathz[ptMapCurrent] + '/map.cfg';
   492 s:= UserPathz[ptMapCurrent] + '/map.cfg';
   460 if not FileExists(s) then s:= Pathz[ptMapCurrent] + '/map.cfg';
   493 if not FileExists(s) then
       
   494     s:= Pathz[ptMapCurrent] + '/map.cfg';
   461 WriteLnToConsole('Fetching map HH limit');
   495 WriteLnToConsole('Fetching map HH limit');
   462 {$I-}
   496 {$I-}
   463 Assign(f, s);
   497 Assign(f, s);
   464 filemode:= 0; // readonly
   498 filemode:= 0; // readonly
   465 Reset(f);
   499 Reset(f);
   466 if IOResult <> 0 then
   500 if IOResult <> 0 then
   467 begin
   501     begin
   468     s:= Pathz[ptMissionMaps] + '/' + mapName + '/map.cfg';
   502     s:= Pathz[ptMissionMaps] + '/' + mapName + '/map.cfg';
   469     Assign(f, s);
   503     Assign(f, s);
   470     Reset(f);
   504     Reset(f);
   471 end;
   505     end;
   472 Readln(f);
   506 Readln(f);
   473 if not eof(f) then Readln(f, MaxHedgehogs);
   507 if not eof(f) then
       
   508     Readln(f, MaxHedgehogs);
   474 {$I+}
   509 {$I+}
   475 if (MaxHedgehogs = 0) then MaxHedgehogs:= 18;
   510 if (MaxHedgehogs = 0) then
       
   511     MaxHedgehogs:= 18;
   476 
   512 
   477 playHeight:= tmpsurf^.h;
   513 playHeight:= tmpsurf^.h;
   478 playWidth:= tmpsurf^.w;
   514 playWidth:= tmpsurf^.w;
   479 leftX:= (LAND_WIDTH - playWidth) div 2;
   515 leftX:= (LAND_WIDTH - playWidth) div 2;
   480 rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1;
   516 rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1;
   595                 LandPixels[(topY + w) div 2, x div 2]:= c;
   631                 LandPixels[(topY + w) div 2, x div 2]:= c;
   596             end;
   632             end;
   597         end;
   633         end;
   598     end;
   634     end;
   599 
   635 
   600 if (GameFlags and gfBottomBorder) <> 0 then DrawBottomBorder;
   636 if (GameFlags and gfBottomBorder) <> 0 then
   601 
   637     DrawBottomBorder;
   602 if (GameFlags and gfDisableGirders) <> 0 then hasGirders:= false;
   638 
   603 
   639 if (GameFlags and gfDisableGirders) <> 0 then
   604 if ((GameFlags and gfForts) = 0)
   640     hasGirders:= false;
   605     and (Pathz[ptMapCurrent] = '')
   641 
   606     then AddObjects
   642 if ((GameFlags and gfForts) = 0) and (Pathz[ptMapCurrent] = '') then
   607 else AddProgress();
   643     AddObjects
       
   644     
       
   645 else
       
   646     AddProgress();
   608 
   647 
   609 FreeLandObjects;
   648 FreeLandObjects;
   610 
   649 
   611 if cGrayScale then
   650 if cGrayScale then
   612     begin
   651     begin
   616                 begin
   655                 begin
   617                 w:= LandPixels[y,x];
   656                 w:= LandPixels[y,x];
   618                 w:= round(((w shr RShift and $FF) * RGB_LUMINANCE_RED +
   657                 w:= round(((w shr RShift and $FF) * RGB_LUMINANCE_RED +
   619                       (w shr BShift and $FF) * RGB_LUMINANCE_GREEN +
   658                       (w shr BShift and $FF) * RGB_LUMINANCE_GREEN +
   620                       (w shr GShift and $FF) * RGB_LUMINANCE_BLUE));
   659                       (w shr GShift and $FF) * RGB_LUMINANCE_BLUE));
   621                 if w > 255 then w:= 255;
   660                 if w > 255 then
       
   661                     w:= 255;
   622                 w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y,x] and AMask);
   662                 w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y,x] and AMask);
   623                 LandPixels[y,x]:= w or (LandPixels[y, x] and AMask)
   663                 LandPixels[y,x]:= w or (LandPixels[y, x] and AMask)
   624                 end
   664                 end
   625     else
   665     else
   626         for x:= leftX div 2 to rightX div 2 do
   666         for x:= leftX div 2 to rightX div 2 do
   627             for y:= topY div 2 to LAND_HEIGHT-1 div 2 do
   667             for y:= topY div 2 to LAND_HEIGHT-1 div 2 do
   628                 begin
   668                 begin
   629                 w:= LandPixels[y div 2,x div 2];
   669                 w:= LandPixels[y div 2,x div 2];
   630                 w:= ((w shr RShift and $FF) +  (w shr BShift and $FF) + (w shr GShift and $FF)) div 3;
   670                 w:= ((w shr RShift and $FF) +  (w shr BShift and $FF) + (w shr GShift and $FF)) div 3;
   631                 if w > 255 then w:= 255;
   671                 if w > 255 then
   632                w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y div 2,x div 2] and AMask);
   672                     w:= 255;
       
   673                 w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y div 2,x div 2] and AMask);
   633                 LandPixels[y,x]:= w or (LandPixels[y div 2, x div 2] and AMask)
   674                 LandPixels[y,x]:= w or (LandPixels[y div 2, x div 2] and AMask)
   634                 end
   675                 end
   635     end;
   676     end;
   636 
   677 
   637 UpdateLandTexture(0, LAND_WIDTH, 0, LAND_HEIGHT);
   678 UpdateLandTexture(0, LAND_WIDTH, 0, LAND_HEIGHT);
   660             begin
   701             begin
   661                 t:= 0;
   702                 t:= 0;
   662                 cbit:= bit * 8;
   703                 cbit:= bit * 8;
   663                 for yy:= y * lh to y * lh + 7 do
   704                 for yy:= y * lh to y * lh + 7 do
   664                     for xx:= x * lw + cbit to x * lw + cbit + 7 do
   705                     for xx:= x * lw + cbit to x * lw + cbit + 7 do
   665                         if Land[yy, xx] <> 0 then inc(t);
   706                         if Land[yy, xx] <> 0 then
       
   707                             inc(t);
   666                 if t > 8 then
   708                 if t > 8 then
   667                     Preview[y, x]:= Preview[y, x] or ($80 shr bit);
   709                     Preview[y, x]:= Preview[y, x] or ($80 shr bit);
   668             end;
   710             end;
   669         end;
   711         end;
   670 
   712