OSDN Git Service

finalize changelog
[jnethack/source.git] / src / lock.c
index 17c8112..b7b5bad 100644 (file)
@@ -1,11 +1,11 @@
-/* NetHack 3.6 lock.c  $NHDT-Date: 1521499715 2018/03/19 22:48:35 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.80 $ */
+/* NetHack 3.6 lock.c  $NHDT-Date: 1548978605 2019/01/31 23:50:05 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.84 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2011. */
 /* NetHack may be freely redistributed.  See license for details. */
 
 /* JNetHack Copyright */
 /* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000  */
-/* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2016            */
+/* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2022            */
 /* JNetHack may be freely redistributed.  See license for details. */
 
 #include "hack.h"
@@ -54,7 +54,7 @@ lock_action()
 {
     /* "unlocking"+2 == "locking" */
     static const char *actions[] = {
-#if 0 /*JP*/
+#if 0 /*JP:T*/
         "unlocking the door",   /* [0] */
         "unlocking the chest",  /* [1] */
         "unlocking the box",    /* [2] */
@@ -150,25 +150,42 @@ picklock(VOID_ARGS)
         /* unfortunately we don't have a 'tknown' flag to record
            "known to be trapped" so declining to disarm and then
            retrying lock manipulation will find it all over again */
+/*JP
         if (yn("You find a trap!  Do you want to try to disarm it?") == 'y') {
+*/
+        if (yn("ã©\82ð\8c©\82Â\82¯\82½\81I\8aO\82µ\82Ü\82·\82©\81H") == 'y') {
             const char *what;
             boolean alreadyunlocked;
 
             /* disarming while using magic key always succeeds */
             if (xlock.door) {
                 xlock.door->doormask &= ~D_TRAPPED;
+/*JP
                 what = "door";
+*/
+                what = "\94à";
                 alreadyunlocked = !(xlock.door->doormask & D_LOCKED);
             } else {
                 xlock.box->otrapped = 0;
+/*JP
                 what = (xlock.box->otyp == CHEST) ? "chest" : "box";
+*/
+                what = (xlock.box->otyp == CHEST) ? "\95ó\94 " : "\94 ";
                 alreadyunlocked = !xlock.box->olocked;
             }
+#if 0 /*JP:T*/
             You("succeed in disarming the trap.  The %s is still %slocked.",
                 what, alreadyunlocked ? "un" : "");
+#else
+            You("ã©\82ð\8aO\82µ\82½\81D%s\82Í\8c®\82ª%s\82Ü\82Ü\82¾\81D",
+                what, alreadyunlocked ? "\8aJ\82¢\82½" : "\82©\82©\82Á\82½");
+#endif
             exercise(A_WIS, TRUE);
         } else {
+/*JP
             You("stop %s.", lock_action());
+*/
+            You("%s\82Ì\82ð\82â\82ß\82½\81D", lock_action());
             exercise(A_WIS, FALSE);
         }
         return ((xlock.usedtime = 0));
@@ -236,12 +253,13 @@ boolean destroyit;
             if (!rn2(3) || otmp->oclass == POTION_CLASS) {
                 chest_shatter_msg(otmp);
                 if (costly)
-                    loss +=
-                        stolen_value(otmp, u.ux, u.uy, peaceful_shk, TRUE);
+                    loss += stolen_value(otmp, u.ux, u.uy, peaceful_shk, TRUE);
                 if (otmp->quan == 1L) {
                     obfree(otmp, (struct obj *) 0);
                     continue;
                 }
+                /* this works because we're sure to have at least 1 left;
+                   otherwise it would fail since otmp is not in inventory */
                 useup(otmp);
             }
             if (box->otyp == ICE_BOX && otmp->otyp == CORPSE) {
@@ -285,7 +303,7 @@ forcelock(VOID_ARGS)
             /* for a +0 weapon, probability that it survives an unsuccessful
              * attempt to force the lock is (.992)^50 = .67
              */
-#if 0 /*JP*/
+#if 0 /*JP:T*/
             pline("%sour %s broke!", (uwep->quan > 1L) ? "One of y" : "Y",
                   xname(uwep));
 #else
@@ -309,10 +327,14 @@ forcelock(VOID_ARGS)
     You("succeed in forcing the lock.");
 */
     pline("\8c®\82ð\82±\82\8aJ\82¯\82½\81D");
+    exercise(xlock.picktyp ? A_DEX : A_STR, TRUE);
+    /* breakchestlock() might destroy xlock.box; if so, xlock context will
+       be cleared (delobj -> obfree -> maybe_reset_pick); but it might not,
+       so explicitly clear that manually */
     breakchestlock(xlock.box, (boolean) (!xlock.picktyp && !rn2(3)));
+    reset_pick(); /* lock-picking context is no longer valid */
 
-    exercise((xlock.picktyp) ? A_DEX : A_STR, TRUE);
-    return ((xlock.usedtime = 0));
+    return 0;
 }
 
 void
@@ -320,15 +342,28 @@ reset_pick()
 {
     xlock.usedtime = xlock.chance = xlock.picktyp = 0;
     xlock.magic_key = FALSE;
-    xlock.door = 0;
-    xlock.box = 0;
+    xlock.door = (struct rm *) 0;
+    xlock.box = (struct obj *) 0;
 }
 
-/* level change; don't reset if hero is carrying xlock.box with him/her */
+/* level change or object deletion; context may no longer be valid */
 void
-maybe_reset_pick()
+maybe_reset_pick(container)
+struct obj *container; /* passed from obfree() */
 {
-    if (!xlock.box || !carried(xlock.box))
+    /*
+     * If a specific container, only clear context if it is for that
+     * particular container (which is being deleted).  Other stuff on
+     * the current dungeon level remains valid.
+     * However if 'container' is Null, clear context if not carrying
+     * xlock.box (which might be Null if context is for a door).
+     * Used for changing levels, where a floor container or a door is
+     * being left behind and won't be valid on the new level but a
+     * carried container will still be.  There might not be any context,
+     * in which case redundantly clearing it is harmless.
+     */
+    if (container ? (container == xlock.box)
+                  : (!xlock.box || !carried(xlock.box)))
         reset_pick();
 }
 
@@ -404,7 +439,7 @@ struct obj *pick;
         You("%s\82ð\82Â\82©\82Þ\82±\82Æ\82ª\82Å\82«\82È\82¢\81I\8eè\82ª\82È\82¢\82ñ\82¾\82à\82Ì\81I", xname(pick));
         return PICKLOCK_DID_NOTHING;
     } else if (u.uswallow) {
-#if 0 /*JP*/
+#if 0 /*JP:T*/
         You_cant("%sunlock %s.", (picktyp == CREDIT_CARD) ? "" : "lock or ",
                  mon_nam(u.ustuck));
 #else
@@ -431,11 +466,13 @@ struct obj *pick;
     if (cc.x == u.ux && cc.y == u.uy) { /* pick lock on a container */
         const char *verb;
         char qsfx[QBUFSZ];
+#if 0 /*JP*/
         boolean it;
+#endif
         int count;
 
         if (u.dz < 0) {
-#if 0 /*JP*/
+#if 0 /*JP:T*/
             There("isn't any sort of lock up %s.",
                   Levitation ? "here" : "there");
 #else
@@ -469,7 +506,9 @@ struct obj *pick;
                     You("\82±\82±\82©\82ç%s\82É\93Í\82©\82È\82¢\81D", the(xname(otmp)));
                     return PICKLOCK_LEARNED_SOMETHING;
                 }
+#if 0 /*JP*/
                 it = 0;
+#endif
                 if (otmp->obroken)
 /*JP
                     verb = "fix";
@@ -479,12 +518,12 @@ struct obj *pick;
 /*JP
                     verb = "lock", it = 1;
 */
-                    verb = "\8c®\82ð\82©\82¯\82é", it = 1;
+                    verb = "\8c®\82ð\82©\82¯\82é";
                 else if (picktyp != LOCK_PICK)
 /*JP
                     verb = "unlock", it = 1;
 */
-                    verb = "\8c®\82ð\82Í\82¸\82·", it = 1;
+                    verb = "\8c®\82ð\82Í\82¸\82·";
                 else
 /*JP
                     verb = "pick";
@@ -496,7 +535,7 @@ struct obj *pick;
                 Sprintf(qsfx, " here; %s %s?", verb, it ? "it" : "its lock");
 */
                 Sprintf(qsfx, "\82ª\82 \82é\81D%s\81H", verb);
-#if 0 /*JP*/
+#if 0 /*JP:T*/
                 (void) safe_qbuf(qbuf, "There is ", qsfx, otmp, doname,
                                  ansimpleoname, "a box");
 #else
@@ -519,7 +558,7 @@ struct obj *pick;
                     return PICKLOCK_LEARNED_SOMETHING;
                 } else if (picktyp == CREDIT_CARD && !otmp->olocked) {
                     /* credit cards are only good for unlocking */
-#if 0 /*JP*/
+#if 0 /*JP:T*/
                     You_cant("do that with %s.",
                              an(simple_typename(picktyp)));
 #else
@@ -569,8 +608,8 @@ struct obj *pick;
 
         door = &levl[cc.x][cc.y];
         mtmp = m_at(cc.x, cc.y);
-        if (mtmp && canseemon(mtmp) && mtmp->m_ap_type != M_AP_FURNITURE
-            && mtmp->m_ap_type != M_AP_OBJECT) {
+        if (mtmp && canseemon(mtmp) && M_AP_TYPE(mtmp) != M_AP_FURNITURE
+            && M_AP_TYPE(mtmp) != M_AP_OBJECT) {
             if (picktyp == CREDIT_CARD
                 && (mtmp->isshk || mtmp->data == &mons[PM_ORACLE]))
 /*JP
@@ -578,7 +617,7 @@ struct obj *pick;
 */
                 verbalize("\82¢\82Â\82à\83j\83R\83j\83R\8c»\8bà\95¥\82¢\81D");
             else
-#if 0 /*JP*/
+#if 0 /*JP:T*/
                 pline("I don't think %s would appreciate that.",
                       mon_nam(mtmp));
 #else
@@ -634,7 +673,7 @@ struct obj *pick;
                 return PICKLOCK_LEARNED_SOMETHING;
             }
 
-#if 0 /*JP*/
+#if 0 /*JP:T*/
             Sprintf(qbuf, "%s it?",
                     (door->doormask & D_LOCKED) ? "Unlock" : "Lock");
 #else
@@ -693,7 +732,7 @@ doforce()
                   || objects[uwep->otyp].oc_skill == P_FLAIL
                   || objects[uwep->otyp].oc_skill > P_LANCE)
                : uwep->oclass != ROCK_CLASS)) {
-#if 0 /*JP*/
+#if 0 /*JP:T*/
         You_cant("force anything %s weapon.",
                  !uwep ? "when not wielding a"
                        : (uwep->oclass != WEAPON_CLASS && !is_weptool(uwep))
@@ -736,7 +775,7 @@ doforce()
                    since we're about to set lknown, there's no need to
                    remember and then reset its current value */
                 otmp->lknown = 0;
-#if 0 /*JP*/
+#if 0 /*JP:T*/
                 There("is %s here, but its lock is already %s.",
                       doname(otmp), otmp->obroken ? "broken" : "unlocked");
 #else
@@ -747,7 +786,7 @@ doforce()
                 otmp->lknown = 1;
                 continue;
             }
-#if 0 /*JP*/
+#if 0 /*JP:T*/
             (void) safe_qbuf(qbuf, "There is ", " here; force its lock?",
                              otmp, doname, ansimpleoname, "a box");
 #else
@@ -883,8 +922,12 @@ int x, y;
 */
             pline_The("\92µ\82Ë\8b´\82Í\82à\82¤\8aJ\82¢\82Ä\82¢\82é\81D");
         else if (container_at(cc.x, cc.y, TRUE))
+#if 0 /*JP:T*/
             pline("%s like something lootable over there.",
                   Blind ? "Feels" : "Seems");
+#else
+            pline("\82±\82±\82É\82Í\89½\82©\93ü\82ê\95¨\82ª\82 \82é\82æ\82¤\82¾\81D");
+#endif
         else
 /*JP
             You("%s no door there.", Blind ? "feel" : "see");
@@ -973,13 +1016,13 @@ boolean quietly;
 {
     register struct monst *mtmp = m_at(x, y);
 
-    if (mtmp && mtmp->m_ap_type != M_AP_FURNITURE) {
-        if (mtmp->m_ap_type == M_AP_OBJECT)
+    if (mtmp && M_AP_TYPE(mtmp) != M_AP_FURNITURE) {
+        if (M_AP_TYPE(mtmp) == M_AP_OBJECT)
             goto objhere;
         if (!quietly) {
             if ((mtmp->mx != x) || (mtmp->my != y)) {
                 /* worm tail */
-#if 0 /*JP*/
+#if 0 /*JP:T*/
                 pline("%s%s blocks the way!",
                       !canspotmon(mtmp) ? Something : s_suffix(Monnam(mtmp)),
                       !canspotmon(mtmp) ? "" : " tail");
@@ -989,7 +1032,7 @@ boolean quietly;
                       !canspotmon(mtmp) ? "" : "\82Ì\90K\94ö");
 #endif
             } else {
-#if 0 /*JP*/
+#if 0 /*JP:T*/
                 pline("%s blocks the way!",
                       !canspotmon(mtmp) ? "Some creature" : Monnam(mtmp));
 #else
@@ -1003,7 +1046,7 @@ boolean quietly;
         return TRUE;
     }
     if (OBJ_AT(x, y)) {
   objhere:
+ objhere:
         if (!quietly)
 /*JP
             pline("%s's in the way.", Something);
@@ -1087,7 +1130,7 @@ doclose()
 */
             pline("\92µ\82Ë\8b´\82ð\95Â\82ß\82é\96¾\94\92\82È\95û\96@\82Í\82È\82¢\81D");
         else {
       nodoor:
+ nodoor:
 /*JP
             You("%s no door there.", Blind ? "feel" : "see");
 */
@@ -1270,7 +1313,7 @@ int x, y;
                 return FALSE;
             }
             block_point(x, y);
-            door->typ = SDOOR;
+            door->typ = SDOOR, door->doormask = D_NODOOR;
             if (vis)
 /*JP
                 pline_The("doorway vanishes!");
@@ -1285,7 +1328,7 @@ int x, y;
         /* & trap doors, but is it ever OK for anything else? */
         if (t_at(x, y)) {
             /* maketrap() clears doormask, so it should be NODOOR */
-#if 0 /*JP*/
+#if 0 /*JP:T*/
             pline("%s springs up in the doorway, but %s.", dustcloud,
                   quickly_dissipates);
 #else
@@ -1300,7 +1343,7 @@ int x, y;
 /*JP
             msg = "The door locks!";
 */
-                msg = "\94à\82É\8c®\82ª\82©\82©\82Á\82½\81I";
+            msg = "\94à\82É\8c®\82ª\82©\82©\82Á\82½\81I";
             break;
         case D_ISOPEN:
 /*JP
@@ -1319,7 +1362,7 @@ int x, y;
 /*JP
                "A cloud of dust springs up and assembles itself into a door!";
 */
-                "\82Ù\82±\82è\82ª\82½\82¿\82±\82ß\81C\8fW\82Ü\82Á\82Ä\94à\82É\82È\82Á\82½\81I";
+               "\82Ù\82±\82è\82ª\82½\82¿\82±\82ß\81C\8fW\82Ü\82Á\82Ä\94à\82É\82È\82Á\82½\81I";
             break;
         default:
             res = FALSE;
@@ -1416,7 +1459,7 @@ struct obj *otmp;
     long save_Blinded;
 
     if (otmp->oclass == POTION_CLASS) {
-#if 0 /*JP*/
+#if 0 /*JP:T*/
         You("%s %s shatter!", Blind ? "hear" : "see", an(bottlename()));
 #else
         if (Blind)