* 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. */
| 1541 | * than trying to match the calculation used by weight() in mkobj.c. |
| 1542 | */ |
| 1543 | staticfn int |
| 1544 | delta_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? */ |
| 1569 | staticfn long |
no test coverage detected