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

Function delta_cwt

src/pickup.c:1543–1566  ·  view source on GitHub ↗

* How much the weight of the given container will change when the given * object is removed from it. Use before and after weight amounts rather * than trying to match the calculation used by weight() in mkobj.c. */

Source from the content-addressed store, hash-verified

1541 * than trying to match the calculation used by weight() in mkobj.c.
1542 */
1543staticfn int
1544delta_cwt(struct obj *container, struct obj *obj)
1545{
1546 struct obj **prev;
1547 int owt, nwt;
1548
1549 if (container->otyp != BAG_OF_HOLDING)
1550 return obj->owt;
1551
1552 owt = nwt = container->owt;
1553 /* find the object so that we can remove it */
1554 for (prev = &container->cobj; *prev; prev = &(*prev)->nobj)
1555 if (*prev == obj)
1556 break;
1557 if (!*prev) {
1558 panic("delta_cwt: obj not inside container?");
1559 } else {
1560 /* temporarily remove the object and calculate resulting weight */
1561 *prev = obj->nobj;
1562 nwt = weight(container);
1563 *prev = obj; /* put the object back; obj->nobj is still valid */
1564 }
1565 return owt - nwt;
1566}
1567
1568/* could we carry `obj'? if not, could we carry some of it/them? */
1569staticfn long

Callers 1

carry_countFunction · 0.85

Calls 2

weightFunction · 0.85
panicFunction · 0.50

Tested by

no test coverage detected