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

Function nextoid

src/mkobj.c:535–551  ·  view source on GitHub ↗

when splitting a stack that has o_id-based shop prices, pick an o_id value for the new stack that will maintain the same price */

Source from the content-addressed store, hash-verified

533/* when splitting a stack that has o_id-based shop prices, pick an
534 o_id value for the new stack that will maintain the same price */
535staticfn unsigned
536nextoid(struct obj *oldobj, struct obj *newobj)
537{
538 int olddif, newdif, trylimit = 256; /* limit of 4 suffices at present */
539 unsigned oid = svc.context.ident - 1; /* loop increment will reverse -1 */
540
541 olddif = oid_price_adjustment(oldobj, oldobj->o_id);
542 do {
543 ++oid;
544 if (!oid) /* avoid using 0 (in case value wrapped) */
545 ++oid;
546 newdif = oid_price_adjustment(newobj, oid);
547 } while (newdif != olddif && --trylimit >= 0);
548 svc.context.ident = oid; /* update 'last ident used' */
549 (void) next_ident(); /* increment context.ident for next use */
550 return oid; /* caller will use this ident */
551}
552
553/* try to find the stack obj was split from, then merge them back together;
554 returns the combined object if unsplit is successful, null otherwise */

Callers 2

splitobjFunction · 0.85
bill_dummy_objectFunction · 0.85

Calls 2

oid_price_adjustmentFunction · 0.85
next_identFunction · 0.85

Tested by

no test coverage detected