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

Function canwearobj

src/do_wear.c:2029–2206  ·  view source on GitHub ↗

* canwearobj checks to see whether the player can wear a piece of armor * * inputs: otmp (the piece of armor) * noisy (if TRUE give error messages, otherwise be quiet about it) * output: mask (otmp's armor type) */

Source from the content-addressed store, hash-verified

2027 * output: mask (otmp's armor type)
2028 */
2029int
2030canwearobj(struct obj *otmp, long *mask, boolean noisy)
2031{
2032 int err = 0;
2033 const char *which;
2034
2035 /* this is the same check as for 'W' (dowear), but different message,
2036 in case we get here via 'P' (doputon) */
2037 if (verysmall(gy.youmonst.data) || nohands(gy.youmonst.data)) {
2038 if (noisy)
2039 You("can't wear any armor in your current form.");
2040 return 0;
2041 }
2042
2043 which = is_cloak(otmp) ? c_cloak
2044 : is_shirt(otmp) ? c_shirt
2045 : is_suit(otmp) ? c_suit
2046 : 0;
2047 if (which && cantweararm(gy.youmonst.data)
2048 /* same exception for cloaks as used in m_dowear() */
2049 && (which != c_cloak
2050 || ((otmp->otyp != MUMMY_WRAPPING)
2051 ? gy.youmonst.data->msize != MZ_SMALL
2052 : !WrappingAllowed(gy.youmonst.data)))
2053 && (racial_exception(&gy.youmonst, otmp) < 1)) {
2054 if (noisy)
2055 pline_The("%s will not fit on your body.", which);
2056 return 0;
2057 } else if (otmp->owornmask & W_ARMOR) {
2058 if (noisy)
2059 already_wearing(c_that_);
2060 return 0;
2061 }
2062
2063 if (welded(uwep) && bimanual(uwep) && (is_suit(otmp) || is_shirt(otmp))) {
2064 if (noisy)
2065 You("cannot do that while holding your %s.",
2066 is_sword(uwep) ? c_sword : c_weapon);
2067 return 0;
2068 }
2069
2070 if (is_helmet(otmp)) {
2071 if (uarmh) {
2072 if (noisy)
2073 already_wearing(an(helm_simple_name(uarmh)));
2074 err++;
2075 } else if (Upolyd && has_horns(gy.youmonst.data) && !is_flimsy(otmp)) {
2076 /* (flimsy exception matches polyself handling) */
2077 if (noisy)
2078 pline_The("%s won't fit over your horn%s.",
2079 helm_simple_name(otmp),
2080 plur(num_horns(gy.youmonst.data)));
2081 err++;
2082 } else
2083 *mask = W_ARMH;
2084 } else if (is_shield(otmp)) {
2085 if (uarms) {
2086 if (noisy)

Callers 2

accessory_or_armor_onFunction · 0.85
equip_okFunction · 0.85

Calls 15

YouFunction · 0.85
racial_exceptionFunction · 0.85
pline_TheFunction · 0.85
already_wearingFunction · 0.85
weldedFunction · 0.85
anFunction · 0.85
helm_simple_nameFunction · 0.85
num_hornsFunction · 0.85
YourFunction · 0.85
body_partFunction · 0.85
makepluralFunction · 0.85
surfaceFunction · 0.85

Tested by

no test coverage detected