From: Pasi Kallinen Date: Sat, 19 Dec 2015 12:44:39 +0000 (+0200) Subject: Improve the tin opener X-Git-Tag: NetHack-3.6.1_RC01~1141 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=43bf9c978db1cf4a94dc8a7188da97d33e9e9e2e;p=nethack Improve the tin opener --- diff --git a/doc/fixes36.1 b/doc/fixes36.1 index 5dc93f056..465be7241 100644 --- a/doc/fixes36.1 +++ b/doc/fixes36.1 @@ -76,6 +76,7 @@ Platform- and/or Interface-Specific New Features NetHack Community Patches (or Variation) Included ------------------------------------------------- +Malcolm Ryan's improved tin opener Code Cleanup and Reorganization diff --git a/include/extern.h b/include/extern.h index 564d863fd..2591f9ec5 100644 --- a/include/extern.h +++ b/include/extern.h @@ -604,6 +604,7 @@ E void NDECL(init_uhunger); E int NDECL(Hear_again); E void NDECL(reset_eat); E int NDECL(doeat); +E int FDECL(use_tin_opener, (struct obj *)); E void NDECL(gethungry); E void FDECL(morehungry, (int)); E void FDECL(lesshungry, (int)); diff --git a/src/apply.c b/src/apply.c index 96c77386c..66e291946 100644 --- a/src/apply.c +++ b/src/apply.c @@ -3494,18 +3494,8 @@ doapply() res = dowrite(obj); break; case TIN_OPENER: - if (!carrying(TIN)) { - You("have no tin to open."); - goto xit; - } - You("cannot open a tin without eating or discarding its contents."); - if (flags.verbose) - pline("In order to eat, use the 'e' command."); - if (obj != uwep) - pline( - "Opening the tin will be much easier if you wield the tin opener."); - goto xit; - + res = use_tin_opener(obj); + break; case FIGURINE: use_figurine(&obj); break; diff --git a/src/eat.c b/src/eat.c index fe3e4e071..2fb798b25 100644 --- a/src/eat.c +++ b/src/eat.c @@ -2579,6 +2579,34 @@ doeat() return 1; } +int +use_tin_opener(obj) +register struct obj *obj; +{ + register struct obj *otmp; + int res = 0; + + if (!carrying(TIN)) { + You("have no tin to open."); + return 0; + } + + if (obj != uwep) { + if (obj->cursed && obj->bknown) { + char qbuf[QBUFSZ]; + (void) safe_qbuf(qbuf, "Really wield ", "?", obj, doname, ansimpleoname, "that"); + if (ynq(qbuf) != 'y') return 0; + } + if (!wield_tool(obj, "use")) return 0; + else res = 1; + } + + otmp = getobj((const char *)comestibles, "open"); + if (!otmp) return 0; + start_tin(otmp); + return(1); +} + /* Take a single bite from a piece of food, checking for choking and * modifying usedtime. Returns 1 if they choked and survived, 0 otherwise. */ diff --git a/src/invent.c b/src/invent.c index 6c3a22107..3f0c15b85 100644 --- a/src/invent.c +++ b/src/invent.c @@ -1099,6 +1099,7 @@ register const char *let, *word; && (otmp->otyp != HORN_OF_PLENTY || !otmp->dknown || !objects[HORN_OF_PLENTY].oc_name_known)) || (!strcmp(word, "charge") && !is_chargeable(otmp)) + || (!strcmp(word, "open") && otyp != TIN) || (!strcmp(word, "call") && !objtyp_is_callable(otyp)) ) { foo--;