99 |
99 |
100 procedure ChangeCircleLines(x, y, dx, dy: LongInt; doSet: boolean); |
100 procedure ChangeCircleLines(x, y, dx, dy: LongInt; doSet: boolean); |
101 var i: LongInt; |
101 var i: LongInt; |
102 begin |
102 begin |
103 if not doSet then |
103 if not doSet then |
104 begin |
104 begin |
105 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then |
105 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then |
106 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
106 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
107 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 |
107 if (Land[y + dy, i] > 0) and (Land[y + dy, i] < 256) then |
108 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then |
108 dec(Land[y + dy, i]); // check > 0 because explosion can erase collision data |
109 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
109 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then |
110 if (Land[y - dy, i] > 0) and (Land[y - dy, i] < 256) then dec(Land[y - dy, i]); |
110 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
111 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then |
111 if (Land[y - dy, i] > 0) and (Land[y - dy, i] < 256) then |
112 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
112 dec(Land[y - dy, i]); |
113 if (Land[y + dx, i] > 0) and (Land[y + dx, i] < 256) then dec(Land[y + dx, i]); |
113 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then |
114 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then |
114 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
115 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
115 if (Land[y + dx, i] > 0) and (Land[y + dx, i] < 256) then |
116 if (Land[y - dx, i] > 0) and (Land[y - dx, i] < 256) then dec(Land[y - dx, i]); |
116 dec(Land[y + dx, i]); |
117 end else |
117 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then |
118 begin |
118 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
119 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then |
119 if (Land[y - dx, i] > 0) and (Land[y - dx, i] < 256) then |
120 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
120 dec(Land[y - dx, i]); |
121 if (Land[y + dy, i] < 256) then |
121 end |
122 inc(Land[y + dy, i]); |
122 else |
123 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then |
123 begin |
124 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
124 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then |
125 if (Land[y - dy, i] < 256) then |
125 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
126 inc(Land[y - dy, i]); |
126 if (Land[y + dy, i] < 256) then |
127 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then |
127 inc(Land[y + dy, i]); |
128 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
128 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then |
129 if (Land[y + dx, i] < 256) then |
129 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
130 inc(Land[y + dx, i]); |
130 if (Land[y - dy, i] < 256) then |
131 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then |
131 inc(Land[y - dy, i]); |
132 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
132 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then |
133 if (Land[y - dx, i] < 256) then |
133 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
134 inc(Land[y - dx, i]); |
134 if (Land[y + dx, i] < 256) then |
135 end |
135 inc(Land[y + dx, i]); |
|
136 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then |
|
137 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
|
138 if (Land[y - dx, i] < 256) then |
|
139 inc(Land[y - dx, i]); |
|
140 end |
136 end; |
141 end; |
137 |
142 |
138 procedure FillRoundInLand(X, Y, Radius: LongInt; Value: Longword); |
143 procedure FillRoundInLand(X, Y, Radius: LongInt; Value: Longword); |
139 var dx, dy, d: LongInt; |
144 var dx, dy, d: LongInt; |
140 begin |
145 begin |
141 dx:= 0; |
146 dx:= 0; |
142 dy:= Radius; |
147 dy:= Radius; |
143 d:= 3 - 2 * Radius; |
148 d:= 3 - 2 * Radius; |
144 while (dx < dy) do |
149 while (dx < dy) do |
145 begin |
150 begin |
146 FillCircleLines(x, y, dx, dy, Value); |
151 FillCircleLines(x, y, dx, dy, Value); |
147 if (d < 0) |
152 if (d < 0) then |
148 then d:= d + 4 * dx + 6 |
153 d:= d + 4 * dx + 6 |
149 else begin |
154 else |
150 d:= d + 4 * (dx - dy) + 10; |
155 begin |
151 dec(dy) |
156 d:= d + 4 * (dx - dy) + 10; |
152 end; |
157 dec(dy) |
153 inc(dx) |
158 end; |
154 end; |
159 inc(dx) |
155 if (dx = dy) then FillCircleLines(x, y, dx, dy, Value); |
160 end; |
|
161 if (dx = dy) then |
|
162 FillCircleLines(x, y, dx, dy, Value); |
156 end; |
163 end; |
157 |
164 |
158 procedure ChangeRoundInLand(X, Y, Radius: LongInt; doSet: boolean); |
165 procedure ChangeRoundInLand(X, Y, Radius: LongInt; doSet: boolean); |
159 var dx, dy, d: LongInt; |
166 var dx, dy, d: LongInt; |
160 begin |
167 begin |
161 dx:= 0; |
168 dx:= 0; |
162 dy:= Radius; |
169 dy:= Radius; |
163 d:= 3 - 2 * Radius; |
170 d:= 3 - 2 * Radius; |
164 while (dx < dy) do |
171 while (dx < dy) do |
165 begin |
172 begin |
166 ChangeCircleLines(x, y, dx, dy, doSet); |
173 ChangeCircleLines(x, y, dx, dy, doSet); |
167 if (d < 0) |
174 if (d < 0) then |
168 then d:= d + 4 * dx + 6 |
175 d:= d + 4 * dx + 6 |
169 else begin |
176 else |
170 d:= d + 4 * (dx - dy) + 10; |
177 begin |
171 dec(dy) |
178 d:= d + 4 * (dx - dy) + 10; |
172 end; |
179 dec(dy) |
173 inc(dx) |
180 end; |
174 end; |
181 inc(dx) |
175 if (dx = dy) then ChangeCircleLines(x, y, dx, dy, doSet) |
182 end; |
|
183 if (dx = dy) then |
|
184 ChangeCircleLines(x, y, dx, dy, doSet) |
176 end; |
185 end; |
177 |
186 |
178 procedure FillLandCircleLines0(x, y, dx, dy: LongInt); |
187 procedure FillLandCircleLines0(x, y, dx, dy: LongInt); |
179 var i, t: LongInt; |
188 var i, t: LongInt; |
180 begin |
189 begin |
221 cnt: Longword; |
230 cnt: Longword; |
222 begin |
231 begin |
223 cnt:= 0; |
232 cnt:= 0; |
224 t:= y + dy; |
233 t:= y + dy; |
225 if (t and LAND_HEIGHT_MASK) = 0 then |
234 if (t and LAND_HEIGHT_MASK) = 0 then |
226 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
235 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
227 if (Land[t, i] and lfIndestructible) = 0 then |
236 if (Land[t, i] and lfIndestructible) = 0 then |
228 begin |
237 begin |
229 if (cReducedQuality and rqBlurryLand) = 0 then |
238 if (cReducedQuality and rqBlurryLand) = 0 then |
230 begin |
239 begin |
231 by:= t; bx:= i; |
240 by:= t; bx:= i; |
232 end |
241 end |
233 else |
242 else |
234 begin |
243 begin |
235 by:= t div 2; bx:= i div 2; |
244 by:= t div 2; bx:= i div 2; |
236 end; |
245 end; |
237 if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then |
246 if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then |
238 begin |
247 begin |
239 inc(cnt); |
248 inc(cnt); |
240 LandPixels[by, bx]:= LandBackPixel(i, t) |
249 LandPixels[by, bx]:= LandBackPixel(i, t) |
241 end |
250 end |
242 else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then |
251 else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then |
243 LandPixels[by, bx]:= 0 |
252 LandPixels[by, bx]:= 0 |
244 end; |
253 end; |
245 |
254 |
246 t:= y - dy; |
255 t:= y - dy; |
247 if (t and LAND_HEIGHT_MASK) = 0 then |
256 if (t and LAND_HEIGHT_MASK) = 0 then |
248 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
257 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
249 if (Land[t, i] and lfIndestructible) = 0 then |
258 if (Land[t, i] and lfIndestructible) = 0 then |
250 begin |
259 begin |
251 if (cReducedQuality and rqBlurryLand) = 0 then |
260 if (cReducedQuality and rqBlurryLand) = 0 then |
252 begin |
261 begin |
253 by:= t; bx:= i; |
262 by:= t; bx:= i; |
254 end |
263 end |
255 else |
264 else |
256 begin |
265 begin |
257 by:= t div 2; bx:= i div 2; |
266 by:= t div 2; bx:= i div 2; |
258 end; |
267 end; |
259 if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then |
268 if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then |
260 begin |
269 begin |
261 inc(cnt); |
270 inc(cnt); |
262 LandPixels[by, bx]:= LandBackPixel(i, t) |
271 LandPixels[by, bx]:= LandBackPixel(i, t) |
263 end |
272 end |
264 else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then |
273 else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then |
265 LandPixels[by, bx]:= 0 |
274 LandPixels[by, bx]:= 0 |
266 end; |
275 end; |
267 |
276 |
268 t:= y + dx; |
277 t:= y + dx; |
269 if (t and LAND_HEIGHT_MASK) = 0 then |
278 if (t and LAND_HEIGHT_MASK) = 0 then |
270 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
279 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
271 if (Land[t, i] and lfIndestructible) = 0 then |
280 if (Land[t, i] and lfIndestructible) = 0 then |
272 begin |
281 begin |
273 if (cReducedQuality and rqBlurryLand) = 0 then |
282 if (cReducedQuality and rqBlurryLand) = 0 then |
274 begin |
283 begin |
275 by:= t; bx:= i; |
284 by:= t; bx:= i; |
276 end |
285 end |
277 else |
286 else |
278 begin |
287 begin |
279 by:= t div 2; bx:= i div 2; |
288 by:= t div 2; bx:= i div 2; |
280 end; |
289 end; |
281 if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then |
290 if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then |
282 begin |
291 begin |
283 inc(cnt); |
292 inc(cnt); |
284 LandPixels[by, bx]:= LandBackPixel(i, t) |
293 LandPixels[by, bx]:= LandBackPixel(i, t) |
285 end |
294 end |
286 else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then |
295 else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then |
287 LandPixels[by, bx]:= 0 |
296 LandPixels[by, bx]:= 0 |
288 end; |
297 end; |
289 t:= y - dx; |
298 t:= y - dx; |
290 if (t and LAND_HEIGHT_MASK) = 0 then |
299 if (t and LAND_HEIGHT_MASK) = 0 then |
291 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
300 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
292 if (Land[t, i] and lfIndestructible) = 0 then |
301 if (Land[t, i] and lfIndestructible) = 0 then |
293 begin |
302 begin |
294 if (cReducedQuality and rqBlurryLand) = 0 then |
303 if (cReducedQuality and rqBlurryLand) = 0 then |
295 begin |
304 begin |
296 by:= t; bx:= i; |
305 by:= t; bx:= i; |
297 end |
306 end |
298 else |
307 else |
299 begin |
308 begin |
300 by:= t div 2; bx:= i div 2; |
309 by:= t div 2; bx:= i div 2; |
301 end; |
310 end; |
302 if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then |
311 if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then |
303 begin |
312 begin |
304 inc(cnt); |
313 inc(cnt); |
305 LandPixels[by, bx]:= LandBackPixel(i, t) |
314 LandPixels[by, bx]:= LandBackPixel(i, t) |
306 end |
315 end |
307 else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then |
316 else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then |
308 LandPixels[by, bx]:= 0 |
317 LandPixels[by, bx]:= 0 |
309 end; |
318 end; |
310 FillLandCircleLinesBG:= cnt; |
319 FillLandCircleLinesBG:= cnt; |
311 end; |
320 end; |
312 |
321 |
313 procedure FillLandCircleLinesEBC(x, y, dx, dy: LongInt); |
322 procedure FillLandCircleLinesEBC(x, y, dx, dy: LongInt); |
314 var i, t: LongInt; |
323 var i, t: LongInt; |
315 begin |
324 begin |
316 t:= y + dy; |
325 t:= y + dy; |
317 if (t and LAND_HEIGHT_MASK) = 0 then |
326 if (t and LAND_HEIGHT_MASK) = 0 then |
318 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
327 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
319 if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then |
328 if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then |
320 begin |
329 begin |
321 if (cReducedQuality and rqBlurryLand) = 0 then |
330 if (cReducedQuality and rqBlurryLand) = 0 then |
322 LandPixels[t, i]:= cExplosionBorderColor |
331 LandPixels[t, i]:= cExplosionBorderColor |
323 else |
332 else |
324 LandPixels[t div 2, i div 2]:= cExplosionBorderColor; |
333 LandPixels[t div 2, i div 2]:= cExplosionBorderColor; |
325 |
334 |
326 Land[t, i]:= Land[t, i] or lfDamaged; |
335 Land[t, i]:= Land[t, i] or lfDamaged; |
327 //Despeckle(i, t); |
336 //Despeckle(i, t); |
328 LandDirty[t div 32, i div 32]:= 1; |
337 LandDirty[t div 32, i div 32]:= 1; |
329 end; |
338 end; |
330 |
339 |
331 t:= y - dy; |
340 t:= y - dy; |
332 if (t and LAND_HEIGHT_MASK) = 0 then |
341 if (t and LAND_HEIGHT_MASK) = 0 then |
333 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
342 for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do |
334 if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then |
343 if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then |
335 begin |
344 begin |
336 if (cReducedQuality and rqBlurryLand) = 0 then |
345 if (cReducedQuality and rqBlurryLand) = 0 then |
337 LandPixels[t, i]:= cExplosionBorderColor |
346 LandPixels[t, i]:= cExplosionBorderColor |
338 else |
347 else |
339 LandPixels[t div 2, i div 2]:= cExplosionBorderColor; |
348 LandPixels[t div 2, i div 2]:= cExplosionBorderColor; |
340 Land[t, i]:= Land[t, i] or lfDamaged; |
349 Land[t, i]:= Land[t, i] or lfDamaged; |
341 //Despeckle(i, t); |
350 //Despeckle(i, t); |
342 LandDirty[t div 32, i div 32]:= 1; |
351 LandDirty[t div 32, i div 32]:= 1; |
343 end; |
352 end; |
344 |
353 |
345 t:= y + dx; |
354 t:= y + dx; |
346 if (t and LAND_HEIGHT_MASK) = 0 then |
355 if (t and LAND_HEIGHT_MASK) = 0 then |
347 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
356 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
348 if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then |
357 if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then |
349 begin |
358 begin |
350 if (cReducedQuality and rqBlurryLand) = 0 then |
359 if (cReducedQuality and rqBlurryLand) = 0 then |
351 LandPixels[t, i]:= cExplosionBorderColor |
360 LandPixels[t, i]:= cExplosionBorderColor |
352 else |
361 else |
353 LandPixels[t div 2, i div 2]:= cExplosionBorderColor; |
362 LandPixels[t div 2, i div 2]:= cExplosionBorderColor; |
354 |
363 |
355 Land[t, i]:= Land[t, i] or lfDamaged; |
364 Land[t, i]:= Land[t, i] or lfDamaged; |
356 //Despeckle(i, t); |
365 //Despeckle(i, t); |
357 LandDirty[t div 32, i div 32]:= 1; |
366 LandDirty[t div 32, i div 32]:= 1; |
358 end; |
367 end; |
359 |
368 |
360 t:= y - dx; |
369 t:= y - dx; |
361 if (t and LAND_HEIGHT_MASK) = 0 then |
370 if (t and LAND_HEIGHT_MASK) = 0 then |
362 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
371 for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do |
363 if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then |
372 if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then |
364 begin |
373 begin |
365 if (cReducedQuality and rqBlurryLand) = 0 then |
374 if (cReducedQuality and rqBlurryLand) = 0 then |
366 LandPixels[t, i]:= cExplosionBorderColor |
375 LandPixels[t, i]:= cExplosionBorderColor |
367 else |
376 else |
368 LandPixels[t div 2, i div 2]:= cExplosionBorderColor; |
377 LandPixels[t div 2, i div 2]:= cExplosionBorderColor; |
369 |
378 |
370 Land[t, i]:= Land[t, i] or lfDamaged; |
379 Land[t, i]:= Land[t, i] or lfDamaged; |
371 //Despeckle(i, y - dy); |
380 //Despeckle(i, y - dy); |
372 LandDirty[t div 32, i div 32]:= 1; |
381 LandDirty[t div 32, i div 32]:= 1; |
373 end; |
382 end; |
374 end; |
383 end; |
375 |
384 |
376 function DrawExplosion(X, Y, Radius: LongInt): Longword; |
385 function DrawExplosion(X, Y, Radius: LongInt): Longword; |
377 var dx, dy, ty, tx, d: LongInt; |
386 var dx, dy, ty, tx, d: LongInt; |
378 cnt: Longword; |
387 cnt: Longword; |
665 h:= SpritesData[Obj].Height; |
680 h:= SpritesData[Obj].Height; |
666 row:= Frame mod numFramesFirstCol; |
681 row:= Frame mod numFramesFirstCol; |
667 col:= Frame div numFramesFirstCol; |
682 col:= Frame div numFramesFirstCol; |
668 |
683 |
669 if SDL_MustLock(Image) then |
684 if SDL_MustLock(Image) then |
670 SDLTry(SDL_LockSurface(Image) >= 0, true); |
685 SDLTry(SDL_LockSurface(Image) >= 0, true); |
671 |
686 |
672 bpp:= Image^.format^.BytesPerPixel; |
687 bpp:= Image^.format^.BytesPerPixel; |
673 TryDo(bpp = 4, 'It should be 32 bpp sprite', true); |
688 TryDo(bpp = 4, 'It should be 32 bpp sprite', true); |
674 // Check that sprite fits free space |
689 // Check that sprite fits free space |
675 p:= @(PByteArray(Image^.pixels)^[ Image^.pitch * row * h + col * w * 4 ]); |
690 p:= @(PByteArray(Image^.pixels)^[ Image^.pitch * row * h + col * w * 4 ]); |
676 case bpp of |
691 case bpp of |
677 4: for y:= 0 to Pred(h) do |
692 4: for y:= 0 to Pred(h) do |
678 begin |
693 begin |
679 for x:= 0 to Pred(w) do |
694 for x:= 0 to Pred(w) do |
680 if (PLongword(@(p^[x * 4]))^) <> 0 then |
695 if (PLongword(@(p^[x * 4]))^) <> 0 then |
681 if ((cpY + y) <= Longint(topY)) or |
696 if ((cpY + y) <= Longint(topY)) or ((cpY + y) >= LAND_HEIGHT) |
682 ((cpY + y) >= LAND_HEIGHT) or |
697 or ((cpX + x) <= Longint(leftX)) or ((cpX + x) >= Longint(rightX)) or (Land[cpY + y, cpX + x] <> 0) then |
683 ((cpX + x) <= Longint(leftX)) or |
698 begin |
684 ((cpX + x) >= Longint(rightX)) or |
699 if SDL_MustLock(Image) then |
685 (Land[cpY + y, cpX + x] <> 0) then |
700 SDL_UnlockSurface(Image); |
686 begin |
701 exit(false) |
687 if SDL_MustLock(Image) then |
702 end; |
688 SDL_UnlockSurface(Image); |
703 p:= @(p^[Image^.pitch]); |
689 exit(false) |
704 end; |
690 end; |
705 end; |
691 p:= @(p^[Image^.pitch]); |
|
692 end; |
|
693 end; |
|
694 |
706 |
695 TryPlaceOnLand:= true; |
707 TryPlaceOnLand:= true; |
696 if not doPlace then |
708 if not doPlace then |
697 begin |
709 begin |
698 if SDL_MustLock(Image) then |
710 if SDL_MustLock(Image) then |
699 SDL_UnlockSurface(Image); |
711 SDL_UnlockSurface(Image); |
700 exit |
712 exit |
701 end; |
713 end; |
702 |
714 |
703 // Checked, now place |
715 // Checked, now place |
704 p:= @(PByteArray(Image^.pixels)^[ Image^.pitch * row * h + col * w * 4 ]); |
716 p:= @(PByteArray(Image^.pixels)^[ Image^.pitch * row * h + col * w * 4 ]); |
705 case bpp of |
717 case bpp of |
706 4: for y:= 0 to Pred(h) do |
718 4: for y:= 0 to Pred(h) do |
707 begin |
719 begin |
708 for x:= 0 to Pred(w) do |
720 for x:= 0 to Pred(w) do |
709 if (PLongword(@(p^[x * 4]))^) <> 0 then |
721 if (PLongword(@(p^[x * 4]))^) <> 0 then |
710 begin |
722 begin |
711 if (cReducedQuality and rqBlurryLand) = 0 then |
723 if (cReducedQuality and rqBlurryLand) = 0 then |
712 begin |
724 begin |
713 gX:= cpX + x; |
725 gX:= cpX + x; |
714 gY:= cpY + y; |
726 gY:= cpY + y; |
715 end |
727 end |
716 else |
728 else |
717 begin |
729 begin |
718 gX:= (cpX + x) div 2; |
730 gX:= (cpX + x) div 2; |
719 gY:= (cpY + y) div 2; |
731 gY:= (cpY + y) div 2; |
720 end; |
732 end; |
721 if indestructible then |
733 if indestructible then |
722 Land[cpY + y, cpX + x]:= lfIndestructible |
734 Land[cpY + y, cpX + x]:= lfIndestructible |
723 else if (LandPixels[gY, gX] and AMask) shr AShift = 255 then // This test assumes lfBasic and lfObject differ only graphically |
735 else if (LandPixels[gY, gX] and AMask) shr AShift = 255 then // This test assumes lfBasic and lfObject differ only graphically |
724 Land[cpY + y, cpX + x]:= lfBasic |
736 Land[cpY + y, cpX + x]:= lfBasic |
725 else |
737 else |
726 Land[cpY + y, cpX + x]:= lfObject; |
738 Land[cpY + y, cpX + x]:= lfObject; |
727 // For testing only. Intent is to flag this on objects with masks, or use it for an ice ray gun |
739 // For testing only. Intent is to flag this on objects with masks, or use it for an ice ray gun |
728 if (Theme = 'Snow') or (Theme = 'Christmas') then Land[cpY + y, cpX + x]:= Land[cpY + y, cpX + x] or lfIce; |
740 if (Theme = 'Snow') or (Theme = 'Christmas') then |
729 LandPixels[gY, gX]:= PLongword(@(p^[x * 4]))^ |
741 Land[cpY + y, cpX + x]:= Land[cpY + y, cpX + x] or lfIce; |
730 end; |
742 LandPixels[gY, gX]:= PLongword(@(p^[x * 4]))^ |
731 p:= @(p^[Image^.pitch]); |
743 end; |
732 end; |
744 p:= @(p^[Image^.pitch]); |
733 end; |
745 end; |
|
746 end; |
734 if SDL_MustLock(Image) then |
747 if SDL_MustLock(Image) then |
735 SDL_UnlockSurface(Image); |
748 SDL_UnlockSurface(Image); |
736 |
749 |
737 x:= Max(cpX, leftX); |
750 x:= Max(cpX, leftX); |
738 w:= Min(cpX + Image^.w, LAND_WIDTH) - x; |
751 w:= Min(cpX + Image^.w, LAND_WIDTH) - x; |
739 y:= Max(cpY, topY); |
752 y:= Max(cpY, topY); |
740 h:= Min(cpY + Image^.h, LAND_HEIGHT) - y; |
753 h:= Min(cpY + Image^.h, LAND_HEIGHT) - y; |
786 LandPixels[yy, xx]:= LandBackPixel(X, Y) |
801 LandPixels[yy, xx]:= LandBackPixel(X, Y) |
787 else |
802 else |
788 LandPixels[yy, xx]:= 0; |
803 LandPixels[yy, xx]:= 0; |
789 |
804 |
790 Land[Y, X]:= 0; |
805 Land[Y, X]:= 0; |
791 if not pixelsweep then exit(true); |
806 if not pixelsweep then |
|
807 exit(true); |
792 end; |
808 end; |
793 end; |
809 end; |
794 Despeckle:= false |
810 Despeckle:= false |
795 end; |
811 end; |
796 |
812 |
797 procedure Smooth(X, Y: LongInt); |
813 procedure Smooth(X, Y: LongInt); |
798 begin |
814 begin |
799 // a bit of AA for explosions |
815 // a bit of AA for explosions |
800 if (Land[Y, X] = 0) and (Y > LongInt(topY) + 1) and |
816 if (Land[Y, X] = 0) and (Y > LongInt(topY) + 1) and |
801 (Y < LAND_HEIGHT-2) and (X > LongInt(leftX) + 1) and (X < LongInt(rightX) - 1) then |
817 (Y < LAND_HEIGHT-2) and (X > LongInt(leftX) + 1) and (X < LongInt(rightX) - 1) then |
802 begin |
818 begin |
803 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 |
819 if ((((Land[y, x-1] and lfDamaged) <> 0) and (((Land[y+1,x] and lfDamaged) <> 0)) or ((Land[y-1,x] and lfDamaged) <> 0)) |
804 (((Land[y, x+1] and lfDamaged) <> 0) and (((Land[y-1,x] and lfDamaged) <> 0) or ((Land[y+1,x] and lfDamaged) <> 0)))) then |
820 or (((Land[y, x+1] and lfDamaged) <> 0) and (((Land[y-1,x] and lfDamaged) <> 0) or ((Land[y+1,x] and lfDamaged) <> 0)))) then |
805 begin |
821 begin |
806 if (cReducedQuality and rqBlurryLand) = 0 then |
822 if (cReducedQuality and rqBlurryLand) = 0 then |
807 begin |
823 begin |
808 if ((LandPixels[y,x] and AMask) shr AShift) < 10 then LandPixels[y,x]:= (cExplosionBorderColor and (not AMask)) or (128 shl AShift) |
824 if ((LandPixels[y,x] and AMask) shr AShift) < 10 then |
|
825 LandPixels[y,x]:= (cExplosionBorderColor and (not AMask)) or (128 shl AShift) |
809 else |
826 else |
810 LandPixels[y,x]:= |
827 LandPixels[y,x]:= |
811 (((((LandPixels[y,x] and RMask shr RShift) div 2)+((cExplosionBorderColor and RMask) shr RShift) div 2) and $FF) shl RShift) or |
828 (((((LandPixels[y,x] and RMask shr RShift) div 2)+((cExplosionBorderColor and RMask) shr RShift) div 2) and $FF) shl RShift) or |
812 (((((LandPixels[y,x] and GMask shr GShift) div 2)+((cExplosionBorderColor and GMask) shr GShift) div 2) and $FF) shl GShift) or |
829 (((((LandPixels[y,x] and GMask shr GShift) div 2)+((cExplosionBorderColor and GMask) shr GShift) div 2) and $FF) shl GShift) or |
813 (((((LandPixels[y,x] and BMask shr BShift) div 2)+((cExplosionBorderColor and BMask) shr BShift) div 2) and $FF) shl BShift) or ($FF shl AShift) |
830 (((((LandPixels[y,x] and BMask shr BShift) div 2)+((cExplosionBorderColor and BMask) shr BShift) div 2) and $FF) shl BShift) or ($FF shl AShift) |
814 end; |
831 end; |
815 if (Land[y, x-1] = lfObject) then Land[y,x]:= lfObject |
832 if (Land[y, x-1] = lfObject) then |
816 else if (Land[y, x+1] = lfObject) then Land[y,x]:= lfObject |
833 Land[y,x]:= lfObject |
817 else Land[y,x]:= lfBasic; |
834 else if (Land[y, x+1] = lfObject) then |
|
835 Land[y,x]:= lfObject |
|
836 else |
|
837 Land[y,x]:= lfBasic; |
818 end |
838 end |
819 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 |
839 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)) |
820 (((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 |
840 or (((Land[y, x-1] and lfDamaged) <> 0) and ((Land[y-1,x-1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0)) |
821 (((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 |
841 or (((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y+2,x] and lfDamaged) <> 0)) |
822 (((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 |
842 or (((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0)) |
823 (((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 |
843 or (((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0)) |
824 (((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 |
844 or (((Land[y-1, x] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0)) |
825 (((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 |
845 or (((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x-1] and lfDamaged) <> 0) and ((Land[y,x-2] and lfDamaged) <> 0)) |
826 (((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 |
846 or (((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 |
827 begin |
847 begin |
828 if (cReducedQuality and rqBlurryLand) = 0 then |
848 if (cReducedQuality and rqBlurryLand) = 0 then |
829 begin |
849 begin |
830 if ((LandPixels[y,x] and AMask) shr AShift) < 10 then LandPixels[y,x]:= (cExplosionBorderColor and (not AMask)) or (64 shl AShift) |
850 if ((LandPixels[y,x] and AMask) shr AShift) < 10 then |
|
851 LandPixels[y,x]:= (cExplosionBorderColor and (not AMask)) or (64 shl AShift) |
831 else |
852 else |
832 LandPixels[y,x]:= |
853 LandPixels[y,x]:= |
833 (((((LandPixels[y,x] and RMask shr RShift) * 3 div 4)+((cExplosionBorderColor and RMask) shr RShift) div 4) and $FF) shl RShift) or |
854 (((((LandPixels[y,x] and RMask shr RShift) * 3 div 4)+((cExplosionBorderColor and RMask) shr RShift) div 4) and $FF) shl RShift) or |
834 (((((LandPixels[y,x] and GMask shr GShift) * 3 div 4)+((cExplosionBorderColor and GMask) shr GShift) div 4) and $FF) shl GShift) or |
855 (((((LandPixels[y,x] and GMask shr GShift) * 3 div 4)+((cExplosionBorderColor and GMask) shr GShift) div 4) and $FF) shl GShift) or |
835 (((((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) |
856 (((((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) |
836 end; |
857 end; |
837 if (Land[y, x-1] = lfObject) then Land[y, x]:= lfObject |
858 if (Land[y, x-1] = lfObject) then |
838 else if (Land[y, x+1] = lfObject) then Land[y, x]:= lfObject |
859 Land[y, x]:= lfObject |
839 else if (Land[y+1, x] = lfObject) then Land[y, x]:= lfObject |
860 else if (Land[y, x+1] = lfObject) then |
840 else if (Land[y-1, x] = lfObject) then Land[y, x]:= lfObject |
861 Land[y, x]:= lfObject |
|
862 else if (Land[y+1, x] = lfObject) then |
|
863 Land[y, x]:= lfObject |
|
864 else if (Land[y-1, x] = lfObject) then |
|
865 Land[y, x]:= lfObject |
841 else Land[y,x]:= lfBasic |
866 else Land[y,x]:= lfBasic |
842 end |
867 end |
843 end |
868 end |
844 else if ((cReducedQuality and rqBlurryLand) = 0) and (LandPixels[Y, X] and AMask = 255) and |
869 else if ((cReducedQuality and rqBlurryLand) = 0) and (LandPixels[Y, X] and AMask = 255) |
845 ((Land[Y, X] and (lfDamaged or lfBasic) = lfBasic) or (Land[Y, X] and (lfDamaged or lfBasic) = lfBasic)) and |
870 and ((Land[Y, X] and (lfDamaged or lfBasic) = lfBasic) or (Land[Y, X] and (lfDamaged or lfBasic) = lfBasic)) |
846 (Y > LongInt(topY) + 1) and (Y < LAND_HEIGHT-2) and (X > LongInt(leftX) + 1) and (X < LongInt(rightX) - 1) then |
871 and (Y > LongInt(topY) + 1) and (Y < LAND_HEIGHT-2) and (X > LongInt(leftX) + 1) and (X < LongInt(rightX) - 1) then |
847 begin |
872 begin |
848 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 |
873 if ((((Land[y, x-1] and lfDamaged) <> 0) and (((Land[y+1,x] and lfDamaged) <> 0)) or ((Land[y-1,x] and lfDamaged) <> 0)) |
849 (((Land[y, x+1] and lfDamaged) <> 0) and (((Land[y-1,x] and lfDamaged) <> 0) or ((Land[y+1,x] and lfDamaged) <> 0)))) then |
874 or (((Land[y, x+1] and lfDamaged) <> 0) and (((Land[y-1,x] and lfDamaged) <> 0) or ((Land[y+1,x] and lfDamaged) <> 0)))) then |
850 begin |
875 begin |
851 LandPixels[y,x]:= |
876 LandPixels[y,x]:= |
852 (((((LandPixels[y,x] and RMask shr RShift) div 2)+((cExplosionBorderColor and RMask) shr RShift) div 2) and $FF) shl RShift) or |
877 (((((LandPixels[y,x] and RMask shr RShift) div 2)+((cExplosionBorderColor and RMask) shr RShift) div 2) and $FF) shl RShift) or |
853 (((((LandPixels[y,x] and GMask shr GShift) div 2)+((cExplosionBorderColor and GMask) shr GShift) div 2) and $FF) shl GShift) or |
878 (((((LandPixels[y,x] and GMask shr GShift) div 2)+((cExplosionBorderColor and GMask) shr GShift) div 2) and $FF) shl GShift) or |
854 (((((LandPixels[y,x] and BMask shr BShift) div 2)+((cExplosionBorderColor and BMask) shr BShift) div 2) and $FF) shl BShift) or ($FF shl AShift) |
879 (((((LandPixels[y,x] and BMask shr BShift) div 2)+((cExplosionBorderColor and BMask) shr BShift) div 2) and $FF) shl BShift) or ($FF shl AShift) |
855 end |
880 end |
856 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 |
881 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)) |
857 (((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 |
882 or (((Land[y, x-1] and lfDamaged) <> 0) and ((Land[y-1,x-1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0)) |
858 (((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 |
883 or (((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y+2,x] and lfDamaged) <> 0)) |
859 (((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 |
884 or (((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0)) |
860 (((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 |
885 or (((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0)) |
861 (((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 |
886 or (((Land[y-1, x] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0)) |
862 (((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 |
887 or (((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x-1] and lfDamaged) <> 0) and ((Land[y,x-2] and lfDamaged) <> 0)) |
863 (((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 |
888 or (((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 |
864 begin |
889 begin |
865 LandPixels[y,x]:= |
890 LandPixels[y,x]:= |
866 (((((LandPixels[y,x] and RMask shr RShift) * 3 div 4)+((cExplosionBorderColor and RMask) shr RShift) div 4) and $FF) shl RShift) or |
891 (((((LandPixels[y,x] and RMask shr RShift) * 3 div 4)+((cExplosionBorderColor and RMask) shr RShift) div 4) and $FF) shl RShift) or |
867 (((((LandPixels[y,x] and GMask shr GShift) * 3 div 4)+((cExplosionBorderColor and GMask) shr GShift) div 4) and $FF) shl GShift) or |
892 (((((LandPixels[y,x] and GMask shr GShift) * 3 div 4)+((cExplosionBorderColor and GMask) shr GShift) div 4) and $FF) shl GShift) or |
868 (((((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) |
893 (((((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) |