Give object to a random object-liking monster on or adjacent to x,y but skipping hero's location. If no such monster, place object on floor at x,y. */
| 223 | but skipping hero's location. |
| 224 | If no such monster, place object on floor at x,y. */ |
| 225 | staticfn void |
| 226 | give_to_nearby_mon(struct obj *otmp, coordxy x, coordxy y) |
| 227 | { |
| 228 | struct monst *mtmp; |
| 229 | struct monst *selected = (struct monst *) 0; |
| 230 | int nmon = 0, xx, yy; |
| 231 | |
| 232 | for (xx = x - 1; xx <= x + 1; ++xx) { |
| 233 | for (yy = y - 1; yy <= y + 1; ++yy) { |
| 234 | if (!isok(xx, yy)) |
| 235 | continue; |
| 236 | if (u_at(xx, yy)) |
| 237 | continue; |
| 238 | if (!(mtmp = m_at(xx, yy))) |
| 239 | continue; |
| 240 | /* This doesn't do any checks on otmp to see that it matches the |
| 241 | * likes_* property, intentionally. Assume that the monster is |
| 242 | * rifling through and taking things that look interesting. */ |
| 243 | if (!(likes_gold(mtmp->data) || likes_gems(mtmp->data) |
| 244 | || likes_objs(mtmp->data) || likes_magic(mtmp->data))) |
| 245 | continue; |
| 246 | nmon++; |
| 247 | if (!rn2(nmon)) |
| 248 | selected = mtmp; |
| 249 | } |
| 250 | } |
| 251 | if (selected && can_carry(selected, otmp)) |
| 252 | add_to_minv(selected, otmp); |
| 253 | else |
| 254 | place_object(otmp, x, y); |
| 255 | } |
| 256 | |
| 257 | /* called by savebones(); also by finish_paybill(shk.c) */ |
| 258 | void |
no test coverage detected