From: cohrs Date: Fri, 10 Oct 2003 22:53:28 +0000 (+0000) Subject: U685 - billing for tin usage X-Git-Tag: MOVE2GIT~1722 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=219e091d821cb618f156bf14a4cc89acf8edaeb9;p=nethack U685 - billing for tin usage When moving the code to bill for tins before eating them (to charge for them at the pre-eating hunger status), several cases were able to bypass billing. Moved the bill checking code to a new costly_tin() subroutine so it could be called in all the necessary places. --- diff --git a/doc/fixes34.3 b/doc/fixes34.3 index 5ac1d0997..cc5171602 100644 --- a/doc/fixes34.3 +++ b/doc/fixes34.3 @@ -44,6 +44,7 @@ nagas eat always have warriors on the Valkyrie quest be female be more consistent with sounds when dropping into water surface() returns "bottom" when Underwater +bill for all discarded, opened tins Platform- and/or Interface-Specific Fixes diff --git a/src/eat.c b/src/eat.c index d84531806..e597f847a 100644 --- a/src/eat.c +++ b/src/eat.c @@ -15,6 +15,7 @@ STATIC_PTR int NDECL(eatmdone); STATIC_PTR int NDECL(eatfood); +STATIC_PTR void FDECL(costly_tin, (const char*)); STATIC_PTR int NDECL(opentin); STATIC_PTR int NDECL(unfaint); @@ -957,6 +958,27 @@ violated_vegetarian() return; } +/* common code to check and possibly charge for 1 context.tin.tin, + * will split() context.tin.tin if necessary */ +STATIC_PTR +void +costly_tin(verb) + const char* verb; /* if 0, the verb is "open" */ +{ + if(((!carried(context.tin.tin) && + costly_spot(context.tin.tin->ox, context.tin.tin->oy) && + !context.tin.tin->no_charge) + || context.tin.tin->unpaid)) { + verbalize("You %s it, you bought it!", verb ? verb : "open"); + if(context.tin.tin->quan > 1L) { + context.tin.tin = splitobj(context.tin.tin, 1L); + if (context.tin.tin) + context.tin.o_id = context.tin.tin->o_id; + } + bill_dummy_object(context.tin.tin); + } +} + STATIC_PTR int opentin() /* called during each move whilst opening a tin */ @@ -977,6 +999,7 @@ opentin() /* called during each move whilst opening a tin */ if(context.tin.tin->otrapped || (context.tin.tin->cursed && context.tin.tin->spe != -1 && !rn2(8))) { b_trapped("tin", 0); + costly_tin("destroyed"); goto use_me; } You("succeed in opening the tin."); @@ -984,6 +1007,7 @@ opentin() /* called during each move whilst opening a tin */ if (context.tin.tin->corpsenm == NON_PM) { pline("It turns out to be empty."); context.tin.tin->dknown = context.tin.tin->known = TRUE; + costly_tin((const char*)0); goto use_me; } r = context.tin.tin->cursed ? ROTTEN_TIN : /* always rotten if cursed */ @@ -1007,6 +1031,7 @@ opentin() /* called during each move whilst opening a tin */ if (yn("Eat it?") == 'n') { if (!Hallucination) context.tin.tin->dknown = context.tin.tin->known = TRUE; if (flags.verbose) You("discard the open tin."); + costly_tin((const char*)0); goto use_me; } /* in case stop_occupation() was called on previous meal */ @@ -1025,20 +1050,11 @@ opentin() /* called during each move whilst opening a tin */ violated_vegetarian(); context.tin.tin->dknown = context.tin.tin->known = TRUE; - cprefx(context.tin.tin->corpsenm); cpostfx(context.tin.tin->corpsenm); - - if(((!carried(context.tin.tin) && costly_spot(context.tin.tin->ox, context.tin.tin->oy) && - !context.tin.tin->no_charge) - || context.tin.tin->unpaid)) { - verbalize("You open it, you bought it!"); - /* charge for one at pre-eating cost */ - if(context.tin.tin->quan > 1L) { - context.tin.tin = splitobj(context.tin.tin, 1L); - if (context.tin.tin) - context.tin.o_id = context.tin.tin->o_id; - } - bill_dummy_object(context.tin.tin); - } + cprefx(context.tin.tin->corpsenm); + cpostfx(context.tin.tin->corpsenm); + + /* charge for one at pre-eating cost */ + costly_tin((const char*)0); /* check for vomiting added by GAN 01/16/87 */ if(tintxts[r].nut < 0) make_vomiting((long)rn1(15,10), FALSE); @@ -1062,22 +1078,12 @@ opentin() /* called during each move whilst opening a tin */ context.tin.tin->dknown = context.tin.tin->known = TRUE; if (flags.verbose) You("discard the open tin."); + costly_tin((const char*)0); goto use_me; } context.tin.tin->dknown = context.tin.tin->known = TRUE; - if(((!carried(context.tin.tin) && costly_spot(context.tin.tin->ox, context.tin.tin->oy) && - !context.tin.tin->no_charge) - || context.tin.tin->unpaid)) { - verbalize("You open it, you bought it!"); - /* charge for one at pre-eating cost */ - if(context.tin.tin->quan > 1L) { - context.tin.tin = splitobj(context.tin.tin, 1L); - if (context.tin.tin) - context.tin.o_id = context.tin.tin->o_id; - } - bill_dummy_object(context.tin.tin); - } + costly_tin((const char*)0); if (!context.tin.tin->cursed) pline("This makes you feel like %s!",