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

Function gem_learned

src/shk.c:3197–3231  ·  view source on GitHub ↗

unlike alter_cost() which operates on a specific item, identifying or forgetting a gem causes all unpaid gems of its type to change value */

Source from the content-addressed store, hash-verified

3195/* unlike alter_cost() which operates on a specific item, identifying or
3196 forgetting a gem causes all unpaid gems of its type to change value */
3197void
3198gem_learned(int oindx)
3199{
3200 struct obj *obj;
3201 struct monst *shkp;
3202 struct bill_x *bp;
3203 int ct;
3204
3205 /*
3206 * Unfortunately, shop bill doesn't have object type included,
3207 * just obj->oid for each unpaid stack, so we have to go through
3208 * every bill and every item on that bill and match up against
3209 * every unpaid stack on the level....
3210 *
3211 * Fortunately, there's no need to catch up when changing dungeon
3212 * levels even if we ID'd or forget some gems while gone from a
3213 * level. There won't be any shop bills when arriving; they were
3214 * either paid before leaving or got treated as robbery and it's
3215 * too late to adjust pricing.
3216 */
3217 for (shkp = next_shkp(fmon, TRUE); shkp;
3218 shkp = next_shkp(shkp->nmon, TRUE)) {
3219 ct = ESHK(shkp)->billct;
3220 bp = ESHK(shkp)->bill_p;
3221 while (--ct >= 0) {
3222 obj = find_oid(bp->bo_id);
3223 if (!obj) /* shouldn't happen */
3224 continue;
3225 if ((oindx != STRANGE_OBJECT) ? (obj->otyp == oindx)
3226 : (obj->oclass == GEM_CLASS))
3227 bp->price = get_cost(obj, shkp);
3228 ++bp;
3229 }
3230 }
3231}
3232
3233/* called when an item's value has been enhanced; if it happens to be
3234 on any shop bill, update that bill to reflect the new higher price

Callers 2

discover_objectFunction · 0.85
undiscover_objectFunction · 0.85

Calls 3

next_shkpFunction · 0.85
find_oidFunction · 0.85
get_costFunction · 0.85

Tested by

no test coverage detected