From: cohrs <cohrs>
Date: Tue, 2 Apr 2002 05:32:02 +0000 (+0000)
Subject: ensure touch_artifact is always called via hold_another_object
X-Git-Tag: MOVE2GIT~2822
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5c1ea899bf58a7c413df3cc039621f8b501dee1c;p=nethack

ensure touch_artifact is always called via hold_another_object
- remove the touch_artifact calls just added
- put a check into hold_another_object itself, based on the complete check
removed from makewish
---

diff --git a/src/apply.c b/src/apply.c
index f95cd1f4a..7e41f1e11 100644
--- a/src/apply.c
+++ b/src/apply.c
@@ -2267,10 +2267,7 @@ struct obj *obj;
 			pline("Snatching %s is a fatal mistake.", kbuf);
 			instapetrify(kbuf);
 		    }
-		    if (!touch_artifact(otmp, &youmonst))
-			dropy(otmp);
-		    else
-			otmp = hold_another_object(otmp, "You drop %s!",
+		    otmp = hold_another_object(otmp, "You drop %s!",
 					       doname(otmp), (const char *)0);
 		    break;
 		default:
diff --git a/src/invent.c b/src/invent.c
index 87b9b96d6..27ceffd0f 100644
--- a/src/invent.c
+++ b/src/invent.c
@@ -365,10 +365,12 @@ struct obj *obj;
 #endif /* OVL1 */
 #ifdef OVLB
 
-/* Add an item to the inventory unless we're fumbling, and give a message.
+/* Add an item to the inventory unless we're fumbling or it refuses to be
+ * held (via touch_artifact), and give a message.
  * If there aren't any free inventory slots, we'll drop it instead.
  * If both success and failure messages are NULL, then we're just doing the
- * fumbling/slot-limit checking for a silent grab.
+ * fumbling/slot-limit checking for a silent grab.  In any case,
+ * touch_artifact will print its own messages if they are warranted.
  */
 struct obj *
 hold_another_object(obj, drop_fmt, drop_arg, hold_msg)
@@ -378,12 +380,32 @@ const char *drop_fmt, *drop_arg, *hold_msg;
 	char buf[BUFSZ];
 
 	if (!Blind) obj->dknown = 1;	/* maximize mergibility */
+	if (obj->oartifact) {
+	    /* place_object may change these */
+	    boolean crysknife = (obj->otyp == CRYSKNIFE);
+	    int oerode = obj->oerodeproof;
+
+	    /* in case touching this object turns out to be fatal */
+	    place_object(obj, u.ux, u.uy);
+
+	    if (!touch_artifact(obj, &youmonst)) {
+		obj_extract_self(obj);	/* remove it from the floor */
+		dropy(obj);		/* now put it back again :-) */
+		return obj;
+	    }
+	    obj_extract_self(obj);
+	    if (crysknife) {
+		obj->otyp = CRYSKNIFE;
+		obj->oerodeproof = oerode;
+	    }
+	}
 	if (Fumbling) {
 		if (drop_fmt) pline(drop_fmt, drop_arg);
 		dropy(obj);
 	} else {
 		long oquan = obj->quan;
 		int prev_encumbr = near_capacity();	/* before addinv() */
+
 		/* encumbrance only matters if it would now become worse
 		   than max( current_value, stressed ) */
 		if (prev_encumbr < MOD_ENCUMBER) prev_encumbr = MOD_ENCUMBER;
diff --git a/src/uhitm.c b/src/uhitm.c
index c41083403..d2459cc35 100644
--- a/src/uhitm.c
+++ b/src/uhitm.c
@@ -1115,13 +1115,10 @@ struct attack *mattk;
 		    pline("%s finishes taking off %s suit.",
 			  Monnam(mdef), mhis(mdef));
 	    }
-	    if (!touch_artifact(otmp, &youmonst)) {
-		dropy(otmp);
-		continue;
-	    }
 	    /* give the object to the character */
 	    otmp = hold_another_object(otmp, "You steal %s.",
 				       doname(otmp), "You steal: ");
+	    if (otmp->where != OBJ_INVENT) continue;
 	    if (otmp->otyp == CORPSE &&
 		    touch_petrifies(&mons[otmp->corpsenm]) && !uarmg) {
 		char kbuf[BUFSZ];
diff --git a/src/zap.c b/src/zap.c
index ecf8a794a..87a104e24 100644
--- a/src/zap.c
+++ b/src/zap.c
@@ -4055,24 +4055,8 @@ retry:
 	u.uconduct.wishes++;
 
 	if (otmp != &zeroobj) {
-	    /* place_object looses these */
-	    boolean crysknife = (otmp->otyp == CRYSKNIFE);
-	    int oerode = otmp->oerodeproof;
-
-	    /* in case touching this object turns out to be fatal */
-	    place_object(otmp, u.ux, u.uy);
-
-	    if (otmp->oartifact && !touch_artifact(otmp,&youmonst)) {
-		obj_extract_self(otmp);	/* remove it from the floor */
-		dropy(otmp);		/* now put it back again :-) */
-	    } else {
-		obj_extract_self(otmp);
-		if (crysknife) {
-		    otmp->otyp = CRYSKNIFE;
-		    otmp->oerodeproof = oerode;
-		}
-		/* The(aobjnam()) is safe since otmp is unidentified -dlc */
-		(void) hold_another_object(otmp, u.uswallow ?
+	    /* The(aobjnam()) is safe since otmp is unidentified -dlc */
+	    (void) hold_another_object(otmp, u.uswallow ?
 				       "Oops!  %s out of your reach!" :
 				       (Is_airlevel(&u.uz) ||
 					Is_waterlevel(&u.uz) ||
@@ -4084,7 +4068,6 @@ retry:
 					     Is_airlevel(&u.uz) || u.uinwater ?
 						   "slip" : "drop")),
 				       (const char *)0);
-	    }
 	    u.ublesscnt += rn1(100,50);  /* the gods take notice */
 	}
 }