MCPcopy Create free account
hub / github.com/NetHack/NetHack / ghitm

Function ghitm

src/dokick.c:294–407  ·  view source on GitHub ↗

* Return TRUE if caught (the gold taken care of), FALSE otherwise. * The gold object is *not* attached to the fobj chain! */

Source from the content-addressed store, hash-verified

292 * The gold object is *not* attached to the fobj chain!
293 */
294boolean
295ghitm(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!");

Callers 2

throw_goldFunction · 0.85
really_kick_objectFunction · 0.85

Calls 15

wakeupFunction · 0.85
canseemonFunction · 0.85
pline_TheFunction · 0.85
xnameFunction · 0.85
otenseFunction · 0.85
mon_namFunction · 0.85
finish_meatingFunction · 0.85
rn2Function · 0.85
setmangryFunction · 0.85
MonnamFunction · 0.85
mpickobjFunction · 0.85
make_happy_shkFunction · 0.85

Tested by

no test coverage detected