fix #H6942 - dropx vs hold_another_object

Dropping an existing fragile item while levitating will usually
break it.  Getting a new wished-for fragile item and dropping it
because of fumbling or overfull inventory never would.

Some callers of hold_another_object() held on to its return value,
others discarded that.  That return value was unsafe if the item
was dropped and fell down a hole (or broke [after this change]).
Return Null if we can't be sure of the value, and make sure all
callers are prepared to deal with Null.
This commit is contained in:
PatR
2018-12-23 12:37:26 -08:00
parent df5dc6050d
commit 7bc36ddef4
11 changed files with 68 additions and 47 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 artifact.c $NHDT-Date: 1543745353 2018/12/02 10:09:13 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.127 $ */
/* NetHack 3.6 artifact.c $NHDT-Date: 1545597414 2018/12/23 20:36:54 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.128 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2013. */
/* NetHack may be freely redistributed. See license for details. */
@@ -1479,6 +1479,7 @@ struct obj *obj;
}
case ENERGY_BOOST: {
int epboost = (u.uenmax + 1 - u.uen) / 2;
if (epboost > 120)
epboost = 120; /* arbitrary */
else if (epboost < 12)
@@ -1598,6 +1599,7 @@ struct obj *obj;
otmp->owt = weight(otmp);
otmp = hold_another_object(otmp, "Suddenly %s out.",
aobjnam(otmp, "fall"), (char *) 0);
nhUse(otmp);
break;
}
}
@@ -1621,7 +1623,7 @@ struct obj *obj;
}
if ((eprop & ~W_ARTI) || iprop) {
nothing_special:
nothing_special:
/* you had the property from some other source too */
if (carried(obj))
You_feel("a surge of power, but nothing seems to happen.");
@@ -1975,7 +1977,7 @@ boolean loseit; /* whether to drop it if hero can longer touch it */
if (loseit && obj) {
if (Levitation) {
freeinv(obj);
hitfloor(obj);
hitfloor(obj, TRUE);
} else {
/* dropx gives a message iff item lands on an altar */
if (!IS_ALTAR(levl[u.ux][u.uy].typ))