have guard pick gold off the floor, possibly moving to the gold's position before message and back to his current spot after */
| 749 | /* have guard pick gold off the floor, possibly moving to the gold's |
| 750 | position before message and back to his current spot after */ |
| 751 | staticfn void |
| 752 | gd_pick_corridor_gold(struct monst *grd, int goldx, int goldy) |
| 753 | { |
| 754 | struct obj *gold; |
| 755 | coord newcc, bestcc; |
| 756 | int gdelta, newdelta, bestdelta, tryct, |
| 757 | guardx = grd->mx, guardy = grd->my; |
| 758 | boolean under_u = u_at(goldx, goldy), |
| 759 | see_it = cansee(goldx, goldy); |
| 760 | |
| 761 | if (under_u) { |
| 762 | /* Grab the gold from between the hero's feet. |
| 763 | If guard is two or more steps away; bring him closer first. */ |
| 764 | gold = g_at(goldx, goldy); |
| 765 | if (!gold) { |
| 766 | impossible("vault guard: no gold at hero's feet?"); |
| 767 | return; |
| 768 | } |
| 769 | gdelta = distu(guardx, guardy); |
| 770 | if (gdelta > 2 && see_it) { /* skip if player won't see it */ |
| 771 | bestdelta = gdelta; |
| 772 | bestcc.x = (coordxy) guardx, bestcc.y = (coordxy) guardy; |
| 773 | tryct = 9; |
| 774 | do { |
| 775 | /* pick an available spot nearest the hero and also try |
| 776 | to find the one meeting that criterium which is nearest |
| 777 | the guard's current location */ |
| 778 | if (enexto(&newcc, goldx, goldy, grd->data)) { |
| 779 | if ((newdelta = distu(newcc.x, newcc.y)) < bestdelta |
| 780 | || (newdelta == bestdelta |
| 781 | && dist2(newcc.x, newcc.y, guardx, guardy) |
| 782 | < dist2(bestcc.x, bestcc.y, guardx, guardy))) { |
| 783 | bestdelta = newdelta; |
| 784 | bestcc = newcc; |
| 785 | } |
| 786 | } |
| 787 | } while (--tryct >= 0); |
| 788 | |
| 789 | if (bestdelta < gdelta) { |
| 790 | remove_monster(guardx, guardy); |
| 791 | newsym(guardx, guardy); |
| 792 | place_monster(grd, (int) bestcc.x, (int) bestcc.y); |
| 793 | newsym(grd->mx, grd->my); |
| 794 | } |
| 795 | } |
| 796 | obj_extract_self(gold); |
| 797 | add_to_minv(grd, gold); |
| 798 | newsym(goldx, goldy); |
| 799 | |
| 800 | /* guard is already at gold's location */ |
| 801 | } else if (goldx == guardx && goldy == guardy) { |
| 802 | mpickgold(grd); /* does a newsym */ |
| 803 | |
| 804 | /* gold is at some third spot, neither guard's nor hero's */ |
| 805 | } else { |
| 806 | /* just for insurance... */ |
| 807 | gd_mv_monaway(grd, goldx, goldy); /* make room for guard */ |
| 808 | if (see_it) { /* skip if player won't see the message */ |
no test coverage detected