238 playWidth:= Template.TemplateWidth; |
238 playWidth:= Template.TemplateWidth; |
239 leftX:= ((LAND_WIDTH - playWidth) div 2); |
239 leftX:= ((LAND_WIDTH - playWidth) div 2); |
240 rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1; |
240 rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1; |
241 topY:= LAND_HEIGHT - playHeight; |
241 topY:= LAND_HEIGHT - playHeight; |
242 |
242 |
|
243 |
243 // HACK: force to only cavern even if a cavern map is invertable if cTemplateFilter = 4 ? |
244 // HACK: force to only cavern even if a cavern map is invertable if cTemplateFilter = 4 ? |
244 if (cTemplateFilter = 4) |
245 if (cTemplateFilter = 4) |
245 or (Template.canInvert and (getrandom(2) = 0)) |
246 or (Template.canInvert and (getrandom(2) = 0)) |
246 or (not Template.canInvert and Template.isNegative) then |
247 or (not Template.canInvert and Template.isNegative) then |
247 begin |
248 begin |
456 x, y, cpX, cpY: Longword; |
457 x, y, cpX, cpY: Longword; |
457 mapName: shortstring; |
458 mapName: shortstring; |
458 begin |
459 begin |
459 tmpsurf:= LoadDataImage(ptMapCurrent, 'mask', ifAlpha or ifTransparent or ifIgnoreCaps); |
460 tmpsurf:= LoadDataImage(ptMapCurrent, 'mask', ifAlpha or ifTransparent or ifIgnoreCaps); |
460 if tmpsurf = nil then |
461 if tmpsurf = nil then |
461 begin |
462 tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps); |
|
463 if tmpsurf = nil then |
|
464 begin |
462 mapName:= ExtractFileName(Pathz[ptMapCurrent]); |
465 mapName:= ExtractFileName(Pathz[ptMapCurrent]); |
463 tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps); |
466 tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps); |
464 end; |
467 end; |
465 |
468 |
466 |
469 |
522 SDL_FreeSurface(tmpsurf); |
525 SDL_FreeSurface(tmpsurf); |
523 tmpsurf:= nil; |
526 tmpsurf:= nil; |
524 end; |
527 end; |
525 |
528 |
526 procedure LoadMap; |
529 procedure LoadMap; |
527 var tmpsurf: PSDL_Surface; |
530 var tmpsurf : PSDL_Surface; |
528 s: shortstring; |
531 s : shortstring; |
529 mapName: shortstring = ''; |
532 f : textfile; |
|
533 mapName : shortstring = ''; |
|
534 |
530 begin |
535 begin |
531 WriteLnToConsole('Loading land from file...'); |
536 WriteLnToConsole('Loading land from file...'); |
532 AddProgress; |
537 AddProgress; |
533 tmpsurf:= LoadDataImage(ptMapCurrent, 'map', ifAlpha or ifTransparent or ifIgnoreCaps); |
538 tmpsurf:= LoadDataImage(ptMapCurrent, 'map', ifAlpha or ifTransparent or ifIgnoreCaps); |
534 if tmpsurf = nil then |
539 if tmpsurf = nil then |
539 // (bare) Sanity check. Considering possible LongInt comparisons as well as just how much system memoery it would take |
544 // (bare) Sanity check. Considering possible LongInt comparisons as well as just how much system memoery it would take |
540 TryDo((tmpsurf^.w < $40000000) and (tmpsurf^.h < $40000000) and (tmpsurf^.w * tmpsurf^.h < 6*1024*1024*1024), 'Map dimensions too big!', true); |
545 TryDo((tmpsurf^.w < $40000000) and (tmpsurf^.h < $40000000) and (tmpsurf^.w * tmpsurf^.h < 6*1024*1024*1024), 'Map dimensions too big!', true); |
541 |
546 |
542 ResizeLand(tmpsurf^.w, tmpsurf^.h); |
547 ResizeLand(tmpsurf^.w, tmpsurf^.h); |
543 LoadMapConfig; |
548 LoadMapConfig; |
|
549 |
|
550 // unC0Rr - should this be passed from the GUI? I am not sure which layer does what |
|
551 s:= UserPathz[ptMapCurrent] + '/map.cfg'; |
|
552 if not FileExists(s) then |
|
553 s:= Pathz[ptMapCurrent] + '/map.cfg'; |
|
554 WriteLnToConsole('Fetching map HH limit'); |
|
555 {$I-} |
|
556 Assign(f, s); |
|
557 filemode:= 0; // readonly |
|
558 Reset(f); |
|
559 if IOResult <> 0 then |
|
560 begin |
|
561 s:= Pathz[ptMissionMaps] + '/' + mapName + '/map.cfg'; |
|
562 Assign(f, s); |
|
563 Reset(f); |
|
564 end; |
|
565 Readln(f); |
|
566 if not eof(f) then |
|
567 Readln(f, MaxHedgehogs); |
|
568 |
|
569 {$I+} |
|
570 if (MaxHedgehogs = 0) then |
|
571 MaxHedgehogs:= 18; |
544 |
572 |
545 playHeight:= tmpsurf^.h; |
573 playHeight:= tmpsurf^.h; |
546 playWidth:= tmpsurf^.w; |
574 playWidth:= tmpsurf^.w; |
547 leftX:= (LAND_WIDTH - playWidth) div 2; |
575 leftX:= (LAND_WIDTH - playWidth) div 2; |
548 rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1; |
576 rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1; |
553 BlitImageAndGenerateCollisionInfo( |
581 BlitImageAndGenerateCollisionInfo( |
554 (LAND_WIDTH - tmpsurf^.w) div 2, |
582 (LAND_WIDTH - tmpsurf^.w) div 2, |
555 LAND_HEIGHT - tmpsurf^.h, |
583 LAND_HEIGHT - tmpsurf^.h, |
556 tmpsurf^.w, |
584 tmpsurf^.w, |
557 tmpsurf); |
585 tmpsurf); |
|
586 |
558 SDL_FreeSurface(tmpsurf); |
587 SDL_FreeSurface(tmpsurf); |
559 |
588 |
560 LoadMask; |
589 LoadMask; |
|
590 |
561 end; |
591 end; |
562 |
592 |
563 procedure DrawBottomBorder; // broken out from other borders for doing a floor-only map, or possibly updating bottom during SD |
593 procedure DrawBottomBorder; // broken out from other borders for doing a floor-only map, or possibly updating bottom during SD |
564 var x, w, c: Longword; |
594 var x, w, c: Longword; |
565 begin |
595 begin |
578 LandPixels[(Longword(cWaterLine) - 1 - w) div 2, x div 2]:= c |
608 LandPixels[(Longword(cWaterLine) - 1 - w) div 2, x div 2]:= c |
579 end |
609 end |
580 end; |
610 end; |
581 |
611 |
582 procedure GenMap; |
612 procedure GenMap; |
583 var x, y, w, c: Longword; |
613 var x, y, w, c : Longword; |
584 usermap, usermask, map, mask: shortstring; |
614 usermap, usermask, map, mask: shortstring; |
585 maskOnly: boolean; |
615 maskOnly : boolean; |
586 begin |
616 begin |
587 hasBorder:= false; |
617 hasBorder:= false; |
588 maskOnly:= false; |
618 maskOnly:= false; |
589 |
619 |
590 LoadThemeConfig; |
620 LoadThemeConfig; |
788 else |
817 else |
789 TryDo(s = digest, 'Different maps generated, sorry', true); |
818 TryDo(s = digest, 'Different maps generated, sorry', true); |
790 end; |
819 end; |
791 |
820 |
792 procedure chSendLandDigest(var s: shortstring); |
821 procedure chSendLandDigest(var s: shortstring); |
793 var adler, i: LongInt; |
822 var adler, i : LongInt; |
794 begin |
823 begin |
795 adler:= 1; |
824 adler:= 1; |
796 for i:= 0 to LAND_HEIGHT-1 do |
825 for i:= 0 to LAND_HEIGHT-1 do |
|
826 begin |
797 adler:= Adler32Update(adler, @Land[i,0], LAND_WIDTH); |
827 adler:= Adler32Update(adler, @Land[i,0], LAND_WIDTH); |
|
828 end; |
798 s:= 'M' + IntToStr(adler) + cScriptName; |
829 s:= 'M' + IntToStr(adler) + cScriptName; |
799 |
830 |
800 chLandCheck(s); |
831 chLandCheck(s); |
801 SendIPCRaw(@s[0], Length(s) + 1) |
832 SendIPCRaw(@s[0], Length(s) + 1) |
802 end; |
833 end; |
821 *) |
852 *) |
822 end; |
853 end; |
823 |
854 |
824 procedure freeModule; |
855 procedure freeModule; |
825 begin |
856 begin |
826 SetLength(Land, 0, 0); |
857 |
827 SetLength(LandPixels, 0, 0); |
858 SetLength(LandPixels, 0, 0); |
828 SetLength(LandDirty, 0, 0); |
859 |
|
860 SetLength(Land, 0, 0); |
|
861 |
|
862 SetLength(LandDirty, 0, 0); |
|
863 |
829 end; |
864 end; |
830 |
865 |
831 end. |
866 end. |