298
300
SDL_FreeSurface(tmpsurf);
300
302
// freed in freeModule() below
301
LandBackSurface:= LoadImage(Pathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent);
303
LandBackSurface:= LoadImage(UserPathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent);
304
if LandBackSurface = nil then LandBackSurface:= LoadImage(Pathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent);
303
tmpsurf:= LoadImage(Pathz[ptCurrTheme] + '/Border', ifCritical or ifIgnoreCaps or ifTransparent);
306
tmpsurf:= LoadImage(UserPathz[ptCurrTheme] + '/Border', ifIgnoreCaps or ifTransparent);
307
if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptCurrTheme] + '/Border', ifCritical or ifIgnoreCaps or ifTransparent);
304
308
for x:= 0 to LAND_WIDTH - 1 do
306
310
yd:= LAND_HEIGHT - 1;
1059
1064
LandSurface2LandPixels(tmpsurf);
1060
1065
SDL_FreeSurface(tmpsurf);
1066
for x:= leftX+2 to rightX-2 do
1067
for y:= topY+2 to LAND_HEIGHT-3 do
1068
if (Land[y, x] = 0) and
1069
(((Land[y, x-1] = lfBasic) and ((Land[y+1,x] = lfBasic)) or (Land[y-1,x] = lfBasic)) or
1070
((Land[y, x+1] = lfBasic) and ((Land[y-1,x] = lfBasic) or (Land[y+1,x] = lfBasic)))) then
1072
if (cReducedQuality and rqBlurryLand) = 0 then
1074
if (Land[y, x-1] = lfBasic) and (LandPixels[y, x-1] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y, x-1]
1075
else if (Land[y, x+1] = lfBasic) and (LandPixels[y, x+1] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y, x+1]
1076
else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1, x] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y-1, x]
1077
else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1, x] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y+1, x];
1078
if (((LandPixels[y,x] and AMask) shr AShift) > 10) then LandPixels[y,x]:= (LandPixels[y,x] and not AMask) or (128 shl AShift)
1080
Land[y,x]:= lfObject
1082
else if (Land[y, x] = 0) and
1083
(((Land[y, x-1] = lfBasic) and (Land[y+1,x-1] = lfBasic) and (Land[y+2,x] = lfBasic)) or
1084
((Land[y, x-1] = lfBasic) and (Land[y-1,x-1] = lfBasic) and (Land[y-2,x] = lfBasic)) or
1085
((Land[y, x+1] = lfBasic) and (Land[y+1,x+1] = lfBasic) and (Land[y+2,x] = lfBasic)) or
1086
((Land[y, x+1] = lfBasic) and (Land[y-1,x+1] = lfBasic) and (Land[y-2,x] = lfBasic)) or
1087
((Land[y+1, x] = lfBasic) and (Land[y+1,x+1] = lfBasic) and (Land[y,x+2] = lfBasic)) or
1088
((Land[y-1, x] = lfBasic) and (Land[y-1,x+1] = lfBasic) and (Land[y,x+2] = lfBasic)) or
1089
((Land[y+1, x] = lfBasic) and (Land[y+1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic)) or
1090
((Land[y-1, x] = lfBasic) and (Land[y-1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic))) then
1092
if (cReducedQuality and rqBlurryLand) = 0 then
1094
if (Land[y, x-1] = lfBasic) and (LandPixels[y,x-1] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y, x-1]
1095
else if (Land[y, x+1] = lfBasic) and (LandPixels[y,x+1] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y, x+1]
1096
else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1,x] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y+1, x]
1097
else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1,x] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y-1, x];
1098
if (((LandPixels[y,x] and AMask) shr AShift) > 10) then LandPixels[y,x]:= (LandPixels[y,x] and not AMask) or (64 shl AShift)
1100
Land[y,x]:= lfObject
1075
1117
WriteLnToConsole('Generating forts land...');
1077
tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
1119
tmpsurf:= LoadImage(UserPathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifTransparent or ifIgnoreCaps);
1120
if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
1078
1121
BlitImageAndGenerateCollisionInfo(leftX+150, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
1079
1122
SDL_FreeSurface(tmpsurf);
1081
tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
1124
tmpsurf:= LoadImage(UserPathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifTransparent or ifIgnoreCaps);
1125
if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
1082
1126
BlitImageAndGenerateCollisionInfo(rightX - 150 - tmpsurf^.w, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
1083
1127
SDL_FreeSurface(tmpsurf);
1087
// This is a function that Tiy assures me would not be good for gameplay.
1088
// It allows the setting of arbitrary portions of landscape as indestructible, or regular, or even blank.
1089
// He said I could add it here only when I swore it would not impact gameplay. Which, as far as I can tell, is true.
1090
// I would just like to play with it with my friends if you do not mind.
1091
// Can allow for amusing maps.
1130
// Loads Land[] from an image, allowing overriding standard collision
1092
1131
procedure LoadMask(mapName: shortstring);
1093
1132
var tmpsurf: PSDL_Surface;
1094
1133
p: PLongwordArray;
1095
1134
x, y, cpX, cpY: Longword;
1097
tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
1098
if (tmpsurf = nil) and (mapName <> '') then
1099
tmpsurf:= LoadImage(Pathz[ptMissionMaps] + '/' + mapName +'/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
1136
tmpsurf:= LoadImage(UserPathz[ptMapCurrent] + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
1137
if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
1138
if tmpsurf = nil then
1140
mapName:= ExtractFileName(Pathz[ptMapCurrent]);
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);
1101
1145
if (tmpsurf <> nil) and (tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT) and (tmpsurf^.format^.BytesPerPixel = 4) then
1138
1182
WriteLnToConsole('Loading land from file...');
1140
tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/map', ifAlpha or ifTransparent or ifIgnoreCaps);
1184
tmpsurf:= LoadImage(UserPathz[ptMapCurrent] + '/map', ifAlpha or ifTransparent or ifIgnoreCaps);
1185
if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/map', ifAlpha or ifTransparent or ifIgnoreCaps);
1141
1186
if tmpsurf = nil then
1143
1188
mapName:= ExtractFileName(Pathz[ptMapCurrent]);
1144
tmpsurf:= LoadImage(Pathz[ptMissionMaps] + '/' + mapName + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
1189
tmpsurf:= LoadImage(UserPathz[ptMissionMaps] + '/' + mapName + '/map', ifAlpha or ifTransparent or ifIgnoreCaps);
1190
if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptMissionMaps] + '/' + mapName + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
1146
1192
TryDo((tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT), 'Map dimensions too big!', true);
1148
1194
// unC0Rr - should this be passed from the GUI? I am not sure which layer does what
1149
s:= Pathz[ptMapCurrent] + '/map.cfg';
1195
s:= UserPathz[ptMapCurrent] + '/map.cfg';
1196
if not FileExists(s) then s:= Pathz[ptMapCurrent] + '/map.cfg';
1150
1197
WriteLnToConsole('Fetching map HH limit');
1181
1228
LoadMask(mapname);
1231
procedure DrawBottomBorder; // broken out from other borders for doing a floor-only map, or possibly updating bottom during SD
1232
var x, w, c: Longword;
1235
for x:= leftX to rightX do
1237
Land[cWaterLine-1 - w, x]:= lfIndestructible;
1238
if (x + w) mod 32 < 16 then
1241
c:= AMask or RMask or GMask; // FF00FFFF
1243
if (cReducedQuality and rqBlurryLand) = 0 then
1244
LandPixels[cWaterLine-1 - w, x]:= c
1246
LandPixels[(cWaterLine-1 - w) div 2, x div 2]:= c
1184
1250
procedure GenMap;
1185
1251
var x, y, w, c: Longword;
1240
1306
c:= AMask or RMask or GMask; // FF00FFFF
1242
1308
if (cReducedQuality and rqBlurryLand) = 0 then
1244
1310
LandPixels[y, leftX + w]:= c;
1245
1311
LandPixels[y, rightX - w]:= c;
1249
1315
LandPixels[y div 2, (leftX + w) div 2]:= c;
1250
1316
LandPixels[y div 2, (rightX - w) div 2]:= c;
1254
1320
for x:= leftX to rightX do
1256
Land[topY + w, x]:= lfIndestructible;
1257
if (x + w) mod 32 < 16 then
1260
c:= AMask or RMask or GMask; // FF00FFFF
1322
Land[topY + w, x]:= lfIndestructible;
1323
if (x + w) mod 32 < 16 then
1326
c:= AMask or RMask or GMask; // FF00FFFF
1262
if (cReducedQuality and rqBlurryLand) = 0 then
1263
LandPixels[topY + w, x]:= c
1265
LandPixels[(topY + w) div 2, x div 2]:= c;
1328
if (cReducedQuality and rqBlurryLand) = 0 then
1329
LandPixels[topY + w, x]:= c
1331
LandPixels[(topY + w) div 2, x div 2]:= c;
1336
if (GameFlags and gfBottomBorder) <> 0 then DrawBottomBorder;
1270
1338
if (GameFlags and gfDisableGirders) <> 0 then hasGirders:= false;
1272
1340
if ((GameFlags and gfForts) = 0)
1277
1345
FreeLandObjects;
1349
if (cReducedQuality and rqBlurryLand) = 0 then
1350
for x:= leftX to rightX do
1351
for y:= topY to LAND_HEIGHT-1 do
1353
w:= LandPixels[y,x];
1354
w:= round(((w shr RShift and $FF) * RGB_LUMINANCE_RED +
1355
(w shr BShift and $FF) * RGB_LUMINANCE_GREEN +
1356
(w shr GShift and $FF) * RGB_LUMINANCE_BLUE));
1357
if w > 255 then w:= 255;
1358
w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y,x] and AMask);
1359
LandPixels[y,x]:= w or (LandPixels[y, x] and AMask)
1362
for x:= leftX div 2 to rightX div 2 do
1363
for y:= topY div 2 to LAND_HEIGHT-1 div 2 do
1365
w:= LandPixels[y div 2,x div 2];
1366
w:= ((w shr RShift and $FF) + (w shr BShift and $FF) + (w shr GShift and $FF)) div 3;
1367
if w > 255 then w:= 255;
1368
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);
1369
LandPixels[y,x]:= w or (LandPixels[y div 2, x div 2] and AMask)
1279
1373
UpdateLandTexture(0, LAND_WIDTH, 0, LAND_HEIGHT);