From jry@pinn.net Mon Oct 30 13:03:09 2000
Path: ulcc.ac.uk!server3.netnews.ja.net!newspeer.clara.net!news.clara.net!feed2.onemain.com!feed1.onemain.com!xfer13.netnews.com!netnews.com!news-xfer.newsread.com!bad-news.newsread.com!netaxs.com!newsread.com!POSTED.monger.newsread.com!not-for-mail
From: jry@pinn.net (Wingnut)
Newsgroups: rec.games.roguelike.nethack
Subject: Re: YANI - Auto credit accept when shopkeepers run out of money - Patch
Reply-To: jry@pinn.net
Message-ID: <39fba02d.9443061@news.pinn.net>
References: <Locnar-2010000230190001@lex-ts2-7.iglou.com> <39F7A633.8D4B7E6D@earthlink.net>
X-Newsreader: Forte Agent 1.5/32.452
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 263
Date: Sun, 29 Oct 2000 04:00:54 GMT
NNTP-Posting-Host: 207.226.105.62
X-Complaints-To: Abuse Role <abuse@pinn.net>, We Care <abuse@newsread.com>
X-Trace: monger.newsread.com 972792054 207.226.105.62 (Sun, 29 Oct 2000 00:00:54 EDT)
NNTP-Posting-Date: Sun, 29 Oct 2000 00:00:54 EDT
Organization: Pinnacle Online (pinn.net)
Xref: ulcc.ac.uk rec.games.roguelike.nethack:115527

On Thu, 26 Oct 2000 03:33:49 GMT, ManaUser <manauser@earthlink.net> wrote:

>Governor Rocknar wrote:
>> 
>> I'm sick of having to say y all the time when the shopkeepers run out of money.
>> 
>> YES, I want a line of credit...:/
>
>But it always asks if you are sure you want to sell. The only difernece
>is the extra message explaining that you'd be getting paid in credit.

No, the extra difference is that when selling multiple items for credit, you get
a (ynq) prompt instead of a (ynaq) prompt, making you confirm each item whether
you like it or not.

Being unafraid of the code of source and compiler of C, I made this change to my
compile several months ago. To use this code, edit src/shk.c and replace the
lines from the opening comment to the end of sellobj() with this version:


/* auto-response flag for/from "sell foo?" 'a' => 'y', 'q' => 'n' */
static char sell_response = 'a';
static boolean sell_voluntarily = FALSE;
static boolean auto_credit = FALSE;

void
sellobj_state(deliberate)       /* called from dodrop(do.c) and doddrop() */
boolean deliberate;
{
        /* If we're deliberately dropping something, there's no automatic
        response to the shopkeeper's "want to sell" query; however, if we
        accidentally drop anything, the shk will buy it/them without asking.
        This retains the old pre-query risk that slippery fingers while in
        shops entailed:  you drop it, you've lost it.
         */
        sell_response = deliberate ? '\0' : 'a';
        sell_voluntarily = deliberate;
        auto_credit = FALSE;
}

