Subject: Re: YANI - Auto credit accept when shopkeepers run out of money - Patch

From: [email-masked] (Wingnut)
Date: Sun, 29 Oct 2000 04:00:54 GMT

On Thu, 26 Oct 2000 03:33:49 GMT, ManaUser <[email-masked]> 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------