hedgewars/uLand.pas
changeset 1784 dfe9bafb4590
parent 1779 9d88af62a3bb
child 1792 c30c6944bd49
equal deleted inserted replaced
1783:169ebeefd7ab 1784:dfe9bafb4590
    39 procedure CheckLandDigest(s: shortstring);
    39 procedure CheckLandDigest(s: shortstring);
    40 procedure UpdateLandTexture(Y, Height: LongInt);
    40 procedure UpdateLandTexture(Y, Height: LongInt);
    41 procedure RealLandTexUpdate;
    41 procedure RealLandTexUpdate;
    42 
    42 
    43 implementation
    43 implementation
    44 uses uConsole, uStore, uMisc, uRandom, uTeams, uLandObjects, uSHA, uIO;
    44 uses uConsole, uStore, uMisc, uRandom, uTeams, uLandObjects, uSHA, uIO, uAmmos;
    45 
    45 
    46 type TPixAr = record
    46 type TPixAr = record
    47               Count: Longword;
    47               Count: Longword;
    48               ar: array[0..Pred(cMaxEdgePoints)] of TPoint;
    48               ar: array[0..Pred(cMaxEdgePoints)] of TPoint;
    49               end;
    49               end;
   582 end;
   582 end;
   583 
   583 
   584 procedure MakeFortsMap;
   584 procedure MakeFortsMap;
   585 var tmpsurf: PSDL_Surface;
   585 var tmpsurf: PSDL_Surface;
   586 begin
   586 begin
   587 // For now, defining a fort's playable area as 4096x1536 - there are no tall forts.  The extra height is to avoid triggering border with current code, also if user turns on a border, it'll give a bit more maneuvering room.
   587 // For now, defining a fort's playable area as 3072x1200 - there are no tall forts.  The extra height is to avoid triggering border with current code, also if user turns on a border, it'll give a bit more maneuvering room.
   588 playHeight:= 1536;
   588 playHeight:= 1200;
   589 playWidth:= 4096;
   589 playWidth:= 3072;
   590 leftX:= (LAND_WIDTH - playWidth) div 2;
   590 leftX:= (LAND_WIDTH - playWidth) div 2;
   591 rightX:= ((playWidth + (LAND_WIDTH - playWidth) div 2) - 1);
   591 rightX:= ((playWidth + (LAND_WIDTH - playWidth) div 2) - 1);
   592 topY:= LAND_HEIGHT - playHeight;
   592 topY:= LAND_HEIGHT - playHeight;
   593 
   593 
   594 WriteLnToConsole('Generating forts land...');
   594 WriteLnToConsole('Generating forts land...');
   595 
   595 
   596 tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', true, true, true);
   596 tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', true, true, true);
   597 BlitImageAndGenerateCollisionInfo(0, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
   597 BlitImageAndGenerateCollisionInfo(leftX+150, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
   598 SDL_FreeSurface(tmpsurf);
   598 SDL_FreeSurface(tmpsurf);
   599 
   599 
   600 tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', true, true, true);
   600 tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', true, true, true);
   601 BlitImageAndGenerateCollisionInfo(LAND_WIDTH - tmpsurf^.w, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
   601 BlitImageAndGenerateCollisionInfo(rightX - 150 - tmpsurf^.w, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
   602 SDL_FreeSurface(tmpsurf);
   602 SDL_FreeSurface(tmpsurf);
   603 end;
   603 end;
   604 
   604 
   605 procedure LoadMap;
   605 procedure LoadMap;
   606 var tmpsurf: PSDL_Surface;
   606 var tmpsurf: PSDL_Surface;
   626 	tmpsurf);
   626 	tmpsurf);
   627 SDL_FreeSurface(tmpsurf);
   627 SDL_FreeSurface(tmpsurf);
   628 end;
   628 end;
   629 
   629 
   630 procedure GenMap;
   630 procedure GenMap;
   631 var i, j, t: LongInt;
   631 var x, y, w, c: Longword;
   632 	x, y, w, c: Longword;
       
   633 begin
   632 begin
   634 hasBorder:= false;
   633 hasBorder:= false;
   635 hasGirders:= true;
   634 hasGirders:= true;
   636 LoadThemeConfig;
   635 LoadThemeConfig;
   637 
   636 
   642 AddProgress;
   641 AddProgress;
   643 
   642 
   644 {$IFDEF DEBUGFILE}LogLandDigest;{$ENDIF}
   643 {$IFDEF DEBUGFILE}LogLandDigest;{$ENDIF}
   645 
   644 
   646 // check for land near top
   645 // check for land near top
   647 for y:= topY to topY + 5 do
   646 c:= 0;
   648     for x:= leftX to rightX do
   647 if (GameFlags and gfBorder) <> 0 then
   649 		if Land[y, x] <> 0 then
   648     hasBorder:= true
   650 			begin
   649 else
   651 			hasBorder:= true;
   650     for y:= topY to topY + 5 do
   652 			break;
   651         for x:= leftX to rightX do
   653 			end;
   652             if Land[y, x] <> 0 then
       
   653                 begin
       
   654                 inc(c);
       
   655                 if c > 200 then // avoid accidental triggering
       
   656                     begin
       
   657                     hasBorder:= true;
       
   658                     break;
       
   659                     end;
       
   660                 end;
   654 
   661 
   655 if hasBorder then
   662 if hasBorder then
   656 	begin
   663 	begin
   657     for y:= 0 to LAND_HEIGHT - 1 do
   664 	for y:= 0 to LAND_HEIGHT - 1 do
   658         for x:= 0 to LAND_WIDTH - 1 do
   665 		for x:= 0 to LAND_WIDTH - 1 do
   659             if (y < topY) or (x < leftX) or (x > rightX) then
   666 			if (y < topY) or (x < leftX) or (x > rightX) then
   660                 Land[y, x]:= COLOR_INDESTRUCTIBLE;
   667 				Land[y, x]:= COLOR_INDESTRUCTIBLE;
   661 	// experiment hardcoding cave
   668 	// experiment hardcoding cave
   662     // also try basing cave dimensions on map/template dimensions, if they exist
   669 	// also try basing cave dimensions on map/template dimensions, if they exist
   663     for w:= 0 to 5 do // width of 3 allowed worms to be knocked through with grenade
   670 	for w:= 0 to 5 do // width of 3 allowed worms to be knocked through with grenade
   664         begin
   671 		begin
   665         for y:= topY to LAND_HEIGHT - 1 do
   672 		for y:= topY to LAND_HEIGHT - 1 do
   666             begin
   673 			begin
   667             Land[y, leftX + w]:= COLOR_INDESTRUCTIBLE;
   674 			Land[y, leftX + w]:= COLOR_INDESTRUCTIBLE;
   668             Land[y, rightX - w]:= COLOR_INDESTRUCTIBLE;
   675 			Land[y, rightX - w]:= COLOR_INDESTRUCTIBLE;
   669             if y mod 32 < 16 then c:= $FF000000
   676 			if (y + w) mod 32 < 16 then
   670             else c:= $FF00FFFF;
   677 				c:= $FF000000
   671             LandPixels[y, leftX + w]:= c;
   678 			else
   672             LandPixels[y, rightX - w]:= c;
   679 				c:= $FF00FFFF;
   673             end;
   680 			LandPixels[y, leftX + w]:= c;
   674 
   681 			LandPixels[y, rightX - w]:= c;
   675         for x:= leftX to rightX do
   682 			end;
   676             begin
   683 
   677             Land[topY + w, x]:= COLOR_INDESTRUCTIBLE;
   684 		for x:= leftX to rightX do
   678             if x mod 32 < 16 then c:= $FF000000
   685 			begin
   679             else c:= $FF00FFFF;
   686 			Land[topY + w, x]:= COLOR_INDESTRUCTIBLE;
   680             LandPixels[topY + w, x]:= c;
   687 			if (x + w) mod 32 < 16 then
   681             end;
   688 				c:= $FF000000
   682         end;
   689 			else
   683      // This is almost certainly not the right place to do this
   690 				c:= $FF00FFFF;
   684      // I just want it to be disabled after a border is added, which could by by map constraints as well as player desire
   691 			LandPixels[topY + w, x]:= c;
   685      t:= 0;
   692 			end;
   686      while (t < cMaxTeams) and (TeamsArray[t] <> nil) do
   693 		end;
   687          begin
       
   688          for i:= 0 to cMaxHHIndex do
       
   689              if TeamsArray[t]^.Hedgehogs[i].Gear <> nil then
       
   690                  begin
       
   691                  for j:= 0 to cMaxSlotAmmoIndex do
       
   692                      begin
       
   693                      TeamsArray[t]^.Hedgehogs[i].Ammo^[Ammoz[amAirAttack].Slot, j].Count:= 0;
       
   694                      TeamsArray[t]^.Hedgehogs[i].Ammo^[Ammoz[amMineStrike].Slot, j].Count:= 0;
       
   695                      TeamsArray[t]^.Hedgehogs[i].Ammo^[Ammoz[amNapalm].Slot, j].Count:= 0;
       
   696                      end;
       
   697                  end;
       
   698          inc(t);
       
   699          end;
       
   700 	end;
   694 	end;
   701 
   695 
   702 if ((GameFlags and gfForts) = 0) and (Pathz[ptMapCurrent] = '') then AddObjects;
   696 if ((GameFlags and gfForts) = 0) and (Pathz[ptMapCurrent] = '') then AddObjects;
   703 
   697 
   704 UpdateLandTexture(0, LAND_HEIGHT);
   698 UpdateLandTexture(0, LAND_HEIGHT);