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

Function can_carry

src/mon.c:1989–2053  ·  view source on GitHub ↗

for restricting monsters' object-pickup. * * to support the new pet behavior, this now returns the max # of objects * that a given monster could pick up from a pile. frequently this will be * otmp->quan, but special cases for 'only one' now exist. * * this will probably cause very amusing behavior with pets and gold coins. * * TODO: allow picking up 2-N objects from a pile of N based on we

Source from the content-addressed store, hash-verified

1987 * likesgold handling m_move results in picking up the whole stack.
1988 */
1989int
1990can_carry(struct monst *mtmp, struct obj *otmp)
1991{
1992 int iquan, otyp = otmp->otyp, newload = otmp->owt;
1993 struct permonst *mdat = mtmp->data;
1994 short nattk = 0;
1995
1996 if (notake(mdat))
1997 return 0; /* can't carry anything */
1998
1999 if (!can_touch_safely(mtmp, otmp))
2000 return 0;
2001
2002 /* hostile monsters who like gold will pick up the whole stack;
2003 tame monsters with hands will pick up the partial stack */
2004 iquan = (otmp->quan > (long) LARGEST_INT)
2005 ? 20000 + rn2(LARGEST_INT - 20000 + 1)
2006 : (int) otmp->quan;
2007
2008 /* monsters without hands can't pick up multiple objects at once
2009 * unless they have an engulfing attack
2010 *
2011 * ...dragons, of course, can always carry gold pieces and gems somehow
2012 */
2013 if (iquan > 1) {
2014 boolean glomper = FALSE;
2015
2016 if (mtmp->data->mlet == S_DRAGON
2017 && (otmp->oclass == COIN_CLASS
2018 || otmp->oclass == GEM_CLASS))
2019 glomper = TRUE;
2020 else
2021 for (nattk = 0; nattk < NATTK; nattk++)
2022 if (mtmp->data->mattk[nattk].aatyp == AT_ENGL) {
2023 glomper = TRUE;
2024 break;
2025 }
2026 if ((mtmp->data->mflags1 & M1_NOHANDS) && !glomper)
2027 return 1;
2028 }
2029
2030 /* steeds don't pick up stuff (to avoid shop abuse) */
2031 if (mtmp == u.usteed)
2032 return 0;
2033 if (mtmp->isshk)
2034 return iquan; /* no limit */
2035 if (mtmp->mpeaceful && !mtmp->mtame)
2036 return 0;
2037 /* otherwise players might find themselves obligated to violate
2038 * their alignment if the monster takes something they need
2039 */
2040
2041 /* special--boulder throwers carry unlimited amounts of boulders */
2042 if (throws_rocks(mdat) && otyp == BOULDER)
2043 return iquan;
2044
2045 /* nymphs deal in stolen merchandise, but not boulders or statues */
2046 if (mdat->mlet == S_NYMPH)

Callers 7

give_to_nearby_monFunction · 0.85
stealFunction · 0.85
dog_inventFunction · 0.85
dog_goalFunction · 0.85
mpickstuffFunction · 0.85
m_search_itemsFunction · 0.85
mloot_containerFunction · 0.85

Calls 4

can_touch_safelyFunction · 0.85
rn2Function · 0.85
curr_mon_loadFunction · 0.85
max_mon_loadFunction · 0.85

Tested by

no test coverage detected