37
39
procedure ChangeRoundInLand(X, Y, Radius: LongInt; doSet: boolean);
38
40
function LandBackPixel(x, y: LongInt): LongWord;
40
function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace: boolean): boolean;
42
function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace: boolean; indestructible: boolean): boolean;
43
45
uses SDLh, uLandTexture, uVariables, uUtils, uDebug;
47
function addBgColor(OldColor, NewColor: LongWord): LongWord;
48
// Factor ranges from 0 to 100% NewColor
50
oRed, oBlue, oGreen, oAlpha, nRed, nBlue, nGreen, nAlpha: LongWord;
52
oAlpha := (OldColor shr AShift) and $FF;
53
nAlpha := (NewColor shr AShift) and $FF;
55
if (oAlpha = 0) or (nAlpha = $FF) then
57
addBgColor:= NewColor;
61
oRed := (OldColor shr RShift) and $FF;
62
oGreen := (OldColor shr GShift) and $FF;
63
oBlue := (OldColor shr BShift) and $FF;
65
nRed := (NewColor shr RShift) and $FF;
66
nGreen := (NewColor shr GShift) and $FF;
67
nBlue := (NewColor shr BShift) and $FF;
70
nRed := min(255,((nRed*nAlpha) div 255) + ((oRed*oAlpha*(255-nAlpha)) div 65025));
71
nGreen := min(255,((nGreen*nAlpha) div 255) + ((oGreen*oAlpha*(255-nAlpha)) div 65025));
72
nBlue := min(255,((nBlue*nAlpha) div 255) + ((oBlue*oAlpha*(255-nAlpha)) div 65025));
73
nAlpha := min(255, oAlpha + nAlpha);
75
addBgColor := (nAlpha shl AShift) or (nRed shl RShift) or (nGreen shl GShift) or (nBlue shl BShift);
45
78
procedure FillCircleLines(x, y, dx, dy: LongInt; Value: Longword);
185
218
function FillLandCircleLinesBG(x, y, dx, dy: LongInt): Longword;
219
var i, t, by, bx: LongInt;
191
224
if (t and LAND_HEIGHT_MASK) = 0 then
192
225
for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
193
if ((Land[t, i] and lfBasic) <> 0) and not disableLandBack then
227
if (cReducedQuality and rqBlurryLand) = 0 then
233
by:= t div 2; bx:= i div 2;
235
if ((Land[t, i] and lfBasic) <> 0) and ((LandPixels[by,bx] and AMask) shr AShift = 255) and not disableLandBack then
196
if (cReducedQuality and rqBlurryLand) = 0 then
197
LandPixels[t, i]:= LandBackPixel(i, t)
199
LandPixels[t div 2, i div 2]:= LandBackPixel(i, t)
238
LandPixels[by, bx]:= LandBackPixel(i, t)
202
if ((Land[t, i] and lfObject) <> 0) or (disableLandBack and ((Land[t, i] and lfIndestructible) = 0)) then
203
if (cReducedQuality and rqBlurryLand) = 0 then
206
LandPixels[t div 2, i div 2]:= 0;
241
if ((Land[t, i] and lfObject) <> 0) or (disableLandBack and ((Land[t, i] and lfIndestructible) = 0)) or ((LandPixels[by,bx] and AMask) shr AShift < 255) then
242
LandPixels[by, bx]:= 0
209
246
if (t and LAND_HEIGHT_MASK) = 0 then
210
247
for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
211
if ((Land[t, i] and lfBasic) <> 0) and not disableLandBack then
249
if (cReducedQuality and rqBlurryLand) = 0 then
255
by:= t div 2; bx:= i div 2;
257
if ((Land[t, i] and lfBasic) <> 0) and ((LandPixels[by,bx] and AMask) shr AShift = 255) and not disableLandBack then
214
if (cReducedQuality and rqBlurryLand) = 0 then
215
LandPixels[t, i]:= LandBackPixel(i, t)
217
LandPixels[t div 2, i div 2]:= LandBackPixel(i, t)
260
LandPixels[by, bx]:= LandBackPixel(i, t)
220
if ((Land[t, i] and lfObject) <> 0) or (disableLandBack and ((Land[t, i] and lfIndestructible) = 0)) then
221
if (cReducedQuality and rqBlurryLand) = 0 then
224
LandPixels[t div 2, i div 2]:= 0;
262
else if ((Land[t, i] and lfObject) <> 0) or (disableLandBack and ((Land[t, i] and lfIndestructible) = 0)) or ((LandPixels[by,bx] and AMask) shr AShift < 255) then
263
LandPixels[by, bx]:= 0
227
267
if (t and LAND_HEIGHT_MASK) = 0 then
228
268
for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
229
if ((Land[t, i] and lfBasic) <> 0) and not disableLandBack then
270
if (cReducedQuality and rqBlurryLand) = 0 then
276
by:= t div 2; bx:= i div 2;
278
if ((Land[t, i] and lfBasic) <> 0) and ((LandPixels[by,bx] and AMask) shr AShift = 255) and not disableLandBack then
232
if (cReducedQuality and rqBlurryLand) = 0 then
233
LandPixels[t, i]:= LandBackPixel(i, t)
235
LandPixels[t div 2, i div 2]:= LandBackPixel(i, t)
281
LandPixels[by, bx]:= LandBackPixel(i, t)
238
if ((Land[t, i] and lfObject) <> 0) or (disableLandBack and ((Land[t, i] and lfIndestructible) = 0)) then
239
if (cReducedQuality and rqBlurryLand) = 0 then
242
LandPixels[t div 2, i div 2]:= 0;
283
else if ((Land[t, i] and lfObject) <> 0) or (disableLandBack and ((Land[t, i] and lfIndestructible) = 0)) or ((LandPixels[by,bx] and AMask) shr AShift < 255) then
284
LandPixels[by, bx]:= 0
245
287
if (t and LAND_HEIGHT_MASK) = 0 then
246
288
for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
247
if ((Land[t, i] and lfBasic) <> 0) and not disableLandBack then
290
if (cReducedQuality and rqBlurryLand) = 0 then
296
by:= t div 2; bx:= i div 2;
298
if ((Land[t, i] and lfBasic) <> 0) and ((LandPixels[by,bx] and AMask) shr AShift = 255) and not disableLandBack then
250
if (cReducedQuality and rqBlurryLand) = 0 then
251
LandPixels[t, i]:= LandBackPixel(i, t)
253
LandPixels[t div 2, i div 2]:= LandBackPixel(i, t)
301
LandPixels[by, bx]:= LandBackPixel(i, t)
256
if ((Land[t, i] and lfObject) <> 0) or (disableLandBack and ((Land[t, i] and lfIndestructible) = 0)) then
257
if (cReducedQuality and rqBlurryLand) = 0 then
260
LandPixels[t div 2, i div 2]:= 0;
303
else if ((Land[t, i] and lfObject) <> 0) or (disableLandBack and ((Land[t, i] and lfIndestructible) = 0)) or ((LandPixels[by,bx] and AMask) shr AShift < 255) then
304
LandPixels[by, bx]:= 0
261
306
FillLandCircleLinesBG:= cnt;
405
450
procedure DrawHLinesExplosions(ar: PRangeArray; Radius: LongInt; y, dY: LongInt; Count: Byte);
406
var tx, ty, i: LongInt;
451
var tx, ty, by, bx, i: LongInt;
408
453
for i:= 0 to Pred(Count) do
410
455
for ty:= Max(y - Radius, 0) to Min(y + Radius, LAND_HEIGHT) do
411
456
for tx:= Max(0, ar^[i].Left - Radius) to Min(LAND_WIDTH, ar^[i].Right + Radius) do
412
if ((Land[ty, tx] and lfBasic) <> 0) and not disableLandBack then
413
if (cReducedQuality and rqBlurryLand) = 0 then
414
LandPixels[ty, tx]:= LandBackPixel(tx, ty)
416
LandPixels[ty div 2, tx div 2]:= LandBackPixel(tx, ty)
458
if (cReducedQuality and rqBlurryLand) = 0 then
418
if ((Land[ty, tx] and lfObject) <> 0) or (disableLandBack and ((Land[ty, tx] and lfIndestructible) = 0)) then
419
if (cReducedQuality and rqBlurryLand) = 0 then
420
LandPixels[ty, tx]:= 0
422
LandPixels[ty div 2, tx div 2]:= 0;
464
by:= ty div 2; bx:= tx div 2;
466
if ((Land[ty, tx] and lfBasic) <> 0) and ((LandPixels[by,bx] and AMask) shr AShift = 255) and not disableLandBack then
467
LandPixels[by, bx]:= LandBackPixel(tx, ty)
468
else if ((Land[ty, tx] and lfObject) <> 0) or (disableLandBack and ((Land[ty, tx] and lfIndestructible) = 0)) or ((LandPixels[by,bx] and AMask) shr AShift < 255) then
469
LandPixels[by, bx]:= 0
453
501
procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: LongInt);
454
502
var nx, ny, dX8, dY8: hwFloat;
455
i, t, tx, ty, stX, stY, ddy, ddx: Longint;
503
i, t, tx, ty, by, bx, stX, stY, ddy, ddx: Longint;
456
505
begin // (-dY, dX) is (dX, dY) rotated by PI/2
457
506
stY:= hwRound(Y);
458
507
stX:= hwRound(X);
509
despeckle:= HalfWidth > 1;
460
511
nx:= X + dY * (HalfWidth + 8);
461
512
ny:= Y - dX * (HalfWidth + 8);
522
575
if ((ty and LAND_HEIGHT_MASK) = 0) and ((tx and LAND_WIDTH_MASK) = 0) and ((Land[ty, tx] and lfIndestructible) = 0) then
524
if ((Land[ty, tx] and lfBasic) <> 0) and not disableLandBack then
525
if (cReducedQuality and rqBlurryLand) = 0 then
526
LandPixels[ty, tx]:= LandBackPixel(tx, ty)
528
LandPixels[ty div 2, tx div 2]:= LandBackPixel(tx, ty)
577
if (cReducedQuality and rqBlurryLand) = 0 then
530
if ((Land[ty, tx] and lfObject) <> 0) or (disableLandBack and ((Land[ty, tx] and lfIndestructible) = 0)) then
531
if (cReducedQuality and rqBlurryLand) = 0 then
532
LandPixels[ty, tx]:= 0
534
LandPixels[ty div 2, tx div 2]:= 0;
583
by:= ty div 2; bx:= tx div 2;
585
if ((Land[ty, tx] and lfBasic) <> 0) and ((LandPixels[by,bx] and AMask) shr AShift = 255) and not disableLandBack then
586
LandPixels[by, bx]:= LandBackPixel(tx, ty)
587
else if ((Land[ty, tx] and lfObject) <> 0) or (disableLandBack and ((Land[ty, tx] and lfIndestructible) = 0)) or ((LandPixels[by,bx] and AMask) shr AShift < 255) then
588
LandPixels[by, bx]:= 0;
536
590
Land[ty, tx]:= 0;
722
777
Despeckle:= false
780
procedure Smooth(X, Y: LongInt);
782
// a bit of AA for explosions
783
if (Land[Y, X] = 0) and (Y > topY+1) and
784
(Y < LAND_HEIGHT-2) and (X>leftX+1) and (X<rightX-1) then
786
if ((((Land[y, x-1] and lfDamaged) <> 0) and (((Land[y+1,x] and lfDamaged) <> 0)) or ((Land[y-1,x] and lfDamaged) <> 0)) or
787
(((Land[y, x+1] and lfDamaged) <> 0) and (((Land[y-1,x] and lfDamaged) <> 0) or ((Land[y+1,x] and lfDamaged) <> 0)))) then
789
if (cReducedQuality and rqBlurryLand) = 0 then
791
if ((LandPixels[y,x] and AMask) shr AShift) < 10 then LandPixels[y,x]:= (cExplosionBorderColor and not AMask) or (128 shl AShift)
794
(((((LandPixels[y,x] and RMask shr RShift) div 2)+((cExplosionBorderColor and RMask) shr RShift) div 2) and $FF) shl RShift) or
795
(((((LandPixels[y,x] and GMask shr GShift) div 2)+((cExplosionBorderColor and GMask) shr GShift) div 2) and $FF) shl GShift) or
796
(((((LandPixels[y,x] and BMask shr BShift) div 2)+((cExplosionBorderColor and BMask) shr BShift) div 2) and $FF) shl BShift) or ($FF shl AShift)
798
if (Land[y, x-1] = lfObject) then Land[y,x]:= lfObject
799
else if (Land[y, x+1] = lfObject) then Land[y,x]:= lfObject
800
else Land[y,x]:= lfBasic;
802
else if ((((Land[y, x-1] and lfDamaged) <> 0) and ((Land[y+1,x-1] and lfDamaged) <> 0) and ((Land[y+2,x] and lfDamaged) <> 0)) or
803
(((Land[y, x-1] and lfDamaged) <> 0) and ((Land[y-1,x-1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0)) or
804
(((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y+2,x] and lfDamaged) <> 0)) or
805
(((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0)) or
806
(((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0)) or
807
(((Land[y-1, x] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0)) or
808
(((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x-1] and lfDamaged) <> 0) and ((Land[y,x-2] and lfDamaged) <> 0)) or
809
(((Land[y-1, x] and lfDamaged) <> 0) and ((Land[y-1,x-1] and lfDamaged) <> 0) and ((Land[y,x-2] and lfDamaged) <> 0))) then
811
if (cReducedQuality and rqBlurryLand) = 0 then
813
if ((LandPixels[y,x] and AMask) shr AShift) < 10 then LandPixels[y,x]:= (cExplosionBorderColor and not AMask) or (64 shl AShift)
816
(((((LandPixels[y,x] and RMask shr RShift) * 3 div 4)+((cExplosionBorderColor and RMask) shr RShift) div 4) and $FF) shl RShift) or
817
(((((LandPixels[y,x] and GMask shr GShift) * 3 div 4)+((cExplosionBorderColor and GMask) shr GShift) div 4) and $FF) shl GShift) or
818
(((((LandPixels[y,x] and BMask shr BShift) * 3 div 4)+((cExplosionBorderColor and BMask) shr BShift) div 4) and $FF) shl BShift) or ($FF shl AShift)
820
if (Land[y, x-1] = lfObject) then Land[y, x]:= lfObject
821
else if (Land[y, x+1] = lfObject) then Land[y, x]:= lfObject
822
else if (Land[y+1, x] = lfObject) then Land[y, x]:= lfObject
823
else if (Land[y-1, x] = lfObject) then Land[y, x]:= lfObject
824
else Land[y,x]:= lfBasic
725
829
function SweepDirty: boolean;
726
830
var x, y, xx, yy, ty, tx: LongInt;
727
831
bRes, updateBlock, resweep, recheck: boolean;