38 function LandBackPixel(x, y: LongInt): LongWord; |
38 function LandBackPixel(x, y: LongInt): LongWord; |
39 |
39 |
40 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace: boolean): boolean; |
40 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace: boolean): boolean; |
41 |
41 |
42 implementation |
42 implementation |
43 uses SDLh, uMisc, uLandTexture, uVariables; |
43 uses SDLh, uMisc, uLandTexture, uVariables, uUtils; |
44 |
44 |
45 procedure FillCircleLines(x, y, dx, dy: LongInt; Value: Longword); |
45 procedure FillCircleLines(x, y, dx, dy: LongInt; Value: Longword); |
46 var i: LongInt; |
46 var i: LongInt; |
47 begin |
47 begin |
48 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then |
48 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then |
49 for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do |
49 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
50 if (Land[y + dy, i] and lfIndestructible) = 0 then |
50 if (Land[y + dy, i] and lfIndestructible) = 0 then |
51 Land[y + dy, i]:= Value; |
51 Land[y + dy, i]:= Value; |
52 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then |
52 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then |
53 for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do |
53 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
54 if (Land[y - dy, i] and lfIndestructible) = 0 then |
54 if (Land[y - dy, i] and lfIndestructible) = 0 then |
55 Land[y - dy, i]:= Value; |
55 Land[y - dy, i]:= Value; |
56 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then |
56 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then |
57 for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do |
57 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
58 if (Land[y + dx, i] and lfIndestructible) = 0 then |
58 if (Land[y + dx, i] and lfIndestructible) = 0 then |
59 Land[y + dx, i]:= Value; |
59 Land[y + dx, i]:= Value; |
60 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then |
60 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then |
61 for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do |
61 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
62 if (Land[y - dx, i] and lfIndestructible) = 0 then |
62 if (Land[y - dx, i] and lfIndestructible) = 0 then |
63 Land[y - dx, i]:= Value; |
63 Land[y - dx, i]:= Value; |
64 end; |
64 end; |
65 |
65 |
66 procedure ChangeCircleLines(x, y, dx, dy: LongInt; doSet: boolean); |
66 procedure ChangeCircleLines(x, y, dx, dy: LongInt; doSet: boolean); |
67 var i: LongInt; |
67 var i: LongInt; |
68 begin |
68 begin |
69 if not doSet then |
69 if not doSet then |
70 begin |
70 begin |
71 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then |
71 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then |
72 for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do |
72 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
73 if (Land[y + dy, i] > 0) and (Land[y + dy, i] < 256) then dec(Land[y + dy, i]); // check > 0 because explosion can erase collision data |
73 if (Land[y + dy, i] > 0) and (Land[y + dy, i] < 256) then dec(Land[y + dy, i]); // check > 0 because explosion can erase collision data |
74 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then |
74 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then |
75 for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do |
75 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
76 if (Land[y - dy, i] > 0) and (Land[y - dy, i] < 256) then dec(Land[y - dy, i]); |
76 if (Land[y - dy, i] > 0) and (Land[y - dy, i] < 256) then dec(Land[y - dy, i]); |
77 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then |
77 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then |
78 for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do |
78 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
79 if (Land[y + dx, i] > 0) and (Land[y + dx, i] < 256) then dec(Land[y + dx, i]); |
79 if (Land[y + dx, i] > 0) and (Land[y + dx, i] < 256) then dec(Land[y + dx, i]); |
80 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then |
80 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then |
81 for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do |
81 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
82 if (Land[y - dx, i] > 0) and (Land[y - dx, i] < 256) then dec(Land[y - dx, i]); |
82 if (Land[y - dx, i] > 0) and (Land[y - dx, i] < 256) then dec(Land[y - dx, i]); |
83 end else |
83 end else |
84 begin |
84 begin |
85 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then |
85 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then |
86 for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do |
86 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
87 if (Land[y + dy, i] < 256) then |
87 if (Land[y + dy, i] < 256) then |
88 inc(Land[y + dy, i]); |
88 inc(Land[y + dy, i]); |
89 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then |
89 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then |
90 for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do |
90 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
91 if (Land[y - dy, i] < 256) then |
91 if (Land[y - dy, i] < 256) then |
92 inc(Land[y - dy, i]); |
92 inc(Land[y - dy, i]); |
93 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then |
93 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then |
94 for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do |
94 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
95 if (Land[y + dx, i] < 256) then |
95 if (Land[y + dx, i] < 256) then |
96 inc(Land[y + dx, i]); |
96 inc(Land[y + dx, i]); |
97 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then |
97 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then |
98 for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do |
98 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
99 if (Land[y - dx, i] < 256) then |
99 if (Land[y - dx, i] < 256) then |
100 inc(Land[y - dx, i]); |
100 inc(Land[y - dx, i]); |
101 end |
101 end |
102 end; |
102 end; |
103 |
103 |
144 procedure FillLandCircleLines0(x, y, dx, dy: LongInt); |
144 procedure FillLandCircleLines0(x, y, dx, dy: LongInt); |
145 var i, t: LongInt; |
145 var i, t: LongInt; |
146 begin |
146 begin |
147 t:= y + dy; |
147 t:= y + dy; |
148 if (t and LAND_HEIGHT_MASK) = 0 then |
148 if (t and LAND_HEIGHT_MASK) = 0 then |
149 for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do |
149 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
150 if (not isMap and ((Land[t, i] and lfIndestructible) = 0)) or ((Land[t, i] and lfBasic) <> 0) then |
150 if (not isMap and ((Land[t, i] and lfIndestructible) = 0)) or ((Land[t, i] and lfBasic) <> 0) then |
151 if (cReducedQuality and rqBlurryLand) = 0 then |
151 if (cReducedQuality and rqBlurryLand) = 0 then |
152 LandPixels[t, i]:= 0 |
152 LandPixels[t, i]:= 0 |
153 else |
153 else |
154 LandPixels[t div 2, i div 2]:= 0; |
154 LandPixels[t div 2, i div 2]:= 0; |
155 |
155 |
156 t:= y - dy; |
156 t:= y - dy; |
157 if (t and LAND_HEIGHT_MASK) = 0 then |
157 if (t and LAND_HEIGHT_MASK) = 0 then |
158 for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do |
158 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
159 if (not isMap and ((Land[t, i] and lfIndestructible) = 0)) or ((Land[t, i] and lfBasic) <> 0) then |
159 if (not isMap and ((Land[t, i] and lfIndestructible) = 0)) or ((Land[t, i] and lfBasic) <> 0) then |
160 if (cReducedQuality and rqBlurryLand) = 0 then |
160 if (cReducedQuality and rqBlurryLand) = 0 then |
161 LandPixels[t, i]:= 0 |
161 LandPixels[t, i]:= 0 |
162 else |
162 else |
163 LandPixels[t div 2, i div 2]:= 0; |
163 LandPixels[t div 2, i div 2]:= 0; |
164 |
164 |
165 t:= y + dx; |
165 t:= y + dx; |
166 if (t and LAND_HEIGHT_MASK) = 0 then |
166 if (t and LAND_HEIGHT_MASK) = 0 then |
167 for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do |
167 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
168 if (not isMap and ((Land[t, i] and lfIndestructible) = 0)) or ((Land[t, i] and lfBasic) <> 0) then |
168 if (not isMap and ((Land[t, i] and lfIndestructible) = 0)) or ((Land[t, i] and lfBasic) <> 0) then |
169 if (cReducedQuality and rqBlurryLand) = 0 then |
169 if (cReducedQuality and rqBlurryLand) = 0 then |
170 LandPixels[t, i]:= 0 |
170 LandPixels[t, i]:= 0 |
171 else |
171 else |
172 LandPixels[t div 2, i div 2]:= 0; |
172 LandPixels[t div 2, i div 2]:= 0; |
173 |
173 |
174 t:= y - dx; |
174 t:= y - dx; |
175 if (t and LAND_HEIGHT_MASK) = 0 then |
175 if (t and LAND_HEIGHT_MASK) = 0 then |
176 for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do |
176 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
177 if (not isMap and ((Land[t, i] and lfIndestructible) = 0)) or ((Land[t, i] and lfBasic) <> 0) then |
177 if (not isMap and ((Land[t, i] and lfIndestructible) = 0)) or ((Land[t, i] and lfBasic) <> 0) then |
178 if (cReducedQuality and rqBlurryLand) = 0 then |
178 if (cReducedQuality and rqBlurryLand) = 0 then |
179 LandPixels[t, i]:= 0 |
179 LandPixels[t, i]:= 0 |
180 else |
180 else |
181 LandPixels[t div 2, i div 2]:= 0; |
181 LandPixels[t div 2, i div 2]:= 0; |
392 inc(dx) |
392 inc(dx) |
393 end; |
393 end; |
394 if (dx = dy) then FillLandCircleLinesEBC(x, y, dx, dy); |
394 if (dx = dy) then FillLandCircleLinesEBC(x, y, dx, dy); |
395 end; |
395 end; |
396 |
396 |
397 tx:= max(X - Radius - 1, 0); |
397 tx:= Max(X - Radius - 1, 0); |
398 dx:= min(X + Radius + 1, LAND_WIDTH) - tx; |
398 dx:= Min(X + Radius + 1, LAND_WIDTH) - tx; |
399 ty:= max(Y - Radius - 1, 0); |
399 ty:= Max(Y - Radius - 1, 0); |
400 dy:= min(Y + Radius + 1, LAND_HEIGHT) - ty; |
400 dy:= Min(Y + Radius + 1, LAND_HEIGHT) - ty; |
401 UpdateLandTexture(tx, dx, ty, dy); |
401 UpdateLandTexture(tx, dx, ty, dy); |
402 DrawExplosion:= cnt |
402 DrawExplosion:= cnt |
403 end; |
403 end; |
404 |
404 |
405 procedure DrawHLinesExplosions(ar: PRangeArray; Radius: LongInt; y, dY: LongInt; Count: Byte); |
405 procedure DrawHLinesExplosions(ar: PRangeArray; Radius: LongInt; y, dY: LongInt; Count: Byte); |
406 var tx, ty, i: LongInt; |
406 var tx, ty, i: LongInt; |
407 begin |
407 begin |
408 for i:= 0 to Pred(Count) do |
408 for i:= 0 to Pred(Count) do |
409 begin |
409 begin |
410 for ty:= max(y - Radius, 0) to min(y + Radius, LAND_HEIGHT) do |
410 for ty:= Max(y - Radius, 0) to Min(y + Radius, LAND_HEIGHT) do |
411 for tx:= max(0, ar^[i].Left - Radius) to min(LAND_WIDTH, ar^[i].Right + Radius) do |
411 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 then |
412 if (Land[ty, tx] and lfBasic) <> 0 then |
413 if (cReducedQuality and rqBlurryLand) = 0 then |
413 if (cReducedQuality and rqBlurryLand) = 0 then |
414 LandPixels[ty, tx]:= LandBackPixel(tx, ty) |
414 LandPixels[ty, tx]:= LandBackPixel(tx, ty) |
415 else |
415 else |
416 LandPixels[ty div 2, tx div 2]:= LandBackPixel(tx, ty) |
416 LandPixels[ty div 2, tx div 2]:= LandBackPixel(tx, ty) |