/* called with two args on merge */ void obfree(struct obj *obj, struct obj *merge) { struct bill_x *bp = onbill(obj); struct bill_x *bpm; if (bp) { if (!merge) { bp->useup = 1; obj->unpaid = 0; /* only for doinvbill */ obj->nobj = billobjs; billobjs = obj; return; } bpm = onbill(merge); if (!bpm) { /* this used to be a rename */ impossible("obfree: not on bill??"); return; } else { /* this was a merger */ bpm->bquan += bp->bquan; ESHK(shopkeeper)->billct--; *bp = bill[ESHK(shopkeeper)->billct]; } } free(obj); }
/* called with two args on merge */ void free_obj(obj_t *obj, obj_t *merge) // was called obfree { bill_t *bp = onbill(obj); bill_t *bpm; if (bp) { if (!merge) { bp->useup = true; obj->bitflags &= ~O_IS_UNPAID; /* only for doinvbill */ obj->nobj = billobjs; billobjs = obj; return; } bpm = onbill(merge); if (!bpm) { /* this used to be a rename */ message("BUG: obfree: not on bill??"); return; } else { /* this was a merger */ bpm->bquantity += bp->bquantity; ESHK(shopkeeper)->billct--; *bp = bill[ESHK(shopkeeper)->billct]; } } free_me((VoidPtr) obj); }
void splitbill(struct obj *obj, struct obj *otmp) { /* otmp has been split off from obj */ struct bill_x *bp; int tmp; bp = onbill(obj); if (!bp) { impossible("splitbill: not on bill?"); return; } if (bp->bquan < otmp->quan) impossible("Negative quantity on bill??"); if (bp->bquan == otmp->quan) impossible("Zero quantity on bill??"); bp->bquan -= otmp->quan; if (ESHK(shopkeeper)->billct == BILLSZ) otmp->unpaid = 0; else { tmp = bp->price; bp = &bill[ESHK(shopkeeper)->billct]; bp->bo_id = otmp->o_id; bp->bquan = otmp->quan; bp->useup = 0; bp->price = tmp; ESHK(shopkeeper)->billct++; } }
void splitbill(obj_t *obj, obj_t *otmp) { /* otmp has been split off from obj */ bill_t *bp; Short tmp; bp = onbill(obj); if (!bp) { message("BUG: splitbill: not on bill?"); return; } if (bp->bquantity < otmp->quantity) { message("BUG: Negative quantity on bill??"); return; } if (bp->bquantity == otmp->quantity) { message("BUG: Zero quantity on bill??"); return; } bp->bquantity -= otmp->quantity; /* addtobill(otmp); */ // this line was commented out when I found it. if (ESHK(shopkeeper)->billct == BILLSZ) otmp->bitflags &= ~O_IS_UNPAID; else { tmp = bp->price; bp = &bill[ESHK(shopkeeper)->billct]; bp->bo_id = otmp->o_id; bp->bquantity = otmp->quantity; bp->useup = false; bp->price = tmp; ESHK(shopkeeper)->billct++; } }
/* called in hack.c when we pickup an object */ void addtobill(struct obj *obj) { struct bill_x *bp; if(!inshop() || (u.ux == ESHK(shopkeeper)->shk.x && u.uy == ESHK(shopkeeper)->shk.y) || (u.ux == ESHK(shopkeeper)->shd.x && u.uy == ESHK(shopkeeper)->shd.y) || onbill(obj) /* perhaps we threw it away earlier */ ) return; if(ESHK(shopkeeper)->billct == BILLSZ){ pline("You got that for free!"); return; } bp = &bill[ESHK(shopkeeper)->billct]; bp->bo_id = obj->o_id; bp->bquan = obj->quan; bp->useup = 0; bp->price = getprice(obj); ESHK(shopkeeper)->billct++; obj->unpaid = 1; }
/* called in hack.c (or whatever) when we pickup an object */ void addtobill(obj_t *obj) { bill_t *bp; eshk_t *eshk = (shopkeeper ? ESHK(shopkeeper) : NULL); if (!inshop() || (you.ux == eshk->shk.x && you.uy == eshk->shk.y) || (you.ux == eshk->shd.x && you.uy == eshk->shd.y) || onbill(obj)) /* perhaps we threw it away earlier */ return; eshk = ESHK(shopkeeper); if (eshk->billct == BILLSZ) { // Well, I guess that's one way to address predefined limitations message("You got that for free!"); return; } bp = &bill[eshk->billct]; bp->bo_id = obj->o_id; bp->bquantity = obj->quantity; bp->useup = false; bp->price = getprice(obj); eshk->billct++; obj->bitflags |= O_IS_UNPAID; }
void subfrombill(struct obj *obj) { long ltmp; int tmp; struct obj *otmp; struct bill_x *bp; if (!inshop() || (u.ux == ESHK(shopkeeper)->shk.x && u.uy == ESHK(shopkeeper)->shk.y) || (u.ux == ESHK(shopkeeper)->shd.x && u.uy == ESHK(shopkeeper)->shd.y)) return; if ((bp = onbill(obj)) != NULL) { obj->unpaid = 0; if (bp->bquan > obj->quan) { otmp = newobj(0); *otmp = *obj; bp->bo_id = otmp->o_id = flags.ident++; otmp->quan = (bp->bquan -= obj->quan); otmp->owt = 0; /* superfluous */ otmp->onamelth = 0; bp->useup = 1; otmp->nobj = billobjs; billobjs = otmp; return; } ESHK(shopkeeper)->billct--; *bp = bill[ESHK(shopkeeper)->billct]; return; } if (obj->unpaid) { pline("%s didn't notice.", Monnam(shopkeeper)); obj->unpaid = 0; return; /* %% */ } /* he dropped something of his own - probably wants to sell it */ if (shopkeeper->msleep || shopkeeper->mfroz || inroom(shopkeeper->mx, shopkeeper->my) != ESHK(shopkeeper)->shoproom) return; if (ESHK(shopkeeper)->billct == BILLSZ || ((tmp = shtypes[rooms[ESHK(shopkeeper)->shoproom].rtype - 8]) && tmp != obj->olet) || strchr("_0", obj->olet)) { pline("%s seems not interested.", Monnam(shopkeeper)); return; } ltmp = getprice(obj) * obj->quan; if (ANGRY(shopkeeper)) { ltmp /= 3; NOTANGRY(shopkeeper) = 1; } else ltmp /= 2; if (ESHK(shopkeeper)->robbed) { if ((ESHK(shopkeeper)->robbed -= ltmp) < 0) ESHK(shopkeeper)->robbed = 0; pline("Thank you for your contribution to restock this recently plundered shop."); return; } if (ltmp > shopkeeper->mgold) ltmp = shopkeeper->mgold; pay(-ltmp, shopkeeper); if (!ltmp) pline("%s gladly accepts %s but cannot pay you at present.", Monnam(shopkeeper), doname(obj)); else pline("You sold %s and got %ld gold piece%s.", doname(obj), ltmp, plur(ltmp)); }
void subfrombill(struct obj *obj) { Long ltmp; Short tmp; obj_t *otmp; bill_t *bp; eshk_t *eshk = (shopkeeper ? ESHK(shopkeeper) : NULL); if (!inshop() || (you.ux == eshk->shk.x && you.uy == eshk->shk.y) || (you.ux == eshk->shd.x && you.uy == eshk->shd.y)) return; if ((bp = onbill(obj)) != 0) { obj->bitflags &= ~O_IS_UNPAID; if (bp->bquantity > obj->quantity) { otmp = (obj_t *) md_malloc(sizeof(obj_t));// newobj(0); *otmp = *obj; bp->bo_id = otmp->o_id = flags.ident++; otmp->quantity = (bp->bquantity -= obj->quantity); otmp->owt = 0; /* superfluous */ do_name(otmp, NULL); // otmp->onamelth = 0; // Undo name (if any) bp->useup = true; otmp->nobj = billobjs; billobjs = otmp; return; } eshk->billct--; *bp = bill[eshk->billct]; return; } if (obj->bitflags & O_IS_UNPAID) { StrPrintF(ScratchBuffer, "%s didn't notice.", Monnam(shopkeeper)); message(ScratchBuffer); obj->bitflags &= ~O_IS_UNPAID; return; /* %% */ } /* he dropped something of his own - probably wants to sell it */ if ((shopkeeper->bitflags & (M_IS_ASLEEP | M_IS_FROZEN)) || inroom(shopkeeper->mx,shopkeeper->my) != eshk->shoproom) return; if (eshk->billct == BILLSZ || ((tmp = shtypes[rooms[eshk->shoproom].rtype-8]) && tmp != obj->olet) || StrChr("_0", obj->olet)) { StrPrintF(ScratchBuffer, "%s seems not interested.", Monnam(shopkeeper)); message(ScratchBuffer); return; } ltmp = getprice(obj) * obj->quantity; if (ANGRY(shopkeeper)) { ltmp /= 3; shopkeeper->bitflags |= M_IS_PEACEFUL; // NOTANGRY(shopkeeper) = 1; } else ltmp /= 2; if (eshk->robbed) { if ((eshk->robbed -= ltmp) < 0) eshk->robbed = 0; message("Thank you for your contribution to restock this recently plundered shop."); return; } if (ltmp > shopkeeper->mgold) ltmp = shopkeeper->mgold; pay(-ltmp, shopkeeper); if (!ltmp) StrPrintF(ScratchBuffer, "%s gladly accepts %s but cannot pay you at present.", Monnam(shopkeeper), doname(obj)); else StrPrintF(ScratchBuffer, "You sold %s and got %ld gold piece%s", doname(obj), ltmp, (ltmp == 1 ? "." : "s.")); message(ScratchBuffer); }