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

Function equip_ok

src/do_wear.c:3403–3447  ·  view source on GitHub ↗

not a getobj callback - unifies code among the other 4 getobj callbacks */

Source from the content-addressed store, hash-verified

3401
3402/* not a getobj callback - unifies code among the other 4 getobj callbacks */
3403staticfn int
3404equip_ok(struct obj *obj, boolean removing, boolean accessory)
3405{
3406 boolean is_worn;
3407 long dummymask = 0;
3408
3409 if (!obj)
3410 return GETOBJ_EXCLUDE;
3411
3412 /* ignore for putting on if already worn, or removing if not worn */
3413 is_worn = ((obj->owornmask & (W_ARMOR | W_ACCESSORY)) != 0);
3414 if (removing ^ is_worn)
3415 return GETOBJ_EXCLUDE_INACCESS;
3416
3417 /* exclude most object classes outright */
3418 if (obj->oclass != ARMOR_CLASS && obj->oclass != RING_CLASS
3419 && obj->oclass != AMULET_CLASS) {
3420 /* ... except for a few wearable exceptions outside these classes */
3421 if (obj->otyp != MEAT_RING && obj->otyp != BLINDFOLD
3422 && obj->otyp != TOWEL && obj->otyp != LENSES)
3423 return GETOBJ_EXCLUDE;
3424 }
3425
3426 /* armor with 'P' or 'R' or accessory with 'W' or 'T' */
3427 if (accessory ^ (obj->oclass != ARMOR_CLASS))
3428 return GETOBJ_DOWNPLAY;
3429
3430 /* armor we can't wear, e.g. from polyform */
3431 if (obj->oclass == ARMOR_CLASS && !removing
3432 && !canwearobj(obj, &dummymask, FALSE))
3433 return GETOBJ_DOWNPLAY;
3434
3435 /* Possible extension: downplay items (both accessories and armor) which
3436 * can't be worn because the slot is filled with something else. */
3437
3438 /* removing inaccessible equipment */
3439 if (removing && !gi.item_action_in_progress) {
3440 if (inaccessible_equipment(obj, (const char *) 0,
3441 (obj->oclass == RING_CLASS)))
3442 return GETOBJ_EXCLUDE_INACCESS;
3443 }
3444
3445 /* all good to go */
3446 return GETOBJ_SUGGEST;
3447}
3448
3449/* getobj callback for P command */
3450staticfn int

Callers 4

puton_okFunction · 0.85
remove_okFunction · 0.85
wear_okFunction · 0.85
takeoff_okFunction · 0.85

Calls 2

canwearobjFunction · 0.85
inaccessible_equipmentFunction · 0.85

Tested by

no test coverage detected