void
sellobj(obj, x, y)
register struct obj *obj;
xchar x, y;
{
        register struct monst *shkp;
        register struct eshk *eshkp;
        long ltmp = 0L, cltmp = 0L, gltmp = 0L, offer;
        boolean saleitem, cgold = FALSE, container = Has_contents(obj);
        boolean isgold = (obj->oclass == GOLD_CLASS);

        if(!(shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) ||
           !inhishop(shkp)) return;
        if(!costly_spot(x, y))  return;
        if(!*u.ushops) return;

        if(obj->unpaid && !container && !isgold) {
            sub_one_frombill(obj, shkp);
            return;
        }
        if(container) {
                /* find the price of content before subfrombill */
                cltmp += contained_cost(obj, shkp, cltmp, TRUE);
                /* find the value of contained gold */
                gltmp += contained_gold(obj);
                cgold = (gltmp > 0L);
        }

        saleitem = saleable(shkp, obj);
        if(!isgold && !obj->unpaid && saleitem)
            ltmp = set_cost(obj, shkp);

        offer = ltmp + cltmp;

        /* get one case out of the way: nothing to sell, and no gold */
        if(!isgold && (offer + gltmp) == 0L) {
                register boolean unpaid = (obj->unpaid ||
                                  (container && count_unpaid(obj->cobj)));

                if(container) {
                        dropped_container(obj, shkp, FALSE);
                        if(!obj->unpaid && !saleitem)
                            obj->no_charge = 1;
                        if(obj->unpaid || count_unpaid(obj->cobj))
                            subfrombill(obj, shkp);
                } else obj->no_charge = 1;

                if(!unpaid)
                    pline("%s seems uninterested.", Monnam(shkp));
                return;
        }

        /* you dropped something of your own - probably want to sell it */
        if (shkp->msleeping || !shkp->mcanmove) {
                if (container)
                    dropped_container(obj, shkp, TRUE);
                if (!obj->unpaid)
                    obj->no_charge = 1;
                if (!shkp->mcanmove) {
                    if(ANGRY(shkp) && !rn2(4))
                        pline("%s utters a curse.", Monnam(shkp));
                    else pline("%s is indisposed.", Monnam(shkp));
                } else if(!rn2(3)) {
                    pline("%s snores indifferently.", Monnam(shkp));
                }
                subfrombill(obj, shkp);
                return;
        }

        eshkp = ESHK(shkp);

        if (ANGRY(shkp)) { /* they become shop-objects, no pay */
                pline("Thank you, scum!");
                subfrombill(obj, shkp);
                return;
        }

        if(eshkp->robbed) {  /* shkp is not angry? */
                if(isgold) offer = obj->quan;
                else if(cgold) offer += cgold;
                if((eshkp->robbed -= offer < 0L))
                        eshkp->robbed = 0L;
                if(offer) verbalize(
  "Thank you for your contribution to restock this recently plundered shop.");
                subfrombill(obj, shkp);
                return;
        }

        if(isgold || cgold) {
                if(!cgold) gltmp = obj->quan;

                if(eshkp->debit >= gltmp) {
                    if(eshkp->loan) { /* you carry shop's gold */
                         if(eshkp->loan >= gltmp)
                             eshkp->loan -= gltmp;
                         else eshkp->loan = 0L;
                    }
                    eshkp->debit -= gltmp;
                    Your("debt is %spaid off.",
                                eshkp->debit ? "partially " : "");
                } else {
                    long delta = gltmp - eshkp->debit;

                    eshkp->credit += delta;
                    if(eshkp->debit) {
                        eshkp->debit = 0L;
                        eshkp->loan = 0L;
                        Your("debt is paid off.");
                    }
                    pline("%ld zorkmid%s added to your credit.",
                                delta, delta > 1L ? "s are" : " is");
                }
                if(offer) goto move_on;
                else {
                    if(!isgold) {
                        if (container)
                            dropped_container(obj, shkp, FALSE);
                        if (!obj->unpaid && !saleitem) obj->no_charge = 1;
                        subfrombill(obj, shkp);
                    }
                    return;
                }
        }
move_on:
        if((!saleitem && !(container && cltmp > 0L))
           || eshkp->billct == BILLSZ
           || obj->oclass == BALL_CLASS
           || obj->oclass == CHAIN_CLASS || offer == 0L
           || (obj->oclass == FOOD_CLASS && obj->oeaten)
           || (Is_candle(obj) &&
                   obj->age < 20L * (long)objects[obj->otyp].oc_cost)) {
                pline("%s seems not interested%s.", Monnam(shkp),
                        cgold ? " in the rest" : "");
                if (container)
                    dropped_container(obj, shkp, FALSE);
                obj->no_charge = 1;
                return;
        }

        if(!shkp->mgold) {
                char c, qbuf[BUFSZ];
                long tmpcr = ((offer * 9L) / 10L) + (offer <= 1L);

                if (!sell_voluntarily || auto_credit) {
                    c = sell_response = 'y';
                } else if (sell_response != 'n') {
                    pline("%s cannot pay you at present.", Monnam(shkp));
                    Sprintf(qbuf,
                            "Will you accept %ld zorkmid%s in credit for %s?",
                            tmpcr, plur(tmpcr), doname(obj));
                    /* won't accept 'a' response here */
                    /* KLY - 3/2000 yes, we will, it's a damn nuisance
                       to have to constantly hit 'y' to sell for credit */
                    c = ynaq(qbuf);
                    if(c=='a')
                    {
                        c ='y';
                        auto_credit=TRUE;
                    }
                } else          /* previously specified "quit" */
                    c = 'n';

                if (c == 'y') {
                    shk_names_obj(shkp, obj, sell_voluntarily ?
                            "traded %s for %ld zorkmid%s in %scredit." :
                        "relinquish %s and acquire %ld zorkmid%s in %scredit.",
                            tmpcr,
                            (eshkp->credit > 0L) ? "additional " : "");
                    eshkp->credit += tmpcr;
                    subfrombill(obj, shkp);
                } else {
                    if (c == 'q') sell_response = 'n';
                    if (container)
                        dropped_container(obj, shkp, FALSE);
                    if (!obj->unpaid) obj->no_charge = 1;
                    subfrombill(obj, shkp);
                }
        } else {
                char qbuf[BUFSZ];
                boolean short_funds = (offer > shkp->mgold);

                if (short_funds) offer = shkp->mgold;

                if (!sell_response) {
                    Sprintf(qbuf,
                         "%s offers%s %ld gold piece%s for%s %s %s.  Sell %s?",
                            Monnam(shkp), short_funds ? " only" : "",
                            offer, plur(offer),
                            (!ltmp && cltmp) ? " the contents of" : "",
                            obj->unpaid ? "the" : "your", xname(obj),
                            (obj->quan == 1L) ? "it" : "them");
                } else  qbuf[0] = '\0';         /* just to pacify lint */

                switch (sell_response ? sell_response : ynaq(qbuf)) {
                 case 'q':  sell_response = 'n';
                 case 'n':  if (container)
                                dropped_container(obj, shkp, FALSE);
                            if (!obj->unpaid) obj->no_charge = 1;
                            subfrombill(obj, shkp);
                            break;
                 case 'a':  sell_response = 'y';
                 case 'y':  if (container)
                                dropped_container(obj, shkp, TRUE);
                            if (!obj->unpaid && !saleitem) obj->no_charge = 1;
                            subfrombill(obj, shkp);
                            pay(-offer, shkp);
                            shk_names_obj(shkp, obj, sell_voluntarily ?
                                    "sold %s for %ld gold piece%s.%s" :
               "relinquish %s and receive %ld gold piece%s in compensation.%s",
                                    offer, "");
                            break;
                 default:   impossible("invalid sell response");
                }
        }
}

Wingnut

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d- s-:+ a--- C++ ULS P L+ E---- W+ N++ !o K- w(---) O-- M- V?
PS++ PE-- Y+ PGP- t-- 5+++ X- R tv b DI+ D+ G e>++ h! r--- y--
------END GEEK CODE BLOCK------

