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

Function set_cost

src/shk.c:3147–3193  ·  view source on GitHub ↗

calculate how much the shk will pay when buying [all of] an object */

Source from the content-addressed store, hash-verified

3145
3146/* calculate how much the shk will pay when buying [all of] an object */
3147staticfn long
3148set_cost(struct obj *obj, struct monst *shkp)
3149{
3150 long tmp, unit_price = getprice(obj, TRUE), multiplier = 1L, divisor = 1L;
3151
3152 tmp = get_pricing_units(obj) * unit_price;
3153
3154 if (uarmh && uarmh->otyp == DUNCE_CAP)
3155 divisor *= 3L;
3156 else if ((Role_if(PM_TOURIST) && u.ulevel < (MAXULEV / 2))
3157 || (uarmu && !uarm && !uarmc)) /* touristy shirt visible */
3158 divisor *= 3L;
3159 else
3160 divisor *= 2L;
3161
3162 /* shopkeeper may notice if the player isn't very knowledgeable -
3163 especially when gem prices are concerned */
3164 if (!obj->dknown || !objects[obj->otyp].oc_name_known) {
3165 if (obj->oclass == GEM_CLASS) {
3166 /* different shop keepers give different prices */
3167 if (objects[obj->otyp].oc_material == GEMSTONE
3168 || objects[obj->otyp].oc_material == GLASS) {
3169 tmp = ((obj->otyp - FIRST_REAL_GEM) % (6 - shkp->m_id % 3));
3170 tmp = (tmp + 3) * obj->quan;
3171 divisor = 1L;
3172 }
3173 } else if (tmp > 1L && !(shkp->m_id % 4))
3174 multiplier *= 3L, divisor *= 4L;
3175 }
3176
3177 if (tmp >= 1L) {
3178 /* [see get_cost()] */
3179 tmp *= multiplier;
3180 if (divisor > 1L) {
3181 tmp *= 10L;
3182 tmp /= divisor;
3183 tmp += 5L;
3184 tmp /= 10L;
3185 }
3186 /* avoid adjusting nonzero to zero */
3187 if (tmp < 1L)
3188 tmp = 1L;
3189 }
3190
3191 /* (no adjustment for angry shk here) */
3192 return tmp;
3193}
3194
3195/* unlike alter_cost() which operates on a specific item, identifying or
3196 forgetting a gem causes all unpaid gems of its type to change value */

Callers 3

contained_costFunction · 0.85
sellobjFunction · 0.85
globby_bill_fixupFunction · 0.85

Calls 2

getpriceFunction · 0.85
get_pricing_unitsFunction · 0.85

Tested by

no test coverage detected