* Return TRUE if caught (the gold taken care of), FALSE otherwise. * The gold object is *not* attached to the fobj chain! */
| 292 | * The gold object is *not* attached to the fobj chain! |
| 293 | */ |
| 294 | boolean |
| 295 | ghitm(struct monst *mtmp, struct obj *gold) |
| 296 | { |
| 297 | boolean msg_given = FALSE; |
| 298 | |
| 299 | if (!likes_gold(mtmp->data) && !mtmp->isshk && !mtmp->ispriest |
| 300 | && !mtmp->isgd && !is_mercenary(mtmp->data)) { |
| 301 | wakeup(mtmp, TRUE); |
| 302 | } else if (!mtmp->mcanmove) { |
| 303 | /* too light to do real damage */ |
| 304 | if (canseemon(mtmp)) { |
| 305 | pline_The("%s harmlessly %s %s.", xname(gold), |
| 306 | otense(gold, "hit"), mon_nam(mtmp)); |
| 307 | msg_given = TRUE; |
| 308 | } |
| 309 | } else { |
| 310 | unsigned was_sleeping = mtmp->msleeping; |
| 311 | long umoney, value = gold->quan * objects[gold->otyp].oc_cost; |
| 312 | |
| 313 | mtmp->msleeping = 0; /* end indeterminate sleep (won't get here |
| 314 | * for temporary--counted--sleep since that |
| 315 | * uses mfrozen and mfrozen implies !mcanmove) */ |
| 316 | finish_meating(mtmp); |
| 317 | if (!mtmp->isgd && !rn2(4)) /* not always pleasing */ |
| 318 | setmangry(mtmp, TRUE); |
| 319 | /* greedy monsters catch gold */ |
| 320 | if (cansee(mtmp->mx, mtmp->my)) |
| 321 | pline("%s %scatches the gold.", Monnam(mtmp), |
| 322 | was_sleeping ? "awakens and " : ""); |
| 323 | (void) mpickobj(mtmp, gold); |
| 324 | gold = (struct obj *) 0; /* obj has been freed */ |
| 325 | if (mtmp->isshk) { |
| 326 | long robbed = ESHK(mtmp)->robbed; |
| 327 | |
| 328 | if (robbed) { |
| 329 | robbed -= value; |
| 330 | if (robbed < 0L) |
| 331 | robbed = 0L; |
| 332 | pline_The("amount %scovers %s recent losses.", |
| 333 | !robbed ? "" : "partially ", mhis(mtmp)); |
| 334 | ESHK(mtmp)->robbed = robbed; |
| 335 | if (!robbed) |
| 336 | make_happy_shk(mtmp, FALSE); |
| 337 | } else { |
| 338 | SetVoice(mtmp, 0, 80, 0); |
| 339 | if (mtmp->mpeaceful) { |
| 340 | ESHK(mtmp)->credit += value; |
| 341 | You("have %ld %s in credit.", ESHK(mtmp)->credit, |
| 342 | currency(ESHK(mtmp)->credit)); |
| 343 | } else |
| 344 | verbalize("Thanks, scum!"); |
| 345 | } |
| 346 | } else if (mtmp->ispriest) { |
| 347 | SetVoice(mtmp, 0, 80, 0); |
| 348 | if (mtmp->mpeaceful) |
| 349 | verbalize("Thank you for your contribution."); |
| 350 | else |
| 351 | verbalize("Thanks, scum!"); |
no test coverage detected