hedgewars/uLand.pas
changeset 7687 c73fd8cfa7c0
parent 7613 ce6ead3327b2
parent 7640 e9e6b4d740f6
child 7939 f951c4b5b335
equal deleted inserted replaced
7613:ce6ead3327b2 7687:c73fd8cfa7c0
    60 procedure ColorizeLand(Surface: PSDL_Surface);
    60 procedure ColorizeLand(Surface: PSDL_Surface);
    61 var tmpsurf: PSDL_Surface;
    61 var tmpsurf: PSDL_Surface;
    62     r, rr: TSDL_Rect;
    62     r, rr: TSDL_Rect;
    63     x, yd, yu: LongInt;
    63     x, yd, yu: LongInt;
    64 begin
    64 begin
    65     tmpsurf:= LoadImage(UserPathz[ptCurrTheme] + '/LandTex', ifIgnoreCaps);
    65     tmpsurf:= LoadDataImage(ptCurrTheme, 'LandTex', ifCritical or ifIgnoreCaps);
    66     if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptCurrTheme] + '/LandTex', ifCritical or ifIgnoreCaps);
       
    67     r.y:= 0;
    66     r.y:= 0;
    68     while r.y < LAND_HEIGHT do
    67     while r.y < LAND_HEIGHT do
    69     begin
    68     begin
    70         r.x:= 0;
    69         r.x:= 0;
    71         while r.x < LAND_WIDTH do
    70         while r.x < LAND_WIDTH do
    76         inc(r.y, tmpsurf^.h)
    75         inc(r.y, tmpsurf^.h)
    77     end;
    76     end;
    78     SDL_FreeSurface(tmpsurf);
    77     SDL_FreeSurface(tmpsurf);
    79 
    78 
    80     // freed in freeModule() below
    79     // freed in freeModule() below
    81     LandBackSurface:= LoadImage(UserPathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent);
    80     LandBackSurface:= LoadDataImage(ptCurrTheme, 'LandBackTex', ifIgnoreCaps or ifTransparent);
    82     if LandBackSurface = nil then LandBackSurface:= LoadImage(Pathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent);
       
    83     if (LandBackSurface <> nil) and GrayScale then Surface2GrayScale(LandBackSurface);
    81     if (LandBackSurface <> nil) and GrayScale then Surface2GrayScale(LandBackSurface);
    84 
    82 
    85     tmpsurf:= LoadImage(UserPathz[ptCurrTheme] + '/Border', ifIgnoreCaps or ifTransparent);
    83     tmpsurf:= LoadDataImage(ptCurrTheme, 'Border', ifCritical or ifIgnoreCaps or ifTransparent);
    86     if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptCurrTheme] + '/Border', ifCritical or ifIgnoreCaps or ifTransparent);
       
    87     for x:= 0 to LAND_WIDTH - 1 do
    84     for x:= 0 to LAND_WIDTH - 1 do
    88     begin
    85     begin
    89         yd:= LAND_HEIGHT - 1;
    86         yd:= LAND_HEIGHT - 1;
    90         repeat
    87         repeat
    91             while (yd > 0) and (Land[yd, x] =  0) do dec(yd);
    88             while (yd > 0) and (Land[yd, x] =  0) do dec(yd);
   418 rightX:= ((playWidth + (LAND_WIDTH - playWidth) div 2) - 1);
   415 rightX:= ((playWidth + (LAND_WIDTH - playWidth) div 2) - 1);
   419 topY:= LAND_HEIGHT - playHeight;
   416 topY:= LAND_HEIGHT - playHeight;
   420 
   417 
   421 WriteLnToConsole('Generating forts land...');
   418 WriteLnToConsole('Generating forts land...');
   422 
   419 
   423 tmpsurf:= LoadImage(UserPathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifTransparent or ifIgnoreCaps);
   420 tmpsurf:= LoadDataImage(ptForts, ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
   424 if tmpsurf = nil then
       
   425     tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
       
   426 BlitImageAndGenerateCollisionInfo(leftX+150, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
   421 BlitImageAndGenerateCollisionInfo(leftX+150, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
   427 SDL_FreeSurface(tmpsurf);
   422 SDL_FreeSurface(tmpsurf);
   428 
   423 
   429 tmpsurf:= LoadImage(UserPathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifTransparent or ifIgnoreCaps);
   424 tmpsurf:= LoadDataImage(ptForts, ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
   430 if tmpsurf = nil then
       
   431     tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
       
   432 BlitImageAndGenerateCollisionInfo(rightX - 150 - tmpsurf^.w, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
   425 BlitImageAndGenerateCollisionInfo(rightX - 150 - tmpsurf^.w, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
   433 SDL_FreeSurface(tmpsurf);
   426 SDL_FreeSurface(tmpsurf);
   434 end;
   427 end;
   435 
   428 
   436 // Loads Land[] from an image, allowing overriding standard collision
   429 // Loads Land[] from an image, allowing overriding standard collision
   437 procedure LoadMask(mapName: shortstring);
   430 procedure LoadMask(mapName: shortstring);
   438 var tmpsurf: PSDL_Surface;
   431 var tmpsurf: PSDL_Surface;
   439     p: PLongwordArray;
   432     p: PLongwordArray;
   440     x, y, cpX, cpY: Longword;
   433     x, y, cpX, cpY: Longword;
   441 begin
   434 begin
   442 tmpsurf:= LoadImage(UserPathz[ptMapCurrent] + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
   435 tmpsurf:= LoadDataImage(ptMapCurrent, 'mask', ifAlpha or ifTransparent or ifIgnoreCaps);
   443 if tmpsurf = nil then
   436 if tmpsurf = nil then
   444     tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
       
   445 if tmpsurf = nil then
       
   446     begin
   437     begin
   447     mapName:= ExtractFileName(Pathz[ptMapCurrent]);
   438     mapName:= ExtractFileName(Pathz[ptMapCurrent]);
   448     tmpsurf:= LoadImage(UserPathz[ptMissionMaps] + '/' + mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
   439     tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
   449     if tmpsurf = nil then
       
   450         tmpsurf:= LoadImage(Pathz[ptMissionMaps] + '/' + mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
       
   451     end;
   440     end;
   452 
   441 
   453 
   442 
   454 if (tmpsurf <> nil) and (tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT) and (tmpsurf^.format^.BytesPerPixel = 4) then
   443 if (tmpsurf <> nil) and (tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT) and (tmpsurf^.format^.BytesPerPixel = 4) then
   455     begin
   444     begin
   488     if SDL_MustLock(tmpsurf) then
   477     if SDL_MustLock(tmpsurf) then
   489         SDL_UnlockSurface(tmpsurf);
   478         SDL_UnlockSurface(tmpsurf);
   490     if not disableLandBack then
   479     if not disableLandBack then
   491         begin
   480         begin
   492         // freed in freeModule() below
   481         // freed in freeModule() below
   493         LandBackSurface:= LoadImage(UserPathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent);
   482         LandBackSurface:= LoadDataImage(ptCurrTheme, 'LandBackTex', ifIgnoreCaps or ifTransparent);
   494         if LandBackSurface = nil then
       
   495             LandBackSurface:= LoadImage(Pathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent);
       
   496         if (LandBackSurface <> nil) and GrayScale then
   483         if (LandBackSurface <> nil) and GrayScale then
   497             Surface2GrayScale(LandBackSurface)
   484             Surface2GrayScale(LandBackSurface)
   498         end;
   485         end;
   499 end;
   486 end;
   500 if (tmpsurf <> nil) then
   487 if (tmpsurf <> nil) then
   508     f: textfile;
   495     f: textfile;
   509     mapName: shortstring = '';
   496     mapName: shortstring = '';
   510 begin
   497 begin
   511 WriteLnToConsole('Loading land from file...');
   498 WriteLnToConsole('Loading land from file...');
   512 AddProgress;
   499 AddProgress;
   513 tmpsurf:= LoadImage(UserPathz[ptMapCurrent] + '/map', ifAlpha or ifTransparent or ifIgnoreCaps);
   500 tmpsurf:= LoadDataImage(ptMapCurrent, 'map', ifAlpha or ifTransparent or ifIgnoreCaps);
   514 if tmpsurf = nil then
   501 if tmpsurf = nil then
   515     tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/map', ifAlpha or ifTransparent or ifIgnoreCaps);
       
   516 if tmpsurf = nil then
       
   517     begin
   502     begin
   518     mapName:= ExtractFileName(Pathz[ptMapCurrent]);
   503     mapName:= ExtractFileName(Pathz[ptMapCurrent]);
   519     tmpsurf:= LoadImage(UserPathz[ptMissionMaps] + '/' + mapName + '/map', ifAlpha or ifTransparent or ifIgnoreCaps);
   504     tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
   520     if tmpsurf = nil then
       
   521         tmpsurf:= LoadImage(Pathz[ptMissionMaps] + '/' + mapName + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
       
   522     end;
   505     end;
   523 // (bare) Sanity check. Considering possible LongInt comparisons as well as just how much system memoery it would take
   506 // (bare) Sanity check. Considering possible LongInt comparisons as well as just how much system memoery it would take
   524 TryDo((tmpsurf^.w < $40000000) and (tmpsurf^.h < $40000000) and (tmpsurf^.w * tmpsurf^.h < 6*1024*1024*1024), 'Map dimensions too big!', true);
   507 TryDo((tmpsurf^.w < $40000000) and (tmpsurf^.h < $40000000) and (tmpsurf^.w * tmpsurf^.h < 6*1024*1024*1024), 'Map dimensions too big!', true);
   525 
   508 
   526 ResizeLand(tmpsurf^.w, tmpsurf^.h);
   509 ResizeLand(tmpsurf^.w, tmpsurf^.h);