]> granicus.if.org Git - nethack/commitdiff
ensure touch_artifact is always called via hold_another_object
authorcohrs <cohrs>
Tue, 2 Apr 2002 05:32:02 +0000 (05:32 +0000)
committercohrs <cohrs>
Tue, 2 Apr 2002 05:32:02 +0000 (05:32 +0000)
- remove the touch_artifact calls just added
- put a check into hold_another_object itself, based on the complete check
removed from makewish

src/apply.c
src/invent.c
src/uhitm.c
src/zap.c

index f95cd1f4a9be098015a9cbd75216006ccb878e0b..7e41f1e11b2a21fc9723f9116c7b69cbff67ac92 100644 (file)
@@ -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:
index 87b9b96d6625848fd4f8b571070c3cda704a25df..27ceffd0fc4eecbfb96c34aaf6721f0c8ff69e8b 100644 (file)
@@ -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;
index c41083403357eabdb24027622e82c27862f6453a..d2459cc35c5b0b0539eb233c2804768ff6ceecc8 100644 (file)
@@ -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];
index ecf8a794ac1cc8aaba3ec9b1da7499d02aa08978..87a104e24755359e051f529b92032a84dba26e8d 100644 (file)
--- 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 */
        }
 }