Fix: bill_dummy_obj billed excessively for stacks

Add a way to request that unpaid_cost() produce the cost for a single
item, which is necessary for the price adjustment made in
bill_dummy_object.  Another option would be to simply divide by quan in
bill_dummy_object, but this might be more future-proof in case
unpaid_cost ever involves more than simple multiplication by quan
(e.g. the use of alternate units vs the base price, as are used for
globs).

Fixes #1236
This commit is contained in:
Michael Meyer
2024-04-27 11:22:48 -04:00
committed by PatR
parent 1f8db3a0f3
commit b662134eba
7 changed files with 24 additions and 11 deletions

View File

@@ -2705,7 +2705,7 @@ alter_cost(
long
unpaid_cost(
struct obj *unp_obj, /* known to be unpaid or contain unpaid */
boolean include_contents)
uchar cost_type) /* COST_NOCONTENTS, COST_CONTENTS, or COST_SINGLEOBJ */
{
struct bill_x *bp = (struct bill_x *) 0;
struct monst *shkp = 0;
@@ -2729,9 +2729,15 @@ unpaid_cost(
#endif
for (shop = u.ushops; *shop; shop++) {
if ((shkp = shop_keeper(*shop)) != 0) {
if ((bp = onbill(unp_obj, shkp, TRUE)))
amt = unp_obj->quan * bp->price;
if (include_contents && Has_contents(unp_obj))
if ((bp = onbill(unp_obj, shkp, TRUE))) {
amt = bp->price;
if (cost_type != COST_SINGLEOBJ) {
/* use quan rather than get_pricing_units -- glob weight
should already be factored into bp->price */
amt *= unp_obj->quan;
}
}
if (cost_type == COST_CONTENTS && Has_contents(unp_obj))
amt = contained_cost(unp_obj, shkp, amt, FALSE, TRUE);
if (bp || (!unp_obj->unpaid && amt))
break;