From 7d27dca47f3ea5846d55ea6c024f6243b042c325 Mon Sep 17 00:00:00 2001 From: copperwater Date: Sun, 14 Aug 2022 07:09:35 -0400 Subject: [PATCH] Fix a couple latent bugs with initial rings/other charged items These bugs are currently latent only because no role's starting inventory happens to satisfy the conditions under which it would show up. This commit contains the xNetHack fixes for them. Bug 1: if a role received a specific charged ring (versus a random ring), it would be possible for that ring's charge to be <= 0, since the code currently only caught this case for random rings. Move that clause outside the if (UNDEF_TYP) clause. Bug 2: non-ring oc_charged items of UNDEF_TYP that randomly rolled a starting charge/enchantment <= 0 would always be enchanted, sometimes very highly, because their enchantment was getting set to rne(3) by hitting this case, which is only intended for rings as a comment indicates. In particular, Archeologists' starting pick-axe would hit this case after moving it out of the UNDEF_TYP block, but it would also apply to any role receiving a random tool or weapon-tool at the start of the game. --- src/u_init.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/u_init.c b/src/u_init.c index 652605fde..d35254adf 100644 --- a/src/u_init.c +++ b/src/u_init.c @@ -1050,10 +1050,6 @@ ini_inv(struct trobj *trop) break; } - /* Don't start with +0 or negative rings */ - if (objects[otyp].oc_charged && obj->spe <= 0) - obj->spe = rne(3); - /* Heavily relies on the fact that 1) we create wands * before rings, 2) that we create rings before * spellbooks, and that 3) not more than 1 object of a @@ -1075,6 +1071,13 @@ ini_inv(struct trobj *trop) if (obj->oclass == RING_CLASS || obj->oclass == SPBOOK_CLASS) g.nocreate4 = otyp; } + /* Put post-creation object adjustments that don't depend on whether it + * was UNDEF_TYP or not after this. */ + + /* Don't start with +0 or negative rings */ + if (objects[otyp].oc_class == RING_CLASS && objects[otyp].oc_charged + && obj->spe <= 0) + obj->spe = rne(3); if (g.urace.mnum != PM_HUMAN) { /* substitute race-specific items; this used to be in