hedgewars/uLand.pas
changeset 1792 c30c6944bd49
parent 1784 dfe9bafb4590
child 1795 2457fcc0dcd9
equal deleted inserted replaced
1791:7c9d645d2591 1792:c30c6944bd49
    28      LandPixels: TLandArray;
    28      LandPixels: TLandArray;
    29      LandTexture: PTexture = nil;
    29      LandTexture: PTexture = nil;
    30      LandDirty: TDirtyTag;
    30      LandDirty: TDirtyTag;
    31      hasBorder: boolean; // I'm putting this here for now.  I'd like it to be toggleable by user (so user can set a border on a non-cave map) - will turn off air attacks
    31      hasBorder: boolean; // I'm putting this here for now.  I'd like it to be toggleable by user (so user can set a border on a non-cave map) - will turn off air attacks
    32      hasGirders: boolean;  // I think should be on template by template basis. some caverns might have open water and large spaces.  Some islands don't need? It might be better to tweak the girder code based upon space above.  dunno.
    32      hasGirders: boolean;  // I think should be on template by template basis. some caverns might have open water and large spaces.  Some islands don't need? It might be better to tweak the girder code based upon space above.  dunno.
    33      playHeight, playWidth, leftX, rightX, topY: Longword;  // idea is that a template can specify height/width.  Or, a map, a height/width by the dimensions of the image.  If the map has pixels near top of image, it triggers border.  Maybe not a good idea, but, for now?  Could also be used to prevent placing a girder outside play area on maps with hasBorder = true
    33      playHeight, playWidth, leftX, rightX, topY, MaxHedgehogs: Longword;  // idea is that a template can specify height/width.  Or, a map, a height/width by the dimensions of the image.  If the map has pixels near top of image, it triggers border.  Maybe not a good idea, but, for now?  Could also be used to prevent placing a girder outside play area on maps with hasBorder = true
    34 
    34 
    35 // in your coding style, it appears to be "isXXXX" for a verb, and "FooBar" for everything else - should be PlayHeight ?
    35 // in your coding style, it appears to be "isXXXX" for a verb, and "FooBar" for everything else - should be PlayHeight ?
    36 
    36 
    37 procedure GenMap;
    37 procedure GenMap;
    38 function  GenPreview: TPreview;
    38 function  GenPreview: TPreview;
   374      begin
   374      begin
   375      pa.Count:= BasePointsCount;
   375      pa.Count:= BasePointsCount;
   376      for i:= 0 to pred(pa.Count) do
   376      for i:= 0 to pred(pa.Count) do
   377          begin
   377          begin
   378          pa.ar[i].x:= BasePoints^[i].x + LongInt(GetRandom(BasePoints^[i].w));
   378          pa.ar[i].x:= BasePoints^[i].x + LongInt(GetRandom(BasePoints^[i].w));
       
   379          if pa.ar[i].x <> NTPX then
       
   380             pa.ar[i].x:= pa.ar[i].x + ((LAND_WIDTH - Template.TemplateWidth) div 2);
   379          pa.ar[i].y:= BasePoints^[i].y + LongInt(GetRandom(BasePoints^[i].h)) + LAND_HEIGHT - Template.TemplateHeight
   381          pa.ar[i].y:= BasePoints^[i].y + LongInt(GetRandom(BasePoints^[i].h)) + LAND_HEIGHT - Template.TemplateHeight
   380          end;
   382          end;
   381 
   383 
   382      if canMirror then
   384      if canMirror then
   383         if getrandom(2) = 0 then
   385         if getrandom(2) = 0 then
   503          with FillPoints^[i] do
   505          with FillPoints^[i] do
   504               FillLand(x, y);
   506               FillLand(x, y);
   505 
   507 
   506 DrawEdge(pa, COLOR_LAND);
   508 DrawEdge(pa, COLOR_LAND);
   507 
   509 
       
   510 MaxHedgehogs:= Template.MaxHedgehogs;
   508 hasGirders:= Template.hasGirders;
   511 hasGirders:= Template.hasGirders;
   509 playHeight:= Template.TemplateHeight;
   512 playHeight:= Template.TemplateHeight;
   510 playWidth:= Template.TemplateWidth;
   513 playWidth:= Template.TemplateWidth;
   511 //TryDo(playWidth<>0, 'freakin magic man!  Why the HELL does having a TryDo here make the following calculations work?', true);
       
   512 leftX:= ((LAND_WIDTH - playWidth) div 2);
   514 leftX:= ((LAND_WIDTH - playWidth) div 2);
   513 rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1;
   515 rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1;
   514 topY:= LAND_HEIGHT - playHeight;
   516 topY:= LAND_HEIGHT - playHeight;
   515 
   517 
   516 if (Template.canInvert and (getrandom(2) = 0)) or
   518 if (Template.canInvert and (getrandom(2) = 0)) or
   531     end;
   533     end;
   532 end;
   534 end;
   533 
   535 
   534 function SelectTemplate: LongInt;
   536 function SelectTemplate: LongInt;
   535 begin
   537 begin
   536 SelectTemplate:= getrandom(Succ(High(EdgeTemplates)))
   538 SelectTemplate:= getrandom(Succ(High(EdgeTemplates)));
       
   539 WriteLnToConsole('Selected template #'+inttostr(SelectTemplate));
   537 end;
   540 end;
   538 
   541 
   539 procedure LandSurface2LandPixels(Surface: PSDL_Surface);
   542 procedure LandSurface2LandPixels(Surface: PSDL_Surface);
   540 var x, y: LongInt;
   543 var x, y: LongInt;
   541 	p: PLongwordArray;
   544 	p: PLongwordArray;
   600 tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', true, true, true);
   603 tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', true, true, true);
   601 BlitImageAndGenerateCollisionInfo(rightX - 150 - tmpsurf^.w, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
   604 BlitImageAndGenerateCollisionInfo(rightX - 150 - tmpsurf^.w, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
   602 SDL_FreeSurface(tmpsurf);
   605 SDL_FreeSurface(tmpsurf);
   603 end;
   606 end;
   604 
   607 
       
   608 // Hi unC0Rr.
       
   609 // This is a function that Tiy assures me would not be good for gameplay.
       
   610 // It allows the setting of arbitrary portions of landscape as indestructible, or regular, or even blank.
       
   611 // He said I could add it here only when I swore it wouldn't impact gameplay.  Which, as far as I can tell, is true.
       
   612 // I'd just like to play with it with my friends if you don't mind.
       
   613 // Can allow for amusing maps.
       
   614 procedure LoadMask;
       
   615 var tmpsurf: PSDL_Surface;
       
   616     p: PLongwordArray;
       
   617     x, y, cpX, cpY: Longword;
       
   618 begin
       
   619 tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/mask', true, false, true);
       
   620 if (tmpsurf <> nil) and (tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT) and (tmpsurf^.format^.BytesPerPixel = 4) then
       
   621     begin
       
   622 	cpX:= (LAND_WIDTH - tmpsurf^.w) div 2;
       
   623 	cpY:= LAND_HEIGHT - tmpsurf^.h;
       
   624     if SDL_MustLock(tmpsurf) then
       
   625        SDLTry(SDL_LockSurface(tmpsurf) >= 0, true);
       
   626   
       
   627     p:= tmpsurf^.pixels;
       
   628     for y:= 0 to Pred(tmpsurf^.h) do
       
   629         begin
       
   630         for x:= 0 to Pred(tmpsurf^.w) do
       
   631             Land[cpY + y, cpX + x]:= p^[x];
       
   632         p:= @(p^[tmpsurf^.pitch div 4]);
       
   633         end;
       
   634   
       
   635     if SDL_MustLock(tmpsurf) then
       
   636        SDL_UnlockSurface(tmpsurf);
       
   637     SDL_FreeSurface(tmpsurf);
       
   638     end;
       
   639 end;
       
   640 
   605 procedure LoadMap;
   641 procedure LoadMap;
   606 var tmpsurf: PSDL_Surface;
   642 var tmpsurf: PSDL_Surface;
       
   643     s: string;
       
   644     a,b: shortstring;
       
   645     f: textfile;
       
   646     tn: Longint;
       
   647 
   607 begin
   648 begin
   608 WriteLnToConsole('Loading land from file...');
   649 WriteLnToConsole('Loading land from file...');
   609 AddProgress;
   650 AddProgress;
   610 tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/map', true, true, true);
   651 tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/map', true, true, true);
   611 TryDo((tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT), 'Map dimensions too big!', true);
   652 TryDo((tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT), 'Map dimensions too big!', true);
   612 
   653 
       
   654 // unC0Rr - should this be passed from the GUI? I'm not sure which layer does what
       
   655 s:= Pathz[ptMapCurrent] + '/map.cfg';
       
   656 WriteLnToConsole('Fetching map HH limit');
       
   657 Assign(f, s);
       
   658 Reset(f);
       
   659 Readln(f, a);
       
   660 SplitBySpace(a,b);
       
   661 Val(b,MaxHedgehogs,tn);
       
   662 if(MaxHedgehogs = 0) then MaxHedgehogs:= 18;
       
   663 
   613 playHeight:= tmpsurf^.h;
   664 playHeight:= tmpsurf^.h;
   614 playWidth:= tmpsurf^.w;
   665 playWidth:= tmpsurf^.w;
   615 TryDo(playWidth<>0, 'freakin magic man!  Why the HELL does having a TryDo here make the following calculations work?', true);
       
   616 leftX:= (LAND_WIDTH - playWidth) div 2;
   666 leftX:= (LAND_WIDTH - playWidth) div 2;
   617 rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1;
   667 rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1;
   618 topY:= LAND_HEIGHT - playHeight;
   668 topY:= LAND_HEIGHT - playHeight;
   619 
   669 
   620 TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Map should be 32bit', true);
   670 TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Map should be 32bit', true);
   623 	(LAND_WIDTH - tmpsurf^.w) div 2,
   673 	(LAND_WIDTH - tmpsurf^.w) div 2,
   624 	LAND_HEIGHT - tmpsurf^.h,
   674 	LAND_HEIGHT - tmpsurf^.h,
   625 	tmpsurf^.w,
   675 	tmpsurf^.w,
   626 	tmpsurf);
   676 	tmpsurf);
   627 SDL_FreeSurface(tmpsurf);
   677 SDL_FreeSurface(tmpsurf);
       
   678 
       
   679 LoadMask;
   628 end;
   680 end;
   629 
   681 
   630 procedure GenMap;
   682 procedure GenMap;
   631 var x, y, w, c: Longword;
   683 var x, y, w, c: Longword;
   632 begin
   684 begin