hedgewars/uLand.pas
changeset 754 94ac14829085
parent 753 40fc0deb388f
child 755 edf26e9554ac
equal deleted inserted replaced
753:40fc0deb388f 754:94ac14829085
   512 WriteLnToConsole('Generating land...');
   512 WriteLnToConsole('Generating land...');
   513 
   513 
   514 GenBlank(EdgeTemplates[SelectTemplate]);
   514 GenBlank(EdgeTemplates[SelectTemplate]);
   515 
   515 
   516 AddProgress;
   516 AddProgress;
   517 with PixelFormat^ do
   517 
   518      tmpsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 2048, 1024, 32, $FF, $FF00, $FF0000, 0);
   518 tmpsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 2048, 1024, 32, RMask, GMask, BMask, AMask);
       
   519 
   519 TryDo(tmpsurf <> nil, 'Error creating pre-land surface', true);
   520 TryDo(tmpsurf <> nil, 'Error creating pre-land surface', true);
   520 ColorizeLand(tmpsurf);
   521 ColorizeLand(tmpsurf);
   521 AddProgress;
   522 AddProgress;
   522 AddBorder(tmpsurf);
   523 AddBorder(tmpsurf);
   523 with PixelFormat^ do
   524 
   524      LandSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, 2048, 1024, 32, $FF, $FF00, $FF0000, 0);
   525 LandSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, 2048, 1024, 32, RMask, GMask, BMask, AMask);
       
   526 
   525 TryDo(LandSurface <> nil, 'Error creating land surface', true);
   527 TryDo(LandSurface <> nil, 'Error creating land surface', true);
   526 SDL_FillRect(LandSurface, nil, 0);
   528 SDL_FillRect(LandSurface, nil, 0);
   527 AddProgress;
   529 AddProgress;
   528 
   530 
   529 SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0);
   531 SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0);
   538 var tmpsurf: PSDL_Surface;
   540 var tmpsurf: PSDL_Surface;
   539 begin
   541 begin
   540 WriteLnToConsole('Generating forts land...');
   542 WriteLnToConsole('Generating forts land...');
   541 TryDo(TeamsCount = 2, 'More or less than 2 teams on map in forts mode!', true);
   543 TryDo(TeamsCount = 2, 'More or less than 2 teams on map in forts mode!', true);
   542 
   544 
   543 with PixelFormat^ do
   545 LandSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, 32, RMask, GMask, BMask, AMask);
   544      LandSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, 32, RMask, GMask, BMask, AMask);
   546 
   545 SDL_FillRect(LandSurface, nil, 0);
   547 SDL_FillRect(LandSurface, nil, 0);
   546 
   548 
   547 tmpsurf:= LoadImage(Pathz[ptForts] + '/' + TeamsArray[0]^.FortName + 'L', false, true, true);
   549 tmpsurf:= LoadImage(Pathz[ptForts] + '/' + TeamsArray[0]^.FortName + 'L', false, true, true);
   548 BlitImageAndGenerateCollisionInfo(0, 0, tmpsurf, LandSurface);
   550 BlitImageAndGenerateCollisionInfo(0, 0, tmpsurf, LandSurface);
   549 SDL_FreeSurface(tmpsurf);
   551 SDL_FreeSurface(tmpsurf);
   550 
   552 
   551 tmpsurf:= LoadImage(Pathz[ptForts] + '/' + TeamsArray[1]^.FortName + 'R', false, true, true);
   553 tmpsurf:= LoadImage(Pathz[ptForts] + '/' + TeamsArray[1]^.FortName + 'R', false, true, true);
   552 BlitImageAndGenerateCollisionInfo(1024, 0, tmpsurf, LandSurface);
   554 BlitImageAndGenerateCollisionInfo(1024, 0, tmpsurf, LandSurface);
   553 SDL_FreeSurface(tmpsurf);
   555 SDL_FreeSurface(tmpsurf);
       
   556 
       
   557 LandTexture:= Surface2Tex(LandSurface)
   554 end;
   558 end;
   555 
   559 
   556 procedure LoadMap;
   560 procedure LoadMap;
   557 var x, y: Longword;
   561 var x, y: Longword;
   558     p: PByteArray;
   562     p: PByteArray;
   566    SDLTry(SDL_LockSurface(LandSurface) >= 0, true);
   570    SDLTry(SDL_LockSurface(LandSurface) >= 0, true);
   567 
   571 
   568 p:= LandSurface^.pixels;
   572 p:= LandSurface^.pixels;
   569 case LandSurface^.format^.BytesPerPixel of
   573 case LandSurface^.format^.BytesPerPixel of
   570      1: OutError('We don''t work with 8 bit surfaces', true);
   574      1: OutError('We don''t work with 8 bit surfaces', true);
   571      2: for y:= 0 to 1023 do
   575      2: OutError('We don''t work with 16 bit surfaces', true);
   572             begin
       
   573             for x:= 0 to 2047 do
       
   574                 if PWord(@(p^[x * 2]))^ <> 0 then Land[y, x]:= COLOR_LAND;
       
   575             p:= @(p^[LandSurface^.pitch]);
       
   576             end;
       
   577      3: for y:= 0 to 1023 do
   576      3: for y:= 0 to 1023 do
   578             begin
   577             begin
   579             for x:= 0 to 2047 do
   578             for x:= 0 to 2047 do
   580                 if  (p^[x * 3 + 0] <> 0)
   579                 if  (p^[x * 3 + 0] <> 0)
   581                  or (p^[x * 3 + 1] <> 0)
   580                  or (p^[x * 3 + 1] <> 0)
   590             end;
   589             end;
   591      end;
   590      end;
   592 
   591 
   593 if SDL_MustLock(LandSurface) then
   592 if SDL_MustLock(LandSurface) then
   594    SDL_UnlockSurface(LandSurface);
   593    SDL_UnlockSurface(LandSurface);
       
   594 
       
   595 LandTexture:= Surface2Tex(LandSurface)
   595 end;
   596 end;
   596 
   597 
   597 procedure GenMap;
   598 procedure GenMap;
   598 begin
   599 begin
   599 if (GameFlags and gfForts) = 0 then
   600 if (GameFlags and gfForts) = 0 then