hedgewars/uLand.pas
changeset 12592 00b539e6115d
parent 12104 f61bd25b9f70
child 12711 20dbb3a03e61
equal deleted inserted replaced
12591:7bae1fab444b 12592:00b539e6115d
    51 var tmpsurf: PSDL_Surface;
    51 var tmpsurf: PSDL_Surface;
    52     //r, rr: TSDL_Rect;
    52     //r, rr: TSDL_Rect;
    53     x, yd, yu: LongInt;
    53     x, yd, yu: LongInt;
    54     targetMask: Word;
    54     targetMask: Word;
    55 begin
    55 begin
    56     tmpsurf:= LoadDataImage(ptCurrTheme, 'Border', ifCritical or ifIgnoreCaps or ifTransparent);
    56     tmpsurf:= LoadDataImage(ptCurrTheme, 'Border', ifCritical or ifIgnoreCaps or ifColorKey);
    57 
    57 
    58     // if mask only, all land gets filled with landtex and therefore needs borders
    58     // if mask only, all land gets filled with landtex and therefore needs borders
    59     if maskOnly then
    59     if maskOnly then
    60         targetMask:= lfLandMask
    60         targetMask:= lfLandMask
    61     else
    61     else
   249     dstp:= nil;
   249     dstp:= nil;
   250     stopp:= nil;
   250     stopp:= nil;
   251     SDL_UnlockSurface(mapsurf);
   251     SDL_UnlockSurface(mapsurf);
   252 
   252 
   253     // freed in freeModule() below
   253     // freed in freeModule() below
   254     LandBackSurface:= LoadDataImage(ptCurrTheme, 'LandBackTex', ifIgnoreCaps or ifTransparent);
   254     LandBackSurface:= LoadDataImage(ptCurrTheme, 'LandBackTex', ifIgnoreCaps or ifColorKey);
   255     if (LandBackSurface <> nil) and GrayScale then Surface2GrayScale(LandBackSurface);
   255     if (LandBackSurface <> nil) and GrayScale then Surface2GrayScale(LandBackSurface);
   256 end;
   256 end;
   257 
   257 
   258 procedure ColorizeLand(Surface: PSDL_Surface);
   258 procedure ColorizeLand(Surface: PSDL_Surface);
   259 var tmpsurf: PSDL_Surface;
   259 var tmpsurf: PSDL_Surface;
   276         r.y:= y
   276         r.y:= y
   277         end;
   277         end;
   278     SDL_FreeSurface(tmpsurf);
   278     SDL_FreeSurface(tmpsurf);
   279 
   279 
   280     // freed in freeModule() below
   280     // freed in freeModule() below
   281     LandBackSurface:= LoadDataImage(ptCurrTheme, 'LandBackTex', ifIgnoreCaps or ifTransparent);
   281     LandBackSurface:= LoadDataImage(ptCurrTheme, 'LandBackTex', ifIgnoreCaps or ifColorKey);
   282     if (LandBackSurface <> nil) and GrayScale then Surface2GrayScale(LandBackSurface);
   282     if (LandBackSurface <> nil) and GrayScale then Surface2GrayScale(LandBackSurface);
   283 end;
   283 end;
   284 
   284 
   285 
   285 
   286 procedure GenDrawnMap;
   286 procedure GenDrawnMap;
   542         mirror:= (i <> 0) and (mirror or (i = ClansCount - 1));
   542         mirror:= (i <> 0) and (mirror or (i = ClansCount - 1));
   543 
   543 
   544     if mirror then
   544     if mirror then
   545         begin
   545         begin
   546         // not critical because if no R we can fallback to mirrored L
   546         // not critical because if no R we can fallback to mirrored L
   547         tmpsurf:= LoadDataImage(ptForts, SpawnClansArray[i]^.Teams[0]^.FortName + 'R', ifAlpha or ifTransparent or ifIgnoreCaps);
   547         tmpsurf:= LoadDataImage(ptForts, SpawnClansArray[i]^.Teams[0]^.FortName + 'R', ifAlpha or ifColorKey or ifIgnoreCaps);
   548         // fallback
   548         // fallback
   549         if tmpsurf = nil then
   549         if tmpsurf = nil then
   550             begin
   550             begin
   551             tmpsurf:= LoadDataImage(ptForts, SpawnClansArray[i]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
   551             tmpsurf:= LoadDataImage(ptForts, SpawnClansArray[i]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifColorKey or ifIgnoreCaps);
   552             BlitImageAndGenerateCollisionInfo(leftX + sectionWidth * i + ((sectionWidth - tmpsurf^.w) div 2), LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf, 0, true);
   552             BlitImageAndGenerateCollisionInfo(leftX + sectionWidth * i + ((sectionWidth - tmpsurf^.w) div 2), LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf, 0, true);
   553             end
   553             end
   554         else
   554         else
   555             BlitImageAndGenerateCollisionInfo(leftX + sectionWidth * i + ((sectionWidth - tmpsurf^.w) div 2), LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
   555             BlitImageAndGenerateCollisionInfo(leftX + sectionWidth * i + ((sectionWidth - tmpsurf^.w) div 2), LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
   556         SDL_FreeSurface(tmpsurf);
   556         SDL_FreeSurface(tmpsurf);
   557         end
   557         end
   558     else
   558     else
   559         begin
   559         begin
   560         tmpsurf:= LoadDataImage(ptForts, SpawnClansArray[i]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
   560         tmpsurf:= LoadDataImage(ptForts, SpawnClansArray[i]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifColorKey or ifIgnoreCaps);
   561         BlitImageAndGenerateCollisionInfo(leftX + sectionWidth * i + ((sectionWidth - tmpsurf^.w) div 2), LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
   561         BlitImageAndGenerateCollisionInfo(leftX + sectionWidth * i + ((sectionWidth - tmpsurf^.w) div 2), LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
   562         SDL_FreeSurface(tmpsurf);
   562         SDL_FreeSurface(tmpsurf);
   563         end;
   563         end;
   564 
   564 
   565     end;
   565     end;
   595 var tmpsurf: PSDL_Surface;
   595 var tmpsurf: PSDL_Surface;
   596     p: PLongwordArray;
   596     p: PLongwordArray;
   597     x, y, cpX, cpY: Longword;
   597     x, y, cpX, cpY: Longword;
   598     mapName: shortstring;
   598     mapName: shortstring;
   599 begin
   599 begin
   600 tmpsurf:= LoadDataImage(ptMapCurrent, 'mask', ifAlpha or ifTransparent or ifIgnoreCaps);
   600 tmpsurf:= LoadDataImage(ptMapCurrent, 'mask', ifAlpha or ifColorKey or ifIgnoreCaps);
   601 if tmpsurf = nil then
   601 if tmpsurf = nil then
   602     begin
   602     begin
   603     mapName:= ExtractFileName(cPathz[ptMapCurrent]);
   603     mapName:= ExtractFileName(cPathz[ptMapCurrent]);
   604     tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
   604     tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/mask', ifAlpha or ifColorKey or ifIgnoreCaps);
   605     end;
   605     end;
   606 
   606 
   607 
   607 
   608 if (tmpsurf <> nil) and (tmpsurf^.format^.BytesPerPixel = 4) then
   608 if (tmpsurf <> nil) and (tmpsurf^.format^.BytesPerPixel = 4) then
   609     begin
   609     begin
   637         if SDL_MustLock(tmpsurf) then
   637         if SDL_MustLock(tmpsurf) then
   638             SDL_UnlockSurface(tmpsurf);
   638             SDL_UnlockSurface(tmpsurf);
   639         if not disableLandBack then
   639         if not disableLandBack then
   640             begin
   640             begin
   641             // freed in freeModule() below
   641             // freed in freeModule() below
   642             LandBackSurface:= LoadDataImage(ptCurrTheme, 'LandBackTex', ifIgnoreCaps or ifTransparent);
   642             LandBackSurface:= LoadDataImage(ptCurrTheme, 'LandBackTex', ifIgnoreCaps or ifColorKey);
   643             if (LandBackSurface <> nil) and GrayScale then
   643             if (LandBackSurface <> nil) and GrayScale then
   644                 Surface2GrayScale(LandBackSurface)
   644                 Surface2GrayScale(LandBackSurface)
   645             end;
   645             end;
   646     end;
   646     end;
   647 end;
   647 end;
   654 var tmpsurf: PSDL_Surface;
   654 var tmpsurf: PSDL_Surface;
   655     mapName: shortstring = '';
   655     mapName: shortstring = '';
   656 begin
   656 begin
   657 WriteLnToConsole('Loading land from file...');
   657 WriteLnToConsole('Loading land from file...');
   658 AddProgress;
   658 AddProgress;
   659 tmpsurf:= LoadDataImage(ptMapCurrent, 'map', ifAlpha or ifTransparent or ifIgnoreCaps);
   659 tmpsurf:= LoadDataImage(ptMapCurrent, 'map', ifAlpha or ifColorKey or ifIgnoreCaps);
   660 if tmpsurf = nil then
   660 if tmpsurf = nil then
   661     begin
   661     begin
   662     mapName:= ExtractFileName(cPathz[ptMapCurrent]);
   662     mapName:= ExtractFileName(cPathz[ptMapCurrent]);
   663     tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
   663     tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/map', ifAlpha or ifCritical or ifColorKey or ifIgnoreCaps);
   664     if not allOK then exit;
   664     if not allOK then exit;
   665     end;
   665     end;
   666 // (bare) Sanity check. Considering possible LongInt comparisons as well as just how much system memoery it would take
   666 // (bare) Sanity check. Considering possible LongInt comparisons as well as just how much system memoery it would take
   667 if checkFails((tmpsurf^.w < $40000000) and (tmpsurf^.h < $40000000) and (QWord(tmpsurf^.w) * tmpsurf^.h < 6*1024*1024*1024), 'Map dimensions too big!', true)
   667 if checkFails((tmpsurf^.w < $40000000) and (tmpsurf^.h < $40000000) and (QWord(tmpsurf^.w) * tmpsurf^.h < 6*1024*1024*1024), 'Map dimensions too big!', true)
   668         then exit;
   668         then exit;