hedgewars/uLandGraphics.pas
changeset 3509 d72c2219595d
parent 3236 4ab3917d7d44
child 3518 772b37c9c3ba
equal deleted inserted replaced
3507:2e40893e6034 3509:d72c2219595d
    27                                    Left, Right: LongInt;
    27                                    Left, Right: LongInt;
    28                                    end;
    28                                    end;
    29 
    29 
    30 function  SweepDirty: boolean;
    30 function  SweepDirty: boolean;
    31 function  Despeckle(X, Y: LongInt): boolean;
    31 function  Despeckle(X, Y: LongInt): boolean;
    32 function  CheckLandValue(X, Y: LongInt; Color: Word): boolean;
    32 function  CheckLandValue(X, Y: LongInt; LandFlag: Word): boolean;
    33 procedure DrawExplosion(X, Y, Radius: LongInt);
    33 procedure DrawExplosion(X, Y, Radius: LongInt);
    34 procedure DrawHLinesExplosions(ar: PRangeArray; Radius: LongInt; y, dY: LongInt; Count: Byte);
    34 procedure DrawHLinesExplosions(ar: PRangeArray; Radius: LongInt; y, dY: LongInt; Count: Byte);
    35 procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: LongInt);
    35 procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: LongInt);
    36 procedure FillRoundInLand(X, Y, Radius: LongInt; Value: Longword);
    36 procedure FillRoundInLand(X, Y, Radius: LongInt; Value: Longword);
    37 procedure ChangeRoundInLand(X, Y, Radius: LongInt; doSet: boolean);
    37 procedure ChangeRoundInLand(X, Y, Radius: LongInt; doSet: boolean);
    44 procedure FillCircleLines(x, y, dx, dy: LongInt; Value: Longword);
    44 procedure FillCircleLines(x, y, dx, dy: LongInt; Value: Longword);
    45 var i: LongInt;
    45 var i: LongInt;
    46 begin
    46 begin
    47 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
    47 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
    48     for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
    48     for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
    49         if Land[y + dy, i] <> COLOR_INDESTRUCTIBLE then
    49         if (Land[y + dy, i] and LAND_INDESTRUCTIBLE) = 0 then
    50             Land[y + dy, i]:= Value;
    50             Land[y + dy, i]:= Value;
    51 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
    51 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
    52    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
    52    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
    53         if Land[y - dy, i] <> COLOR_INDESTRUCTIBLE then
    53         if (Land[y - dy, i] and LAND_INDESTRUCTIBLE) = 0 then
    54             Land[y - dy, i]:= Value;
    54             Land[y - dy, i]:= Value;
    55 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
    55 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
    56     for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
    56     for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
    57         if Land[y + dx, i] <> COLOR_INDESTRUCTIBLE then
    57         if (Land[y + dx, i] and LAND_INDESTRUCTIBLE) = 0 then
    58             Land[y + dx, i]:= Value;
    58             Land[y + dx, i]:= Value;
    59 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
    59 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
    60     for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
    60     for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
    61         if Land[y - dx, i] <> COLOR_INDESTRUCTIBLE then
    61         if (Land[y - dx, i] and LAND_INDESTRUCTIBLE) = 0 then
    62             Land[y - dx, i]:= Value;
    62             Land[y - dx, i]:= Value;
    63 end;
    63 end;
    64 
    64 
    65 procedure ChangeCircleLines(x, y, dx, dy: LongInt; doSet: boolean);
    65 procedure ChangeCircleLines(x, y, dx, dy: LongInt; doSet: boolean);
    66 var i: LongInt;
    66 var i: LongInt;
   143 procedure FillLandCircleLines0(x, y, dx, dy: LongInt);
   143 procedure FillLandCircleLines0(x, y, dx, dy: LongInt);
   144 var i: LongInt;
   144 var i: LongInt;
   145 begin
   145 begin
   146 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
   146 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
   147     for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   147     for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   148         if (not isMap and (Land[y + dy, i] <> COLOR_INDESTRUCTIBLE)) or (Land[y + dy, i] = COLOR_LAND) then
   148         if (not isMap and ((Land[y + dy, i] and LAND_INDESTRUCTIBLE) = 0)) or ((Land[y + dy, i] and LAND_BASIC) <> 0) then
       
   149 {$IFDEF DOWNSCALE}
       
   150             LandPixels[(y + dy) div 2, i div 2]:= 0;
       
   151 {$ELSE}
   149             LandPixels[y + dy, i]:= 0;
   152             LandPixels[y + dy, i]:= 0;
       
   153 {$ENDIF}
   150 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
   154 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
   151     for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   155     for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   152         if (not isMap and (Land[y - dy, i] <> COLOR_INDESTRUCTIBLE)) or (Land[y - dy, i] = COLOR_LAND) then
   156         if (not isMap and ((Land[y - dy, i] and LAND_INDESTRUCTIBLE) = 0)) or ((Land[y - dy, i] and LAND_BASIC) <> 0) then
       
   157 {$IFDEF DOWNSCALE}
       
   158              LandPixels[(y - dy) div 2, i div 2]:= 0;
       
   159 {$ELSE}
   153              LandPixels[y - dy, i]:= 0;
   160              LandPixels[y - dy, i]:= 0;
       
   161 {$ENDIF}
   154 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
   162 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
   155     for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   163     for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   156         if (not isMap and (Land[y + dx, i] <> COLOR_INDESTRUCTIBLE)) or (Land[y + dx, i] = COLOR_LAND) then
   164         if (not isMap and ((Land[y + dx, i] and LAND_INDESTRUCTIBLE) = 0)) or ((Land[y + dx, i] and LAND_BASIC) <> 0) then
       
   165 {$IFDEF DOWNSCALE}
       
   166             LandPixels[(y + dx) div 2, i div 2]:= 0;
       
   167 {$ELSE}
   157             LandPixels[y + dx, i]:= 0;
   168             LandPixels[y + dx, i]:= 0;
       
   169 {$ENDIF}
   158 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
   170 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
   159     for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   171     for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   160         if (not isMap and (Land[y - dx, i] <> COLOR_INDESTRUCTIBLE)) or (Land[y - dx, i] = COLOR_LAND) then
   172         if (not isMap and ((Land[y - dx, i] and LAND_INDESTRUCTIBLE) = 0)) or ((Land[y - dx, i] and LAND_BASIC) <> 0) then
       
   173 {$IFDEF DOWNSCALE}
       
   174              LandPixels[(y - dx) div 2, i div 2]:= 0;
       
   175 {$ELSE}
   161              LandPixels[y - dx, i]:= 0;
   176              LandPixels[y - dx, i]:= 0;
       
   177 {$ENDIF}
   162 end;
   178 end;
   163 
   179 
   164 procedure FillLandCircleLinesBG(x, y, dx, dy: LongInt);
   180 procedure FillLandCircleLinesBG(x, y, dx, dy: LongInt);
   165 var i: LongInt;
   181 var i: LongInt;
   166 begin
   182 begin
   167 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
   183 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
   168    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   184    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   169        if (Land[y + dy, i] = COLOR_LAND) then
   185        if ((Land[y + dy, i] and LAND_BASIC) <> 0) then
       
   186 {$IFDEF DOWNSCALE}
       
   187           LandPixels[(y + dy) div 2, i div 2]:= LandBackPixel(i, y + dy)
       
   188 {$ELSE}
   170           LandPixels[y + dy, i]:= LandBackPixel(i, y + dy)
   189           LandPixels[y + dy, i]:= LandBackPixel(i, y + dy)
       
   190 {$ENDIF}
   171        else
   191        else
   172           if (Land[y + dy, i] = COLOR_OBJECT) then LandPixels[y + dy, i]:= 0;
   192 {$IFDEF DOWNSCALE}
       
   193           if (Land[y + dy, i] = LAND_OBJECT) then LandPixels[(y + dy) div 2, i div 2]:= 0;
       
   194 {$ELSE}
       
   195           if (Land[y + dy, i] = LAND_OBJECT) then LandPixels[y + dy, i]:= 0;
       
   196 {$ENDIF}
   173 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
   197 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
   174    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   198    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   175        if (Land[y - dy, i] = COLOR_LAND) then
   199        if ((Land[y - dy, i] and LAND_BASIC) <> 0) then
       
   200 {$IFDEF DOWNSCALE}
       
   201           LandPixels[(y - dy) div 2, i div 2]:= LandBackPixel(i, y - dy)
       
   202 {$ELSE}
   176           LandPixels[y - dy, i]:= LandBackPixel(i, y - dy)
   203           LandPixels[y - dy, i]:= LandBackPixel(i, y - dy)
       
   204 {$ENDIF}
   177        else
   205        else
   178           if (Land[y - dy, i] = COLOR_OBJECT) then LandPixels[y - dy, i]:= 0;
   206 {$IFDEF DOWNSCALE}
       
   207           if (Land[y - dy, i] = LAND_OBJECT) then LandPixels[(y - dy) div 2, i div 2]:= 0;
       
   208 {$ELSE}
       
   209           if (Land[y - dy, i] = LAND_OBJECT) then LandPixels[y - dy, i]:= 0;
       
   210 {$ENDIF}
   179 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
   211 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
   180    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   212    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   181        if (Land[y + dx, i] = COLOR_LAND) then
   213        if ((Land[y + dx, i] and LAND_BASIC) <> 0) then
       
   214 {$IFDEF DOWNSCALE}
       
   215            LandPixels[(y + dx) div 2, i div 2]:= LandBackPixel(i, y + dx)
       
   216 {$ELSE}
   182            LandPixels[y + dx, i]:= LandBackPixel(i, y + dx)
   217            LandPixels[y + dx, i]:= LandBackPixel(i, y + dx)
       
   218 {$ENDIF}
   183        else
   219        else
   184           if (Land[y + dx, i] = COLOR_OBJECT) then LandPixels[y + dx, i]:= 0;
   220 {$IFDEF DOWNSCALE}
       
   221           if (Land[y + dx, i] = LAND_OBJECT) then LandPixels[(y + dx) div 2, i div 2]:= 0;
       
   222 {$ELSE}
       
   223           if (Land[y + dx, i] = LAND_OBJECT) then LandPixels[y + dx, i]:= 0;
       
   224 {$ENDIF}
   185 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
   225 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
   186    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   226    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   187        if (Land[y - dx, i] = COLOR_LAND) then
   227        if ((Land[y - dx, i] and LAND_BASIC) <> 0) then
       
   228 {$IFDEF DOWNSCALE}
       
   229           LandPixels[(y - dx) div 2, i div 2]:= LandBackPixel(i, y - dx)
       
   230 {$ELSE}
   188           LandPixels[y - dx, i]:= LandBackPixel(i, y - dx)
   231           LandPixels[y - dx, i]:= LandBackPixel(i, y - dx)
       
   232 {$ENDIF}
   189        else
   233        else
   190           if (Land[y - dx, i] = COLOR_OBJECT) then LandPixels[y - dx, i]:= 0;
   234 {$IFDEF DOWNSCALE}
       
   235           if (Land[y - dx, i] = LAND_OBJECT) then LandPixels[(y - dx) div 2, i div 2]:= 0;
       
   236 {$ELSE}
       
   237           if (Land[y - dx, i] = LAND_OBJECT) then LandPixels[y - dx, i]:= 0;
       
   238 {$ENDIF}
   191 end;
   239 end;
   192 
   240 
   193 procedure FillLandCircleLinesEBC(x, y, dx, dy: LongInt);
   241 procedure FillLandCircleLinesEBC(x, y, dx, dy: LongInt);
   194 var i: LongInt;
   242 var i: LongInt;
   195 begin
   243 begin
   196 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
   244 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
   197    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   245    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   198        if (Land[y + dy, i] = COLOR_LAND) or (Land[y + dy, i] = COLOR_OBJECT) then
   246        if ((Land[y + dy, i] and LAND_BASIC) <> 0) or (Land[y + dy, i] = LAND_OBJECT) then
   199           begin
   247           begin
       
   248 {$IFDEF DOWNSCALE}
       
   249           LandPixels[(y + dy) div 2, i div 2]:= cExplosionBorderColor;
       
   250 {$ELSE}
   200           LandPixels[y + dy, i]:= cExplosionBorderColor;
   251           LandPixels[y + dy, i]:= cExplosionBorderColor;
       
   252 {$ENDIF}
       
   253           Land[y + dy, i]:= Land[y + dy, i] or LAND_DAMAGED;
   201           Despeckle(i, y + dy);
   254           Despeckle(i, y + dy);
   202           LandDirty[(y + dy) div 32, i div 32]:= 1;
   255           LandDirty[(y + dy) div 32, i div 32]:= 1;
   203           end;
   256           end;
   204 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
   257 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
   205    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   258    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
   206        if (Land[y - dy, i] = COLOR_LAND) or (Land[y - dy, i] = COLOR_OBJECT) then
   259        if ((Land[y - dy, i] and LAND_BASIC) <> 0) or (Land[y - dy, i] = LAND_OBJECT) then
   207           begin
   260           begin
       
   261 {$IFDEF DOWNSCALE}
       
   262           LandPixels[(y - dy) div 2, i div 2]:= cExplosionBorderColor;
       
   263 {$ELSE}
   208           LandPixels[y - dy, i]:= cExplosionBorderColor;
   264           LandPixels[y - dy, i]:= cExplosionBorderColor;
       
   265 {$ENDIF}
       
   266           Land[y - dy, i]:= Land[y - dy, i] or LAND_DAMAGED;
   209           Despeckle(i, y - dy);
   267           Despeckle(i, y - dy);
   210           LandDirty[(y - dy) div 32, i div 32]:= 1;
   268           LandDirty[(y - dy) div 32, i div 32]:= 1;
   211           end;
   269           end;
   212 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
   270 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
   213    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   271    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   214        if (Land[y + dx, i] = COLOR_LAND) or (Land[y + dx, i] = COLOR_OBJECT) then
   272        if ((Land[y + dx, i] and LAND_BASIC) <> 0) or (Land[y + dx, i] = LAND_OBJECT) then
   215            begin
   273            begin
       
   274 {$IFDEF DOWNSCALE}
       
   275            LandPixels[(y + dx) div 2, i div 2]:= cExplosionBorderColor;
       
   276 {$ELSE}
   216            LandPixels[y + dx, i]:= cExplosionBorderColor;
   277            LandPixels[y + dx, i]:= cExplosionBorderColor;
       
   278 {$ENDIF}
       
   279            Land[y + dx, i]:= Land[y + dx, i] or LAND_DAMAGED;
   217            Despeckle(i, y + dx);
   280            Despeckle(i, y + dx);
   218            LandDirty[(y + dx) div 32, i div 32]:= 1;
   281            LandDirty[(y + dx) div 32, i div 32]:= 1;
   219            end;
   282            end;
   220 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
   283 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
   221    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   284    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
   222        if (Land[y - dx, i] = COLOR_LAND) or (Land[y - dx, i] = COLOR_OBJECT) then
   285        if ((Land[y - dx, i] and LAND_BASIC) <> 0) or (Land[y - dx, i] = LAND_OBJECT) then
   223           begin
   286           begin
       
   287 {$IFDEF DOWNSCALE}
       
   288           LandPixels[(y - dx) div 2, i div 2]:= cExplosionBorderColor;
       
   289 {$ELSE}
   224           LandPixels[y - dx, i]:= cExplosionBorderColor;
   290           LandPixels[y - dx, i]:= cExplosionBorderColor;
       
   291 {$ENDIF}
       
   292           Land[y - dx, i]:= Land[y - dx, i] or LAND_DAMAGED;
   225           Despeckle(i, y - dy);
   293           Despeckle(i, y - dy);
   226           LandDirty[(y - dx) div 32, i div 32]:= 1;
   294           LandDirty[(y - dx) div 32, i div 32]:= 1;
   227           end;
   295           end;
   228 end;
   296 end;
   229 
   297 
   307 begin
   375 begin
   308 for i:= 0 to Pred(Count) do
   376 for i:= 0 to Pred(Count) do
   309     begin
   377     begin
   310     for ty:= max(y - Radius, 0) to min(y + Radius, LAND_HEIGHT) do
   378     for ty:= max(y - Radius, 0) to min(y + Radius, LAND_HEIGHT) do
   311         for tx:= max(0, ar^[i].Left - Radius) to min(LAND_WIDTH, ar^[i].Right + Radius) do
   379         for tx:= max(0, ar^[i].Left - Radius) to min(LAND_WIDTH, ar^[i].Right + Radius) do
   312             if Land[ty, tx] = COLOR_LAND then
   380             if (Land[ty, tx] and LAND_BASIC) <> 0 then
       
   381 {$IFDEF DOWNSCALE}
       
   382                 LandPixels[ty div 2, tx div 2]:= LandBackPixel(tx, ty)
       
   383 {$ELSE}
   313                 LandPixels[ty, tx]:= LandBackPixel(tx, ty)
   384                 LandPixels[ty, tx]:= LandBackPixel(tx, ty)
   314             else if Land[ty, tx] = COLOR_OBJECT then
   385 {$ENDIF}
       
   386             else if Land[ty, tx] = LAND_OBJECT then
       
   387 {$IFDEF DOWNSCALE}
       
   388                 LandPixels[ty div 2, tx div 2]:= 0;
       
   389 {$ELSE}
   315                 LandPixels[ty, tx]:= 0;
   390                 LandPixels[ty, tx]:= 0;
       
   391 {$ENDIF}
   316     inc(y, dY)
   392     inc(y, dY)
   317     end;
   393     end;
   318 
   394 
   319 inc(Radius, 4);
   395 inc(Radius, 4);
   320 dec(y, Count * dY);
   396 dec(y, Count * dY);
   321 
   397 
   322 for i:= 0 to Pred(Count) do
   398 for i:= 0 to Pred(Count) do
   323     begin
   399     begin
   324     for ty:= max(y - Radius, 0) to min(y + Radius, LAND_HEIGHT) do
   400     for ty:= max(y - Radius, 0) to min(y + Radius, LAND_HEIGHT) do
   325         for tx:= max(0, ar^[i].Left - Radius) to min(LAND_WIDTH, ar^[i].Right + Radius) do
   401         for tx:= max(0, ar^[i].Left - Radius) to min(LAND_WIDTH, ar^[i].Right + Radius) do
   326             if (Land[ty, tx] = COLOR_LAND) or (Land[ty, tx] = COLOR_OBJECT) then
   402             if ((Land[ty, tx] and LAND_BASIC) <> 0) or (Land[ty, tx] = LAND_OBJECT) then
   327                 begin
   403                 begin
       
   404 {$IFDEF DOWNSCALE}
       
   405                 LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor;
       
   406 {$ELSE}
   328                 LandPixels[ty, tx]:= cExplosionBorderColor;
   407                 LandPixels[ty, tx]:= cExplosionBorderColor;
       
   408 {$ENDIF}
       
   409                 Land[ty, tx]:= Land[ty, tx] or LAND_DAMAGED;
   329                 LandDirty[(y + dy) shr 5, i shr 5]:= 1;
   410                 LandDirty[(y + dy) shr 5, i shr 5]:= 1;
   330                 end;
   411                 end;
   331     inc(y, dY)
   412     inc(y, dY)
   332     end;
   413     end;
   333 
   414 
   360     Y:= Y + dY;
   441     Y:= Y + dY;
   361     tx:= hwRound(X);
   442     tx:= hwRound(X);
   362     ty:= hwRound(Y);
   443     ty:= hwRound(Y);
   363     if ((ty and LAND_HEIGHT_MASK) = 0) and
   444     if ((ty and LAND_HEIGHT_MASK) = 0) and
   364        ((tx and LAND_WIDTH_MASK) = 0) and
   445        ((tx and LAND_WIDTH_MASK) = 0) and
   365        ((Land[ty, tx] = COLOR_LAND) or 
   446        (((Land[ty, tx] and LAND_BASIC) <> 0) or 
   366        (Land[ty, tx] = COLOR_OBJECT)) then
   447        (Land[ty, tx] = LAND_OBJECT)) then
       
   448         begin
       
   449         Land[ty, tx]:= Land[ty, tx] or LAND_DAMAGED;
       
   450 {$IFDEF DOWNSCALE}
       
   451         LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor
       
   452 {$ELSE}
   367         LandPixels[ty, tx]:= cExplosionBorderColor
   453         LandPixels[ty, tx]:= cExplosionBorderColor
       
   454 {$ENDIF}
       
   455         end
   368     end;
   456     end;
   369     nx:= nx - dY;
   457     nx:= nx - dY;
   370     ny:= ny + dX;
   458     ny:= ny + dX;
   371     end;
   459     end;
   372 
   460 
   380     Y:= Y + dY;
   468     Y:= Y + dY;
   381     tx:= hwRound(X);
   469     tx:= hwRound(X);
   382     ty:= hwRound(Y);
   470     ty:= hwRound(Y);
   383     if ((ty and LAND_HEIGHT_MASK) = 0) and
   471     if ((ty and LAND_HEIGHT_MASK) = 0) and
   384        ((tx and LAND_WIDTH_MASK) = 0) and
   472        ((tx and LAND_WIDTH_MASK) = 0) and
   385        ((Land[ty, tx] = COLOR_LAND) or 
   473        (((Land[ty, tx] and LAND_BASIC) <> 0) or 
   386        (Land[ty, tx] = COLOR_OBJECT)) then
   474        (Land[ty, tx] = LAND_OBJECT)) then
       
   475         begin
       
   476         Land[ty, tx]:= Land[ty, tx] or LAND_DAMAGED;
       
   477 {$IFDEF DOWNSCALE}
       
   478         LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor
       
   479 {$ELSE}
   387         LandPixels[ty, tx]:= cExplosionBorderColor
   480         LandPixels[ty, tx]:= cExplosionBorderColor
       
   481 {$ENDIF}
       
   482         end
   388     end;
   483     end;
   389     X:= nx;
   484     X:= nx;
   390     Y:= ny;
   485     Y:= ny;
   391     for t:= 0 to ticks do
   486     for t:= 0 to ticks do
   392         begin
   487         begin
   393         X:= X + dX;
   488         X:= X + dX;
   394         Y:= Y + dY;
   489         Y:= Y + dY;
   395         tx:= hwRound(X);
   490         tx:= hwRound(X);
   396         ty:= hwRound(Y);
   491         ty:= hwRound(Y);
   397         if ((ty and LAND_HEIGHT_MASK) = 0) and ((tx and LAND_WIDTH_MASK) = 0) and (Land[ty, tx] <> COLOR_INDESTRUCTIBLE) then
   492         if ((ty and LAND_HEIGHT_MASK) = 0) and ((tx and LAND_WIDTH_MASK) = 0) and ((Land[ty, tx] and LAND_INDESTRUCTIBLE) = 0) then
   398             begin
   493             begin
   399             if Land[ty, tx] = COLOR_LAND then
   494             if (Land[ty, tx] and LAND_BASIC) <> 0 then
       
   495 {$IFDEF DOWNSCALE}
       
   496                 LandPixels[ty div 2, tx div 2]:= LandBackPixel(tx, ty)
       
   497 {$ELSE}
   400                 LandPixels[ty, tx]:= LandBackPixel(tx, ty)
   498                 LandPixels[ty, tx]:= LandBackPixel(tx, ty)
   401             else if Land[ty, tx] = COLOR_OBJECT then
   499 {$ENDIF}
       
   500             else if Land[ty, tx] = LAND_OBJECT then
       
   501 {$IFDEF DOWNSCALE}
       
   502                 LandPixels[ty div 2, tx div 2]:= 0;
       
   503 {$ELSE}
   402                 LandPixels[ty, tx]:= 0;
   504                 LandPixels[ty, tx]:= 0;
       
   505 {$ENDIF}
   403             Land[ty, tx]:= 0;
   506             Land[ty, tx]:= 0;
   404             end
   507             end
   405         end;
   508         end;
   406     for t:= 0 to 7 do
   509     for t:= 0 to 7 do
   407     begin
   510     begin
   409     Y:= Y + dY;
   512     Y:= Y + dY;
   410     tx:= hwRound(X);
   513     tx:= hwRound(X);
   411     ty:= hwRound(Y);
   514     ty:= hwRound(Y);
   412     if ((ty and LAND_HEIGHT_MASK) = 0) and
   515     if ((ty and LAND_HEIGHT_MASK) = 0) and
   413        ((tx and LAND_WIDTH_MASK) = 0) and
   516        ((tx and LAND_WIDTH_MASK) = 0) and
   414        ((Land[ty, tx] = COLOR_LAND) or 
   517        (((Land[ty, tx] and LAND_BASIC) <> 0) or 
   415        (Land[ty, tx] = COLOR_OBJECT)) then
   518        (Land[ty, tx] = LAND_OBJECT)) then
       
   519         begin
       
   520         Land[ty, tx]:= Land[ty, tx] or LAND_DAMAGED;
       
   521 {$IFDEF DOWNSCALE}
       
   522         LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor
       
   523 {$ELSE}
   416         LandPixels[ty, tx]:= cExplosionBorderColor
   524         LandPixels[ty, tx]:= cExplosionBorderColor
       
   525 {$ENDIF}
       
   526         end
   417     end;
   527     end;
   418     nx:= nx - dY;
   528     nx:= nx - dY;
   419     ny:= ny + dX;
   529     ny:= ny + dX;
   420     end;
   530     end;
   421 
   531 
   429     Y:= Y + dY;
   539     Y:= Y + dY;
   430     tx:= hwRound(X);
   540     tx:= hwRound(X);
   431     ty:= hwRound(Y);
   541     ty:= hwRound(Y);
   432     if ((ty and LAND_HEIGHT_MASK) = 0) and
   542     if ((ty and LAND_HEIGHT_MASK) = 0) and
   433        ((tx and LAND_WIDTH_MASK) = 0) and
   543        ((tx and LAND_WIDTH_MASK) = 0) and
   434        ((Land[ty, tx] = COLOR_LAND) or 
   544        (((Land[ty, tx] and LAND_BASIC) <> 0) or 
   435        (Land[ty, tx] = COLOR_OBJECT)) then
   545        (Land[ty, tx] = LAND_OBJECT)) then
       
   546         begin
       
   547         Land[ty, tx]:= Land[ty, tx] or LAND_DAMAGED;
       
   548 {$IFDEF DOWNSCALE}
       
   549         LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor
       
   550 {$ELSE}
   436         LandPixels[ty, tx]:= cExplosionBorderColor
   551         LandPixels[ty, tx]:= cExplosionBorderColor
       
   552 {$ENDIF}
       
   553         end
   437     end;
   554     end;
   438     nx:= nx - dY;
   555     nx:= nx - dY;
   439     ny:= ny + dX;
   556     ny:= ny + dX;
   440     end;
   557     end;
   441 
   558 
   501      4: for y:= 0 to Pred(h) do
   618      4: for y:= 0 to Pred(h) do
   502             begin
   619             begin
   503             for x:= 0 to Pred(w) do
   620             for x:= 0 to Pred(w) do
   504                 if PLongword(@(p^[x * 4]))^ <> 0 then
   621                 if PLongword(@(p^[x * 4]))^ <> 0 then
   505                    begin
   622                    begin
   506                    Land[cpY + y, cpX + x]:= COLOR_OBJECT;
   623                    Land[cpY + y, cpX + x]:= LAND_OBJECT;
       
   624 {$IFDEF DOWNSCALE}
       
   625                    LandPixels[(cpY + y) div 2, (cpX + x) div 2]:= PLongword(@(p^[x * 4]))^
       
   626 {$ELSE}
   507                    LandPixels[cpY + y, cpX + x]:= PLongword(@(p^[x * 4]))^
   627                    LandPixels[cpY + y, cpX + x]:= PLongword(@(p^[x * 4]))^
       
   628 {$ENDIF}
   508                    end;
   629                    end;
   509             p:= @(p^[Image^.pitch]);
   630             p:= @(p^[Image^.pitch]);
   510             end;
   631             end;
   511      end;
   632      end;
   512 if SDL_MustLock(Image) then
   633 if SDL_MustLock(Image) then
   521 
   642 
   522 // was experimenting with applying as damage occurred.
   643 // was experimenting with applying as damage occurred.
   523 function Despeckle(X, Y: LongInt): boolean;
   644 function Despeckle(X, Y: LongInt): boolean;
   524 var nx, ny, i, j, c: LongInt;
   645 var nx, ny, i, j, c: LongInt;
   525 begin
   646 begin
   526 if (Land[Y, X] > 255) and (Land[Y, X] <> COLOR_INDESTRUCTIBLE) and (LandPixels[Y, X] = cExplosionBorderColor)then // check neighbours
   647 if (Land[Y, X] > 255) and ((Land[Y, X] and LAND_INDESTRUCTIBLE) = 0) and ((Land[Y, X] and LAND_DAMAGED) <> 0)then // check neighbours
   527     begin
   648     begin
   528     c:= 0;
   649     c:= 0;
   529     for i:= -1 to 1 do
   650     for i:= -1 to 1 do
   530         for j:= -1 to 1 do
   651         for j:= -1 to 1 do
   531             if (i <> 0) or (j <> 0) then
   652             if (i <> 0) or (j <> 0) then
   537                         inc(c);
   658                         inc(c);
   538                 end;
   659                 end;
   539 
   660 
   540     if c < 4 then // 0-3 neighbours
   661     if c < 4 then // 0-3 neighbours
   541         begin
   662         begin
   542         if Land[Y, X] = COLOR_LAND then LandPixels[Y, X]:= LandBackPixel(X, Y) else LandPixels[Y, X]:= 0;
   663 {$IFDEF DOWNSCALE}
       
   664         if (Land[Y, X] and LAND_BASIC) <> 0 then LandPixels[Y div 2, X div 2]:= LandBackPixel(X, Y) else LandPixels[Y div 2, X div 2]:= 0;
       
   665 {$ELSE}
       
   666         if (Land[Y, X] and LAND_BASIC) <> 0 then LandPixels[Y, X]:= LandBackPixel(X, Y) else LandPixels[Y, X]:= 0;
       
   667 {$ENDIF}
   543         Land[Y, X]:= 0;
   668         Land[Y, X]:= 0;
   544         exit(true);
   669         exit(true);
   545         end;
   670         end;
   546     end;
   671     end;
   547 Despeckle:= false
   672 Despeckle:= false
   582 
   707 
   583 SweepDirty:= bRes;
   708 SweepDirty:= bRes;
   584 end;
   709 end;
   585 
   710 
   586 // Return true if outside of land or not the value tested, used right now for some X/Y movement that does not use normal hedgehog movement in GSHandlers.inc
   711 // Return true if outside of land or not the value tested, used right now for some X/Y movement that does not use normal hedgehog movement in GSHandlers.inc
   587 function CheckLandValue(X, Y: LongInt; Color: Word): boolean;
   712 function CheckLandValue(X, Y: LongInt; LandFlag: Word): boolean;
   588 begin
   713 begin
   589      CheckLandValue:= ((X and LAND_WIDTH_MASK <> 0) or (Y and LAND_HEIGHT_MASK <> 0)) or (Land[Y, X] <> Color)
   714      CheckLandValue:= ((X and LAND_WIDTH_MASK <> 0) or (Y and LAND_HEIGHT_MASK <> 0)) or ((Land[Y, X] and LandFlag) = 0)
   590 end;
   715 end;
   591 end.
   716 end.