From 1ab038dca5e4228668b15f5001b301c81358ac35 Mon Sep 17 00:00:00 2001 From: "nethack.rankin" Date: Sat, 28 Mar 2009 01:36:12 +0000 Subject: [PATCH] dropping unpaid items vs containers (trunk only) From a bug report, the 'D' command would list 'u' as an item category choice if you were carrying unpaid items inside a container, but if those were the only unpaid items then nothing would happen once the dropping stage was reached. Applied to all menustyles (except partial, which bypasses categories and goes straight to a menu listing all items). There were two alternatives for the fix: suppress 'u' as an applicable category when it only applies to container contents, or include the container among the drop candidates even though it isn't an unpaid item itself. I went with the latter; it's simpler to implement and also feels a little more intuitive than behaving like there aren't any unpaid items present. --- doc/fixes35.0 | 2 ++ src/invent.c | 2 +- src/pickup.c | 32 +++++++++++++++++--------------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/doc/fixes35.0 b/doc/fixes35.0 index cbb81ff17..f2e513612 100644 --- a/doc/fixes35.0 +++ b/doc/fixes35.0 @@ -315,6 +315,8 @@ auto-wielding a polearm took no time if ESC was used to cancel target choice applying a bullwhip while at very edge of map could target beyond edge, potentially leading to a panic or crash prevent temple priests and minions from wearing helms of opposite alignment +'D' drop command didn't handle 'u' choice correctly if the only unpaid items + were inside containers Platform- and/or Interface-Specific Fixes diff --git a/src/invent.c b/src/invent.c index be9a08412..c0be0ebe7 100644 --- a/src/invent.c +++ b/src/invent.c @@ -1233,7 +1233,7 @@ STATIC_PTR int ckunpaid(otmp) register struct obj *otmp; { - return((int)(otmp->unpaid)); + return (otmp->unpaid || (Has_contents(otmp) && count_unpaid(otmp))); } boolean diff --git a/src/pickup.c b/src/pickup.c index 5fa1a1044..b01b6d523 100644 --- a/src/pickup.c +++ b/src/pickup.c @@ -379,23 +379,25 @@ allow_category(obj) struct obj *obj; { if (Role_if(PM_PRIEST)) obj->bknown = TRUE; - if (((index(valid_menu_classes,'u') != (char *)0) && obj->unpaid) || - (index(valid_menu_classes, obj->oclass) != (char *)0)) + + /* if obj's class is in the list, then obj is acceptable */ + if (index(valid_menu_classes, obj->oclass)) return TRUE; - else if (((index(valid_menu_classes,'U') != (char *)0) && - (obj->oclass != COIN_CLASS && obj->bknown && !obj->blessed && !obj->cursed))) - return TRUE; - else if (((index(valid_menu_classes,'B') != (char *)0) && - (obj->oclass != COIN_CLASS && obj->bknown && obj->blessed))) - return TRUE; - else if (((index(valid_menu_classes,'C') != (char *)0) && - (obj->oclass != COIN_CLASS && obj->bknown && obj->cursed))) - return TRUE; - else if (((index(valid_menu_classes,'X') != (char *)0) && - (obj->oclass != COIN_CLASS && !obj->bknown))) - return TRUE; - else + /* unpaid and BUC checks don't apply to coins */ + if (obj->oclass == COIN_CLASS) return FALSE; + /* check for unpaid item */ + if (index(valid_menu_classes, 'u') && + (obj->unpaid || (Has_contents(obj) && count_unpaid(obj)))) + return TRUE; + /* check for particular bless/curse state */ + if (!obj->bknown ? index(valid_menu_classes, 'X') : /* unknown BUC state */ + obj->blessed ? index(valid_menu_classes, 'B') : /* known blessed */ + !obj->cursed ? index(valid_menu_classes, 'U') : /* known uncursed */ + index(valid_menu_classes, 'C')) /* known cursed */ + return TRUE; + /* obj isn't acceptable */ + return FALSE; } #if 0 /* not used */