MCPcopy Create free account
hub / github.com/NetHack/NetHack / splitbill

Function splitbill

src/shk.c:3622–3658  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3620}
3621
3622void
3623splitbill(struct obj *obj, struct obj *otmp)
3624{
3625 /* otmp has been split off from obj */
3626 struct bill_x *bp;
3627 long tmp;
3628 struct monst *shkp = shop_keeper(*u.ushops);
3629
3630 if (!shkp || !inhishop(shkp)) {
3631 impossible("splitbill: no resident shopkeeper??");
3632 return;
3633 }
3634 bp = onbill(obj, shkp, FALSE);
3635 if (!bp) {
3636 impossible("splitbill: not on bill?");
3637 return;
3638 }
3639 if (bp->bquan < otmp->quan) {
3640 impossible("Negative quantity on bill??");
3641 }
3642 if (bp->bquan == otmp->quan) {
3643 impossible("Zero quantity on bill??");
3644 }
3645 bp->bquan -= otmp->quan;
3646
3647 if (ESHK(shkp)->billct == BILLSZ) {
3648 otmp->unpaid = 0;
3649 } else {
3650 tmp = bp->price;
3651 bp = &(ESHK(shkp)->bill_p[ESHK(shkp)->billct]);
3652 bp->bo_id = otmp->o_id;
3653 bp->bquan = otmp->quan;
3654 bp->useup = FALSE;
3655 bp->price = tmp;
3656 ESHK(shkp)->billct++;
3657 }
3658}
3659
3660staticfn void
3661sub_one_frombill(struct obj *obj, struct monst *shkp)

Callers 1

splitobjFunction · 0.85

Calls 4

shop_keeperFunction · 0.85
inhishopFunction · 0.85
onbillFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected