266 // |
266 // |
267 // - (dX, dY) - direction, vector of length = 0.5 |
267 // - (dX, dY) - direction, vector of length = 0.5 |
268 // |
268 // |
269 procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: LongInt); |
269 procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: LongInt); |
270 var nx, ny, dX8, dY8: hwFloat; |
270 var nx, ny, dX8, dY8: hwFloat; |
271 i, t, tx, ty, stY, ddy: Longint; |
271 i, t, tx, ty, stX, stY, ddy, ddx: Longint; |
272 begin // (-dY, dX) is (dX, dY) rotated by PI/2 |
272 begin // (-dY, dX) is (dX, dY) rotated by PI/2 |
273 stY:= hwRound(Y); |
273 stY:= hwRound(Y); |
|
274 stX:= hwRound(X); |
274 |
275 |
275 nx:= X + dY * (HalfWidth + 8); |
276 nx:= X + dY * (HalfWidth + 8); |
276 ny:= Y - dX * (HalfWidth + 8); |
277 ny:= Y - dX * (HalfWidth + 8); |
277 |
278 |
278 dX8:= dX * 8; |
279 dX8:= dX * 8; |
322 {$include tunsetborder.inc} |
323 {$include tunsetborder.inc} |
323 nx:= nx - dY; |
324 nx:= nx - dY; |
324 ny:= ny + dX; |
325 ny:= ny + dX; |
325 end; |
326 end; |
326 |
327 |
|
328 tx:= max(stX - HalfWidth * 2 - 4 - abs(hwRound(dX * ticks)), 0); |
327 ty:= max(stY - HalfWidth * 2 - 4 - abs(hwRound(dY * ticks)), 0); |
329 ty:= max(stY - HalfWidth * 2 - 4 - abs(hwRound(dY * ticks)), 0); |
328 ddy:= min(stY + HalfWidth * 2 + 4 + abs(hwRound(dY * ticks)), LAND_HEIGHT) - t; |
330 ddx:= min(stX + HalfWidth * 2 + 4 + abs(hwRound(dX * ticks)), LAND_WIDTH) - tx; |
329 UpdateLandTexture(0, LAND_WIDTH, ty, ddy) |
331 ddy:= min(stY + HalfWidth * 2 + 4 + abs(hwRound(dY * ticks)), LAND_HEIGHT) - ty; |
|
332 |
|
333 UpdateLandTexture(tx, ddx, ty, ddy) |
330 end; |
334 end; |
331 |
335 |
332 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace: boolean): boolean; |
336 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace: boolean): boolean; |
333 var X, Y, bpp, h, w: LongInt; |
337 var X, Y, bpp, h, w: LongInt; |
334 p: PByteArray; |
338 p: PByteArray; |
425 Despeckle:= false |
429 Despeckle:= false |
426 end; |
430 end; |
427 |
431 |
428 function SweepDirty: boolean; |
432 function SweepDirty: boolean; |
429 var x, y, xx, yy: LongInt; |
433 var x, y, xx, yy: LongInt; |
430 updatedRow, updatedCell, Result: boolean; |
434 Result, updateBlock: boolean; |
431 begin |
435 begin |
432 Result:= false; |
436 Result:= false; |
433 |
437 |
434 for y:= 0 to LAND_HEIGHT div 32 - 1 do |
438 for y:= 0 to LAND_HEIGHT div 32 - 1 do |
435 begin |
439 begin |
436 updatedRow:= false; |
|
437 |
440 |
438 for x:= 0 to LAND_WIDTH div 32 - 1 do |
441 for x:= 0 to LAND_WIDTH div 32 - 1 do |
439 begin |
442 begin |
440 repeat |
443 if LandDirty[y, x] <> 0 then |
441 updatedCell:= false; |
444 begin |
442 if LandDirty[y, x] <> 0 then |
445 updateBlock:= false; |
443 begin |
446 for yy:= y * 32 to y * 32 + 31 do |
444 updatedRow:= true; |
447 for xx:= x * 32 to x * 32 + 31 do |
445 // testing. should make black squares |
448 if Despeckle(xx, yy) then |
446 for yy:= y * 32 to y * 32 + 31 do |
449 begin |
447 for xx:= x * 32 to x * 32 + 31 do |
450 Result:= true; |
448 if Despeckle(xx, yy) then updatedCell:= true; |
451 updateBlock:= true; |
449 end; |
452 end; |
450 if updatedCell then updatedRow:= true |
453 if updateBlock then UpdateLandTexture(x * 32, 32, y * 32, 32); |
451 until not updatedCell; |
454 LandDirty[y, x]:= 0; |
452 LandDirty[y, x]:= 0; |
455 end; |
453 end; |
456 end; |
454 |
|
455 if updatedRow then |
|
456 begin |
|
457 UpdateLandTexture(x * 32, 32, y * 32, 32); |
|
458 Result:= true |
|
459 end |
|
460 end; |
457 end; |
461 |
458 |
462 SweepDirty:= Result |
459 SweepDirty:= Result |
463 end; |
460 end; |
464 |
461 |