hedgewars/uLand.pas
branchphysfslayer
changeset 8025 07862ab415c8
parent 8011 ffd5eba8f7c2
child 8060 341fa76d0749
equal deleted inserted replaced
8022:10b3b93c1f56 8025:07862ab415c8
   424 
   424 
   425 procedure LoadMapConfig;
   425 procedure LoadMapConfig;
   426 var f: textfile;
   426 var f: textfile;
   427     s: shortstring;
   427     s: shortstring;
   428 begin
   428 begin
   429 // unC0Rr - should this be passed from the GUI? I am not sure which layer does what
   429 s:= cPathz[ptMapCurrent] + '/map.cfg';
   430 s:= UserPathz[ptMapCurrent] + '/map.cfg';
   430 
   431 if not FileExists(s) then
       
   432     s:= Pathz[ptMapCurrent] + '/map.cfg';
       
   433 WriteLnToConsole('Fetching map HH limit');
   431 WriteLnToConsole('Fetching map HH limit');
   434 {$I-}
   432 {$I-}
   435 Assign(f, s);
   433 Assign(f, s);
   436 filemode:= 0; // readonly
   434 filemode:= 0; // readonly
   437 Reset(f);
   435 Reset(f);
   438 if IOResult <> 0 then
   436 if IOResult <> 0 then
   439     begin
   437     begin
   440     s:= Pathz[ptMissionMaps] + '/' + ExtractFileName(Pathz[ptMapCurrent]) + '/map.cfg';
   438     s:= cPathz[ptMissionMaps] + '/' + ExtractFileName(cPathz[ptMapCurrent]) + '/map.cfg';
   441     Assign(f, s);
   439     Assign(f, s);
   442     Reset(f);
   440     Reset(f);
   443     end;
   441     end;
   444 Readln(f);
   442 Readln(f);
   445 if not eof(f) then
   443 if not eof(f) then
   457     mapName: shortstring;
   455     mapName: shortstring;
   458 begin
   456 begin
   459 tmpsurf:= LoadDataImage(ptMapCurrent, 'mask', ifAlpha or ifTransparent or ifIgnoreCaps);
   457 tmpsurf:= LoadDataImage(ptMapCurrent, 'mask', ifAlpha or ifTransparent or ifIgnoreCaps);
   460 if tmpsurf = nil then
   458 if tmpsurf = nil then
   461     begin
   459     begin
   462     mapName:= ExtractFileName(Pathz[ptMapCurrent]);
   460     mapName:= ExtractFileName(cPathz[ptMapCurrent]);
   463     tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
   461     tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
   464     end;
   462     end;
   465 
   463 
   466 
   464 
   467 if (tmpsurf <> nil) and (tmpsurf^.format^.BytesPerPixel = 4) then
   465 if (tmpsurf <> nil) and (tmpsurf^.format^.BytesPerPixel = 4) then
   531 WriteLnToConsole('Loading land from file...');
   529 WriteLnToConsole('Loading land from file...');
   532 AddProgress;
   530 AddProgress;
   533 tmpsurf:= LoadDataImage(ptMapCurrent, 'map', ifAlpha or ifTransparent or ifIgnoreCaps);
   531 tmpsurf:= LoadDataImage(ptMapCurrent, 'map', ifAlpha or ifTransparent or ifIgnoreCaps);
   534 if tmpsurf = nil then
   532 if tmpsurf = nil then
   535     begin
   533     begin
   536     mapName:= ExtractFileName(Pathz[ptMapCurrent]);
   534     mapName:= ExtractFileName(cPathz[ptMapCurrent]);
   537     tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
   535     tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
   538     end;
   536     end;
   539 // (bare) Sanity check. Considering possible LongInt comparisons as well as just how much system memoery it would take
   537 // (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);
   538 TryDo((tmpsurf^.w < $40000000) and (tmpsurf^.h < $40000000) and (tmpsurf^.w * tmpsurf^.h < 6*1024*1024*1024), 'Map dimensions too big!', true);
   541 
   539 
   579         end
   577         end
   580 end;
   578 end;
   581 
   579 
   582 procedure GenMap;
   580 procedure GenMap;
   583 var x, y, w, c: Longword;
   581 var x, y, w, c: Longword;
   584     usermap, usermask, map, mask: shortstring;
   582     map, mask: shortstring;
   585     maskOnly: boolean;
   583     maskOnly: boolean;
   586 begin
   584 begin
   587     hasBorder:= false;
   585     hasBorder:= false;
   588     maskOnly:= false;
   586     maskOnly:= false;
   589 
   587 
   592     // is this not needed any more? lets hope setlength sets also 0s
   590     // is this not needed any more? lets hope setlength sets also 0s
   593     //if ((GameFlags and gfForts) <> 0) or (Pathz[ptMapCurrent] <> '') then
   591     //if ((GameFlags and gfForts) <> 0) or (Pathz[ptMapCurrent] <> '') then
   594     //    FillChar(Land,SizeOf(TCollisionArray),0);*)
   592     //    FillChar(Land,SizeOf(TCollisionArray),0);*)
   595 
   593 
   596     if (GameFlags and gfForts) = 0 then
   594     if (GameFlags and gfForts) = 0 then
   597         if Pathz[ptMapCurrent] <> '' then
   595         if cPathz[ptMapCurrent] <> '' then
   598             begin
   596             begin
   599             usermap:= UserPathz[ptMapCurrent] + '/map.png';
   597             map:= cPathz[ptMapCurrent] + '/map.png';
   600             usermask:= UserPathz[ptMapCurrent] + '/mask.png';
   598             mask:= cPathz[ptMapCurrent] + '/mask.png';
   601             map:= Pathz[ptMapCurrent] + '/map.png';
   599             if (not(FileExists(map)) and FileExists(mask)) then
   602             mask:= Pathz[ptMapCurrent] + '/mask.png';
       
   603             if (not(FileExists(usermap)) and FileExists(usermask)) or
       
   604                (not(FileExists(map)) and FileExists(mask)) then
       
   605                 begin
   600                 begin
   606                 maskOnly:= true;
   601                 maskOnly:= true;
   607                 LoadMask;
   602                 LoadMask;
   608                 GenLandSurface
   603                 GenLandSurface
   609                 end
   604                 end
   694     DrawBottomBorder;
   689     DrawBottomBorder;
   695 
   690 
   696 if (GameFlags and gfDisableGirders) <> 0 then
   691 if (GameFlags and gfDisableGirders) <> 0 then
   697     hasGirders:= false;
   692     hasGirders:= false;
   698 
   693 
   699 if (GameFlags and gfForts = 0) and (maskOnly or (Pathz[ptMapCurrent] = '')) then
   694 if (GameFlags and gfForts = 0) and (maskOnly or (cPathz[ptMapCurrent] = '')) then
   700     AddObjects
   695     AddObjects
   701     
   696     
   702 else
   697 else
   703     AddProgress();
   698     AddProgress();
   704 
   699