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); |
416 rightX:= ((playWidth + (LAND_WIDTH - playWidth) div 2) - 1); |
413 rightX:= ((playWidth + (LAND_WIDTH - playWidth) div 2) - 1); |
417 topY:= LAND_HEIGHT - playHeight; |
414 topY:= LAND_HEIGHT - playHeight; |
418 |
415 |
419 WriteLnToConsole('Generating forts land...'); |
416 WriteLnToConsole('Generating forts land...'); |
420 |
417 |
421 tmpsurf:= LoadImage(UserPathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifTransparent or ifIgnoreCaps); |
418 tmpsurf:= LoadDataImage(ptForts, ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); |
422 if tmpsurf = nil then |
|
423 tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); |
|
424 BlitImageAndGenerateCollisionInfo(leftX+150, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf); |
419 BlitImageAndGenerateCollisionInfo(leftX+150, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf); |
425 SDL_FreeSurface(tmpsurf); |
420 SDL_FreeSurface(tmpsurf); |
426 |
421 |
427 tmpsurf:= LoadImage(UserPathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifTransparent or ifIgnoreCaps); |
422 tmpsurf:= LoadDataImage(ptForts, ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); |
428 if tmpsurf = nil then |
|
429 tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); |
|
430 BlitImageAndGenerateCollisionInfo(rightX - 150 - tmpsurf^.w, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf); |
423 BlitImageAndGenerateCollisionInfo(rightX - 150 - tmpsurf^.w, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf); |
431 SDL_FreeSurface(tmpsurf); |
424 SDL_FreeSurface(tmpsurf); |
432 end; |
425 end; |
433 |
426 |
434 // Loads Land[] from an image, allowing overriding standard collision |
427 // Loads Land[] from an image, allowing overriding standard collision |
435 procedure LoadMask(mapName: shortstring); |
428 procedure LoadMask(mapName: shortstring); |
436 var tmpsurf: PSDL_Surface; |
429 var tmpsurf: PSDL_Surface; |
437 p: PLongwordArray; |
430 p: PLongwordArray; |
438 x, y, cpX, cpY: Longword; |
431 x, y, cpX, cpY: Longword; |
439 begin |
432 begin |
440 tmpsurf:= LoadImage(UserPathz[ptMapCurrent] + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps); |
433 tmpsurf:= LoadDataImage(ptMapCurrent, 'mask', ifAlpha or ifTransparent or ifIgnoreCaps); |
441 if tmpsurf = nil then |
434 if tmpsurf = nil then |
442 tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps); |
|
443 if tmpsurf = nil then |
|
444 begin |
435 begin |
445 mapName:= ExtractFileName(Pathz[ptMapCurrent]); |
436 mapName:= ExtractFileName(Pathz[ptMapCurrent]); |
446 tmpsurf:= LoadImage(UserPathz[ptMissionMaps] + '/' + mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps); |
437 tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps); |
447 if tmpsurf = nil then |
|
448 tmpsurf:= LoadImage(Pathz[ptMissionMaps] + '/' + mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps); |
|
449 end; |
438 end; |
450 |
439 |
451 |
440 |
452 if (tmpsurf <> nil) and (tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT) and (tmpsurf^.format^.BytesPerPixel = 4) then |
441 if (tmpsurf <> nil) and (tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT) and (tmpsurf^.format^.BytesPerPixel = 4) then |
453 begin |
442 begin |
486 if SDL_MustLock(tmpsurf) then |
475 if SDL_MustLock(tmpsurf) then |
487 SDL_UnlockSurface(tmpsurf); |
476 SDL_UnlockSurface(tmpsurf); |
488 if not disableLandBack then |
477 if not disableLandBack then |
489 begin |
478 begin |
490 // freed in freeModule() below |
479 // freed in freeModule() below |
491 LandBackSurface:= LoadImage(UserPathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent); |
480 LandBackSurface:= LoadDataImage(ptCurrTheme, 'LandBackTex', ifIgnoreCaps or ifTransparent); |
492 if LandBackSurface = nil then |
|
493 LandBackSurface:= LoadImage(Pathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent); |
|
494 if (LandBackSurface <> nil) and GrayScale then |
481 if (LandBackSurface <> nil) and GrayScale then |
495 Surface2GrayScale(LandBackSurface) |
482 Surface2GrayScale(LandBackSurface) |
496 end; |
483 end; |
497 end; |
484 end; |
498 if (tmpsurf <> nil) then |
485 if (tmpsurf <> nil) then |
506 f: textfile; |
493 f: textfile; |
507 mapName: shortstring = ''; |
494 mapName: shortstring = ''; |
508 begin |
495 begin |
509 WriteLnToConsole('Loading land from file...'); |
496 WriteLnToConsole('Loading land from file...'); |
510 AddProgress; |
497 AddProgress; |
511 tmpsurf:= LoadImage(UserPathz[ptMapCurrent] + '/map', ifAlpha or ifTransparent or ifIgnoreCaps); |
498 tmpsurf:= LoadDataImage(ptMapCurrent, 'map', ifAlpha or ifTransparent or ifIgnoreCaps); |
512 if tmpsurf = nil then |
499 if tmpsurf = nil then |
513 tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/map', ifAlpha or ifTransparent or ifIgnoreCaps); |
|
514 if tmpsurf = nil then |
|
515 begin |
500 begin |
516 mapName:= ExtractFileName(Pathz[ptMapCurrent]); |
501 mapName:= ExtractFileName(Pathz[ptMapCurrent]); |
517 tmpsurf:= LoadImage(UserPathz[ptMissionMaps] + '/' + mapName + '/map', ifAlpha or ifTransparent or ifIgnoreCaps); |
502 tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); |
518 if tmpsurf = nil then |
|
519 tmpsurf:= LoadImage(Pathz[ptMissionMaps] + '/' + mapName + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); |
|
520 end; |
503 end; |
521 // (bare) Sanity check. Considering possible LongInt comparisons as well as just how much system memoery it would take |
504 // (bare) Sanity check. Considering possible LongInt comparisons as well as just how much system memoery it would take |
522 TryDo((tmpsurf^.w < $40000000) and (tmpsurf^.h < $40000000) and (tmpsurf^.w * tmpsurf^.h < 6*1024*1024*1024), 'Map dimensions too big!', true); |
505 TryDo((tmpsurf^.w < $40000000) and (tmpsurf^.h < $40000000) and (tmpsurf^.w * tmpsurf^.h < 6*1024*1024*1024), 'Map dimensions too big!', true); |
523 |
506 |
524 ResizeLand(tmpsurf^.w, tmpsurf^.h); |
507 ResizeLand(tmpsurf^.w, tmpsurf^.h); |