]> granicus.if.org Git - nethack/commitdiff
Move Pw regen into separate routine
authorPasi Kallinen <paxed@alt.org>
Sat, 18 Sep 2021 17:23:20 +0000 (20:23 +0300)
committerPasi Kallinen <paxed@alt.org>
Sat, 18 Sep 2021 17:23:20 +0000 (20:23 +0300)
src/allmain.c

index 6270fada644c96ccecfee0f4f532b86469abd4d3..92f25d34b5bfbdd26682cbef11cebd2c26841841 100644 (file)
@@ -17,6 +17,7 @@ static void u_calc_moveamt(int);
 #ifdef POSITIONBAR
 static void do_positionbar(void);
 #endif
+static void regen_pw(int);
 static void regen_hp(int);
 static void interrupt_multi(const char *);
 static void debug_fields(const char *);
@@ -258,19 +259,7 @@ moveloop_core(void)
                     }
                 }
 
-                if (u.uen < u.uenmax
-                    && ((mvl_wtcap < MOD_ENCUMBER
-                         && (!(g.moves % ((MAXULEV + 8 - u.ulevel)
-                                          * (Role_if(PM_WIZARD) ? 3 : 4)
-                                          / 6)))) || Energy_regeneration)) {
-                    u.uen += rn1(
-                             (int) (ACURR(A_WIS) + ACURR(A_INT)) / 15 + 1, 1);
-                    if (u.uen > u.uenmax)
-                        u.uen = u.uenmax;
-                    g.context.botl = TRUE;
-                    if (u.uen == u.uenmax)
-                        interrupt_multi("You feel full of energy.");
-                }
+                regen_pw(mvl_wtcap);
 
                 if (!u.uinvulnerable) {
                     if (Teleportation && !rn2(85)) {
@@ -506,6 +495,25 @@ moveloop(boolean resuming)
     }
 }
 
+static void
+regen_pw(int wtcap)
+{
+    if (u.uen < u.uenmax
+        && ((wtcap < MOD_ENCUMBER
+             && (!(g.moves % ((MAXULEV + 8 - u.ulevel)
+                              * (Role_if(PM_WIZARD) ? 3 : 4)
+                              / 6)))) || Energy_regeneration)) {
+        int upper = (int) (ACURR(A_WIS) + ACURR(A_INT)) / 15 + 1;
+
+        u.uen += rn1(upper, 1);
+        if (u.uen > u.uenmax)
+            u.uen = u.uenmax;
+        g.context.botl = TRUE;
+        if (u.uen == u.uenmax)
+            interrupt_multi("You feel full of energy.");
+    }
+}
+
 #define U_CAN_REGEN() (Regeneration || (Sleepy && u.usleep))
 
 /* maybe recover some lost health (or lose some when an eel out of water) */