MCPcopy Index your code
hub / github.com/NetHack/NetHack / gold_detect

Function gold_detect

src/detect.c:334–475  ·  view source on GitHub ↗

look for gold, on the floor or in monsters' possession */

Source from the content-addressed store, hash-verified

332
333/* look for gold, on the floor or in monsters' possession */
334int
335gold_detect(struct obj *sobj)
336{
337 struct obj *obj;
338 struct monst *mtmp;
339 struct obj gold, *temp = 0;
340 boolean stale, ugold = FALSE, steedgold = FALSE;
341 int ter_typ = TER_DETECT | TER_OBJ;
342
343 gk.known = stale = clear_stale_map(COIN_CLASS,
344 (unsigned) (sobj->blessed ? GOLD : 0));
345
346 /* look for gold carried by monsters (might be in a container) */
347 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
348 if (DEADMONSTER(mtmp) || (mtmp->isgd && !mtmp->mx))
349 continue;
350 if (findgold(mtmp->minvent) || monsndx(mtmp->data) == PM_GOLD_GOLEM) {
351 if (mtmp == u.usteed) {
352 steedgold = TRUE;
353 } else {
354 gk.known = TRUE;
355 goto outgoldmap; /* skip further searching */
356 }
357 } else {
358 for (obj = mtmp->minvent; obj; obj = obj->nobj)
359 if ((sobj->blessed && o_material(obj, GOLD))
360 || o_in(obj, COIN_CLASS)) {
361 if (mtmp == u.usteed) {
362 steedgold = TRUE;
363 } else {
364 gk.known = TRUE;
365 goto outgoldmap; /* skip further searching */
366 }
367 }
368 }
369 }
370
371 /* look for gold objects */
372 for (obj = fobj; obj; obj = obj->nobj) {
373 if (sobj->blessed && o_material(obj, GOLD)) {
374 gk.known = TRUE;
375 if (obj->ox != u.ux || obj->oy != u.uy)
376 goto outgoldmap;
377 } else if (o_in(obj, COIN_CLASS)) {
378 gk.known = TRUE;
379 if (obj->ox != u.ux || obj->oy != u.uy)
380 goto outgoldmap;
381 }
382 }
383
384 if (!gk.known) {
385 /* no gold found on floor or monster's inventory.
386 adjust message if you have gold in your inventory */
387 char buf[BUFSZ];
388
389 if (gy.youmonst.data == &mons[PM_GOLD_GOLEM])
390 Sprintf(buf, "You feel like a million %s!", currency(2L));
391 else if (money_cnt(gi.invent) || hidden_gold(TRUE))

Callers 1

seffect_gold_detectionFunction · 0.85

Calls 15

clear_stale_mapFunction · 0.85
findgoldFunction · 0.85
o_materialFunction · 0.85
o_inFunction · 0.85
currencyFunction · 0.85
money_cntFunction · 0.85
hidden_goldFunction · 0.85
s_suffixFunction · 0.85
strange_feelingFunction · 0.85
docrtFunction · 0.85
YouFunction · 0.85
makepluralFunction · 0.85

Tested by

no test coverage detected