* looks for objects of a particular type next to x, y * skips over oid if found (lets us avoid ourselves if * we're looking for a second type of an existing object) * * TODO: return a list of all objects near us so we can more * reliably predict which one we want to 'find' first */
| 3658 | * reliably predict which one we want to 'find' first |
| 3659 | */ |
| 3660 | struct obj * |
| 3661 | obj_nexto_xy(struct obj *obj, coordxy x, coordxy y, boolean recurs) |
| 3662 | { |
| 3663 | struct obj *otmp; |
| 3664 | int fx, fy, ex, ey, otyp = obj->otyp; |
| 3665 | short dx, dy; |
| 3666 | |
| 3667 | /* check under our "feet" first */ |
| 3668 | otmp = sobj_at(otyp, x, y); |
| 3669 | while (otmp) { |
| 3670 | /* don't be clever and find ourselves */ |
| 3671 | if (otmp != obj && mergable(otmp, obj)) |
| 3672 | return otmp; |
| 3673 | otmp = nxtobj(otmp, otyp, TRUE); |
| 3674 | } |
| 3675 | |
| 3676 | if (!recurs) |
| 3677 | return (struct obj *) 0; |
| 3678 | |
| 3679 | /* search in a random order */ |
| 3680 | dx = (rn2(2) ? -1 : 1); |
| 3681 | dy = (rn2(2) ? -1 : 1); |
| 3682 | ex = x - dx; |
| 3683 | ey = y - dy; |
| 3684 | |
| 3685 | for (fx = ex; abs(fx - ex) < 3; fx += dx) { |
| 3686 | for (fy = ey; abs(fy - ey) < 3; fy += dy) { |
| 3687 | /* 0, 0 was checked above */ |
| 3688 | if (isok(fx, fy) && (fx != x || fy != y)) { |
| 3689 | if ((otmp = obj_nexto_xy(obj, fx, fy, FALSE)) != 0) |
| 3690 | return otmp; |
| 3691 | } |
| 3692 | } |
| 3693 | } |
| 3694 | return (struct obj *) 0; |
| 3695 | } |
| 3696 | |
| 3697 | /* |
| 3698 | * Causes one object to absorb another, increasing weight |