hedgewars/uLand.pas
changeset 3509 d72c2219595d
parent 3463 23c50be687a9
child 3513 f589230fa21b
equal deleted inserted replaced
3507:2e40893e6034 3509:d72c2219595d
    20 
    20 
    21 unit uLand;
    21 unit uLand;
    22 interface
    22 interface
    23 uses SDLh, uLandTemplates, uFloat, uConsts, GLunit;
    23 uses SDLh, uLandTemplates, uFloat, uConsts, GLunit;
    24 
    24 
    25 type TLandArray = packed array[0 .. LAND_HEIGHT - 1, 0 .. LAND_WIDTH - 1] of LongWord;
    25 type
       
    26 {$IFDEF DOWNSCALE}
       
    27     TLandArray = packed array[0 .. LAND_HEIGHT div 2 - 1, 0 .. LAND_WIDTH div 2 - 1] of LongWord;
       
    28 {$ELSE}
       
    29     TLandArray = packed array[0 .. LAND_HEIGHT - 1, 0 .. LAND_WIDTH - 1] of LongWord;
       
    30 {$ENDIF}
       
    31  
    26     TCollisionArray = packed array[0 .. LAND_HEIGHT - 1, 0 .. LAND_WIDTH - 1] of Word;
    32     TCollisionArray = packed array[0 .. LAND_HEIGHT - 1, 0 .. LAND_WIDTH - 1] of Word;
    27     TPreview  = packed array[0..127, 0..31] of byte;
    33     TPreview  = packed array[0..127, 0..31] of byte;
    28     TDirtyTag = packed array[0 .. LAND_HEIGHT div 32 - 1, 0 .. LAND_WIDTH div 32 - 1] of byte;
    34     TDirtyTag = packed array[0 .. LAND_HEIGHT div 32 - 1, 0 .. LAND_WIDTH div 32 - 1] of byte;
    29 
    35 
    30 var Land: TCollisionArray;
    36 var Land: TCollisionArray;
   553     i: Longword;
   559     i: Longword;
   554     y, x: Longword;
   560     y, x: Longword;
   555 begin
   561 begin
   556 for y:= 0 to LAND_HEIGHT - 1 do
   562 for y:= 0 to LAND_HEIGHT - 1 do
   557     for x:= 0 to LAND_WIDTH - 1 do
   563     for x:= 0 to LAND_WIDTH - 1 do
   558         Land[y, x]:= COLOR_LAND;
   564         Land[y, x]:= LAND_BASIC;
   559 
   565 
   560 {$HINTS OFF}
   566 {$HINTS OFF}
   561 SetPoints(Template, pa);
   567 SetPoints(Template, pa);
   562 {$HINTS ON}
   568 {$HINTS ON}
   563 for i:= 1 to Template.BezierizeCount do
   569 for i:= 1 to Template.BezierizeCount do
   574 with Template do
   580 with Template do
   575      for i:= 0 to pred(FillPointsCount) do
   581      for i:= 0 to pred(FillPointsCount) do
   576          with FillPoints^[i] do
   582          with FillPoints^[i] do
   577               FillLand(x, y);
   583               FillLand(x, y);
   578 
   584 
   579 DrawEdge(pa, COLOR_LAND);
   585 DrawEdge(pa, LAND_BASIC);
   580 
   586 
   581 MaxHedgehogs:= Template.MaxHedgehogs;
   587 MaxHedgehogs:= Template.MaxHedgehogs;
   582 hasGirders:= Template.hasGirders;
   588 hasGirders:= Template.hasGirders;
   583 playHeight:= Template.TemplateHeight;
   589 playHeight:= Template.TemplateHeight;
   584 playWidth:= Template.TemplateWidth;
   590 playWidth:= Template.TemplateWidth;
   597             if (y < topY) or (x < leftX) or (x > rightX) then
   603             if (y < topY) or (x < leftX) or (x > rightX) then
   598                 Land[y, x]:= 0
   604                 Land[y, x]:= 0
   599             else
   605             else
   600             begin
   606             begin
   601                if Land[y, x] = 0 then
   607                if Land[y, x] = 0 then
   602                    Land[y, x]:= COLOR_LAND
   608                    Land[y, x]:= LAND_BASIC
   603                else if Land[y, x] = COLOR_LAND then
   609                else if Land[y, x] = LAND_BASIC then
   604                    Land[y, x]:= 0;
   610                    Land[y, x]:= 0;
   605             end;
   611             end;
   606     end;
   612     end;
   607 end;
   613 end;
   608 
   614 
   642 
   648 
   643 p:= Surface^.pixels;
   649 p:= Surface^.pixels;
   644 for y:= 0 to LAND_HEIGHT - 1 do
   650 for y:= 0 to LAND_HEIGHT - 1 do
   645     begin
   651     begin
   646     for x:= 0 to LAND_WIDTH - 1 do
   652     for x:= 0 to LAND_WIDTH - 1 do
       
   653 {$IFDEF DOWNSCALE}
       
   654         if Land[y, x] <> 0 then LandPixels[y div 2, x div 2]:= p^[x] or AMask;
       
   655 {$ELSE}
   647         if Land[y, x] <> 0 then LandPixels[y, x]:= p^[x] or AMask;
   656         if Land[y, x] <> 0 then LandPixels[y, x]:= p^[x] or AMask;
       
   657 {$ENDIF}
   648 
   658 
   649     p:= @(p^[Surface^.pitch div 4]);
   659     p:= @(p^[Surface^.pitch div 4]);
   650     end;
   660     end;
   651 
   661 
   652 if SDL_MustLock(Surface) then
   662 if SDL_MustLock(Surface) then
   966     for y := 0 to off_y - 1 do
   976     for y := 0 to off_y - 1 do
   967         Land[y, x] := 0;
   977         Land[y, x] := 0;
   968 
   978 
   969 for x := 0 to playWidth do
   979 for x := 0 to playWidth do
   970     for y := off_y to LAND_HEIGHT - 1 do
   980     for y := off_y to LAND_HEIGHT - 1 do
   971         Land[y, x] := COLOR_LAND;
   981         Land[y, x] := LAND_BASIC;
   972 
   982 
   973 for y := 0 to num_cells_y - 1 do
   983 for y := 0 to num_cells_y - 1 do
   974     for x := 0 to num_cells_x - 1 do
   984     for x := 0 to num_cells_x - 1 do
   975         maze[x, y] := false;
   985         maze[x, y] := false;
   976 
   986 
  1067 if maze_inverted then
  1077 if maze_inverted then
  1068     FillLand(1, 1+off_y)
  1078     FillLand(1, 1+off_y)
  1069 else
  1079 else
  1070 begin
  1080 begin
  1071     x := 0;
  1081     x := 0;
  1072     while Land[cellsize div 2 + cellsize + off_y, x] = COLOR_LAND do
  1082     while Land[cellsize div 2 + cellsize + off_y, x] = LAND_BASIC do
  1073         x := x + 1;
  1083         x := x + 1;
  1074     while Land[cellsize div 2 + cellsize + off_y, x] = 0 do
  1084     while Land[cellsize div 2 + cellsize + off_y, x] = 0 do
  1075         x := x + 1;
  1085         x := x + 1;
  1076     FillLand(x+1, cellsize div 2 + cellsize + off_y);
  1086     FillLand(x+1, cellsize div 2 + cellsize + off_y);
  1077 end;
  1087 end;
  1153                 for x:= 0 to Pred(tmpsurf^.w) do
  1163                 for x:= 0 to Pred(tmpsurf^.w) do
  1154                 begin
  1164                 begin
  1155                     if ((AMask and p^[x]) = 0) then  // Tiy was having trouble generating transparent black
  1165                     if ((AMask and p^[x]) = 0) then  // Tiy was having trouble generating transparent black
  1156                         Land[cpY + y, cpX + x]:= 0
  1166                         Land[cpY + y, cpX + x]:= 0
  1157                     else if p^[x] = (AMask or RMask) then
  1167                     else if p^[x] = (AMask or RMask) then
  1158                         Land[cpY + y, cpX + x]:= COLOR_INDESTRUCTIBLE
  1168                         Land[cpY + y, cpX + x]:= LAND_INDESTRUCTIBLE
  1159                     else if p^[x] = $FFFFFFFF then
  1169                     else if p^[x] = $FFFFFFFF then
  1160                         Land[cpY + y, cpX + x]:= COLOR_LAND;
  1170                         Land[cpY + y, cpX + x]:= LAND_BASIC;
  1161                 end;
  1171                 end;
  1162                 p:= @(p^[tmpsurf^.pitch div 4]);
  1172                 p:= @(p^[tmpsurf^.pitch div 4]);
  1163             end;
  1173             end;
  1164 
  1174 
  1165         if SDL_MustLock(tmpsurf) then
  1175         if SDL_MustLock(tmpsurf) then
  1248 if hasBorder then
  1258 if hasBorder then
  1249     begin
  1259     begin
  1250     for y:= 0 to LAND_HEIGHT - 1 do
  1260     for y:= 0 to LAND_HEIGHT - 1 do
  1251         for x:= 0 to LAND_WIDTH - 1 do
  1261         for x:= 0 to LAND_WIDTH - 1 do
  1252             if (y < topY) or (x < leftX) or (x > rightX) then
  1262             if (y < topY) or (x < leftX) or (x > rightX) then
  1253                 Land[y, x]:= COLOR_INDESTRUCTIBLE;
  1263                 Land[y, x]:= LAND_INDESTRUCTIBLE;
  1254     // experiment hardcoding cave
  1264     // experiment hardcoding cave
  1255     // also try basing cave dimensions on map/template dimensions, if they exist
  1265     // also try basing cave dimensions on map/template dimensions, if they exist
  1256     for w:= 0 to 5 do // width of 3 allowed hogs to be knocked through with grenade
  1266     for w:= 0 to 5 do // width of 3 allowed hogs to be knocked through with grenade
  1257         begin
  1267         begin
  1258         for y:= topY to LAND_HEIGHT - 1 do
  1268         for y:= topY to LAND_HEIGHT - 1 do
  1259             begin
  1269             begin
  1260             Land[y, leftX + w]:= COLOR_INDESTRUCTIBLE;
  1270             Land[y, leftX + w]:= LAND_INDESTRUCTIBLE;
  1261             Land[y, rightX - w]:= COLOR_INDESTRUCTIBLE;
  1271             Land[y, rightX - w]:= LAND_INDESTRUCTIBLE;
  1262             if (y + w) mod 32 < 16 then
  1272             if (y + w) mod 32 < 16 then
  1263                 c:= AMask
  1273                 c:= AMask
  1264             else
  1274             else
  1265                 c:= AMask or RMask or GMask; // FF00FFFF
  1275                 c:= AMask or RMask or GMask; // FF00FFFF
       
  1276 {$IFDEF DOWNSCALE}
       
  1277             LandPixels[y div 2, (leftX + w) div 2]:= c;
       
  1278             LandPixels[y div 2, (rightX - w) div 2]:= c;
       
  1279 {$ELSE}
  1266             LandPixels[y, leftX + w]:= c;
  1280             LandPixels[y, leftX + w]:= c;
  1267             LandPixels[y, rightX - w]:= c;
  1281             LandPixels[y, rightX - w]:= c;
       
  1282 {$ENDIF}
  1268             end;
  1283             end;
  1269 
  1284 
  1270         for x:= leftX to rightX do
  1285         for x:= leftX to rightX do
  1271             begin
  1286             begin
  1272             Land[topY + w, x]:= COLOR_INDESTRUCTIBLE;
  1287             Land[topY + w, x]:= LAND_INDESTRUCTIBLE;
  1273             if (x + w) mod 32 < 16 then
  1288             if (x + w) mod 32 < 16 then
  1274                 c:= AMask
  1289                 c:= AMask
  1275             else
  1290             else
  1276                 c:= AMask or RMask or GMask; // FF00FFFF
  1291                 c:= AMask or RMask or GMask; // FF00FFFF
       
  1292 {$IFDEF DOWNSCALE}
       
  1293             LandPixels[(topY + w) div 2, x div 2]:= c;
       
  1294 {$ELSE}
  1277             LandPixels[topY + w, x]:= c;
  1295             LandPixels[topY + w, x]:= c;
       
  1296 {$ENDIF}
  1278             end;
  1297             end;
  1279         end;
  1298         end;
  1280     end;
  1299     end;
  1281 
  1300 
  1282 if (GameFlags and gfDisableGirders) <> 0 then hasGirders:= false;
  1301 if (GameFlags and gfDisableGirders) <> 0 then hasGirders:= false;