hedgewars/uLand.pas
changeset 6096 a00dbbf49d6c
parent 6082 16ca7a7a6aa6
child 6224 42b256eca362
child 6254 e90fb60cb46d
equal deleted inserted replaced
6095:332d45c08592 6096:a00dbbf49d6c
  1140     mapName:= ExtractFileName(Pathz[ptMapCurrent]);
  1140     mapName:= ExtractFileName(Pathz[ptMapCurrent]);
  1141     tmpsurf:= LoadImage(UserPathz[ptMissionMaps] + '/' + mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
  1141     tmpsurf:= LoadImage(UserPathz[ptMissionMaps] + '/' + mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
  1142     if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptMissionMaps] + '/' + mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
  1142     if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptMissionMaps] + '/' + mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
  1143     end;
  1143     end;
  1144 
  1144 
  1145     if (tmpsurf <> nil) and (tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT) and (tmpsurf^.format^.BytesPerPixel = 4) then
  1145 
  1146     begin
  1146 if (tmpsurf <> nil) and (tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT) and (tmpsurf^.format^.BytesPerPixel = 4) then
  1147         cpX:= (LAND_WIDTH - tmpsurf^.w) div 2;
  1147 begin
  1148         cpY:= LAND_HEIGHT - tmpsurf^.h;
  1148     disableLandBack:= true;
  1149         if SDL_MustLock(tmpsurf) then
  1149 
  1150             SDLTry(SDL_LockSurface(tmpsurf) >= 0, true);
  1150     cpX:= (LAND_WIDTH - tmpsurf^.w) div 2;
  1151 
  1151     cpY:= LAND_HEIGHT - tmpsurf^.h;
  1152             p:= tmpsurf^.pixels;
  1152     if SDL_MustLock(tmpsurf) then
  1153             for y:= 0 to Pred(tmpsurf^.h) do
  1153         SDLTry(SDL_LockSurface(tmpsurf) >= 0, true);
       
  1154 
       
  1155         p:= tmpsurf^.pixels;
       
  1156         for y:= 0 to Pred(tmpsurf^.h) do
       
  1157         begin
       
  1158             for x:= 0 to Pred(tmpsurf^.w) do
  1154             begin
  1159             begin
  1155                 for x:= 0 to Pred(tmpsurf^.w) do
  1160                 if ((AMask and p^[x]) = 0) then
  1156                 begin
  1161                     Land[cpY + y, cpX + x]:= 0
  1157                     if ((AMask and p^[x]) = 0) then  // Tiy was having trouble generating transparent black
  1162                 else if p^[x] = $FFFFFFFF then
  1158                         Land[cpY + y, cpX + x]:= 0
  1163                     Land[cpY + y, cpX + x]:= lfObject
  1159                     else if p^[x] = (AMask or RMask) then
  1164                 else if p^[x] = (AMask or RMask) then
  1160                         Land[cpY + y, cpX + x]:= lfIndestructible
  1165                     Land[cpY + y, cpX + x]:= lfIndestructible
  1161                     else if p^[x] = (AMask or BMask) then
  1166                 else if p^[x] = AMask then
  1162                         Land[cpY + y, cpX + x]:= lfBasic or lfIce
  1167                     begin
  1163                     else if p^[x] = $FFFFFFFF then
  1168                     Land[cpY + y, cpX + x]:= lfBasic;
  1164                         Land[cpY + y, cpX + x]:= lfBasic;
  1169                     disableLandBack:= false
  1165                 end;
  1170                     end
  1166                 p:= @(p^[tmpsurf^.pitch div 4]);
  1171                 else if p^[x] = (AMask or BMask) then
       
  1172                     Land[cpY + y, cpX + x]:= lfObject or lfIce
  1167             end;
  1173             end;
  1168 
  1174             p:= @(p^[tmpsurf^.pitch div 4]);
  1169         if SDL_MustLock(tmpsurf) then
  1175         end;
  1170             SDL_UnlockSurface(tmpsurf);
  1176 
  1171     end;
  1177     if SDL_MustLock(tmpsurf) then
  1172     if (tmpsurf <> nil) then
  1178         SDL_UnlockSurface(tmpsurf);
  1173         SDL_FreeSurface(tmpsurf);
  1179     if not disableLandBack then
  1174     tmpsurf:= nil;
  1180         begin
       
  1181         // freed in freeModule() below
       
  1182         LandBackSurface:= LoadImage(UserPathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent);
       
  1183         if LandBackSurface = nil then LandBackSurface:= LoadImage(Pathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent)
       
  1184         end;
       
  1185 end;
       
  1186 if (tmpsurf <> nil) then
       
  1187     SDL_FreeSurface(tmpsurf);
       
  1188 tmpsurf:= nil;
  1175 end;
  1189 end;
  1176 
  1190 
  1177 procedure LoadMap;
  1191 procedure LoadMap;
  1178 var tmpsurf: PSDL_Surface;
  1192 var tmpsurf: PSDL_Surface;
  1179     s: shortstring;
  1193     s: shortstring;