]> granicus.if.org Git - nethack/commitdiff
modify #untrap prompting further
authornethack.allison <nethack.allison>
Wed, 10 Jul 2002 12:32:03 +0000 (12:32 +0000)
committernethack.allison <nethack.allison>
Wed, 10 Jul 2002 12:32:03 +0000 (12:32 +0000)
> The intention is, I believe, to cater for the situation where you, a
> chest, and a dungeon-trap are all on the same square; previously
> (C340-71), you wouldn't have been able to check the chest for traps
> because an #untrap in direction '.' would always have tried to disarm
> the dungeon trap. However, since you can't trap-check containers on
> adjacent squares, it'd wouldn't hurt if the question was dispensed
> with when you specify a direction that isn't your square.
>
> (Note that "you cannot deal with traps while trapped!", so there's
> still several situations when you can't trap-check a chest on a
> trap-square, even though you can loot it, until you've untrapped
> yourself; is this really consistent? Should the if(u.utrap) check
> be moved to the "case y:" branch of the switch?)

src/trap.c

index 36e13349bc9c915b9812fc8a6e1cd3e0acd9ea39..bfd5ed57af537c8ca09ecddcd475017346f5c247 100644 (file)
@@ -3127,22 +3127,44 @@ boolean force;
        struct trap *ttmp;
        struct monst *mtmp;
        boolean trap_skipped = FALSE;
+       boolean box_here = FALSE;
+       boolean deal_with_floor_trap = FALSE;
+       char the_trap[BUFSZ], qbuf[QBUFSZ];
+       int containercnt = 0;
 
        if(!getdir((char *)0)) return(0);
        x = u.ux + u.dx;
        y = u.uy + u.dy;
 
-       if ((ttmp = t_at(x,y)) && ttmp->tseen) {
-               if (u.utrap) {
-                       You("cannot deal with traps while trapped!");
-                       return 1;
+       for(otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) {
+               if(Is_box(otmp) && !u.dx && !u.dy) {
+                       box_here = TRUE;
+                       containercnt++;
+                       if (containercnt > 1) break;
                }
-               There("is %s here.", an(defsyms[trap_to_defsym(ttmp->ttyp)].explanation));
+       }
 
-               switch (ynq(ttmp->ttyp == WEB ? "Remove it?" : "Disarm it?")) {
-                 case 'q': return(0);
-                 case 'n': trap_skipped = TRUE; break;
-                 case 'y':
+       if ((ttmp = t_at(x,y)) && ttmp->tseen) {
+               deal_with_floor_trap = TRUE;
+               Strcpy(the_trap, the(defsyms[trap_to_defsym(ttmp->ttyp)].explanation));
+               if (box_here) {
+                       Sprintf(qbuf, "There %s and %s here. %s %s?",
+                               (containercnt == 1) ? "is a container" : "are containers",
+                               an(defsyms[trap_to_defsym(ttmp->ttyp)].explanation),
+                               ttmp->ttyp == WEB ? "Remove" : "Disarm", the_trap);
+                       switch (ynq(qbuf)) {
+                         case 'q': return(0);
+                         case 'n': trap_skipped = TRUE;
+                                   deal_with_floor_trap = FALSE;
+                                   break;
+                       }
+               }
+               if (deal_with_floor_trap) {
+                   if (u.utrap) {
+                       You("cannot deal with %s while trapped%s!", the_trap,
+                               (x == u.ux && y == u.uy) ? " in it" : "");
+                       return 1;
+                   }
                    switch(ttmp->ttyp) {
                        case BEAR_TRAP:
                        case WEB: