equal
deleted
inserted
replaced
617 TryPut:= bRes; |
617 TryPut:= bRes; |
618 end; |
618 end; |
619 |
619 |
620 function TryPut2(var Obj: TSprayObject; Surface: PSDL_Surface): boolean; |
620 function TryPut2(var Obj: TSprayObject; Surface: PSDL_Surface): boolean; |
621 const MaxPointsIndex = 8095; |
621 const MaxPointsIndex = 8095; |
622 var x, y: Longword; |
622 var x, y, xStart, yStart: Longword; |
|
623 xWraps, yWraps: Byte; |
623 ar: array[0..MaxPointsIndex] of TPoint; |
624 ar: array[0..MaxPointsIndex] of TPoint; |
624 cnt, i: Longword; |
625 cnt, i: Longword; |
625 r: TSDL_Rect; |
626 r: TSDL_Rect; |
626 bRes: boolean; |
627 bRes: boolean; |
627 begin |
628 begin |
629 cnt:= 0; |
630 cnt:= 0; |
630 with Obj do |
631 with Obj do |
631 begin |
632 begin |
632 if Maxcnt = 0 then |
633 if Maxcnt = 0 then |
633 exit; |
634 exit; |
634 x:= 0; |
635 xWraps:= 0; |
|
636 yWraps:= 0; |
|
637 // Start at random coordinates |
|
638 xStart:= getrandom(LAND_WIDTH - Width); |
|
639 yStart:= 8 + getrandom(LAND_HEIGHT - Height - 16); |
|
640 x:= xStart; |
|
641 y:= yStart; |
635 r.x:= 0; |
642 r.x:= 0; |
636 r.y:= 0; |
643 r.y:= 0; |
637 r.w:= Width; |
644 r.w:= Width; |
638 r.h:= Height + 16; |
645 r.h:= Height + 16; |
|
646 // Then iterate through the whole map; this requires we wrap one time per axis |
639 repeat |
647 repeat |
640 y:= 8; |
648 yWraps:= 0; |
641 repeat |
649 repeat |
642 if CheckLand(r, x, y - 8, lfBasic) |
650 if CheckLand(r, x, y - 8, lfBasic) |
643 and (not CheckIntersect(x, y, Width, Height)) then |
651 and (not CheckIntersect(x, y, Width, Height)) then |
644 begin |
652 begin |
645 ar[cnt].x:= x; |
653 ar[cnt].x:= x; |
650 x:= $FF000000; |
658 x:= $FF000000; |
651 end |
659 end |
652 else inc(cnt); |
660 else inc(cnt); |
653 end; |
661 end; |
654 inc(y, 12); |
662 inc(y, 12); |
655 until y >= LAND_HEIGHT - Height - 8; |
663 if (y >= LAND_HEIGHT - Height - 8) or ((yWraps > 0) and (y >= yStart)) then |
656 inc(x, getrandom(12) + 12) |
664 begin |
657 until x >= LAND_WIDTH - Width; |
665 inc(yWraps); |
|
666 y:= 8; |
|
667 end; |
|
668 until yWraps > 1; |
|
669 inc(x, getrandom(12) + 12); |
|
670 if (x >= LAND_WIDTH - Width) or ((xWraps > 0) and (x >= xStart)) then |
|
671 begin |
|
672 inc(xWraps); |
|
673 x:= 0; |
|
674 end; |
|
675 until xWraps > 1; |
658 bRes:= cnt <> 0; |
676 bRes:= cnt <> 0; |
659 if bRes then |
677 if bRes then |
660 begin |
678 begin |
661 i:= getrandom(cnt); |
679 i:= getrandom(cnt); |
662 copyToXY(Obj.Surf, Surface, ar[i].X, ar[i].Y); |
680 copyToXY(Obj.Surf, Surface, ar[i].X, ar[i].Y); |