Advertisement
Guest User

NetHack self-improving Banes patch

a guest
Oct 15th, 2023
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.61 KB | None | 0 0
  1. diff --git a/include/extern.h b/include/extern.h
  2. index e8285c0..4e2af9a 100644
  3. --- a/include/extern.h
  4. +++ b/include/extern.h
  5. @@ -98,6 +98,7 @@ E void FDECL(retouch_equipment, (int));
  6.  E void NDECL(mkot_trap_warn);
  7.  E boolean FDECL(is_magic_key, (struct monst *, struct obj *));
  8.  E struct obj *FDECL(has_magic_key, (struct monst *));
  9. +E void FDECL(empower_artifact, (struct obj *, struct monst *, BOOLEAN_P));
  10.  
  11.  /* ### attrib.c ### */
  12.  
  13. diff --git a/src/artifact.c b/src/artifact.c
  14. index 03573fe..045d727 100644
  15. --- a/src/artifact.c
  16. +++ b/src/artifact.c
  17. @@ -2202,4 +2202,75 @@ struct monst *mon; /* if null, hero assumed */
  18.      return (struct obj *) 0;
  19.  }
  20.  
  21. +/* Let some artifacts grow in power upon slaying a hated foe. */
  22. +void
  23. +empower_artifact(weapon, victim, silent)
  24. +struct obj *weapon;
  25. +struct monst *victim;
  26. +boolean silent;
  27. +{
  28. +    int chance = 10, tries = 1;
  29. +    const struct artifact *artifact = get_artifact(weapon);
  30. +    if (!artifact || weapon->oclass != WEAPON_CLASS
  31. +        || !bane_applies(artifact, victim))
  32. +        return;
  33. +    if (artifact->spfx & SPFX_DFLAG2) {
  34. +        /* some artifacts have way too common victims -- balance */
  35. +        switch (artifact->mtype) {
  36. +            case M2_ELF:
  37. +                /* somewhat common, moderate levels, mediocre artifact */
  38. +                chance = 25;
  39. +                break;
  40. +            case M2_ORC:
  41. +                /* very common, weak, both artifacts are mundane */
  42. +                chance = 30;
  43. +                break;
  44. +            case M2_DEMON:
  45. +                /* common in hell, can be strong, but artifact is
  46. +                 * hardly better than an ordinary silver saber */
  47. +                chance = 40;
  48. +                break;
  49. +            case M2_UNDEAD:
  50. +                /* very common, can be strong, artifact is actually useful */
  51. +                chance = 60;
  52. +                break;
  53. +            default:
  54. +                /* other banes have rare enough victims */
  55. +                break;
  56. +        }
  57. +    } else if (artifact->spfx & SPFX_DALIGN) {
  58. +        /* Sceptre of Might: really stretching it,
  59. +         * but let's throw a bone to illiterate cavepeople */
  60. +        chance = 1000; /* victims incredibly common, so make it rare */
  61. +    }
  62. +    if (victim->mrevived || victim->mcloned) {
  63. +        /* penalize farming dragons/giants/etc. with turn undead */
  64. +        int died = mvitals[monsndx(victim->data)].died;
  65. +        int counter, step;
  66. +        /* almost the same formula as for experience */
  67. +        for (counter = 1, step = 0; step < died; counter++) {
  68. +            chance += chance;
  69. +            died -= step;
  70. +            if (counter & 1)
  71. +                step += 20;
  72. +        }
  73. +    } else if (victim->data->geno & G_UNIQ)
  74. +        tries += rnd(3); /* up to +4 at once, but +2 more likely */
  75. +    while (tries--) {
  76. +        int plus = weapon->spe;
  77. +        if (plus == 127)
  78. +            break; /* not very likely, but let's not ruin anyone's game */
  79. +        if (rn2(victim->m_lev + chance) < chance) /* level : chance odds */
  80. +            continue;
  81. +        /* penalize "unsafe" enchantments, with a discount for +6 -> +7 */
  82. +        if (plus == 6 && rn2(2) || plus > 6 && rn2(5) || plus > 8 && rn2(plus))
  83. +            continue;
  84. +        if (!silent) {
  85. +            pline("%s looks more powerful!", Yname2(weapon));
  86. +            silent = TRUE;
  87. +        }
  88. +        weapon->spe++;
  89. +    }
  90. +}
  91. +
  92.  /*artifact.c*/
  93. diff --git a/src/mhitm.c b/src/mhitm.c
  94. index 5ebbd84..6ae64f8 100644
  95. --- a/src/mhitm.c
  96. +++ b/src/mhitm.c
  97. @@ -543,6 +543,7 @@ struct attack *mattk;
  98.              silverhit = (weaponhit && otmp
  99.                           && objects[otmp->otyp].oc_material == SILVER),
  100.              showit = FALSE;
  101. +    int result;
  102.  
  103.      /* unhiding or unmimicking happens even if hero can't see it
  104.         because the formerly concealed monster is now in action */
  105. @@ -637,7 +638,10 @@ struct attack *mattk;
  106.      } else
  107.          noises(magr, mattk);
  108.  
  109. -    return mdamagem(magr, mdef, mattk);
  110. +    result = mdamagem(magr, mdef, mattk);
  111. +    if (weaponhit && result & MM_DEF_DIED)
  112. +        empower_artifact(otmp, mdef, !vis);
  113. +    return result;
  114.  }
  115.  
  116.  /* Returns the same values as mdamagem(). */
  117. diff --git a/src/uhitm.c b/src/uhitm.c
  118. index 2eedb18..7b72776 100644
  119. --- a/src/uhitm.c
  120. +++ b/src/uhitm.c
  121. @@ -1327,6 +1327,8 @@ int dieroll;
  122.                  pline("%s appears confused.", Monnam(mon));
  123.          }
  124.      }
  125. +    if (destroyed)
  126. +        empower_artifact(obj, mon, FALSE);
  127.      if (unpoisonmsg)
  128.          Your("%s %s no longer poisoned.", saved_oname,
  129.               vtense(saved_oname, "are"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement