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

Function emergency_disrobe

src/trap.c:4896–4941  ·  view source on GitHub ↗

* This function is potentially expensive - rolling * inventory list multiple times. Luckily it's seldom needed. * Returns TRUE if disrobing made player unencumbered enough to * crawl out of the current predicament. */

Source from the content-addressed store, hash-verified

4894 * crawl out of the current predicament.
4895 */
4896staticfn boolean
4897emergency_disrobe(boolean *lostsome)
4898{
4899 int invc = inv_cnt(TRUE);
4900
4901 while (near_capacity() > (Punished ? UNENCUMBERED : SLT_ENCUMBER)) {
4902 struct obj *obj, *nextobj, *otmp = (struct obj *) 0;
4903 int i;
4904
4905 /* Pick a random object */
4906 if (invc > 0) {
4907 i = rn2(invc);
4908 for (obj = gi.invent; obj; obj = nextobj) {
4909 nextobj = obj->nobj;
4910 /*
4911 * Undroppables are: body armor, boots, gloves,
4912 * amulets, and rings because of the time and effort
4913 * in removing them + loadstone and other cursed stuff
4914 * for obvious reasons. Also, any item in the midst
4915 * of being taken off or stolen.
4916 */
4917 if (!((obj->otyp == LOADSTONE && obj->cursed) || obj == uamul
4918 || obj == uleft || obj == uright || obj == ublindf
4919 || obj == uarm || obj == uarmc || obj == uarmg
4920 || obj == uarmf || obj == uarmu
4921 || (obj->cursed && (obj == uarmh || obj == uarms))
4922 || welded(obj)
4923 || obj->o_id == gs.stealoid || obj->in_use))
4924 otmp = obj;
4925 /* reached the mark and found some stuff to drop? */
4926 if (--i < 0 && otmp)
4927 break;
4928
4929 /* else continue */
4930 }
4931 }
4932 if (!otmp)
4933 return FALSE; /* nothing to drop! */
4934 if (otmp->owornmask)
4935 remove_worn_item(otmp, FALSE);
4936 *lostsome = TRUE;
4937 dropx(otmp);
4938 invc--;
4939 }
4940 return TRUE;
4941}
4942
4943/* pick a random goodpos() next to x,y for monster mtmp.
4944 mtmp could be &gy.youmonst, uses then crawl_destination().

Callers 1

drownFunction · 0.85

Calls 6

inv_cntFunction · 0.85
near_capacityFunction · 0.85
rn2Function · 0.85
weldedFunction · 0.85
remove_worn_itemFunction · 0.85
dropxFunction · 0.85

Tested by

no test coverage detected