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

Function carry_count

src/pickup.c:1569–1701  ·  view source on GitHub ↗

could we carry `obj'? if not, could we carry some of it/them? */

Source from the content-addressed store, hash-verified

1567
1568/* could we carry `obj'? if not, could we carry some of it/them? */
1569staticfn long
1570carry_count(struct obj *obj, /* object to pick up... */
1571 struct obj *container, /* ...bag it is coming out of */
1572 long count,
1573 boolean telekinesis,
1574 int *wt_before, int *wt_after)
1575{
1576 boolean adjust_wt = container && carried(container),
1577 is_gold = obj->oclass == COIN_CLASS;
1578 int wt, iw, ow, oow;
1579 long qq, savequan, umoney;
1580 unsigned saveowt;
1581 const char *verb, *prefx1, *prefx2, *suffx;
1582 char obj_nambuf[BUFSZ], where[BUFSZ];
1583
1584 savequan = obj->quan;
1585 saveowt = obj->owt;
1586 umoney = money_cnt(gi.invent);
1587 iw = max_capacity();
1588
1589 if (count != savequan) {
1590 obj->quan = count;
1591 obj->owt = (unsigned) weight(obj);
1592 }
1593 wt = iw + (int) obj->owt;
1594 if (adjust_wt)
1595 wt -= delta_cwt(container, obj);
1596 /* This will go with silver+copper & new gold weight */
1597 if (is_gold) /* merged gold might affect cumulative weight */
1598 wt -= (GOLD_WT(umoney) + GOLD_WT(count) - GOLD_WT(umoney + count));
1599 if (count != savequan) {
1600 obj->quan = savequan;
1601 obj->owt = saveowt;
1602 }
1603 *wt_before = iw;
1604 *wt_after = wt;
1605
1606 if (wt < 0)
1607 return count;
1608
1609 /* see how many we can lift */
1610 if (is_gold) {
1611 iw -= (int) GOLD_WT(umoney);
1612 if (!adjust_wt) {
1613 qq = GOLD_CAPACITY((long) iw, umoney);
1614 } else {
1615 oow = 0;
1616 qq = 50L - (umoney % 100L) - 1L;
1617 if (qq < 0L)
1618 qq += 100L;
1619 for (; qq <= count; qq += 100L) {
1620 obj->quan = qq;
1621 obj->owt = (unsigned) GOLD_WT(qq);
1622 ow = (int) GOLD_WT(umoney + qq);
1623 ow -= delta_cwt(container, obj);
1624 if (iw + ow >= 0)
1625 break;
1626 oow = ow;

Callers 2

lift_objectFunction · 0.85
pickup_objectFunction · 0.85

Calls 10

money_cntFunction · 0.85
max_capacityFunction · 0.85
weightFunction · 0.85
delta_cwtFunction · 0.85
donameFunction · 0.85
theFunction · 0.85
xnameFunction · 0.85
YouFunction · 0.85
ThereFunction · 0.85
otenseFunction · 0.85

Tested by

no test coverage detected