Skip to content

Commit

Permalink
Identify an tool the hero is enchanting when it's unambiguous
Browse files Browse the repository at this point in the history
Noticed when touching the harp/flute constants in this piece of code
that a tool once successfully enchanted does not auto-identify. In
certain cases (horns and bags), this is fine, because the resulting item
is ambiguous, even though it's unambiguous that it was successfully
enchanted into something. But for the other instruments, it's good
enough quality-of-life to automatically identify it when there's no
other possible candidate.

Another related change: when an instrument is enchanted, its known field
is reset to 0 to avoid showing its charges; it needs to be re-identified
in order to see them. This is driven by the ones that enchant into an
ambiguous object type; it's weird to have a fully identified tooled
horn, enchant it, and then not know the new item's object type but know
that it is (0:1) for charges. Also, a sack turning into a bag of tricks
would immediately be obvious since the other bags aren't chargeable.
  • Loading branch information
copperwater committed Feb 13, 2025
1 parent d6e7224 commit c4a2959
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/xnh-changelog-9.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ changes:
- Falling rocks from traps or from zapping at the ceiling can crack non-tempered
glass helmets; this is considered a light impact so it only happens 10% of the
time.
- Enchanting a mundane harp, flute, whistle, or drum will identify the magical
counterpart it turns into. (Not so for tooled horns or sacks, which could turn
into different items and are ambiguous).

### Interface changes

Expand Down
14 changes: 13 additions & 1 deletion src/wield.c
Original file line number Diff line number Diff line change
Expand Up @@ -1008,41 +1008,53 @@ chwepon(struct obj *otmp, int amount)
}
else if (uwep->oclass == TOOL_CLASS && !is_weptool(uwep) && !otmp->cursed) {
/* enchant a non-magical tool into a magical counterpart; not all tools
* have such a counterpart, however */
* have such a counterpart, however.
* known = 0 is usually set to hide the new charges and avoid e.g. fully
* identified sack turning into a "bag" of unknown type but which has
* charges and is therefore definitely a bag of tricks. */
short old_otyp = uwep->otyp;
char *old_yname = Yname2(uwep);
if (uwep->otyp == MUNDANE_HARP) {
/* may not get any charges; blessed guarantees at least 1 charge */
uwep->otyp = MAGIC_HARP;
uwep->known = 0;
uwep->recharged = 0;
uwep->spe = rn2(2) + (otmp->blessed ? 1 : 0);
makeknown(MAGIC_HARP);
}
else if (uwep->otyp == TOOLED_HORN && rn2(3)) {
/* can't become a horn of plenty; it only turns into "instrumental"
* type horns */
uwep->otyp = rnd_class(FROST_HORN, FIRE_HORN);
uwep->known = 0;
uwep->recharged = 0;
uwep->spe = rn2(2) + (otmp->blessed ? 1 : 0);
}
else if (uwep->otyp == MUNDANE_FLUTE) {
uwep->otyp = MAGIC_FLUTE;
uwep->known = 0;
uwep->recharged = 0;
uwep->spe = rn2(1) + (otmp->blessed ? 1 : 0);
makeknown(MAGIC_FLUTE);
}
else if (uwep->otyp == PEA_WHISTLE && !rn2(3)) {
uwep->otyp = MAGIC_WHISTLE;
makeknown(MAGIC_WHISTLE);
}
else if (uwep->otyp == SACK && !rn2(6)) {
uwep->otyp = rnd_class(BAG_OF_HOLDING, BAG_OF_TRICKS);
if (uwep->otyp == BAG_OF_TRICKS) {
uwep->known = 0;
uwep->recharged = 0;
uwep->spe = rn2(2) + (otmp->blessed ? 1 : 0);
}
}
else if (uwep->otyp == LEATHER_DRUM) {
uwep->otyp = DRUM_OF_EARTHQUAKE;
uwep->known = 0;
uwep->recharged = 0;
uwep->spe = rn2(2) + (otmp->blessed ? 1 : 0);
makeknown(DRUM_OF_EARTHQUAKE);
}

if (uwep->otyp != old_otyp) {
Expand Down

0 comments on commit c4a2959

Please sign in to comment.