]> granicus.if.org Git - nethack/commitdiff
warning fix
authorPatR <rankin@nethack.org>
Tue, 29 Jan 2019 23:00:07 +0000 (15:00 -0800)
committerPatR <rankin@nethack.org>
Tue, 29 Jan 2019 23:00:07 +0000 (15:00 -0800)
The new code provoked several warnings; this fixes one of them.
Moving the declaration of 'rolecount' would have been sufficient,
but I've gone another way.

include/extern.h
src/pray.c
src/role.c

index f67d09c8597305a5b26eee9d2ad6b99e0eda9a8b..6b5da17585fe04cd41d3b7d7a4b22b586ddf30ba 100644 (file)
@@ -2122,7 +2122,7 @@ E boolean FDECL(validrole, (int));
 E boolean FDECL(validrace, (int, int));
 E boolean FDECL(validgend, (int, int, int));
 E boolean FDECL(validalign, (int, int, int));
-E int NDECL(randrole);
+E int FDECL(randrole, (BOOLEAN_P));
 E int FDECL(randrace, (int));
 E int FDECL(randgend, (int, int));
 E int FDECL(randalign, (int, int));
index ff9532fbd49e432a9bd7dc185cfac1a6a03146e2..29cf878a4b092a95a38f31a14ba13e3c0240c0a8 100644 (file)
@@ -2095,15 +2095,13 @@ aligntyp alignment;
     if (!Hallucination)
         return align_gname(alignment);
 
-    /* Count the roles, so that we can pick one at random. */
-    int rolecount = 0;
-    while (roles[rolecount].filecode)
-        rolecount++;
-
-    /* The priest may not have initialized god names. If this is the
-       case, and we roll priest, we need to try again. */
+    /* Some roles (Priest) don't have a pantheon unless we're playing as
+       that role, so keep trying until we get a role which does have one.
+       [If playing a Priest, the current pantheon will be twice as likely
+       to get picked as any of the others.  That's not significant enough
+       to bother dealing with.] */
     do
-        which = rn2_on_display_rng(rolecount);
+        which = randrole(TRUE);
     while (!roles[which].lgod);
 
     switch (rn2_on_display_rng(9)) {
index 2a2acce53aa5078390bfe64f3cd099cb2cf3dc15..f263609a18a22f796649a14ffc2d0c49e3e90063 100644 (file)
@@ -787,9 +787,16 @@ int rolenum;
 }
 
 int
-randrole()
+randrole(for_display)
+boolean for_display;
 {
-    return rn2(SIZE(roles) - 1);
+    int res = SIZE(roles) - 1;
+
+    if (for_display)
+        res = rn2_on_display_rng(res);
+    else
+        res = rn2(res);
+    return res;
 }
 
 STATIC_OVL int
@@ -805,7 +812,7 @@ randrole_filtered()
             && ok_gend(i, ROLE_NONE, ROLE_RANDOM, ROLE_NONE)
             && ok_align(i, ROLE_NONE, ROLE_NONE, ROLE_RANDOM))
             set[n++] = i;
-    return n ? set[rn2(n)] : randrole();
+    return n ? set[rn2(n)] : randrole(FALSE);
 }
 
 int
@@ -2088,7 +2095,7 @@ role_init()
     if (flags.pantheon == -1) {             /* new game */
         flags.pantheon = flags.initrole;    /* use own gods */
         while (!roles[flags.pantheon].lgod) /* unless they're missing */
-            flags.pantheon = randrole();
+            flags.pantheon = randrole(FALSE);
     }
     if (!urole.lgod) {
         urole.lgod = roles[flags.pantheon].lgod;