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

Function cost_per_charge

src/shk.c:5626–5678  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5624}
5625
5626staticfn long
5627cost_per_charge(
5628 struct monst *shkp,
5629 struct obj *otmp,
5630 boolean altusage) /* some items have "alternate" use with different cost */
5631{
5632 long tmp = 0L;
5633
5634 if (!shkp || !inhishop(shkp))
5635 return 0L; /* insurance */
5636 tmp = get_cost(otmp, shkp);
5637
5638 /* The idea is to make the exhaustive use of an unpaid item
5639 * more expensive than buying it outright.
5640 */
5641 if (otmp->otyp == MAGIC_LAMP) { /* 1 */
5642 /* normal use (ie, as light source) of a magic lamp never
5643 degrades its value, but not charging anything would make
5644 identification too easy; charge an amount comparable to
5645 what is charged for an ordinary lamp (don't bother with
5646 angry shk surcharge) */
5647 if (!altusage)
5648 tmp = (long) objects[OIL_LAMP].oc_cost;
5649 else
5650 tmp += tmp / 3L; /* djinni is being released */
5651 } else if (otmp->otyp == MAGIC_MARKER) { /* 70 - 100 */
5652 /* No way to determine in advance how many charges will be
5653 * wasted. So, arbitrarily, one half of the price per use.
5654 */
5655 tmp /= 2L;
5656 } else if (otmp->otyp == BAG_OF_TRICKS /* 1 - 20 */
5657 || otmp->otyp == HORN_OF_PLENTY) {
5658 /* altusage: emptying of all the contents at once */
5659 if (!altusage)
5660 tmp /= 5L;
5661 } else if (otmp->otyp == CRYSTAL_BALL /* 1 - 5 */
5662 || otmp->otyp == OIL_LAMP /* 1 - 10 */
5663 || otmp->otyp == BRASS_LANTERN
5664 || (otmp->otyp >= MAGIC_FLUTE
5665 && otmp->otyp <= DRUM_OF_EARTHQUAKE) /* 5 - 9 */
5666 || otmp->oclass == WAND_CLASS) { /* 3 - 11 */
5667 if (otmp->spe > 1)
5668 tmp /= 4L;
5669 } else if (otmp->oclass == SPBOOK_CLASS) {
5670 tmp -= tmp / 5L;
5671 } else if (otmp->otyp == CAN_OF_GREASE || otmp->otyp == TINNING_KIT
5672 || otmp->otyp == EXPENSIVE_CAMERA) {
5673 tmp /= 10L;
5674 } else if (otmp->otyp == POT_OIL) {
5675 tmp /= 5L;
5676 }
5677 return tmp;
5678}
5679
5680DISABLE_WARNING_FORMAT_NONLITERAL
5681

Callers 1

check_unpaid_usageFunction · 0.85

Calls 2

inhishopFunction · 0.85
get_costFunction · 0.85

Tested by

no test coverage detected