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

Function rndcurse

src/sit.c:568–638  ·  view source on GitHub ↗

curse a few inventory items at random! */

Source from the content-addressed store, hash-verified

566
567/* curse a few inventory items at random! */
568void
569rndcurse(void)
570{
571 int nobj = 0;
572 int cnt, onum;
573 struct obj *otmp;
574 static const char mal_aura[] = "feel a malignant aura surround %s.";
575
576 if (u_wield_art(ART_MAGICBANE) && rn2(20)) {
577 You(mal_aura, "the magic-absorbing blade");
578 return;
579 }
580
581 if (Antimagic) {
582 shieldeff(u.ux, u.uy);
583 }
584
585 You(mal_aura, "you");
586
587 for (otmp = gi.invent; otmp; otmp = otmp->nobj) {
588 /* gold isn't subject to being cursed or blessed */
589 if (otmp->oclass == COIN_CLASS)
590 continue;
591 nobj++;
592 }
593 cnt = rnd(6 / ((!!Antimagic) + (!!Half_spell_damage) + 1));
594 if (nobj) {
595 for (; cnt > 0; cnt--) {
596 onum = rnd(nobj);
597 for (otmp = gi.invent; otmp; otmp = otmp->nobj) {
598 /* as above */
599 if (otmp->oclass == COIN_CLASS)
600 continue;
601 if (--onum == 0)
602 break; /* found the target */
603 }
604 /* the !otmp case should never happen; picking an already
605 cursed item happens--avoid "resists" message in that case */
606 if (!otmp || otmp->cursed)
607 continue; /* next target */
608
609 if (otmp->oartifact && spec_ability(otmp, SPFX_INTEL)
610 && rn2(10) < 8) {
611 pline("%s!", Tobjnam(otmp, "resist"));
612 continue;
613 }
614
615 if (otmp->blessed)
616 unbless(otmp);
617 else
618 curse(otmp);
619 }
620 update_inventory();
621 }
622
623 /* treat steed's saddle as extended part of hero's inventory */
624 if (u.usteed && !rn2(4) && (otmp = which_armor(u.usteed, W_SADDLE)) != 0
625 && !otmp->cursed) { /* skip if already cursed */

Callers 5

throne_sit_effectFunction · 0.85
mcast_spellFunction · 0.85
interveneFunction · 0.85
angrygodsFunction · 0.85
cursed_bookFunction · 0.85

Calls 13

rn2Function · 0.85
YouFunction · 0.85
shieldeffFunction · 0.85
rndFunction · 0.85
spec_abilityFunction · 0.85
TobjnamFunction · 0.85
unblessFunction · 0.85
curseFunction · 0.85
update_inventoryFunction · 0.85
which_armorFunction · 0.85
Yobjnam2Function · 0.85
hcolorFunction · 0.85

Tested by

no test coverage detected