fix #H7103 - shop pricing

Player came across a stack of 2 gray stones in a shop and kicked one.
That one ended up with a different (in his case, lower) price once it
was separate.  This behavior only applies to non-glass gems which add
a price variation derived from internal ID (obj->o_id) number.  Make
splitting stacks always yield the same price per item in the new stack
as was being charged in the old stack by choosing a similar o_id.  Do
it for all splits (that can vary price by ID, so just non-glass gems),
not just ones performed inside shops.

He picked up the lower priced one and dropped it back on the original
higher priced one; the combined stack took on the lower price.  That
will no longer happen if they come from splitting a stack, but this
fix doesn't address merging with different prices when they start out
as separate stacks.  (Unpaid items won't merge in inventory if prices
are different, but shop-owned items will merge on floor.)
This commit is contained in:
PatR
2018-12-27 14:12:48 -08:00
parent f8b4ad3fdc
commit a6b4322034
4 changed files with 47 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 shk.c $NHDT-Date: 1545786461 2018/12/26 01:07:41 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.147 $ */
/* NetHack 3.6 shk.c $NHDT-Date: 1545948761 2018/12/27 22:12:41 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.148 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2012. */
/* NetHack may be freely redistributed. See license for details. */
@@ -1984,6 +1984,24 @@ register struct obj *obj;
return cost;
}
/* decide whether to apply a surcharge (or hypothetically, a discount) to obj
if it had ID number 'oid'; returns 1: increase, 0: normal, -1: decrease */
int
oid_price_adjustment(obj, oid)
struct obj *obj;
unsigned oid;
{
int res = 0, otyp = obj->otyp;
/* currently only used for non-glass gems */
if (obj->oclass == GEM_CLASS && otyp != ROCK
&& !(obj->dknown && objects[otyp].oc_name_known)
&& objects[otyp].oc_material != GLASS) {
res = ((oid % 4) == 0); /* id%4 ==0 -> +1, ==1..3 -> 0 */
}
return res;
}
/* calculate the value that the shk will charge for [one of] an object */
STATIC_OVL long
get_cost(obj, shkp)
@@ -2043,7 +2061,7 @@ register struct monst *shkp; /* if angry, impose a surcharge */
break;
}
tmp = (long) objects[i].oc_cost;
} else if (!(obj->o_id % 4)) {
} else if (oid_price_adjustment(obj, obj->o_id) > 0) {
/* unid'd, arbitrarily impose surcharge: tmp *= 4/3 */
multiplier *= 4L;
divisor *= 3L;