home · contact · privacy
TCE: Refactor, and refine, dying.
[plomrogue] / plugins / server / TheCrawlingEater.py
index d9b827bc3b28965879878b89300e6e397fef94d5..3bafef91fd3739618f94e60fc9dabf8aa0d1a599 100644 (file)
@@ -43,7 +43,7 @@ def actor_pee(t):
         return
     if t == world_db["Things"][0]:
         log("You LOSE fluid.")
-    if not world_db["catch_air"](t):
+    if not world_db["test_air"](t):
         return
     t["T_BLADDER"] -= 1
     world_db["wetmap"][t["pos"]] += 1
@@ -62,7 +62,7 @@ def actor_drop(t):
         return
     if t == world_db["Things"][0]:
         log("You DROP waste.")
-    if not world_db["catch_air"](t):
+    if not world_db["test_air"](t):
         return
     world_db["MAP"][t["pos"]] += 1
     t["T_BOWEL"] -= 1
@@ -129,14 +129,15 @@ def actor_move(t):
         t["pos"] = move_result[1] * world_db["MAP_LENGTH"] + move_result[2]
         build_fov_map(t)
     else:
-        if t["T_BOWEL"] >= 32 or chr(world_db["MAP"][pos]) == "5":
+        height = world_db["MAP"][pos] - ord("0")
+        if t["T_BOWEL"] >= 32 or height == 5:
             return
         eaten = False
-        if chr(world_db["MAP"][pos]) == "3" and 0 == int(rand.next() % 2):
-            t["T_BOWEL"] += 3
+        if height == 3 and 0 == int(rand.next() % 2):
+            t["T_BOWEL"] += height
             eaten = True
-        elif chr(world_db["MAP"][pos]) == "4" and 0 == int(rand.next() % 5):
-            t["T_BOWEL"] += 4
+        elif height == 4 and 0 == int(rand.next() % 5):
+            t["T_BOWEL"] += height
             eaten = True
         log("You EAT.")
         if eaten:
@@ -145,17 +146,29 @@ def actor_move(t):
                 t["T_BOWEL"] = 32
 
 
+def test_hole(t):
+    if world_db["MAP"][t["pos"]] == ord("-"):
+        world_db["die"](t, "You FALL in a hole, and die.")
+        return False
+    return True
+world_db["test_hole"] = test_hole
 
-def catch_air(t):
+
+def test_air(t):
     if (world_db["wetmap"][t["pos"]] - ord("0")) \
-            + (world_db["MAP"][t["pos"]] - ord("0")) > 4:
-        t["T_LIFEPOINTS"] = 0
-        if t == world_db["Things"][0]:
-            t["fovmap"] = bytearray(b' ' * (world_db["MAP_LENGTH"] ** 2))
-            log("You SUFFOCATE.")
+            + (world_db["MAP"][t["pos"]] - ord("0")) > 5:
+        world_db["die"](t, "You SUFFOCATE")
         return False
     return True
-world_db["catch_air"] = catch_air
+world_db["test_air"] = test_air
+
+
+def die(t, message):
+    t["T_LIFEPOINTS"] = 0
+    if t == world_db["Things"][0]:
+        t["fovmap"] = bytearray(b' ' * (world_db["MAP_LENGTH"] ** 2))
+        log(message)
+world_db["die"] = die
 
 
 def make_map():
@@ -180,7 +193,7 @@ def make_map():
                 and ((not single_allowed) or is_neighbor((y, x), "0")):
             world_db["MAP"][pos] = ord("0")
             i_ground += 1
-    n_water = int((length ** 2) / 64)
+    n_water = int((length ** 2) / 16)
     i_water = 0
     while (i_water <= n_water):
         y, x, pos = new_pos()
@@ -214,42 +227,50 @@ def turn_over():
         for tid in [tid for tid in world_db["Things"]]:
             if not tid in world_db["Things"]:
                 continue
-            Thing = world_db["Things"][tid]
-            if Thing["T_LIFEPOINTS"]:
-                if not Thing["T_COMMAND"]:
-                    update_map_memory(Thing)
+            t = world_db["Things"][tid]
+            if t["T_LIFEPOINTS"]:
+                if not (world_db["test_air"](t) and world_db["test_hole"](t)):
+                    continue
+                if not t["T_COMMAND"]:
+                    update_map_memory(t)
                     if 0 == tid:
                         return
