home · contact · privacy
Improve try_healing() chance.
[plomrogue] / roguelike-server
index 09940395b36e39d222f46f17abd850016d3bc231..462a3428331d01a1f58f7f23659e0e1e371c8eab 100755 (executable)
@@ -12,6 +12,7 @@ import shlex
 import shutil
 import time
 import ctypes
+import math
 
 
 class RandomnessIO:
@@ -743,34 +744,30 @@ def thingproliferation(t, prol_map):
 
 
 def try_healing(t):
-    """Grow t's HP to a 1/32 chance if < HP max, satiation > 0, and waiting.
-
-    On success, decrease satiation score by 32.
-    """
-    if t["T_SATIATION"] > 0 \
-       and t["T_LIFEPOINTS"] < \
-        world_db["ThingTypes"][t["T_TYPE"]]["TT_LIFEPOINTS"] \
-       and 0 == (rand.next() % 31) \
-       and t["T_COMMAND"] == [id for id in world_db["ThingActions"]
-                              if world_db["ThingActions"][id]["TA_NAME"] ==
-                              "wait"][0]:
-        t["T_LIFEPOINTS"] += 1
-        t["T_SATIATION"] -= 32
-        if t == world_db["Things"][0]:
-            strong_write(io_db["file_out"], "LOG You heal.\n")
-
+    """If t's HP < max, increment them if well-nourished, maybe waiting."""
+    if t["T_LIFEPOINTS"] < \
+       world_db["ThingTypes"][t["T_TYPE"]]["TT_LIFEPOINTS"]:
+        wait_id = [id for id in world_db["ThingActions"]
+                      if world_db["ThingActions"][id]["TA_NAME"] == "wait"][0]
+        wait_divider = 8 if t["T_COMMAND"] == wait_id else 1
+        testval = int(abs(t["T_SATIATION"]) / wait_divider)
+        if (testval <= 1 or 1 == (rand.next() % testval)):
+            t["T_LIFEPOINTS"] += 1
+            if t == world_db["Things"][0]:
+                strong_write(io_db["file_out"], "LOG You heal.\n")
 
 def hunger(t):
     """Decrement t's satiation,dependent on it trigger lifepoint dec chance."""
     if t["T_SATIATION"] > -32768:
-        t["T_SATIATION"] -= 1
-    testbase = t["T_SATIATION"] if t["T_SATIATION"] >= 0 else -t["T_SATIATION"]
-    if not world_db["ThingTypes"][t["T_TYPE"]]["TT_LIFEPOINTS"]:
-        raise RuntimeError("A thing that should not hunger is hungering.")
-    stomach = int(32767 / world_db["ThingTypes"][t["T_TYPE"]]["TT_LIFEPOINTS"])
-    if int(int(testbase / stomach) / ((rand.next() % stomach) + 1)):
+        max_hp = world_db["ThingTypes"][t["T_TYPE"]]["TT_LIFEPOINTS"]
+        t["T_SATIATION"] -= int(math.sqrt(max_hp))
+    if 0 != t["T_SATIATION"] and 0 == int(rand.next() / abs(t["T_SATIATION"])):
         if t == world_db["Things"][0]:
-            strong_write(io_db["file_out"], "LOG You suffer from hunger.\n")
+            if t["T_SATIATION"] < 0:
+                strong_write(io_db["file_out"], "LOG You suffer from hunger.\n")
+            else:
+                strong_write(io_db["file_out"],
+                             "LOG You suffer from over-eating.\n")
         decrement_lifepoints(t)