home · contact · privacy
TCE: Refine water cycle.
[plomrogue] / plugins / server / TheCrawlingEater.py
index 7a634165d8e83249426a9a0a3e0f708e2e88e5cb..6492d135531e79f6ee4d2a96cca19bfcb4be6229 100644 (file)
@@ -42,14 +42,13 @@ def actor_pee(t):
         log("You LOSE fluid.")
     t["T_BLADDER"] -= 1
     terrain = world_db["MAP"][t["pos"]]
-    world_db["wetmap"][t["pos"]] += 1
-    if terrain == ord("_"):
-        world_db["MAP"][t["pos"]] = ord("~")
-    elif world_db["wetmap"][t["pos"]] > 51:
+    if world_db["wetmap"][t["pos"]] == 51:
         t["T_LIFEPOINTS"] = 0
         if t == world_db["Things"][0]:
             t["fovmap"] = bytearray(b' ' * (world_db["MAP_LENGTH"] ** 2))
             log("You DROWN.")
+    else:
+        world_db["wet_ground"](t["pos"])
 
 
 def play_drop():
@@ -147,17 +146,21 @@ def actor_move(t):
     else:
         if t["T_BOWEL"] >= 32 or chr(world_db["MAP"][pos]) == "X":
             return
-        elif chr(world_db["MAP"][pos]) == "%" and 0 == int(rand.next() % 2):
+        eaten = False
+        if chr(world_db["MAP"][pos]) == "%" and 0 == int(rand.next() % 2):
             t["T_BOWEL"] += 3
+            eaten = True
         elif chr(world_db["MAP"][pos]) in "#BEH" and 0 == int(rand.next() % 5):
             t["T_BOWEL"] += 4
+            eaten = True
         log("You EAT.")
-        if world_db["wetmap"][pos] == 48:
-            world_db["MAP"][pos] = ord("_")
-        else:
-            world_db["MAP"][pos] = ord("~")
-        if t["T_BOWEL"] > 32:
-            t["T_BOWEL"] = 32
+        if eaten:
+            if world_db["wetmap"][pos] == 48:
+                world_db["MAP"][pos] = ord("_")
+            else:
+                world_db["MAP"][pos] = ord("~")
+            if t["T_BOWEL"] > 32:
+                t["T_BOWEL"] = 32
 
 
 def make_map():
@@ -245,6 +248,29 @@ def turn_over():
                     if Thing["T_BLADDER"] > 16:
                         if 0 == (rand.next() % (33 - Thing["T_BLADDER"])):
                             action_db["actor_pee"](Thing)
+        water = 0
+        positions_to_wet = []
+        for i in range(world_db["MAP_LENGTH"] ** 2):
+            if chr(world_db["MAP"][i]) in "_~" and world_db["wetmap"][i] < 51:
+                positions_to_wet += [i]
+        i_positions_to_wet = len(positions_to_wet)
+        for pos in range(world_db["MAP_LENGTH"] ** 2):
+            if world_db["MAP"][pos] != ord("~") \
+               and  world_db["wetmap"][pos] > 48 \
+               or world_db["wetmap"][pos] > 49and 0 == (rand.next() % 5):
+                world_db["unwet_ground"](pos)
+                water += 1
+                i_positions_to_wet -= 1
+            if i_positions_to_wet == 0:
+                break
+        if water > 0:
+            while water > 0:
+                select = rand.next() % len(positions_to_wet)
+                pos = positions_to_wet[select]
+                world_db["wet_ground"](pos)
+                positions_to_wet.remove(pos)
+                water -= 1
+                log("New water at " + str(pos))
         world_db["TURN"] += 1
         io_db["worldstate_updateable"] = True
         try_worldstate_update()
@@ -306,6 +332,19 @@ def wetmapset(str_int, mapline):
         if not world_db["wetmap"]:
             world_db["wetmap"] = m
 
+def unwet_ground(pos):
+    world_db["wetmap"][pos] -= 1
+    if world_db["MAP"][pos] == ord("~") and world_db["wetmap"][pos] == 48:
+        world_db["MAP"][pos] = ord("_")
+world_db["unwet_ground"] = unwet_ground
+
+
+def wet_ground(pos):
+    if world_db["MAP"][pos] == ord("_"):
+        world_db["MAP"][pos] = ord("~")
+    world_db["wetmap"][pos] += 1
+world_db["wet_ground"] = wet_ground
+
 
 def write_wetmap():
     from server.worldstate_write_helpers import write_map