-                    ai(Thing)
-                if Thing["T_LIFEPOINTS"]:
-                    Thing["T_PROGRESS"] += 1
+                    ai(t)
+                if t["T_LIFEPOINTS"]:
+                    t["T_PROGRESS"] += 1
                     taid = [a for a in world_db["ThingActions"]
-                              if a == Thing["T_COMMAND"]][0]
+                              if a == t["T_COMMAND"]][0]
                     ThingAction = world_db["ThingActions"][taid]
-                    effort = world_db["calc_effort"](ThingAction, Thing)
-                    if Thing["T_PROGRESS"] >= effort:
+                    effort = world_db["calc_effort"](ThingAction, t)
+                    if t["T_PROGRESS"] >= effort:
                         action = action_db["actor_" + ThingAction["TA_NAME"]]
-                        action(Thing)
-                        Thing["T_COMMAND"] = 0
-                        Thing["T_PROGRESS"] = 0
-                    if Thing["T_BOWEL"] > 16:
-                        if 0 == (rand.next() % (33 - Thing["T_BOWEL"])):
-                            action_db["actor_drop"](Thing)
-                    if Thing["T_BLADDER"] > 16:
-                        if 0 == (rand.next() % (33 - Thing["T_BLADDER"])):
-                            action_db["actor_pee"](Thing)
+                        action(t)
+                        t["T_COMMAND"] = 0
+                        t["T_PROGRESS"] = 0
+                    if t["T_BOWEL"] > 16:
+                        if 0 == (rand.next() % (33 - t["T_BOWEL"])):
+                            action_db["actor_drop"](t)
+                    if t["T_BLADDER"] > 16:
+                        if 0 == (rand.next() % (33 - t["T_BLADDER"])):
+                            action_db["actor_pee"](t)
         water = 0
         positions_to_wet = []
-        for i in range(world_db["MAP_LENGTH"] ** 2):
-            if world_db["MAP"][i] == ord("0") \
-                    and world_db["wetmap"][i] < ord("5"):
-                positions_to_wet += [i]
+        for pos in range(world_db["MAP_LENGTH"] ** 2):
+            if world_db["MAP"][pos] == ord("0") \
+                    and world_db["wetmap"][pos] < ord("5"):
+                positions_to_wet += [pos]
         i_positions_to_wet = len(positions_to_wet)
         for pos in range(world_db["MAP_LENGTH"] ** 2):
-            if 0 == rand.next() % 5 \
-                    and ((world_db["wetmap"][pos] > ord("0")
-                          and not world_db["MAP"][pos] == ord("0"))
-                         or world_db["wetmap"][pos] > ord("1")):
+            wetness = world_db["wetmap"][pos] - ord("0")
+            height = world_db["MAP"][pos] - ord("0")
+            if height == 0 and wetness > 0 \
+                    and 0 == rand.next() % ((2 ** 12) / (2 ** wetness)):
+                world_db["MAP"][pos] = ord("-")
+                if pos in positions_to_wet:
+                    positions_to_wet.remove(pos)
+                    i_positions_to_wet -= 1
+            if ((wetness > 0 and height != 0) or wetness > 1) \
+                and 0 == rand.next() % 5:
                 world_db["wetmap"][pos] -= 1
                 water += 1
                 i_positions_to_wet -= 1
@@ -339,7 +360,7 @@ io_db["worldstate_write_order"] += [["T_BLADDER", "player_int"]]
 io_db["worldstate_write_order"] += [[write_wetmap, "func"]]
 import server.config.world_data
 server.config.world_data.symbols_hide = "345"
-server.config.world_data.symbols_passable = "012"
+server.config.world_data.symbols_passable = "012-"
 server.config.world_data.thing_defaults["T_BOWEL"] = 0
 server.config.world_data.thing_defaults["T_BLADDER"] = 0
 world_db["wetmap"] = bytearray(b"0" * world_db["MAP_LENGTH"] ** 2)