]> granicus.if.org Git - nethack/commitdiff
Start with a level 1 spell and enough power
authorPasi Kallinen <paxed@alt.org>
Tue, 22 Feb 2022 10:26:03 +0000 (12:26 +0200)
committerPasi Kallinen <paxed@alt.org>
Tue, 22 Feb 2022 10:26:06 +0000 (12:26 +0200)
Ensure the first spell - if any - given to the hero in initial
inventory is level 1 - otherwise you can end up with a situation
where the hero knows level 3 spells, but won't have enough power
to cast them.

If the hero starts out with a spell, ensure enough power (5)
to cast that level 1 spell.

doc/fixes3-7-0.txt
include/extern.h
src/spell.c
src/u_init.c

index 8449db7a14ef4d4ae11be50cf73081030b3d0666..4f540f85d7cd2a391ab3cd265484ebfcbe704c19 100644 (file)
@@ -807,6 +807,8 @@ flint and hard gems break less often when thrown
 hobbits getting a sling also get some ammo for it
 elves and rangers get alignment penalty for cutting down trees
 casting a forgotten spell uses some random amount of power
+heroes starting with a spell have at least one level one spell, and
+       have just enough power to cast it
 
 
 Fixes to 3.7.0-x Problems that Were Exposed Via git Repository
index cb3432deaf223a05935591588ba1d8c2ff356e14..c5840eb45feb29054a37f2c4aa3567080f654e77 100644 (file)
@@ -2539,6 +2539,7 @@ extern void initialspell(struct obj *);
 extern boolean known_spell(short);
 extern int spell_idx(short);
 extern boolean force_learn_spell(short);
+extern int num_spells(void);
 
 /* ### steal.c ### */
 
index 034794b9052c89b05224e5c13f402d7f471d6731..2b2a0292c4084172d64a05cdf9fc5934937d2fe7 100644 (file)
@@ -1975,4 +1975,16 @@ force_learn_spell(short otyp)
     return FALSE;
 }
 
+/* number of spells hero knows */
+int
+num_spells(void)
+{
+    int i;
+
+    for (i = 0; i < MAXSPELL; i++)
+        if (spellid(i) == NO_SPELL)
+            break;
+    return i;
+}
+
 /*spell.c*/
index 1674509042a6b290dcdb5fcaadad31c012c3b771..cc5e5086fced2adf97d430e8cc9076259a5ad97f 100644 (file)
@@ -932,6 +932,11 @@ u_init(void)
         break;
     }
 
+    /* If we have at least one spell, force starting Pw to be 5,
+       so hero can cast the level 1 spell they should have */
+    if (num_spells() && (u.uenmax < 5))
+        u.uen = u.uenmax = u.uenpeak = u.ueninc[u.ulevel] = 5;
+
     return;
 }
 
@@ -1000,6 +1005,7 @@ ini_inv(struct trobj *trop)
 {
     struct obj *obj;
     int otyp, i;
+    boolean got_sp1 = FALSE; /* got a level 1 spellbook? */
 
        while (trop->trclass) {
         otyp = (int) trop->trotyp;
@@ -1042,7 +1048,7 @@ ini_inv(struct trobj *trop)
                       low level players or unbalancing; also
                       spells in restricted skill categories */
                    || (obj->oclass == SPBOOK_CLASS
-                       && (objects[otyp].oc_level > 3
+                       && (objects[otyp].oc_level > (got_sp1 ? 3 : 1)
                            || restricted_spell_discipline(otyp)))
                    || otyp == SPE_NOVEL) {
                 dealloc_obj(obj);
@@ -1076,6 +1082,9 @@ ini_inv(struct trobj *trop)
             /* Don't have 2 of the same ring or spellbook */
             if (obj->oclass == RING_CLASS || obj->oclass == SPBOOK_CLASS)
                 g.nocreate4 = otyp;
+            /* First spellbook should be level 1 - did we get it? */
+            if (obj->oclass == SPBOOK_CLASS && objects[obj->otyp].oc_level == 1)
+                got_sp1 = TRUE;
         }
 
         if (g.urace.mnum != PM_HUMAN) {