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

Function recharge

src/read.c:728–1008  ·  view source on GitHub ↗

recharge an object; curse_bless is -1 if the recharging implement was cursed, +1 if blessed, 0 otherwise. */

Source from the content-addressed store, hash-verified

726/* recharge an object; curse_bless is -1 if the recharging implement
727 was cursed, +1 if blessed, 0 otherwise. */
728void
729recharge(struct obj *obj, int curse_bless)
730{
731 int n;
732 boolean is_cursed, is_blessed;
733
734 is_cursed = curse_bless < 0;
735 is_blessed = curse_bless > 0;
736
737 if (obj->oclass == WAND_CLASS) {
738 int lim = (obj->otyp == WAN_WISHING)
739 ? 1
740 : (objects[obj->otyp].oc_dir != NODIR) ? 8 : 15;
741
742 /* undo any prior cancellation, even when is_cursed */
743 if (obj->spe == -1)
744 obj->spe = 0;
745
746 /*
747 * Recharging might cause wands to explode.
748 * v = number of previous recharges
749 * v = percentage chance to explode on this attempt
750 * v = cumulative odds for exploding
751 * 0 : 0 0
752 * 1 : 0.29 0.29
753 * 2 : 2.33 2.62
754 * 3 : 7.87 10.28
755 * 4 : 18.66 27.02
756 * 5 : 36.44 53.62
757 * 6 : 62.97 82.83
758 * 7 : 100 100
759 */
760 n = (int) obj->recharged;
761 if (n > 0 && (obj->otyp == WAN_WISHING
762 || (n * n * n > rn2(7 * 7 * 7)))) { /* recharge_limit */
763 wand_explode(obj, rnd(lim));
764 return;
765 }
766 /* didn't explode, so increment the recharge count */
767 obj->recharged = (unsigned) (n + 1);
768
769 /* now handle the actual recharging */
770 if (is_cursed) {
771 stripspe(obj);
772 } else {
773 n = (lim == 1) ? 1 : rn1(5, lim + 1 - 5);
774 if (!is_blessed)
775 n = rnd(n);
776
777 if (obj->spe < n)
778 obj->spe = n;
779 else
780 obj->spe++;
781 if (obj->otyp == WAN_WISHING && obj->spe > 3) {
782 /* wands can't give more than three wishes; this code is
783 currently unreachable but left in case the rules for
784 wands of wishing change in future */
785 wand_explode(obj, 1);

Callers 3

invoke_charge_objFunction · 0.85
maybe_destroy_itemFunction · 0.85
seffect_chargingFunction · 0.85

Calls 15

rn2Function · 0.85
wand_explodeFunction · 0.85
rndFunction · 0.85
stripspeFunction · 0.85
p_glow3Function · 0.85
p_glow2Function · 0.85
p_glow1Function · 0.85
alter_costFunction · 0.85
Yobjnam2Function · 0.85
otenseFunction · 0.85
Ring_goneFunction · 0.85
useupFunction · 0.85

Tested by

no test coverage detected